From 33152cba4bee759b208ceadcb8d57d85675c7888 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 24 Sep 2008 15:00:21 +0000 Subject: [PATCH] update: add basic function set_last_system to gosaTriggered.pm git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12545 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/server/events/clMessages.pm | 1 + gosa-si/server/events/gosaTriggered.pm | 94 ++++++++++++++++++++++++++ gosa-si/tests/client.php | 4 +- gosa-si/tests/deploy-gosa-si.pl | 66 +++++++++--------- 4 files changed, 131 insertions(+), 34 deletions(-) diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 44f1903c4..f3c5de809 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -570,6 +570,7 @@ sub HOOK { return; } + =pod =head1 NAME diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 2ac11a3c2..3ed08e534 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -44,6 +44,7 @@ my @events = ( # "import_dak_key", # "remove_dak_key", # "get_dak_queue", + "set_last_system", ); @EXPORT = @events; @@ -1222,6 +1223,99 @@ sub get_hosts_with_module { return $out_msg; } +## @method set_last_system() +# @details Message set ldap attributes 'gosaLastSystemLogin' and 'gosaLastSystem' +# @param msg - STRING - xml message with tag 'last_system_login' and 'last_system' +# @param msg_hash - HASHREF - message information parsed into a hash +# @param session_id - INTEGER - POE session id of the processing of this message +sub set_last_system { + 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 ($last_system, $last_system_login, $mac); + + # Sanity check of needed parameter + if (not exists $msg_hash->{'last_system'}){ + &main::daemon_log("$session_id ERROR: message does not contain needed xml tag 'last_system', message processing stopped!", 1); + &main::daemon_log($msg, 1); + return; + } + if (@{$msg_hash->{'last_system'}} != 1) { + &main::daemon_log("$session_id ERROR: xml tag 'last_system' has no content or exists more than one time, message processing stopped!"); + &ymain::daemon_log($msg, 1); + return; + } + if (not exists $msg_hash->{'last_system_login'}){ + &main::daemon_log("$session_id ERROR: message does not contain needed xml tag 'last_system_login', message processing stopped!", 1); + &main::daemon_log($msg, 1); + return; + } + if (@{$msg_hash->{'last_system_login'}} != 1) { + &main::daemon_log("$session_id ERROR: xml tag 'last_system_login' has no content or exists more than one time, message processing stopped!"); + &ymain::daemon_log($msg, 1); + return; + } + if (not exists $msg_hash->{'mac_address'}){ + &main::daemon_log("$session_id ERROR: message does not contain needed xml tag 'mac_address', message processing stopped!", 1); + &main::daemon_log($msg, 1); + return; + } + if (@{$msg_hash->{'mac_address'}} != 1) { + &main::daemon_log("$session_id ERROR: xml tag 'mac_address' has no content or exists more than one time, message processing stopped!"); + &ymain::daemon_log($msg, 1); + return; + } + + # Fetch needed parameter + my $mac = @{$msg_hash->{'mac_address'}}[0]; + my $last_system = @{$msg_hash->{'last_system'}}[0]; + my $last_system_login = @{$msg_hash->{'last_system_login'}}[0]; + + # Fetch ldap handle + my $ldap_handle = &main::get_ldap_handle(); + + # Search for an existing entry + my $ldap_mesg= $ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + #filter => "(&(objectClass=GOhard)(|(macAddress=$mac)(dhcpHWaddress=$mac)))", + filter => "(&(objectClass=GOhard)(macAddress=$mac))", + ); + + # Sanity check of ldap resutl + if ($ldap_mesg->count == 0) { + &main::daemon_log("$session_id ERROR: no system with mac address '$mac' was found in base '".$main::ldap_base."', message processing stopped!", 1); + } else { + + # Get the entry from LDAP + my $ldap_entry= $ldap_mesg->pop_entry(); + + # Set 'gosaLastSystem' and 'gosaLastSystemLogin' + if (defined($ldap_entry->get_value('gosaLastSystem'))) { + $ldap_entry->replace ( 'gosaLastSystem' => $last_system ); + } else { + $ldap_entry->add( 'gosaLastSystem' => $last_system ); + } + if (defined($ldap_entry->get_value('gosaLastSystemLogin'))) { + $ldap_entry->replace ( 'gosaLastSystemLogin' => $last_system_login ); + } else { + $ldap_entry->add( 'gosaLastSystemLogin' => $last_system_login ); + } + my $result = $ldap_entry->update($ldap_handle); + if ($result->code() != 0) { + &main::daemon_log("$session_id ERROR: setting 'gosaLastSystem' and 'gosaLastSystemLogin' of system '$mac' failed: ". + $result->{'errorMessage'}, 1); + &main::daemon_log("$session_id ERROR: $msg", 1); + + } + } + + return; +} + + + # vim:ts=4:shiftwidth:expandtab 1; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 450a377f5..fd1d52dbb 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -59,7 +59,7 @@ for($count = 1; $count <= $zahl; $count++) # trigger jobs at client - $data = "
gosa_trigger_goto_settings_reload
00:01:6c:9d:b9:fa GOSA
"; + #$data = "
gosa_trigger_goto_settings_reload
00:01:6c:9d:b9:fa GOSA
"; #$data = "
gosa_detect_hardware
10.89.1.31:20083 GOSA
"; #$data = "
gosa_new_key_for_client
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; #$data = "
job_trigger_action_wake
00:01:6c:9d:b9:fa GOSA 19700101000000
"; @@ -83,6 +83,8 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_send_user_msg
GOSA GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; #$data = "
gosa_send_user_msg
10.89.1.30:20081 GOSA ".base64_encode("eine wichtige nachricht")." admin polle harald 20130101235959 ".base64_encode("kaffeepause")."
"; #$data = "
gosa_send_user_msg
10.89.1.30:20081 GOSA ".base64_encode("eine wichtige nachricht")." admin rettenbe 20130101235959 ".base64_encode("kaffeepause")."
"; + + $data = "
gosa_set_last_system
10.89.1.31:20082 GOSA 00:01:6c:9d:b9:fa 1.2.3.4 20081212000000
"; ################## # recreate fai dbs diff --git a/gosa-si/tests/deploy-gosa-si.pl b/gosa-si/tests/deploy-gosa-si.pl index 71d768464..3a19cf441 100755 --- a/gosa-si/tests/deploy-gosa-si.pl +++ b/gosa-si/tests/deploy-gosa-si.pl @@ -24,42 +24,42 @@ use warnings; my $gosa_path = "/home/rettenbe/gonicus/Projekte/gosa/trunk/gosa-si/"; my %copies = ( - "gosa-si-server"=> "/usr/sbin/gosa-si-server", - "gosa-si-client"=> "/usr/sbin/gosa-si-client", + "/usr/sbin/gosa-si-server" => "gosa-si-server", + "/usr/sbin/gosa-si-client" => "gosa-si-client", - "modules/GosaPackages.pm" => "/usr/lib/gosa-si/modules/GosaPackages.pm", - "modules/ClientPackages.pm" => "/usr/lib/gosa-si/modules/ClientPackages.pm", - "modules/ServerPackages.pm" => "/usr/lib/gosa-si/modules/ServerPackages.pm", - "modules/ArpHandler.pm" => "/usr/lib/gosa-si/modules/ArpHandler.pm", - - "modules/DBsqlite.pm" => "/usr/share/perl5/GOSA/DBsqlite.pm", - "modules/DBmysql.pm" => "/usr/share/perl5/GOSA/DBmysql.pm", - "modules/GosaSupportDaemon.pm" => "/usr/share/perl5/GOSA/GosaSupportDaemon.pm", - - "server/events/clMessages.pm" => "/usr/lib/gosa-si/server/ClientPackages/clMessages.pm", - "server/events/siTriggered" => "/usr/lib/gosa-si/server/ClientPackages/siTriggered.pm", - - "server/events/databases.pm" => "/usr/lib/gosa-si/server/GosaPackages/databases.pm", - "server/events/gosaTriggered.pm" => "/usr/lib/gosa-si/server/GosaPackages/gosaTriggered.pm", - "server/events/logHandling.pm" => "/usr/lib/gosa-si/server/GosaPackages/logHandling.pm", - "server/events/mailqueue_com.pm" => "/usr/lib/gosa-si/server/GosaPackages/mailqueue_com.pm", - "server/events/opsi_com.pm" => "/usr/lib/gosa-si/server/GosaPackages/opsi_com.pm", - - "server/events/opsi_com.pm" => "/usr/lib/gosa-si/server/ServerPackages/opsi_com.pm", - "server/events/databases.pm" => "/usr/lib/gosa-si/server/ServerPackages/databases.pm", - "server/events/gosaTriggered.pm" => "/usr/lib/gosa-si/server/ServerPackages/gosaTriggered.pm", - "server/events/logHandling.pm" => "/usr/lib/gosa-si/server/ServerPackages/logHandling.pm", - "server/events/mailqueue_com.pm" => "/usr/lib/gosa-si/server/ServerPackages/mailqueue_com.pm", - "server/events/server_server_com.pm" => "/usr/lib/gosa-si/server/ServerPackages/server_server_com.pm", - - "client/events/corefunctions.pm" => "/usr/lib/gosa-si/client/events/corefunctions.pm", - "client/events/dak.pm" => "/usr/lib/gosa-si/client/events/dak.pm", - "client/events/gosaTriggered.pm" => "/usr/lib/gosa-si/client/events/gosaTriggered.pm", - "client/events/installation.pm" => "/usr/lib/gosa-si/client/events/installation.pm", - "client/events/mailqueue.pm" => "/usr/lib/gosa-si/client/events/mailqueue.pm", + "/usr/lib/gosa-si/modules/GosaPackages.pm" => "modules/GosaPackages.pm", + "/usr/lib/gosa-si/modules/ClientPackages.pm" => "modules/ClientPackages.pm", + "/usr/lib/gosa-si/modules/ServerPackages.pm" => "modules/ServerPackages.pm", + "/usr/lib/gosa-si/modules/ArpHandler.pm" => "modules/ArpHandler.pm", + + "/usr/share/perl5/GOSA/DBsqlite.pm" => "modules/DBsqlite.pm", + "/usr/share/perl5/GOSA/DBmysql.pm" => "modules/DBmysql.pm", + "/usr/share/perl5/GOSA/GosaSupportDaemon.pm" => "modules/GosaSupportDaemon.pm", + + "/usr/lib/gosa-si/server/ClientPackages/clMessages.pm" => "server/events/clMessages.pm", + "/usr/lib/gosa-si/server/ClientPackages/siTriggered.pm" => "server/events/siTriggered.pm", + + "/usr/lib/gosa-si/server/GosaPackages/databases.pm" => "server/events/databases.pm", + "/usr/lib/gosa-si/server/GosaPackages/gosaTriggered.pm" => "server/events/gosaTriggered.pm", + "/usr/lib/gosa-si/server/GosaPackages/logHandling.pm" => "server/events/logHandling.pm", + "/usr/lib/gosa-si/server/GosaPackages/mailqueue_com.pm" => "server/events/mailqueue_com.pm", + "/usr/lib/gosa-si/server/GosaPackages/opsi_com.pm" => "server/events/opsi_com.pm", + + "/usr/lib/gosa-si/server/ServerPackages/opsi_com.pm" => "server/events/opsi_com.pm", + "/usr/lib/gosa-si/server/ServerPackages/databases.pm" => "server/events/databases.pm" , + "/usr/lib/gosa-si/server/ServerPackages/gosaTriggered.pm" => "server/events/gosaTriggered.pm" , + "/usr/lib/gosa-si/server/ServerPackages/logHandling.pm" => "server/events/logHandling.pm", + "/usr/lib/gosa-si/server/ServerPackages/mailqueue_com.pm" => "server/events/mailqueue_com.pm" , + "/usr/lib/gosa-si/server/ServerPackages/server_server_com.pm" => "server/events/server_server_com.pm" , + + "/usr/lib/gosa-si/client/events/corefunctions.pm" => "client/events/corefunctions.pm", + "/usr/lib/gosa-si/client/events/dak.pm" => "client/events/dak.pm" , + "/usr/lib/gosa-si/client/events/gosaTriggered.pm" => "client/events/gosaTriggered.pm", + "/usr/lib/gosa-si/client/events/installation.pm" => "client/events/installation.pm", + "/usr/lib/gosa-si/client/events/mailqueue.pm" => "client/events/mailqueue.pm", ); -while( my($file_name, $new_file) = each %copies ) { +while( my($new_file, $file_name) = each %copies ) { #print STDERR "copy ../$file_name to $new_file\n"; #system("cp ../$file_name $new_file"); -- 2.30.2