From: rettenbe Date: Tue, 2 Sep 2008 13:16:27 +0000 (+0000) Subject: update: gosa can search for hosts providing opsi functionality X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c96bbd35bb4ccd516170dafaf2ed7552fb3bccbd;p=gosa.git update: gosa can search for hosts providing opsi functionality git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12344 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index cfea9ed8a..fd9a608f4 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -69,6 +69,14 @@ foreach my $log_line (@$result) { &main::daemon_log("0 ERROR: ClientPackages - $log_line", 1); } } +# build vice versa event_hash, event_name => module +my $event2module_hash = {}; +while (my ($module, $mod_events) = each %$event_hash) { + while (my ($event_name, $nothing) = each %$mod_events) { + $event2module_hash->{$event_name} = $module; + } + +} # Unit tag can be defined in config if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { @@ -286,10 +294,10 @@ sub process_incoming_msg { @out_msg_l = &here_i_am($msg, $msg_hash, $session_id) } else { # a event exists with the header as name - if( exists $event_hash->{$header} ) { - &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); + if( exists $event2module_hash->{$header} ) { + &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event2module_hash->{$header}."'", 5); no strict 'refs'; - @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); + @out_msg_l = &{$event2module_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); # if no event handler is implemented } else { diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index cd8550ba7..e5dae76e1 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -44,6 +44,15 @@ foreach my $log_line (@$result) { } } +# build vice versa event_hash, event_name => module +my $event2module_hash = {}; +while (my ($module, $mod_events) = each %$event_hash) { + while (my ($event_name, $nothing) = each %$mod_events) { + $event2module_hash->{$event_name} = $module; + } + +} + ## FUNCTIONS ################################################################# @@ -157,11 +166,11 @@ sub process_gosa_msg { my $target = @{$msg_hash->{'target'}}[0]; # check local installed events - if( exists $event_hash->{$header} ) { + if( exists $event2module_hash->{$header} ) { # a event exists with the header as name - &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); + &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event2module_hash->{$header}."'", 5); no strict 'refs'; - @out_msg_l = &{$event_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id ); + @out_msg_l = &{$event2module_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id ); # check client registered events } else { diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index f71d8df84..cf39ee461 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -28,6 +28,7 @@ my @functions = ( "get_interfaces", "get_mac_for_interface", "get_local_ip_for_remote_ip", + "get_local_mac_for_remote_ip", "is_local", "run_as", "inform_all_other_si_server", @@ -705,6 +706,17 @@ sub get_mac_for_interface { } +sub get_local_mac_for_remote_ip { + my $ip = shift; + + my $local_ip = &get_local_ip_for_remote_ip($ip); + my $network_interface= &get_interface_for_ip($local_ip); + my $mac = &get_mac_for_interface($network_interface); + + return $mac +} + + #=== FUNCTION ================================================================ # NAME: is_local # PARAMETERS: Server Address diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index a524713b5..fc1a84d59 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -39,11 +39,11 @@ my @events = ( "send_user_msg", "get_available_kernel", "trigger_activate_new", + "get_hosts_with_module", # "get_dak_keyring", # "import_dak_key", # "remove_dak_key", # "get_dak_queue", - "get_opsi_hosts", ); @EXPORT = @events; @@ -1115,11 +1115,46 @@ sub trigger_activate_new { # return @out_msg_l; #} +## @method get_hosts_with_module +# Reports all GOsa-si-server providing the given module. +# @param msg - STRING - xml message with tag get_hosts_with_module +# @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 get_hosts_with_module { + my ($msg, $msg_hash, $session_id) = @_; + my $source = @{$msg_hash->{'source'}}[0]; + my $target = @{$msg_hash->{'target'}}[0]; + my $header= @{$msg_hash->{'header'}}[0]; + my $module_name = @{$msg_hash->{'module_name'}}[0]; + my $out_hash = &create_xml_hash($header, $target, $source); + + # Sanity check of module_name + if ((not exists $msg_hash->{'module_name'}) || (@{$msg_hash->{'module_name'}} != 1)) { + &add_content2xml_hash($out_hash, "error_string", "no module_name specified or module_name tag invalid"); + &add_content2xml_hash($out_hash, "error", "module_name"); + &main::daemon_log("$session_id ERROR: no module_name specified or module_name tag invalid: $msg", 1); + return (&create_xml_string($out_hash)); + } -sub get_opsi_hosts { + # Check localhost for module_name + if (exists %{@{$main::known_modules->{'GosaPackages'}}[2]}->{$module_name}) { + my ($remote_ip, $remote_port) = split(/:/, $source); + my $local_mac = &get_local_mac_for_remote_ip($remote_ip); + &add_content2xml_hash($out_hash, "host", $local_mac); + } + # Search for opsi hosts in server_db + my $sql = "SELECT * FROM $main::known_server_tn WHERE loaded_modules LIKE '%$module_name%'"; + my $res = $main::known_server_db->select_dbentry($sql); + while (my ($hit_id, $hit_hash) = each %$res) { + &add_content2xml_hash($out_hash, "host", %$hit_hash->{'macaddress'}); + } + + return (&create_xml_string($out_hash)); } + # vim:ts=4:shiftwidth:expandtab 1; diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index b5519ba20..85f80c092 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -868,6 +868,7 @@ sub opsi_list_clients { } + ## @method opsi_get_client_software # Reports client software inventory. # @param msg - STRING - xml message with tag hostId diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 2068b35f0..cc509f506 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -76,6 +76,9 @@ for($count = 1; $count <= $zahl; $count++) # get_client_for_login_usr #$data = "
gosa_get_client_for_login_usr
GOSA GOSA harald
"; + # List all si-server providing opsi + $data = "
gosa_get_hosts_with_module
GOSA GOSA opsi_com
"; + ################## # recreate fai dbs #$data = "
gosa_recreate_fai_server_db
GOSA GOSA
"; @@ -149,7 +152,7 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_get_client_software
GOSA GOSA linux-cl-2.intranet.gonicus.de
"; # List Opsi clients - $data = "
gosa_opsi_list_clients
GOSA GOSA
"; + #$data = "
gosa_opsi_list_clients
GOSA GOSA
"; # Delete Opsi client #$data = "
gosa_opsi_del_client
GOSA 00:01:6c:9d:b9:fa linux-cl-2.intranet.gonicus.de
";