Code

bugfix: delete debug print out
[gosa.git] / gosa-si / server / events / opsi_com.pm
1 ## @file
2 # @details A GOsa-SI-server event module containing all functions for message handling.
3 # @brief Implementation of an event module for GOsa-SI-server. 
6 package opsi_com;
7 use Exporter;
8 @ISA = qw(Exporter);
9 my @events = (
10     "get_events",
11     "opsi_install_client",
12     "opsi_get_netboot_products",  
13     "opsi_get_local_products",
14     "opsi_get_client_hardware",
15     "opsi_get_client_software",
16     "opsi_get_product_properties",
17     "opsi_set_product_properties",
18     "opsi_list_clients",
19     "opsi_del_client",
20     "opsi_add_client",
21     "opsi_modify_client",
22     "opsi_add_product_to_client",
23     "opsi_del_product_from_client",
24    );
25 @EXPORT = @events;
27 use strict;
28 use warnings;
29 use GOSA::GosaSupportDaemon;
30 use Data::Dumper;
31 use XML::Quote qw(:all);
34 BEGIN {}
36 END {}
38 ## @method get_events()
39 # A brief function returning a list of functions which are exported by importing the module.
40 # @return List of all provided functions
41 sub get_events {
42     return \@events;
43 }
45 ## @method opsi_add_product_to_client
46 # Adds an Opsi product to an Opsi client.
47 # @param msg - STRING - xml message with tags hostId and productId
48 # @param msg_hash - HASHREF - message information parsed into a hash
49 # @param session_id - INTEGER - POE session id of the processing of this message
50 # @return out_msg - STRING - feedback to GOsa in success and error case
51 sub opsi_add_product_to_client {
52     my ($msg, $msg_hash, $session_id) = @_;
53     my $header = @{$msg_hash->{'header'}}[0];
54     my $source = @{$msg_hash->{'source'}}[0];
55     my $target = @{$msg_hash->{'target'}}[0];
56     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
57     my ($hostId, $productId);
58     my $error = 0;
60     # Build return message
61     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
62     if (defined $forward_to_gosa) {
63         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
64     }
66     # Sanity check of needed parameter
67     if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1))  {
68         $error++;
69         &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
70         &add_content2xml_hash($out_hash, "error", "hostId");
71         &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); 
73     }
74     if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1)) {
75         $error++;
76         &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
77         &add_content2xml_hash($out_hash, "error", "productId");
78         &main::daemon_log("$session_id ERROR: no productId specified or procutId tag invalid: $msg", 1); 
79     }
81     if (not $error) {
82         # Get hostID
83         $hostId = @{$msg_hash->{'hostId'}}[0];
84         &add_content2xml_hash($out_hash, "hostId", $hostId);
86         # Get productID
87         $productId = @{$msg_hash->{'productId'}}[0];
88         &add_content2xml_hash($out_hash, "productId", $productId);
90         # Do an action request for all these -> "setup".
91         my $callobj = {
92             method  => 'setProductActionRequest',
93             params  => [ $productId, $hostId, "setup" ],
94             id  => 1, }; 
96         my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
97         my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
98         if ($sres_err){
99             &main::daemon_log("$session_id ERROR: cannot add product: ".$sres_err_string, 1);
100             &add_content2xml_hash($out_hash, "error", $sres_err_string);
101         }
102     } 
104     # return message
105     return ( &create_xml_string($out_hash) );
108 ## @method opsi_del_product_from_client
109 # Deletes an Opsi-product from an Opsi-client. 
110 # @param msg - STRING - xml message with tags hostId and productId
111 # @param msg_hash - HASHREF - message information parsed into a hash
112 # @param session_id - INTEGER - POE session id of the processing of this message
113 # @return out_msg - STRING - feedback to GOsa in success and error case
114 sub opsi_del_product_from_client {
115     my ($msg, $msg_hash, $session_id) = @_;
116     my $header = @{$msg_hash->{'header'}}[0];
117     my $source = @{$msg_hash->{'source'}}[0];
118     my $target = @{$msg_hash->{'target'}}[0];
119     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
120     my ($hostId, $productId);
121     my $error = 0;
122     my ($sres, $sres_err, $sres_err_string);
124     # Build return message
125     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
126     if (defined $forward_to_gosa) {
127         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
128     }
130     # Sanity check of needed parameter
131     if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1))  {
132         $error++;
133         &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
134         &add_content2xml_hash($out_hash, "error", "hostId");
135         &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); 
137     }
138     if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1)) {
139         $error++;
140         &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
141         &add_content2xml_hash($out_hash, "error", "productId");
142         &main::daemon_log("$session_id ERROR: no productId specified or procutId tag invalid: $msg", 1); 
143     }
145     # All parameter available
146     if (not $error) {
147         # Get hostID
148         $hostId = @{$msg_hash->{'hostId'}}[0];
149         &add_content2xml_hash($out_hash, "hostId", $hostId);
151         # Get productID
152         $productId = @{$msg_hash->{'productId'}}[0];
153         &add_content2xml_hash($out_hash, "productId", $productId);
156         #TODO: check the results for more than one entry which is currently installed
157         #$callobj = {
158         #    method  => 'getProductDependencies_listOfHashes',
159         #    params  => [ $productId ],
160         #    id  => 1, };
161         #
162         #my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
163         #my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
164         #if ($sres_err){
165         #  &main::daemon_log("ERROR: cannot perform dependency check: ".$sres_err_string, 1);
166         #  &add_content2xml_hash($out_hash, "error", $sres_err_string);
167         #  return ( &create_xml_string($out_hash) );
168         #}
171     # Check to get product action list 
172         my $callobj = {
173             method  => 'getPossibleProductActions_list',
174             params  => [ $productId ],
175             id  => 1, };
176         $sres = $main::opsi_client->call($main::opsi_url, $callobj);
177         ($sres_err, $sres_err_string) = &check_opsi_res($sres);
178         if ($sres_err){
179             &main::daemon_log("$session_id ERROR: cannot get product action list: ".$sres_err_string, 1);
180             &add_content2xml_hash($out_hash, "error", $sres_err_string);
181             $error++;
182         }
183     }
185     # Check action uninstall of product
186     if (not $error) {
187         my $uninst_possible= 0;
188         foreach my $r (@{$sres->result}) {
189             if ($r eq 'uninstall') {
190                 $uninst_possible= 1;
191             }
192         }
193         if (!$uninst_possible){
194             &main::daemon_log("$session_id ERROR: cannot uninstall product '$productId', product do not has the action 'uninstall'", 1);
195             &add_content2xml_hash($out_hash, "error", "cannot uninstall product '$productId', product do not has the action 'uninstall'");
196             $error++;
197         }
198     }
200     # Set product state to "none"
201     # Do an action request for all these -> "setup".
202     if (not $error) {
203         my $callobj = {
204             method  => 'setProductActionRequest',
205             params  => [ $productId, $hostId, "none" ],
206             id  => 1, 
207         }; 
208         $sres = $main::opsi_client->call($main::opsi_url, $callobj);
209         ($sres_err, $sres_err_string) = &check_opsi_res($sres);
210         if ($sres_err){
211             &main::daemon_log("$session_id ERROR: cannot delete product: ".$sres_err_string, 1);
212             &add_content2xml_hash($out_hash, "error", $sres_err_string);
213         }
214     }
216     # Return message
217     return ( &create_xml_string($out_hash) );
220 ## @method opsi_add_client
221 # Adds an Opsi client to Opsi.
222 # @param msg - STRING - xml message with tags hostId and macaddress
223 # @param msg_hash - HASHREF - message information parsed into a hash
224 # @param session_id - INTEGER - POE session id of the processing of this message
225 # @return out_msg - STRING - feedback to GOsa in success and error case
226 sub opsi_add_client {
227     my ($msg, $msg_hash, $session_id) = @_;
228     my $header = @{$msg_hash->{'header'}}[0];
229     my $source = @{$msg_hash->{'source'}}[0];
230     my $target = @{$msg_hash->{'target'}}[0];
231     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
232     my ($hostId, $mac);
233     my $error = 0;
234     my ($sres, $sres_err, $sres_err_string);
236     # Build return message with twisted target and source
237     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
238     if (defined $forward_to_gosa) {
239         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
240     }
242     # Sanity check of needed parameter
243     if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1))  {
244         $error++;
245         &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
246         &add_content2xml_hash($out_hash, "error", "hostId");
247         &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); 
248     }
249     if ((not exists $msg_hash->{'macaddress'}) || (@{$msg_hash->{'macaddress'}} != 1))  {
250         $error++;
251         &add_content2xml_hash($out_hash, "error_string", "no macaddress specified or macaddress tag invalid");
252         &add_content2xml_hash($out_hash, "error", "macaddress");
253         &main::daemon_log("$session_id ERROR: no macaddress specified or macaddress tag invalid: $msg", 1); 
254     }
256     if (not $error) {
257         # Get hostID
258         $hostId = @{$msg_hash->{'hostId'}}[0];
259         &add_content2xml_hash($out_hash, "hostId", $hostId);
261         # Get macaddress
262         $mac = @{$msg_hash->{'macaddress'}}[0];
263         &add_content2xml_hash($out_hash, "macaddress", $mac);
265         my $name= $hostId;
266         $name=~ s/^([^.]+).*$/$1/;
267         my $domain= $hostId;
268         $domain=~ s/^[^.]+\.(.*)$/$1/;
269         my ($description, $notes, $ip);
271         if (defined @{$msg_hash->{'description'}}[0]){
272             $description = @{$msg_hash->{'description'}}[0];
273         }
274         if (defined @{$msg_hash->{'notes'}}[0]){
275             $notes = @{$msg_hash->{'notes'}}[0];
276         }
277         if (defined @{$msg_hash->{'ip'}}[0]){
278             $ip = @{$msg_hash->{'ip'}}[0];
279         }
281         my $callobj;
282         $callobj = {
283             method  => 'createClient',
284             params  => [ $name, $domain, $description, $notes, $ip, $mac ],
285             id  => 1,
286         };
288         $sres = $main::opsi_client->call($main::opsi_url, $callobj);
289         ($sres_err, $sres_err_string) = &check_opsi_res($sres);
290         if ($sres_err){
291             &main::daemon_log("$session_id ERROR: cannot create client: ".$sres_err_string, 1);
292             &add_content2xml_hash($out_hash, "error", $sres_err_string);
293         } else {
294             &main::daemon_log("$session_id INFO: add opsi client '$hostId' with mac '$mac'", 5); 
295         }
296     }
298     # Return message
299     return ( &create_xml_string($out_hash) );
302 ## @method opsi_modify_client
303 # Modifies the parameters description, mac or notes for an Opsi client if the corresponding message tags are given.
304 # @param msg - STRING - xml message with tag hostId and optional description, mac or notes
305 # @param msg_hash - HASHREF - message information parsed into a hash
306 # @param session_id - INTEGER - POE session id of the processing of this message    
307 # @return out_msg - STRING - feedback to GOsa in success and error case
308 sub opsi_modify_client {
309     my ($msg, $msg_hash, $session_id) = @_;
310     my $header = @{$msg_hash->{'header'}}[0];
311     my $source = @{$msg_hash->{'source'}}[0];
312     my $target = @{$msg_hash->{'target'}}[0];
313     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
314     my $hostId;
315     my $error = 0;
316     my ($sres, $sres_err, $sres_err_string);
318     # Build return message with twisted target and source
319     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
320     if (defined $forward_to_gosa) {
321         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
322     }
324     # Sanity check of needed parameter
325     if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1))  {
326         $error++;
327         &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
328         &add_content2xml_hash($out_hash, "error", "hostId");
329         &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); 
330     }
332     if (not $error) {
333         # Get hostID
334         $hostId = @{$msg_hash->{'hostId'}}[0];
335         &add_content2xml_hash($out_hash, "hostId", $hostId);
336         my $name= $hostId;
337         $name=~ s/^([^.]+).*$/$1/;
338         my $domain= $hostId;
339         $domain=~ s/^[^.]+(.*)$/$1/;
341         # Modify description, notes or mac if defined
342         my ($description, $notes, $mac);
343         my $callobj;
344         if ((exists $msg_hash->{'description'}) && (@{$msg_hash->{'description'}} == 1) ){
345             $description = @{$msg_hash->{'description'}}[0];
346             $callobj = {
347                 method  => 'setHostDescription',
348                 params  => [ $hostId, $description ],
349                 id  => 1,
350             };
351             my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
352             my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
353             if ($sres_err){
354                 &main::daemon_log("ERROR: cannot set description: ".$sres_err_string, 1);
355                 &add_content2xml_hash($out_hash, "error", $sres_err_string);
356             }
357         }
358         if ((exists $msg_hash->{'notes'}) && (@{$msg_hash->{'notes'}} == 1)) {
359             $notes = @{$msg_hash->{'notes'}}[0];
360             $callobj = {
361                 method  => 'setHostNotes',
362                 params  => [ $hostId, $notes ],
363                 id  => 1,
364             };
365             my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
366             my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
367             if ($sres_err){
368                 &main::daemon_log("ERROR: cannot set notes: ".$sres_err_string, 1);
369                 &add_content2xml_hash($out_hash, "error", $sres_err_string);
370             }
371         }
372         if ((exists $msg_hash->{'mac'}) && (@{$msg_hash->{'mac'}} == 1)){
373             $mac = @{$msg_hash->{'mac'}}[0];
374             $callobj = {
375                 method  => 'setMacAddress',
376                 params  => [ $hostId, $mac ],
377                 id  => 1,
378             };
379             my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
380             my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
381             if ($sres_err){
382                 &main::daemon_log("ERROR: cannot set mac address: ".$sres_err_string, 1);
383                 &add_content2xml_hash($out_hash, "error", $sres_err_string);
384             }
385         }
386     }
388     # Return message
389     return ( &create_xml_string($out_hash) );
392     
393 ## @method opsi_get_netboot_products
394 # Get netboot products for specific host.
395 # @param msg - STRING - xml message with tag hostId
396 # @param msg_hash - HASHREF - message information parsed into a hash
397 # @param session_id - INTEGER - POE session id of the processing of this message
398 # @return out_msg - STRING - feedback to GOsa in success and error case
399 sub opsi_get_netboot_products {
400     my ($msg, $msg_hash, $session_id) = @_;
401     my $header = @{$msg_hash->{'header'}}[0];
402     my $source = @{$msg_hash->{'source'}}[0];
403     my $target = @{$msg_hash->{'target'}}[0];
404     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
405     my $hostId;
406     my $xml_msg;
408     # Build return message with twisted target and source
409     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
410     if (defined $forward_to_gosa) {
411         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
412     }
414     # Get hostID if defined
415     if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1))  {
416         $hostId = @{$msg_hash->{'hostId'}}[0];
417         &add_content2xml_hash($out_hash, "hostId", $hostId);
418     }
420     &add_content2xml_hash($out_hash, "xxx", "");
421     $xml_msg= &create_xml_string($out_hash);
423     # For hosts, only return the products that are or get installed
424     my $callobj;
425     $callobj = {
426         method  => 'getNetBootProductIds_list',
427         params  => [ ],
428         id  => 1,
429     };
431     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
432     my %r = ();
433     for (@{$res->result}) { $r{$_} = 1 }
435     if (not &check_opsi_res($res)){
437         if (defined $hostId){
438             $callobj = {
439                 method  => 'getProductStates_hash',
440                 params  => [ $hostId ],
441                 id  => 1,
442             };
444             my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
445             if (not &check_opsi_res($hres)){
446                 my $htmp= $hres->result->{$hostId};
448                 # check state != not_installed or action == setup -> load and add
449                 foreach my $product (@{$htmp}){
451                     if (!defined ($r{$product->{'productId'}})){
452                         next;
453                     }
455                     # Now we've a couple of hashes...
456                     if ($product->{'installationStatus'} ne "not_installed" or
457                             $product->{'actionRequest'} eq "setup"){
458                         my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
460                         $callobj = {
461                             method  => 'getProduct_hash',
462                             params  => [ $product->{'productId'} ],
463                             id  => 1,
464                         };
466                         my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
467                         if (not &check_opsi_res($sres)){
468                             my $tres= $sres->result;
470                             my $name= xml_quote($tres->{'name'});
471                             my $r= $product->{'productId'};
472                             my $description= xml_quote($tres->{'description'});
473                             $name=~ s/\//\\\//;
474                             $description=~ s/\//\\\//;
475                             $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
476                         }
477                     }
478                 }
480             }
482         } else {
483             foreach my $r (@{$res->result}) {
484                 $callobj = {
485                     method  => 'getProduct_hash',
486                     params  => [ $r ],
487                     id  => 1,
488                 };
490                 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
491                 if (not &check_opsi_res($sres)){
492                     my $tres= $sres->result;
494                     my $name= xml_quote($tres->{'name'});
495                     my $description= xml_quote($tres->{'description'});
496                     $name=~ s/\//\\\//;
497                     $description=~ s/\//\\\//;
498                     $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
499                 }
500             }
502         }
503     }
504     $xml_msg=~ s/<xxx><\/xxx>//;
506     # Return message
507     return ( $xml_msg );
511 ## @method opsi_get_product_properties
512 # Get product properties for a product and a specific host or gobally for a product.
513 # @param msg - STRING - xml message with tags productId and optional hostId
514 # @param msg_hash - HASHREF - message information parsed into a hash
515 # @param session_id - INTEGER - POE session id of the processing of this message
516 # @return out_msg - STRING - feedback to GOsa in success and error case
517 sub opsi_get_product_properties {
518     my ($msg, $msg_hash, $session_id) = @_;
519     my $header = @{$msg_hash->{'header'}}[0];
520     my $source = @{$msg_hash->{'source'}}[0];
521     my $target = @{$msg_hash->{'target'}}[0];
522     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
523     my ($hostId, $productId);
524     my $xml_msg;
526     # Build return message with twisted target and source
527     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
528     if (defined $forward_to_gosa) {
529         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
530     }
532     # Sanity check of needed parameter
533     if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1))  {
534         &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
535         &add_content2xml_hash($out_hash, "error", "productId");
536         &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1); 
538         # Return message
539         return ( &create_xml_string($out_hash) );
540     }
542     # Get productid
543     $productId = @{$msg_hash->{'productId'}}[0];
544     &add_content2xml_hash($out_hash, "producId", "$productId");
546     # Get hostID if defined
547     if (defined @{$msg_hash->{'hostId'}}[0]){
548       $hostId = @{$msg_hash->{'hostId'}}[0];
549       &add_content2xml_hash($out_hash, "hostId", $hostId);
550     }
552     # Load actions
553     my $callobj = {
554       method  => 'getPossibleProductActions_list',
555       params  => [ $productId ],
556       id  => 1,
557     };
558     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
559     if (not &check_opsi_res($res)){
560       foreach my $action (@{$res->result}){
561         &add_content2xml_hash($out_hash, "action", $action);
562       }
563     }
565     # Add place holder
566     &add_content2xml_hash($out_hash, "xxx", "");
568     # Move to XML string
569     $xml_msg= &create_xml_string($out_hash);
571     # JSON Query
572     if (defined $hostId){
573       $callobj = {
574           method  => 'getProductProperties_hash',
575           params  => [ $productId, $hostId ],
576           id  => 1,
577       };
578     } else {
579       $callobj = {
580           method  => 'getProductProperties_hash',
581           params  => [ $productId ],
582           id  => 1,
583       };
584     }
586     $res = $main::opsi_client->call($main::opsi_url, $callobj);
587     if (not &check_opsi_res($res)){
588         my $r= $res->result;
589         foreach my $key (keys %{$r}) {
590             my $item= "\n<item>";
591             my $value= $r->{$key};
592             if (UNIVERSAL::isa( $value, "ARRAY" )){
593                 foreach my $subval (@{$value}){
594                     $item.= "<$key>".xml_quote($subval)."</$key>";
595                 }
596             } else {
597                 $item.= "<$key>".xml_quote($value)."</$key>";
598             }
599             $item.= "</item>";
600             $xml_msg=~ s/<xxx><\/xxx>/$item<xxx><\/xxx>/;
601         }
602     }
604     $xml_msg=~ s/<xxx><\/xxx>//;
606     # Return message
607     return ( $xml_msg );
611 ## @method opsi_set_product_properties
612 # Set product properities for a specific host or globaly. Message needs one xml tag 'item' and within one xml tag 'name' and 'value'. The xml tags action and state are optional.
613 # @param msg - STRING - xml message with tags productId, action, state and optional hostId, action and state
614 # @param msg_hash - HASHREF - message information parsed into a hash
615 # @param session_id - INTEGER - POE session id of the processing of this message
616 # @return out_msg - STRING - feedback to GOsa in success and error case
617 sub opsi_set_product_properties {
618     my ($msg, $msg_hash, $session_id) = @_;
619     my $header = @{$msg_hash->{'header'}}[0];
620     my $source = @{$msg_hash->{'source'}}[0];
621     my $target = @{$msg_hash->{'target'}}[0];
622     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
623     my ($productId, $hostId);
625     # Build return message with twisted target and source
626     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
627     if (defined $forward_to_gosa) {
628         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
629     }
631     # Sanity check of needed parameter
632     if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1))  {
633         &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
634         &add_content2xml_hash($out_hash, "error", "productId");
635         &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1); 
636         return ( &create_xml_string($out_hash) );
637     }
638     if (not exists $msg_hash->{'item'}) {
639         &add_content2xml_hash($out_hash, "error_string", "message needs one xml-tag 'item' and within the xml-tags 'name' and 'value'");
640         &add_content2xml_hash($out_hash, "error", "item");
641         &main::daemon_log("$session_id ERROR: message needs one xml-tag 'item' and within the xml-tags 'name' and 'value': $msg", 1); 
642         return ( &create_xml_string($out_hash) );
643     } else {
644         if ((not exists @{$msg_hash->{'item'}}[0]->{'name'}) || (@{@{$msg_hash->{'item'}}[0]->{'name'}} != 1 )) {
645             &add_content2xml_hash($out_hash, "error_string", "message needs within the xml-tag 'item' one xml-tags 'name'");
646             &add_content2xml_hash($out_hash, "error", "name");
647             &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'name': $msg", 1); 
648             return ( &create_xml_string($out_hash) );
649         }
650         if ((not exists @{$msg_hash->{'item'}}[0]->{'value'}) || (@{@{$msg_hash->{'item'}}[0]->{'value'}} != 1 )) {
651             &add_content2xml_hash($out_hash, "error_string", "message needs within the xml-tag 'item' one xml-tags 'value'");
652             &add_content2xml_hash($out_hash, "error", "value");
653             &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'value': $msg", 1); 
654             return ( &create_xml_string($out_hash) );
655         }
656     }
657     if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1))  {
658         &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
659         &add_content2xml_hash($out_hash, "error", "hostId");
660         &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); 
661         return ( &create_xml_string($out_hash) );
662     }
664         
665     # Get productId
666     $productId =  @{$msg_hash->{'productId'}}[0];
667     &add_content2xml_hash($out_hash, "productId", $productId);
669     # Get hostID if defined
670     if (exists $msg_hash->{'hostId'}){
671         $hostId = @{$msg_hash->{'hostId'}}[0];
672         &add_content2xml_hash($out_hash, "hostId", $hostId);
673     }
675     # Set product states if requested
676     if (defined @{$msg_hash->{'action'}}[0]){
677         &_set_action($productId, @{$msg_hash->{'action'}}[0], $hostId);
678     }
679     if (defined @{$msg_hash->{'state'}}[0]){
680         &_set_state($productId, @{$msg_hash->{'state'}}[0], $hostId);
681     }
683     # Find properties
684     foreach my $item (@{$msg_hash->{'item'}}){
685         # JSON Query
686         my $callobj;
688         if (defined $hostId){
689             $callobj = {
690                 method  => 'setProductProperty',
691                 params  => [ $productId, $item->{'name'}[0], $item->{'value'}[0], $hostId ],
692                 id  => 1,
693             };
694         } else {
695             $callobj = {
696                 method  => 'setProductProperty',
697                 params  => [ $productId, $item->{'name'}[0], $item->{'value'}[0] ],
698                 id  => 1,
699             };
700         }
702         my $res = $main::opsi_client->call($main::opsi_url, $callobj);
703         my ($res_err, $res_err_string) = &check_opsi_res($res);
705         if ($res_err){
706             &man::daemon_log("$session_id ERROR: communication failed while setting '".$item->{'name'}[0]."': ".$res_err_string, 1);
707             &add_content2xml_hash($out_hash, "error", $res_err_string);
708         }
709     }
712     # Return message
713     return ( &create_xml_string($out_hash) );
717 ## @method opsi_get_client_hardware
718 # Reports client hardware inventory.
719 # @param msg - STRING - xml message with tag hostId
720 # @param msg_hash - HASHREF - message information parsed into a hash
721 # @param session_id - INTEGER - POE session id of the processing of this message
722 # @return out_msg - STRING - feedback to GOsa in success and error case
723 sub opsi_get_client_hardware {
724     my ($msg, $msg_hash, $session_id) = @_;
725     my $header = @{$msg_hash->{'header'}}[0];
726     my $source = @{$msg_hash->{'source'}}[0];
727     my $target = @{$msg_hash->{'target'}}[0];
728     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
729     my $hostId;
730     my $error = 0;
731     my $xml_msg;
733     # Build return message with twisted target and source
734     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
735     if (defined $forward_to_gosa) {
736       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
737     }
739     # Sanity check of needed parameter
740     if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1))  {
741         $error++;
742         &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
743         &add_content2xml_hash($out_hash, "error", "hostId");
744         &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); 
745     }
747     if (not $error) {
749     # Get hostID
750         $hostId = @{$msg_hash->{'hostId'}}[0];
751         &add_content2xml_hash($out_hash, "hostId", "$hostId");
752         &add_content2xml_hash($out_hash, "xxx", "");
753     }    
755     # Move to XML string
756     $xml_msg= &create_xml_string($out_hash);
757     
758     if (not $error) {
760     # JSON Query
761         my $callobj = {
762             method  => 'getHardwareInformation_hash',
763             params  => [ $hostId ],
764             id  => 1,
765         };
767         my $res = $main::opsi_client->call($main::opsi_url, $callobj);
768         if (not &check_opsi_res($res)){
769             my $result= $res->result;
770             if (ref $result eq "HASH") {
771                 foreach my $r (keys %{$result}){
772                     my $item= "\n<item><id>".xml_quote($r)."</id>";
773                     my $value= $result->{$r};
774                     foreach my $sres (@{$value}){
776                         foreach my $dres (keys %{$sres}){
777                             if (defined $sres->{$dres}){
778                                 $item.= "<$dres>".xml_quote($sres->{$dres})."</$dres>";
779                             }
780                         }
782                     }
783                     $item.= "</item>";
784                     $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
786                 }
787             }
788         }
790         $xml_msg=~ s/<xxx><\/xxx>//;
792     }
794     # Return message
795     return ( $xml_msg );
799 ## @method opsi_list_clients
800 # Reports all Opsi clients. 
801 # @param msg - STRING - xml message 
802 # @param msg_hash - HASHREF - message information parsed into a hash
803 # @param session_id - INTEGER - POE session id of the processing of this message
804 # @return out_msg - STRING - feedback to GOsa in success and error case
805 sub opsi_list_clients {
806     my ($msg, $msg_hash, $session_id) = @_;
807     my $header = @{$msg_hash->{'header'}}[0];
808     my $source = @{$msg_hash->{'source'}}[0];
809     my $target = @{$msg_hash->{'target'}}[0];
810     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
812     # Build return message with twisted target and source
813     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
814     if (defined $forward_to_gosa) {
815       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
816     }
817     &add_content2xml_hash($out_hash, "xxx", "");
819     # Move to XML string
820     my $xml_msg= &create_xml_string($out_hash);
822     # JSON Query
823     my $callobj = {
824         method  => 'getClients_listOfHashes',
825         params  => [ ],
826         id  => 1,
827     };
828     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
829     if (not &check_opsi_res($res)){
830         foreach my $host (@{$res->result}){
831             my $item= "<item><name>".$host->{'hostId'}."</name>";
832             if (defined($host->{'description'})){
833                 $item.= "<description>".xml_quote($host->{'description'})."</description>";
834             }
835             if (defined($host->{'notes'})){
836                 $item.= "<notes>".xml_quote($host->{'notes'})."</notes>";
837             }
839             $callobj = {
840               method  => 'getIpAddress',
841               params  => [ $host->{'hostId'} ],
842               id  => 1,
843             };
844             my $sres= $main::opsi_client->call($main::opsi_url, $callobj);
845             if ( not &check_opsi_res($sres)){
846               $item.= "<ip>".xml_quote($sres->result)."</ip>";
847             }
849             $callobj = {
850               method  => 'getMacAddress',
851               params  => [ $host->{'hostId'} ],
852               id  => 1,
853             };
854             $sres= $main::opsi_client->call($main::opsi_url, $callobj);
855             if ( not &check_opsi_res($sres)){
856                 $item.= "<mac>".xml_quote($sres->result)."</mac>";
857             }
858             $item.= "</item>";
859             $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
860         }
861     }
863     $xml_msg=~ s/<xxx><\/xxx>//;
864     return ( $xml_msg );
868 ## @method opsi_get_client_software
869 # Reports client software inventory.
870 # @param msg - STRING - xml message with tag hostId
871 # @param msg_hash - HASHREF - message information parsed into a hash
872 # @param session_id - INTEGER - POE session id of the processing of this message
873 # @return out_msg - STRING - feedback to GOsa in success and error case
874 sub opsi_get_client_software {
875     my ($msg, $msg_hash, $session_id) = @_;
876     my $header = @{$msg_hash->{'header'}}[0];
877     my $source = @{$msg_hash->{'source'}}[0];
878     my $target = @{$msg_hash->{'target'}}[0];
879     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
880     my $error = 0;
881     my $hostId;
882     my $xml_msg;
884     # Build return message with twisted target and source
885     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
886     if (defined $forward_to_gosa) {
887       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
888     }
890     # Sanity check of needed parameter
891     if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1))  {
892         $error++;
893         &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
894         &add_content2xml_hash($out_hash, "error", "hostId");
895         &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); 
896     }
898     if (not $error) {
900     # Get hostID
901         $hostId = @{$msg_hash->{'hostId'}}[0];
902         &add_content2xml_hash($out_hash, "hostId", "$hostId");
903         &add_content2xml_hash($out_hash, "xxx", "");
904     }
906     $xml_msg= &create_xml_string($out_hash);
908     if (not $error) {
910     # JSON Query
911         my $callobj = {
912             method  => 'getSoftwareInformation_hash',
913             params  => [ $hostId ],
914             id  => 1,
915         };
917         my $res = $main::opsi_client->call($main::opsi_url, $callobj);
918         if (not &check_opsi_res($res)){
919             my $result= $res->result;
920 # TODO : Ist das hier schon fertig???   
921         }
923         $xml_msg=~ s/<xxx><\/xxx>//;
925     }
927     # Return message
928     return ( $xml_msg );
932 ## @method opsi_get_local_products
933 # Reports product for given hostId or globally.
934 # @param msg - STRING - xml message with optional tag hostId
935 # @param msg_hash - HASHREF - message information parsed into a hash
936 # @param session_id - INTEGER - POE session id of the processing of this message
937 # @return out_msg - STRING - feedback to GOsa in success and error case
938 sub opsi_get_local_products {
939     my ($msg, $msg_hash, $session_id) = @_;
940     my $header = @{$msg_hash->{'header'}}[0];
941     my $source = @{$msg_hash->{'source'}}[0];
942     my $target = @{$msg_hash->{'target'}}[0];
943     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
944     my $hostId;
946     # Build return message with twisted target and source
947     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
948     if (defined $forward_to_gosa) {
949         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
950     }
951     &add_content2xml_hash($out_hash, "xxx", "");
953     # Get hostID if defined
954     if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1))  {
955         $hostId = @{$msg_hash->{'hostId'}}[0];
956         &add_content2xml_hash($out_hash, "hostId", $hostId);
957     }
959     # Move to XML string
960     my $xml_msg= &create_xml_string($out_hash);
962     # For hosts, only return the products that are or get installed
963     my $callobj;
964     $callobj = {
965         method  => 'getLocalBootProductIds_list',
966         params  => [ ],
967         id  => 1,
968     };
970     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
971     my %r = ();
972     for (@{$res->result}) { $r{$_} = 1 }
974     if (not &check_opsi_res($res)){
976         if (defined $hostId){
977             $callobj = {
978                 method  => 'getProductStates_hash',
979                 params  => [ $hostId ],
980                 id  => 1,
981             };
983             my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
984             if (not &check_opsi_res($hres)){
985                 my $htmp= $hres->result->{$hostId};
987                 # Check state != not_installed or action == setup -> load and add
988                 foreach my $product (@{$htmp}){
990                     if (!defined ($r{$product->{'productId'}})){
991                         next;
992                     }
994                     # Now we've a couple of hashes...
995                     if ($product->{'installationStatus'} ne "not_installed" or
996                             $product->{'actionRequest'} eq "setup"){
997                         my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
999                         $callobj = {
1000                             method  => 'getProduct_hash',
1001                             params  => [ $product->{'productId'} ],
1002                             id  => 1,
1003                         };
1005                         my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
1006                         if (not &check_opsi_res($sres)){
1007                             my $tres= $sres->result;
1009                             my $name= xml_quote($tres->{'name'});
1010                             my $r= $product->{'productId'};
1011                             my $description= xml_quote($tres->{'description'});
1012                             $name=~ s/\//\\\//;
1013                             $description=~ s/\//\\\//;
1014                             $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
1015                         }
1017                     }
1018                 }
1020             }
1022         } else {
1023             foreach my $r (@{$res->result}) {
1024                 $callobj = {
1025                     method  => 'getProduct_hash',
1026                     params  => [ $r ],
1027                     id  => 1,
1028                 };
1030                 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
1031                 if (not &check_opsi_res($sres)){
1032                     my $tres= $sres->result;
1034                     my $name= xml_quote($tres->{'name'});
1035                     my $description= xml_quote($tres->{'description'});
1036                     $name=~ s/\//\\\//;
1037                     $description=~ s/\//\\\//;
1038                     $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
1039                 }
1041             }
1043         }
1044     }
1046     $xml_msg=~ s/<xxx><\/xxx>//;
1048     # Retrun Message
1049     return ( $xml_msg );
1053 ## @method opsi_del_client
1054 # Deletes a client from Opsi.
1055 # @param msg - STRING - xml message with tag hostId
1056 # @param msg_hash - HASHREF - message information parsed into a hash
1057 # @param session_id - INTEGER - POE session id of the processing of this message
1058 # @return out_msg - STRING - feedback to GOsa in success and error case
1059 sub opsi_del_client {
1060     my ($msg, $msg_hash, $session_id) = @_;
1061     my $header = @{$msg_hash->{'header'}}[0];
1062     my $source = @{$msg_hash->{'source'}}[0];
1063     my $target = @{$msg_hash->{'target'}}[0];
1064     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
1065     my $hostId;
1066     my $error = 0;
1068     # Build return message with twisted target and source
1069     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
1070     if (defined $forward_to_gosa) {
1071       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
1072     }
1074     # Sanity check of needed parameter
1075     if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1))  {
1076         $error++;
1077         &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
1078         &add_content2xml_hash($out_hash, "error", "hostId");
1079         &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); 
1080     }
1082     if (not $error) {
1084     # Get hostID
1085         $hostId = @{$msg_hash->{'hostId'}}[0];
1086         &add_content2xml_hash($out_hash, "hostId", "$hostId");
1088     # JSON Query
1089         my $callobj = {
1090             method  => 'deleteClient',
1091             params  => [ $hostId ],
1092             id  => 1,
1093         };
1094         my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1095     }
1097     # Move to XML string
1098     my $xml_msg= &create_xml_string($out_hash);
1100     # Return message
1101     return ( $xml_msg );
1105 ## @method opsi_install_client
1106 # Set a client in Opsi to install and trigger a wake on lan message (WOL).  
1107 # @param msg - STRING - xml message with tags hostId, macaddress
1108 # @param msg_hash - HASHREF - message information parsed into a hash
1109 # @param session_id - INTEGER - POE session id of the processing of this message
1110 # @return out_msg - STRING - feedback to GOsa in success and error case
1111 sub opsi_install_client {
1112     my ($msg, $msg_hash, $session_id) = @_;
1113     my $header = @{$msg_hash->{'header'}}[0];
1114     my $source = @{$msg_hash->{'source'}}[0];
1115     my $target = @{$msg_hash->{'target'}}[0];
1116     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
1119     my ($hostId, $macaddress);
1121     my $error = 0;
1122     my @out_msg_l;
1124     # Build return message with twisted target and source
1125     my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
1126     if (defined $forward_to_gosa) {
1127         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
1128     }
1130     # Sanity check of needed parameter
1131     if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1))  {
1132         $error++;
1133         &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
1134         &add_content2xml_hash($out_hash, "error", "hostId");
1135         &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); 
1136     }
1137     if ((not exists $msg_hash->{'macaddress'}) || (@{$msg_hash->{'macaddress'}} != 1))  {
1138         $error++;
1139         &add_content2xml_hash($out_hash, "error_string", "no macaddress specified or macaddress tag invalid");
1140         &add_content2xml_hash($out_hash, "error", "macaddress");
1141         &main::daemon_log("$session_id ERROR: no macaddress specified or macaddress tag invalid: $msg", 1); 
1142     } else {
1143         if ((exists $msg_hash->{'macaddress'}) && 
1144                 ($msg_hash->{'macaddress'}[0] =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i)) {  
1145             $macaddress = $1; 
1146         } else { 
1147             $error ++; 
1148             &add_content2xml_hash($out_hash, "error_string", "given mac address is not correct");
1149             &add_content2xml_hash($out_hash, "error", "macaddress");
1150             &main::daemon_log("$session_id ERROR: given mac address is not correct: $msg", 1); 
1151         }
1152     }
1154     if (not $error) {
1156     # Get hostId
1157         $hostId = @{$msg_hash->{'hostId'}}[0];
1158         &add_content2xml_hash($out_hash, "hostId", "$hostId");
1160         # Load all products for this host with status != "not_installed" or actionRequest != "none"
1161         my $callobj = {
1162             method  => 'getProductStates_hash',
1163             params  => [ $hostId ],
1164             id  => 1,
1165         };
1167         my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
1168         if (not &check_opsi_res($hres)){
1169             my $htmp= $hres->result->{$hostId};
1171             # check state != not_installed or action == setup -> load and add
1172             foreach my $product (@{$htmp}){
1173                 # Now we've a couple of hashes...
1174                 if ($product->{'installationStatus'} ne "not_installed" or
1175                         $product->{'actionRequest'} ne "none"){
1177                     # Do an action request for all these -> "setup".
1178                     $callobj = {
1179                         method  => 'setProductActionRequest',
1180                         params  => [ $product->{'productId'}, $hostId, "setup" ],
1181                         id  => 1,
1182                     };
1183                     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1184                     my ($res_err, $res_err_string) = &check_opsi_res($res);
1185                     if ($res_err){
1186                         &main::daemon_log("$session_id ERROR: cannot set product action request for '$hostId': ".$product->{'productId'}, 1);
1187                     } else {
1188                         &main::daemon_log("$session_id INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1);
1189                     }
1190                 }
1191             }
1192         }
1193         push(@out_msg_l, &create_xml_string($out_hash));
1194     
1196     # Build wakeup message for client
1197         if (not $error) {
1198             my $wakeup_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER");
1199             &add_content2xml_hash($wakeup_hash, 'macAddress', $macaddress);
1200             my $wakeup_msg = &create_xml_string($wakeup_hash);
1201             push(@out_msg_l, $wakeup_msg);
1203             # invoke trigger wake for this gosa-si-server
1204             &main::server_server_com::trigger_wake($wakeup_msg, $wakeup_hash, $session_id);
1205         }
1206     }
1207     
1208     # Return messages
1209     return @out_msg_l;
1213 ## @method _set_action
1214 # Set action for an Opsi client
1215 # @param product - STRING - Opsi product
1216 # @param action - STRING - action
1217 # @param hostId - STRING - Opsi hostId
1218 sub _set_action {
1219   my $product= shift;
1220   my $action = shift;
1221   my $hostId = shift;
1222   my $callobj;
1224   $callobj = {
1225     method  => 'setProductActionRequest',
1226     params  => [ $product, $hostId, $action],
1227     id  => 1,
1228   };
1230   $main::opsi_client->call($main::opsi_url, $callobj);
1233 ## @method _set_state
1234 # Set state for an Opsi client
1235 # @param product - STRING - Opsi product
1236 # @param action - STRING - state
1237 # @param hostId - STRING - Opsi hostId
1238 sub _set_state {
1239   my $product = shift;
1240   my $state = shift;
1241   my $hostId = shift;
1242   my $callobj;
1244   $callobj = {
1245     method  => 'setProductState',
1246     params  => [ $product, $hostId, $state ],
1247     id  => 1,
1248   };
1250   $main::opsi_client->call($main::opsi_url, $callobj);
1253 1;