From ab2d97c8d992a34081be225f830b7245aa8525b1 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Mon, 10 Mar 2008 12:12:24 +0000 Subject: [PATCH] change procedure keeping jobqueue up-to-date, closes #359 git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9556 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/gosaTriggered.pm | 42 +++- gosa-si/gosa-si-client | 5 +- gosa-si/gosa-si-server | 164 +++++++++++++- gosa-si/modules/GosaPackages.pm | 11 + gosa-si/modules/GosaSupportDaemon.pm | 22 ++ gosa-si/server/events/clMessages.pm | 297 ++++++++++++++----------- gosa-si/server/events/gosaTriggered.pm | 157 +------------ 7 files changed, 405 insertions(+), 293 deletions(-) diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index d6efde3b8..ec01c4467 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -19,7 +19,7 @@ my @events = ( use strict; use warnings; use utf8; - +use GOSA::GosaSupportDaemon; BEGIN {} @@ -79,6 +79,46 @@ sub trigger_action_faireboot { sub trigger_action_reboot { my ($msg, $msg_hash) = @_; + my $timeout; + + if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) { + $timeout = -1; + } + else { + $timeout = @{$msg_hash->{timeout}}[0]; + } + + # check logged in user + my @user_list = &get_logged_in_users; + if( @user_list >= 1 ) { + # TODO do something + } + else { + $timeout = 0; + } + + # execute function + if( $timeout == 0 ) { + print STDERR ("shutdown -r +$timeout\n"); + } + elsif( $timeout > 0 ) { + print STDERR ("shutdown -r +$timeout\n"); + } + elsif( $timeout < 0 ) { + print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n"; + open(FILE, "> /etc/gosa-si/event"); + print FILE "trigger_action_reboot\n"; + close(FILE); + } + else { + # TODO do something, error handling, logging + } + + return; + + + + print STDERR "jetzt würde ich trigger_action_reboot ausführen\n"; return; } diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 6e4fdc38d..4841038ca 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -899,7 +899,7 @@ sub import_events { eval{ require $event; }; if( $@ ) { daemon_log("ERROR: import of event module '$event' failed", 1); - daemon_log("$@", 8); + daemon_log("$@", 1); next; } @@ -1076,7 +1076,8 @@ sub server_input { $REGISTERED = 1; } else { - &send_msg_to_target($answer, $server_address, $server_key); + $answer =~ /
(\S+)<\/header>/; + &send_msg_to_target($answer, $server_address, $server_key, $1); } # postprocessing diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index d664cadc3..c721cd18f 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -414,7 +414,7 @@ sub check_key_and_xml_validity { $msg = &decrypt_msg($crypted_msg, $module_key); if ($msg =~ //i){ - &main::daemon_log("decrypted_msg: \n$msg", 8); + daemon_log("decrypted_msg: \n$msg", 8); $msg_hash = $xml->XMLin($msg, ForceArray=>1); ############## @@ -443,7 +443,7 @@ sub check_key_and_xml_validity { } }; if($@) { - &main::daemon_log("WARNING: do not understand the message: $@", 5); + daemon_log("WARNING: do not understand the message: $@", 5); $msg = undef; $msg_hash = undef; } @@ -547,7 +547,7 @@ sub input_from_known_server { } if( (!$msg) || (!$msg_hash) || (!$module) ) { - daemon_log("INFO: Incoming message is not from a known server", 5); + daemon_log("DEBUG: Incoming message is not from a known server", 7); } return ($msg, $msg_hash, $module); @@ -584,7 +584,7 @@ sub input_from_known_client { } if( (!$msg) || (!$msg_hash) || (!$module) ) { - &daemon_log("INFO: Incoming message is not from a known client", 5); + &daemon_log("DEBUG: Incoming message is not from a known client", 5); } return ($msg, $msg_hash, $module); @@ -624,7 +624,7 @@ sub input_from_unknown_host { } if( (!$msg) || (!$msg_hash) || (!$module)) { - daemon_log("INFO: Incoming message is not from an unknown host", 5); + daemon_log("DEBUG: Incoming message is not from an unknown host", 7); } return ($msg, $msg_hash, $module); @@ -897,7 +897,15 @@ sub send_msg_to_target { return $error; } - +### +# +# HIER LÄUFT WAS SCHIEF - GENAU HIER KACK MIST +# +# ERROR +# +# TODO +# +### sub update_jobdb_status_for_send_msgs { my ($answer, $error) = @_; if( $answer =~ /(\d+)<\/jobdb_id>/ ) { @@ -912,7 +920,7 @@ sub update_jobdb_status_for_send_msgs { # sending msg was successful my $sql_statement = "UPDATE $job_queue_tn ". "SET status='done' ". - "WHERE id='$jobdb_id'"; + "WHERE id='$jobdb_id' AND status='processed'"; my $res = $job_db->update_dbentry($sql_statement); } } @@ -938,8 +946,9 @@ sub client_input { my ($answer_header, @answer_target_l, $answer_source); my $client_answer; + daemon_log("", 5); daemon_log("INFO: Incoming msg from '".$heap->{'remote_ip'}."'", 5); - daemon_log("DEBUG: Incoming message:\n$input", 8); + daemon_log("DEBUG: Incoming message:\n$input", 9); #################### # check incoming msg @@ -1226,6 +1235,141 @@ sub refresh_ldap_handle { } +sub change_fai_state { + my ($st, $targets) = @_; + + # Set FAI state to localboot + my %mapActions= ( + reboot => '', + update => 'softupdate', + localboot => 'localboot', + reinstall => 'install', + rescan => '', + wake => '', + memcheck => 'memcheck', + sysinfo => 'sysinfo', + ); + + # Return if this is unknown + if (!exists $mapActions{ $st }){ + return; + } + + my $state= $mapActions{ $st }; + + &refresh_ldap_handle(); + if( defined($ldap_handle) ) { + + # Build search filter for hosts + my $search= "(&(objectClass=GOhard)"; + foreach (@{$targets}){ + $search.= "(macAddress=$_)"; + } + $search.= ")"; + + # If there's any host inside of the search string, procress them + if (!($search =~ /macAddress/)){ + return; + } + + # Perform search for Unit Tag + my $mesg = $ldap_handle->search( + base => $ldap_base, + scope => 'sub', + attrs => ['dn', 'FAIstate', 'objectClass'], + filter => "$search" + ); + + if ($mesg->count) { + my @entries = $mesg->entries; + foreach my $entry (@entries) { + + # Only modify entry if it is not set to '$state' + if ($entry->get_value("FAIstate") ne "$state"){ + + daemon_log("INFO: Setting FAIstate to '$state' for ".$entry->dn, 5); + my $result; + my %tmp = map { $_ => 1 } $entry->get_value("objectClass"); + if (exists $tmp{'FAIobject'}){ + if ($state eq ''){ + $result= $ldap_handle->modify($entry->dn, changes => [ + delete => [ FAIstate => [] ] ]); + } else { + $result= $ldap_handle->modify($entry->dn, changes => [ + replace => [ FAIstate => $state ] ]); + } + } elsif ($state ne ''){ + $result= $ldap_handle->modify($entry->dn, changes => [ + add => [ objectClass => 'FAIobject' ], + add => [ FAIstate => $state ] ]); + } + + # Errors? + if ($result->code){ + daemon_log("Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1); + } + + } + } + } + } +} + + +sub change_goto_state { + my ($st, $targets) = @_; + + # Switch on or off? + my $state= $st eq 'active' ? 'active': 'locked'; + + &refresh_ldap_handle(); + if( defined($ldap_handle) ) { + + # Build search filter for hosts + my $search= "(&(objectClass=GOhard)"; + foreach (@{$targets}){ + $search.= "(macAddress=$_)"; + } + $search.= ")"; + + # If there's any host inside of the search string, procress them + if (!($search =~ /macAddress/)){ + return; + } + + # Perform search for Unit Tag + my $mesg = $ldap_handle->search( + base => $ldap_base, + scope => 'sub', + attrs => ['dn', 'gotoMode'], + filter => "$search" + ); + + if ($mesg->count) { + my @entries = $mesg->entries; + foreach my $entry (@entries) { + + # Only modify entry if it is not set to '$state' + if ($entry->get_value("gotoMode") ne $state){ + + daemon_log("INFO: Setting gotoMode to '$state' for ".$entry->dn, 5); + my $result; + $result= $ldap_handle->modify($entry->dn, changes => [ + replace => [ gotoMode => $state ] ]); + + # Errors? + if ($result->code){ + &daemon_log("Error: Setting gotoMode to '$state' for ".$entry->dn. "failed: ".$result->error, 1); + } + + } + } + } + + } +} + + sub create_fai_server_db { my ($table_name) = $_[ARG0]; my $result; @@ -1233,7 +1377,7 @@ sub create_fai_server_db { if(defined($ldap_handle)) { daemon_log("Creating fai_server_db",4); my $mesg= $ldap_handle->search( - base => $main::ldap_base, + base => $ldap_base, scope => 'sub', attrs => ['FAIrepository', 'gosaUnitTag'], filter => "(&(FAIrepository=*)(objectClass=FAIrepositoryServer))", @@ -1271,7 +1415,7 @@ sub create_fai_release_db { if(defined($ldap_handle)) { daemon_log("Creating fai_release_db",4); my $mesg= $ldap_handle->search( - base => $main::ldap_base, + base => $ldap_base, scope => 'sub', attrs => [], filter => "(&(objectClass=organizationalUnit)(ou=fai))", diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 8aa17e531..d5a0a6b4b 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -315,6 +315,17 @@ sub process_gosa_msg { @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); } + # if incoming 'gosa_'-msg is scheduled from job_queue, than it contains xml-tag 'jobdb_id' + # after procesing this msg, set status of this job in job_queue to done + if ($msg =~ /(\d+)<\/jobdb_id>/) { + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done' ". + "WHERE id='$1'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: set job '$1' to status processed", 5); + } + # if delivery not possible raise error and return if( not defined $out_msg_l[0] ) { &main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3); diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index e33c83eaa..de26b59b5 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -18,6 +18,7 @@ my @functions = ( "get_limit_statement", "get_orderby_statement", "get_dns_domains", + "get_logged_in_users", ); @EXPORT = @functions; use strict; @@ -386,4 +387,25 @@ sub get_dns_domains() { return @searches; } + +sub get_logged_in_users { + my $result = qx(/usr/bin/w -hs); + my @res_lines; + + if( defined $result ) { + chomp($result); + @res_lines = split("\n", $result); + } + + my @logged_in_user_list; + foreach my $line (@res_lines) { + chomp($line); + my @line_parts = split(/\s+/, $line); + push(@logged_in_user_list, $line_parts[0]); + } + + return @logged_in_user_list; + +} + 1; diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 088ce5ab7..0ec31d5c1 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -169,56 +169,171 @@ sub CURRENTLY_LOGGED_IN { sub GOTOACTIVATION { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + eval{ if( 0 == keys(%$content) ) { $content = ""; } }; + if( $@ ) { $content = "$content"; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header"."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress'", 5); + return; } sub PROGRESS { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_progress_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content; + my $cont = @{$msg_hash->{$header}}[0]; + eval{ if( 0 == keys(%$cont) ) { $content = ""; } }; + if( $@ ) { $content = "$cont"; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET progress='$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - $content%", 5); + + return; } sub FAIREBOOT { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + eval{ if( 0 == keys(%$content) ) { $content = ""; } }; + if( $@ ) { $content = "$content"; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + + return; } sub TASKSKIP { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + eval{ if( 0 == keys(%$content) ) { $content = ""; } }; + if( $@ ) { $content = "$content"; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + + return; } sub TASKBEGIN { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + my $content = @{$msg_hash->{$header}}[0]; + + # test whether content is an empty hash or a string which is required + eval{ if( 0 == keys(%$content) ) { $content = ""; } }; + if( $@ ) { $content = "$content"; } + + # clean up header + $header =~ s/CLMSG_//g; + + # check if installation finished + if (($content eq 'finish') || ($content eq 'faiend')){ + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done', result='$header "."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + + # set fai_state to localboot + &main::change_fai_state('localboot', \@{$msg_hash->{target}}); + + } else { + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + # -----------------------> Update hier # finish #
CLMSG_TASKBEGIN
# macaddress auslesen, Client im LDAP lokalisieren # FAIstate auf "localboot" setzen, wenn FAIstate "install" oder "softupdate" war + } - return @out_msg_l; + return; } sub TASKEND { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + eval{ if( 0 == keys(%$content) ) { $content = ""; } }; + if( $@ ) { $content = "$content"; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); # -----------------------> Update hier # finish @@ -226,14 +341,30 @@ sub TASKEND { # macaddress auslesen, Client im LDAP lokalisieren # FAIstate auf "error" setzen - return @out_msg_l; + return; } sub TASKERROR { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # clean up header + $header =~ s/CLMSG_//g; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + eval{ if( 0 == keys(%$content) ) { $content = ""; } }; + if( $@ ) { $content = "$content"; } + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); # -----------------------> Update hier # finish @@ -241,136 +372,32 @@ sub TASKERROR { # macaddress auslesen, Client im LDAP lokalisieren # FAIstate auf "error" setzen - return @out_msg_l; + return; } sub HOOK { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; -} - - -sub build_status_result_update_msg { - my ($msg_hash) = @_; - my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'target'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; my $macaddress = @{$msg_hash->{'macaddress'}}[0]; - # test whether content is an empty hash or a string which is required - my $content = @{$msg_hash->{$header}}[0]; - eval{ - if( 0 == keys(%$content) ) { - $content = ""; - } - }; - if( $@ ) { - $content = " $content"; - } - + # clean up header $header =~ s/CLMSG_//g; - my $out_msg = sprintf(" ". - "
gosa_update_status_jobdb_entry
". - "%s ". - "%s". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - "
", $source, "JOBDB", $macaddress, $header.$content); - return $out_msg; -} - - -sub build_progress_update_msg { - my ($msg_hash) = @_; - - my $header = @{$msg_hash->{'header'}}[0]; - my $source = @{$msg_hash->{'target'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; - my $macaddress = @{$msg_hash->{'macaddress'}}[0]; # test whether content is an empty hash or a string which is required my $content = @{$msg_hash->{$header}}[0]; - eval{ - if( 0 == keys(%$content) ) { - $content = ""; - } - }; - if( $@ ) { - $content = "$content"; - } - - $header =~ s/CLMSG_//g; - my $out_msg = sprintf(" ". - "
gosa_update_status_jobdb_entry
". - "%s ". - "%s". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - " ". - " ". - " ". - "%s ". - " ". - "
", $source, "JOBDB", $macaddress, $content); - return $out_msg; -} + eval{ if( 0 == keys(%$content) ) { $content = ""; } }; + if( $@ ) { $content = "$content"; } + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress='$macaddress'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); -sub build_result_update_msg { - my ($msg_hash) = @_; - - my $header = @{$msg_hash->{'header'}}[0]; - my $source = @{$msg_hash->{'target'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; - my $macaddress = @{$msg_hash->{'macaddress'}}[0]; - - # test whether content is an empty hash or a string which is required - my $content = @{$msg_hash->{$header}}[0]; - eval{ - if( 0 == keys(%$content) ) { - $content = ""; - } - }; - if( $@ ) { - $content = " $content"; - } - - $header =~ s/CLMSG_//g; - my $out_msg = sprintf(" ". - "
gosa_update_status_jobdb_entry
". - "%s ". - "%s". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - " ". - " ". - " ". - "%s ". - " ". - "
", $source, "JOBDB", $macaddress, $header.$content); - return $out_msg; + return; } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index a0c885321..973d2b603 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -299,8 +299,8 @@ sub trigger_action_faireboot { $msg =~ s/
gosa_trigger_action_faireboot<\/header>/
trigger_action_faireboot<\/header>/; push(@out_msg_l, $msg); - change_goto_state('locked', \@{$msg_hash->{target}}); - change_fai_state('localboot', \@{$msg_hash->{target}}); + &main::change_goto_state('locked', \@{$msg_hash->{target}}); + &main::change_fai_state('localboot', \@{$msg_hash->{target}}); # delete all jobs from jobqueue which correspond to fai my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ". @@ -316,7 +316,7 @@ sub trigger_action_lock { my $macaddress = @{$msg_hash->{target}}[0]; my $source = @{$msg_hash->{source}}[0]; - change_goto_state('locked', \@{$msg_hash->{target}}); + &main::change_goto_state('locked', \@{$msg_hash->{target}}); my @out_msg_l; return @out_msg_l; @@ -328,7 +328,7 @@ sub trigger_action_activate { my $macaddress = @{$msg_hash->{target}}[0]; my $source = @{$msg_hash->{source}}[0]; - change_goto_state('active', \@{$msg_hash->{target}}); + &main::change_goto_state('active', \@{$msg_hash->{target}}); my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress); if( exists $msg_hash->{'jobdb_id'} ) { @@ -344,7 +344,7 @@ sub trigger_action_localboot { my ($msg, $msg_hash) = @_; $msg =~ s/
gosa_trigger_action_localboot<\/header>/
trigger_action_localboot<\/header>/; - change_fai_state('localboot', \@{$msg_hash->{target}}); + &main::change_fai_state('localboot', \@{$msg_hash->{target}}); my @out_msg_l = ($msg); return @out_msg_l; @@ -355,7 +355,7 @@ sub trigger_action_halt { my ($msg, $msg_hash) = @_; $msg =~ s/
gosa_trigger_action_halt<\/header>/
trigger_action_halt<\/header>/; - change_fai_state('halt', \@{$msg_hash->{target}}); + &main::change_fai_state('halt', \@{$msg_hash->{target}}); my @out_msg_l = ($msg); return @out_msg_l; @@ -366,7 +366,7 @@ sub trigger_action_reboot { my ($msg, $msg_hash) = @_; $msg =~ s/
gosa_trigger_action_reboot<\/header>/
trigger_action_reboot<\/header>/; - change_fai_state('reboot', \@{$msg_hash->{target}}); + &main::change_fai_state('reboot', \@{$msg_hash->{target}}); my @out_msg_l = ($msg); return @out_msg_l; @@ -377,7 +377,7 @@ sub trigger_action_memcheck { my ($msg, $msg_hash) = @_ ; $msg =~ s/
gosa_trigger_action_memcheck<\/header>/
trigger_action_memcheck<\/header>/; - change_fai_state('memcheck', \@{$msg_hash->{target}}); + &main::change_fai_state('memcheck', \@{$msg_hash->{target}}); my @out_msg_l = ($msg); return @out_msg_l; @@ -388,7 +388,7 @@ sub trigger_action_reinstall { my ($msg, $msg_hash) = @_; $msg =~ s/
gosa_trigger_action_reinstall<\/header>/
trigger_action_reinstall<\/header>/; - change_fai_state('reinstall', \@{$msg_hash->{target}}); + &main::change_fai_state('reinstall', \@{$msg_hash->{target}}); my %data = ( 'macAddress' => \@{$msg_hash->{target}} ); my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); @@ -401,7 +401,7 @@ sub trigger_action_update { my ($msg, $msg_hash) = @_; $msg =~ s/
gosa_trigger_action_update<\/header>/
trigger_action_update<\/header>/; - change_fai_state('update', \@{$msg_hash->{target}}); + &main::change_fai_state('update', \@{$msg_hash->{target}}); my %data = ( 'macAddress' => \@{$msg_hash->{target}} ); my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); @@ -414,7 +414,7 @@ sub trigger_action_instant_update { my ($msg, $msg_hash) = @_; $msg =~ s/
gosa_trigger_action_instant_update<\/header>/
trigger_action_instant_update<\/header>/; - change_fai_state('update', \@{$msg_hash->{target}}); + &main::change_fai_state('update', \@{$msg_hash->{target}}); my %data = ( 'macAddress' => \@{$msg_hash->{target}} ); my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); @@ -427,7 +427,7 @@ sub trigger_action_sysinfo { my ($msg, $msg_hash) = @_; $msg =~ s/
gosa_trigger_action_sysinfo<\/header>/
trigger_action_sysinfo<\/header>/; - change_fai_state('sysinfo', \@{$msg_hash->{target}}); + &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}); my @out_msg_l = ($msg); return @out_msg_l; @@ -459,137 +459,4 @@ sub trigger_action_wake { } -sub change_fai_state { - my ($st, $targets) = @_; - - # Set FAI state to localboot - my %mapActions= ( - reboot => '', - update => 'softupdate', - localboot => 'localboot', - reinstall => 'install', - rescan => '', - wake => '', - memcheck => 'memcheck', - sysinfo => 'sysinfo', - ); - - # Return if this is unknown - if (!exists $mapActions{ $st }){ - return; - } - - my $state= $mapActions{ $st }; - - &main::refresh_ldap_handle(); - if( defined($main::ldap_handle) ) { - - # Build search filter for hosts - my $search= "(&(objectClass=GOhard)"; - foreach (@{$targets}){ - $search.= "(macAddress=$_)"; - } - $search.= ")"; - - # If there's any host inside of the search string, procress them - if (!($search =~ /macAddress/)){ - return; - } - - # Perform search for Unit Tag - my $mesg = $main::ldap_handle->search( - base => $main::ldap_base, - scope => 'sub', - attrs => ['dn', 'FAIstate', 'objectClass'], - filter => "$search" - ); - - if ($mesg->count) { - my @entries = $mesg->entries; - foreach my $entry (@entries) { - - # Only modify entry if it is not set to '$state' - if ($entry->get_value("FAIstate") ne "$state"){ - - &main::daemon_log("INFO: Setting FAIstate to '$state' for ".$entry->dn, 5); - my $result; - my %tmp = map { $_ => 1 } $entry->get_value("objectClass"); - if (exists $tmp{'FAIobject'}){ - if ($state eq ''){ - $result= $main::ldap_handle->modify($entry->dn, changes => [ - delete => [ FAIstate => [] ] ]); - } else { - $result= $main::ldap_handle->modify($entry->dn, changes => [ - replace => [ FAIstate => $state ] ]); - } - } elsif ($state ne ''){ - $result= $main::ldap_handle->modify($entry->dn, changes => [ - add => [ objectClass => 'FAIobject' ], - add => [ FAIstate => $state ] ]); - } - - # Errors? - if ($result->code){ - &main::daemon_log("Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1); - } - - } - } - } - } -} - - -sub change_goto_state { - my ($st, $targets) = @_; - - # Switch on or off? - my $state= $st eq 'active' ? 'active': 'locked'; - - &main::refresh_ldap_handle(); - if( defined($main::ldap_handle) ) { - - # Build search filter for hosts - my $search= "(&(objectClass=GOhard)"; - foreach (@{$targets}){ - $search.= "(macAddress=$_)"; - } - $search.= ")"; - - # If there's any host inside of the search string, procress them - if (!($search =~ /macAddress/)){ - return; - } - - # Perform search for Unit Tag - my $mesg = $main::ldap_handle->search( - base => $main::ldap_base, - scope => 'sub', - attrs => ['dn', 'gotoMode'], - filter => "$search" - ); - - if ($mesg->count) { - my @entries = $mesg->entries; - foreach my $entry (@entries) { - - # Only modify entry if it is not set to '$state' - if ($entry->get_value("gotoMode") ne $state){ - - &main::daemon_log("INFO: Setting gotoMode to '$state' for ".$entry->dn, 5); - my $result; - $result= $main::ldap_handle->modify($entry->dn, changes => [ - replace => [ gotoMode => $state ] ]); - - # Errors? - if ($result->code){ - &main::daemon_log("Error: Setting gotoMode to '$state' for ".$entry->dn. "failed: ".$result->error, 1); - } - - } - } - } - - } -} 1; -- 2.30.2