index 98b21712c4042a1f4a169fc1471dfb2dd19334d1..c6fee306ac2a0b02d626b75da569738457fd5b31 100644 (file)
package opsi_com;
+
+use strict;
+use warnings;
+
use Exporter;
-@ISA = qw(Exporter);
+use UNIVERSAL 'isa';
+use GOSA::GosaSupportDaemon;
+use Data::Dumper;
+use XML::Quote qw(:all);
+
+our @ISA = qw(Exporter);
+
my @events = (
"get_events",
"opsi_install_client",
"opsi_unboundHostFromLicense",
"opsi_test",
);
-@EXPORT = @events;
-use strict;
-use warnings;
-use GOSA::GosaSupportDaemon;
-use Data::Dumper;
-use XML::Quote qw(:all);
+our @EXPORT = @events;
+
BEGIN {}
use Time::HiRes qw( time );
$opsi_url= "https://".$opsi_admin.":".$opsi_password."@".$opsi_server.":4447/rpc";
$opsi_client = new JSON::RPC::Client;
+
+ # Check version dependencies
+ eval { &myXmlHashToString(); };
+ if ($@ ) {
+ die "\nThe version of the Opsi plugin you want to use requires a newer version of GosaSupportDaemon. Please update your GOsa-SI or deactivate the Opsi plugin.\n";
+ }
}
# ----------------------------------------------------------------------------
if (defined $values->{$key}){
$vals= $values->{$key};
}
- $item.= "<$key>$dsc<default>".xml_quote($value)."</default>$vals</$key>";
+ $item.= "<$key>$dsc<current>".xml_quote($value)."</current>$vals</$key>";
$item.= "</item>";
$xml_msg=~ s/<xxx><\/xxx>/$item<xxx><\/xxx>/;
}
# Fetch licensePoolId for productId
my ($res, $err) = &_getLicensePoolId('productId'=>$productId);
if ($err){
- return &_giveErrorFeedback($msg_hash, "cannot fetch licensePoolId for given productId : ".$res, $session_id);
+ my $out_hash = &create_xml_hash("answer_$header", $main::server_address, $source);
+ $out_hash->{result} = [];
+ return ( &create_xml_string($out_hash) );
}
-
- my $licensePoolId;
+ my $licensePoolId = $res; # We assume that there is only one pool for each productID!!!
# Fetch softwareLiceceUsages for licensePoolId
($res, $err) = &_getSoftwareLicenseUsages_listOfHashes('licensePoolId'=>$licensePoolId);
if ($err){
return &_giveErrorFeedback($msg_hash, "cannot fetch software licenses from license pool : ".$res, $session_id);
}
-
# Parse Opsi result
my $res_hash = &_parse_getSoftwareLicenseUsages($res);
return ( &create_xml_string($out_hash) );
}
+
+################################
+# @brief Returns a list of values for a given host. Values: priority, onceScript, licenseRequired, packageVersion, productVersion, advice, setupScript, windowsSoftwareIds, installationStatus, pxeConfigTemplate, name, creationTimestamp, alwaysScript, productId, description, properties, actionRequest, uninstallScript, action, updateScript and productClassNames
+# @param hostId Opsi hostId
+sub opsi_get_full_product_host_information {
+ my $startTime = Time::HiRes::time;
+ my ($msg, $msg_hash, $session_id) = @_;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+ my $hostId;
+
+ my ($res, $err) = &_get_full_product_host_information( hostId=>@{$msg_hash->{'hostId'}}[0]);
+ if ($err) {
+ return &_giveErrorFeedback($msg_hash, "cannot fetch full_product_host_information from Opsi server : ".$res, $session_id);
+ }
+
+ # Build return message with twisted target and source
+ my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
+ if (defined $forward_to_gosa) {
+ &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
+ }
+ &add_content2xml_hash($out_hash, "xxx", "");
+
+ # Get hostId if defined
+ if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1)) {
+ $hostId = @{$msg_hash->{'hostId'}}[0];
+ &add_content2xml_hash($out_hash, "hostId", $hostId);
+ }
+
+ # Move to XML string
+ my $xml_msg= &create_xml_string($out_hash);
+
+ # Convert result in something usable
+ my $replace= "";
+ foreach my $product ( @$res) {
+
+ # Open item
+ $replace.= "<item>";
+
+ # Add flat hash information
+ my @entries= ( "priority", "onceScript", "licenseRequired", "packageVersion", "productVersion", "advice",
+ "setupScript", "windowsSoftwareIds", "installationStatus", "pxeConfigTemplate", "name", "type",
+ "creationTimestamp", "alwaysScript", "productId", "description", "actionRequest", "uninstallScript",
+ "action", "updateScript", "productClassNames");
+ foreach my $entry (@entries) {
+ if (defined $product->{$entry}) {
+ my $value= $product->{$entry};
+
+ if(ref($value) eq 'ARRAY'){
+ my $tmp= "";
+ foreach my $element (@$value) {
+ $tmp.= "<element>$element</element>";
+ }
+ $replace.= "<$entry>$tmp</$entry>";
+ } else {
+ $replace.= "<$entry>$value</$entry>";
+ }
+ }
+ }
+
+ # Add property information
+ if (defined $product->{'properties'}) {
+ $replace.= "<properties>";
+ while ((my $key, my $value) = each(%{$product->{'properties'}})){
+ $replace.= "<$key>";
+
+ while ((my $pkey, my $pvalue) = each(%$value)){
+ if(ref($pvalue) eq 'ARRAY'){
+ my $tmp= "";
+ foreach my $element (@$pvalue) {
+ $tmp.= "<element>$element</element>";
+ }
+ $replace.= "<$pkey>$tmp</$pkey>";
+ } else {
+ $replace.= "<$pkey>$pvalue</$pkey>";
+ }
+ }
+ $replace.= "</$key>";
+ }
+ $replace.= "</properties>";
+ }
+
+ # Close item
+ $replace.= "</item>";
+ }
+
+ $xml_msg=~ s/<xxx><\/xxx>/\n$replace/;
+
+ &main::daemon_log("0 DEBUG: time to process gosa-si message '$header' : ".sprintf("%.4f", (Time::HiRes::time - $startTime))." seconds", 1034);
+ return ( $xml_msg );
+}
+
+
sub opsi_test {
my ($msg, $msg_hash, $session_id) = @_;
my $header = @{$msg_hash->{'header'}}[0];
my $source = @{$msg_hash->{'source'}}[0];
my $pram1 = @{$msg_hash->{'productId'}}[0];
-print STDERR Dumper $pram1;
# Fetch infos from Opsi server
my $callobj = {
};
my $res = $main::opsi_client->call($main::opsi_url, $callobj);
- print STDERR Dumper $res;
return ();
}
return ($res->result, 0);
}
+sub _get_full_product_host_information {
+ my %arg = ( 'hostId' => undef, @_ );
-################################
-# @brief Get all host information for a specific host.
-# @param msg - STRING - xml message with hostId tag
-# @param msg_hash - HASHREF - message information parsed into a hash
-# @param session_id - INTEGER - POE session id of the processing of this message
-# @return out_msg - STRING - feedback to GOsa in success and error case
-sub opsi_get_full_product_host_information {
- my $startTime = Time::HiRes::time;
- my ($msg, $msg_hash, $session_id) = @_;
- my $header = @{$msg_hash->{'header'}}[0];
- my $source = @{$msg_hash->{'source'}}[0];
- my $target = @{$msg_hash->{'target'}}[0];
- my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
- my $hostId;
- my $xml_msg;
+ my $res = &_callOpsi( method => 'getFullProductHostInformation_list', params => [$arg{hostId}]);
+ my ($res_error, $res_error_str) = &check_opsi_res($res);
+ if ($res_error){ return ((caller(0))[3]." : ".$res_error_str, 1); }
-# $callobj = {
-# method => 'getFullProductHostInformation_list',
-# params => [ $hostId ],
-# id => 1,
-# };
-# my $res = $main::opsi_client->call($main::opsi_url, $callobj);
-# print STDERR "===================================================================\n";
-# print STDERR Dumper $res;
-# print STDERR "===================================================================\n";
+ return ($res->result, 0);
}
1;