From f79339e4269f219dd33f1ba4cd9a98817d7d810b Mon Sep 17 00:00:00 2001 From: rettenbe Date: Thu, 13 Mar 2008 17:02:39 +0000 Subject: [PATCH] better multitasking and job queue handling git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9757 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 168 ++++++++++---------- gosa-si/modules/GosaPackages.pm | 54 +++---- gosa-si/modules/SIPackages.pm | 62 ++++---- gosa-si/server/events/clMessages.pm | 53 ++++--- gosa-si/server/events/gosaTriggered.pm | 204 ++++++++++++++++++++----- gosa-si/server/events/siTriggered.pm | 4 +- gosa-si/tests/client.php | 8 +- 7 files changed, 348 insertions(+), 205 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 6bd1998cf..47dc89b41 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -146,8 +146,9 @@ my $messaging_file_name; # path to directory to store client install log files our $client_fai_log_dir = "/var/log/fai"; -# queue which stores taskes while max_clients are reached +# queue which stores taskes until one of the $max_children children are ready to process the task my @tasks = qw(); +my $max_children = 2; %cfg_defaults = ( @@ -418,7 +419,7 @@ $SIG{INT} = \&sig_int_handler; sub check_key_and_xml_validity { - my ($crypted_msg, $module_key) = @_; + my ($crypted_msg, $module_key, $session_id) = @_; my $msg; my $msg_hash; my $error_string; @@ -426,7 +427,8 @@ sub check_key_and_xml_validity { $msg = &decrypt_msg($crypted_msg, $module_key); if ($msg =~ //i){ - daemon_log("decrypted_msg: \n$msg", 8); + $msg =~ s/\s+/ /g; # just for better daemon_log + daemon_log("$session_id DEBUG: decrypted_msg: \n$msg", 8); $msg_hash = $xml->XMLin($msg, ForceArray=>1); ############## @@ -455,7 +457,7 @@ sub check_key_and_xml_validity { } }; if($@) { - daemon_log("WARNING: do not understand the message: $@", 5); + daemon_log("$session_id DEBUG: do not understand the message: $@", 7); $msg = undef; $msg_hash = undef; } @@ -528,7 +530,7 @@ sub check_outgoing_xml_validity { sub input_from_known_server { - my ($input, $remote_ip) = @_ ; + my ($input, $remote_ip, $session_id) = @_ ; my ($msg, $msg_hash, $module); my $sql_statement= "SELECT * FROM known_server"; @@ -540,13 +542,13 @@ sub input_from_known_server { next; } my $host_key = $hit->{hostkey}; - daemon_log("DEBUG: input_from_known_server: host_name: $host_name", 7); + daemon_log("$session_id DEBUG: input_from_known_server: host_name: $host_name", 7); daemon_log("DEBUG: input_from_known_server: host_key: $host_key", 7); # check if module can open msg envelope with module key - my ($tmp_msg, $tmp_msg_hash) = &check_key_and_xml_validity($input, $host_key); + my ($tmp_msg, $tmp_msg_hash) = &check_key_and_xml_validity($input, $host_key, $session_id); if( (!$tmp_msg) || (!$tmp_msg_hash) ) { - daemon_log("DEBUG: input_from_known_server: deciphering raise error", 7); + daemon_log("$session_id DEBUG: input_from_known_server: deciphering raise error", 7); daemon_log("$@", 8); next; } @@ -559,7 +561,7 @@ sub input_from_known_server { } if( (!$msg) || (!$msg_hash) || (!$module) ) { - daemon_log("DEBUG: Incoming message is not from a known server", 7); + daemon_log("$session_id DEBUG: Incoming message is not from a known server", 7); } return ($msg, $msg_hash, $module); @@ -567,7 +569,7 @@ sub input_from_known_server { sub input_from_known_client { - my ($input, $remote_ip) = @_ ; + my ($input, $remote_ip, $session_id) = @_ ; my ($msg, $msg_hash, $module); my $sql_statement= "SELECT * FROM known_clients"; @@ -578,14 +580,14 @@ sub input_from_known_client { next; } my $host_key = $hit->{hostkey}; - &daemon_log("DEBUG: input_from_known_client: host_name: $host_name", 7); - &daemon_log("DEBUG: input_from_known_client: host_key: $host_key", 7); + &daemon_log("$session_id DEBUG: input_from_known_client: host_name: $host_name", 7); + &daemon_log("$session_id DEBUG: input_from_known_client: host_key: $host_key", 7); # check if module can open msg envelope with module key - ($msg, $msg_hash) = &check_key_and_xml_validity($input, $host_key); + ($msg, $msg_hash) = &check_key_and_xml_validity($input, $host_key, $session_id); if( (!$msg) || (!$msg_hash) ) { - &daemon_log("DEGUG: input_from_known_client: deciphering raise error", 7); + &daemon_log("$session_id DEGUG: input_from_known_client: deciphering raise error", 7); &daemon_log("$@", 8); next; } @@ -596,7 +598,7 @@ sub input_from_known_client { } if( (!$msg) || (!$msg_hash) || (!$module) ) { - &daemon_log("DEBUG: Incoming message is not from a known client", 7); + &daemon_log("$session_id DEBUG: Incoming message is not from a known client", 7); } return ($msg, $msg_hash, $module); @@ -605,7 +607,7 @@ sub input_from_known_client { sub input_from_unknown_host { no strict "refs"; - my ($input) = @_ ; + my ($input, $session_id) = @_ ; my ($msg, $msg_hash, $module); my $error_string; @@ -619,13 +621,13 @@ sub input_from_unknown_host { if( $mod eq 'ArpHandler' ) { next; } - daemon_log("ERROR: no key specified in config file for $mod", 1); + daemon_log("$session_id ERROR: no key specified in config file for $mod", 1); next; } - daemon_log("DEBUG: $mod: $module_key", 7); + daemon_log("$session_id DEBUG: $mod: $module_key", 7); # check if module can open msg envelope with module key - ($msg, $msg_hash) = &check_key_and_xml_validity($input, $module_key); + ($msg, $msg_hash) = &check_key_and_xml_validity($input, $module_key, $session_id); if( (not defined $msg) || (not defined $msg_hash) ) { next; } @@ -636,7 +638,7 @@ sub input_from_unknown_host { } if( (!$msg) || (!$msg_hash) || (!$module)) { - daemon_log("DEBUG: Incoming message is not from an unknown host", 7); + daemon_log("$session_id DEBUG: Incoming message is not from an unknown host", 7); } return ($msg, $msg_hash, $module); @@ -819,7 +821,7 @@ sub get_local_ip_for_remote_ip { sub send_msg_to_target { - my ($msg, $address, $encrypt_key, $msg_header) = @_ ; + my ($msg, $address, $encrypt_key, $msg_header, $session_id) = @_ ; my $error = 0; my $header; my $new_status; @@ -844,7 +846,7 @@ sub send_msg_to_target { # opensocket my $socket = &open_socket($address); if( !$socket ) { - daemon_log("ERROR: cannot send ".$header."msg to $address , host not reachable", 1); + daemon_log("$session_id ERROR: cannot send ".$header."msg to $address , host not reachable", 1); $error++; } @@ -852,8 +854,8 @@ sub send_msg_to_target { # send xml msg print $socket $crypted_msg."\n"; - daemon_log("INFO: send ".$header."msg to $address", 5); - daemon_log("DEBUG: message:\n$msg", 9); + daemon_log("$session_id INFO: send ".$header."msg to $address", 5); + #daemon_log("DEBUG: message:\n$msg", 9); } @@ -874,14 +876,14 @@ sub send_msg_to_target { if( $act_status eq "down" ) { $sql_statement = "DELETE FROM known_clients WHERE hostname='$address'"; $res = $known_clients_db->del_dbentry($sql_statement); - daemon_log("WARNING: failed 2x to send msg to host '$address', delete host from known_clients", 3); + daemon_log("$session_id WARNING: failed 2x to send msg to host '$address', delete host from known_clients", 3); } else { $sql_statement = "UPDATE known_clients SET status='$new_status' WHERE hostname='$address'"; $res = $known_clients_db->update_dbentry($sql_statement); if($new_status eq "down"){ - daemon_log("WARNING: set '$address' from status '$act_status' to '$new_status'", 3); + daemon_log("$session_id WARNING: set '$address' from status '$act_status' to '$new_status'", 3); } else { - daemon_log("INFO: set '$address' from status '$act_status' to '$new_status'", 5); + daemon_log("$session_id INFO: set '$address' from status '$act_status' to '$new_status'", 5); } } } @@ -894,16 +896,16 @@ sub send_msg_to_target { if( $act_status eq "down" ) { $sql_statement = "DELETE FROM known_server WHERE hostname='$address'"; $res = $known_server_db->del_dbentry($sql_statement); - daemon_log("WARNING: failed 2x to a send msg to host '$address', delete host from known_server", 3); + daemon_log("$session_id WARNING: failed 2x to a send msg to host '$address', delete host from known_server", 3); } else { $sql_statement = "UPDATE known_server SET status='$new_status' WHERE hostname='$address'"; $res = $known_server_db->update_dbentry($sql_statement); if($new_status eq "down"){ - daemon_log("WARNING: set '$address' from status '$act_status' to '$new_status'", 3); + daemon_log("$session_id WARNING: set '$address' from status '$act_status' to '$new_status'", 3); } else { - daemon_log("INFO: set '$address' from status '$act_status' to '$new_status'", 5); + daemon_log("$session_id INFO: set '$address' from status '$act_status' to '$new_status'", 5); } } } @@ -915,16 +917,18 @@ sub update_jobdb_status_for_send_msgs { my ($answer, $error) = @_; if( $answer =~ /(\d+)<\/jobdb_id>/ ) { my $jobdb_id = $1; + + # sending msg faild if( $error ) { if (not $answer =~ /
trigger_action_reinstall<\/header>/) { - # sending msg faild my $sql_statement = "UPDATE $job_queue_tn ". "SET status='error', result='can not deliver msg, please consult log file' ". "WHERE id='$jobdb_id'"; my $res = $job_db->update_dbentry($sql_statement); } + + # sending msg was successful } else { - # sending msg was successful my $sql_statement = "UPDATE $job_queue_tn ". "SET status='done' ". "WHERE id='$jobdb_id' AND status='processed'"; @@ -943,7 +947,7 @@ sub _start { sub next_task { my ($session, $heap) = @_[SESSION, HEAP]; - while ( keys( %{ $heap->{task} } ) < $max_clients ) { + while ( keys( %{ $heap->{task} } ) < $max_children ) { my $next_task = shift @tasks; last unless defined $next_task; @@ -970,7 +974,10 @@ sub handle_task_result { $heap = $session_reference->get_heap(); } } - $heap->{'client'}->put($client_answer); + + if(exists $heap->{'client'}) { + $heap->{'client'}->put($client_answer); + } } $kernel->sig(CHLD => "child_reap"); } @@ -997,30 +1004,32 @@ sub process_task { my $client_answer = ""; daemon_log("", 5); - daemon_log("INFO: Incoming msg with session ID $session_id from '".$heap->{'remote_ip'}."'", 5); - daemon_log("DEBUG: Incoming msg:\n$input", 9); + daemon_log("$session_id INFO: Incoming msg with session ID $session_id from '".$heap->{'remote_ip'}."'", 5); + daemon_log("$session_id DEBUG: Incoming msg:\n$input", 9); #################### # check incoming msg # msg is from a new client or gosa - ($msg, $msg_hash, $module) = &input_from_unknown_host($input); + ($msg, $msg_hash, $module) = &input_from_unknown_host($input, $session_id); # msg is from a gosa-si-server or gosa-si-bus if(( !$msg ) || ( !$msg_hash ) || ( !$module )){ - ($msg, $msg_hash, $module) = &input_from_known_server($input, $heap->{'remote_ip'}); + ($msg, $msg_hash, $module) = &input_from_known_server($input, $heap->{'remote_ip'}, $session_id); } # msg is from a gosa-si-client if(( !$msg ) || ( !$msg_hash ) || ( !$module )){ - ($msg, $msg_hash, $module) = &input_from_known_client($input, $heap->{'remote_ip'}); + ($msg, $msg_hash, $module) = &input_from_known_client($input, $heap->{'remote_ip'}, $session_id); } # an error occurred if(( !$msg ) || ( !$msg_hash ) || ( !$module )){ + # if an incoming msg could not be decrypted (maybe a wrong key), send client a ping. If the client + # could not understand a msg from its server the client cause a re-registering process my $sql_statement = "SELECT * FROM $main::known_clients_tn WHERE (hostname LIKE '".$heap->{'remote_ip'}."%')"; my $query_res = $known_clients_db->select_dbentry( $sql_statement ); while( my ($hit_num, $hit) = each %{ $query_res } ) { my $host_name = $hit->{'hostname'}; my $host_key = $hit->{'hostkey'}; my $ping_msg = "
gosa_ping
$server_address $host_name
"; - my $error = &send_msg_to_target($ping_msg, $host_name, $host_key, "gosa_ping"); + my $error = &send_msg_to_target($ping_msg, $host_name, $host_key, "gosa_ping", $session_id); &update_jobdb_status_for_send_msgs($ping_msg, $error); } $error++; @@ -1029,13 +1038,13 @@ sub process_task { ###################### # process incoming msg if( $error == 0) { - daemon_log("INFO: Incoming msg with header '".@{$msg_hash->{'header'}}[0]."'", 5); - daemon_log("DEBUG: Processing module ".$module, 7); + daemon_log("$session_id INFO: Incoming msg with header '".@{$msg_hash->{'header'}}[0]."'", 5); + daemon_log("$session_id DEBUG: Processing module ".$module, 7); $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id); if ( 0 < @{$answer_l} ) { my $answer_str = join("\n", @{$answer_l}); - daemon_log("DEBUG: $module: Got answer from module: \n".$answer_str,8); + daemon_log("$session_id DEBUG: $module: Got answer from module: \n".$answer_str,8); } } if( !$answer_l ) { $error++ }; @@ -1068,7 +1077,7 @@ sub process_task { while( my ($hit_num, $hit) = each %{ $query_res } ) { my $host_name = $hit->{hostname}; my $host_key = $hit->{hostkey}; - my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header, $session_id); &update_jobdb_status_for_send_msgs($answer, $error); } } @@ -1082,14 +1091,14 @@ sub process_task { my $host_name = $hit->{hostname}; my $host_key = $hit->{hostkey}; $answer =~ s/KNOWN_SERVER/$host_name/g; - my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header, $session_id); &update_jobdb_status_for_send_msgs($answer, $error); } } # target of msg is GOsa elsif( $answer_target eq "GOSA" ) { - my $session_id = ($1) if $answer =~ s/(\d+?)<\/session_id>//; + my $session_id = ($1) if $answer =~ /(\d+?)<\/session_id>/; my $add_on = ""; if( defined $session_id ) { $add_on = ".session_id=$session_id"; @@ -1104,13 +1113,13 @@ sub process_task { $answer =~ /
(\S+)<\/header>/; my $header; if( defined $1 ) { $header = $1; } - my $error = &send_msg_to_target($answer, $server_address, $GosaPackages_key, $header); + my $error = &send_msg_to_target($answer, $server_address, $GosaPackages_key, $header, $session_id); &update_jobdb_status_for_send_msgs($answer, $error); } # target of msg is a mac address elsif( $answer_target =~ /^([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 ) { - daemon_log("INFO: target is mac address '$answer_target', looking for host in known_clients", 5); + daemon_log("$session_id INFO: target is mac address '$answer_target', looking for host in known_clients", 5); my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$answer_target'"; my $query_res = $known_clients_db->select_dbentry( $sql_statement ); my $found_ip_flag = 0; @@ -1118,21 +1127,21 @@ sub process_task { my $host_name = $hit->{hostname}; my $host_key = $hit->{hostkey}; $answer =~ s/$answer_target/$host_name/g; - daemon_log("INFO: found host '$host_name', associated to '$answer_target'", 5); - my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + daemon_log("$session_id INFO: found host '$host_name', associated to '$answer_target'", 5); + my $error = &send_msg_to_target($answer, $host_name, $host_key, $answer_header, $session_id); &update_jobdb_status_for_send_msgs($answer, $error); $found_ip_flag++ ; } if( $found_ip_flag == 0) { - daemon_log("WARNING: no host found in known_clients with mac address '$answer_target'", 3); + daemon_log("$session_id WARNING: no host found in known_clients with mac address '$answer_target'", 3); if( $bus_activ eq "true" ) { - daemon_log("INFO: try to forward msg '$answer_header' to bus '$bus_address'", 5); + daemon_log("$session_id INFO: try to forward msg '$answer_header' to bus '$bus_address'", 5); my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'"; my $query_res = $known_server_db->select_dbentry( $sql_statement ); while( my ($hit_num, $hit) = each %{ $query_res } ) { my $bus_address = $hit->{hostname}; my $bus_key = $hit->{hostkey}; - my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header, $session_id); &update_jobdb_status_for_send_msgs($answer, $error); last; } @@ -1146,27 +1155,27 @@ sub process_task { my $encrypt_key = &get_encrypt_key($answer_target); if( not defined $encrypt_key ) { # unknown target, forward msg to bus - daemon_log("WARNING: unknown target '$answer_target'", 3); + daemon_log("$session_id WARNING: unknown target '$answer_target'", 3); if( $bus_activ eq "true" ) { - daemon_log("INFO: try to forward msg '$answer_header' to bus '$bus_address'", 5); + daemon_log("$session_id INFO: try to forward msg '$answer_header' to bus '$bus_address'", 5); my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'"; my $query_res = $known_server_db->select_dbentry( $sql_statement ); my $res_length = keys( %{$query_res} ); if( $res_length == 0 ){ - daemon_log("WARNING: send '$answer_header' to '$bus_address' failed, ". + daemon_log("$session_id WARNING: send '$answer_header' to '$bus_address' failed, ". "no bus found in known_server", 3); } else { while( my ($hit_num, $hit) = each %{ $query_res } ) { my $bus_key = $hit->{hostkey}; - my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header,$session_id ); &update_jobdb_status_for_send_msgs($answer, $error); } } } next; } - my $error = &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header); + my $error = &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header,$session_id); &update_jobdb_status_for_send_msgs($answer, $error); } } @@ -1221,30 +1230,31 @@ sub watch_for_new_jobs { my $jobdb_id = $hit->{id}; my $macaddress = $hit->{'macaddress'}; my $job_msg = $hit->{'xmlmessage'}; - daemon_log("DEBUG: its time to execute $job_msg", 7); - my $header = $hit->{'headertag'}; + daemon_log("J DEBUG: its time to execute $job_msg", 7); my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$macaddress'"; my $res_hash = $known_clients_db->select_dbentry( $sql_statement ); # expect macaddress is unique!!!!!! my $target = $res_hash->{1}->{hostname}; - if (not defined $target) { - &daemon_log("ERROR: no host found for mac address: $macaddress", 1); - &daemon_log("$hit->{xmlmessage}", 8); - my $sql_statement = "UPDATE $job_queue_tn ". - "SET status='error', result='no host found for mac address' ". - "WHERE id='$jobdb_id'"; - my $res = $job_db->update_dbentry($sql_statement); - next; - } - +# if (not defined $target) { +# &daemon_log("ERROR: no host found for mac address: $macaddress", 1); +# &daemon_log("$hit->{xmlmessage}", 8); +# my $sql_statement = "UPDATE $job_queue_tn ". +# "SET status='error', result='no host found for mac address' ". +# "WHERE id='$jobdb_id'"; +# my $res = $job_db->update_dbentry($sql_statement); +# next; +# } +# # change header $job_msg =~ s/
job_/
gosa_/; # add sqlite_id $job_msg =~ s/<\/xml>$/$jobdb_id<\/jobdb_id><\/xml>/; - my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header); + $job_msg =~ /
(\S+)<\/header>/; + my $header = $1 ; + my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J"); # update status in job queue to 'processing' $sql_statement = "UPDATE $job_queue_tn SET status='processing' WHERE id='$jobdb_id'"; @@ -1290,7 +1300,8 @@ sub refresh_ldap_handle { sub change_fai_state { - my ($st, $targets) = @_; + my ($st, $targets, $session_id) = @_; + $session_id = 0 if not defined $session_id; # Set FAI state to localboot my %mapActions= ( @@ -1337,11 +1348,9 @@ sub change_fai_state { 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); + daemon_log("$session_id INFO: Setting FAIstate to '$state' for ".$entry->dn, 5); my $result; my %tmp = map { $_ => 1 } $entry->get_value("objectClass"); if (exists $tmp{'FAIobject'}){ @@ -1360,7 +1369,7 @@ sub change_fai_state { # Errors? if ($result->code){ - daemon_log("Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1); + daemon_log("$session_id Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1); } } @@ -1371,7 +1380,8 @@ sub change_fai_state { sub change_goto_state { - my ($st, $targets) = @_; + my ($st, $targets, $session_id) = @_; + $session_id = 0 if not defined $session_id; # Switch on or off? my $state= $st eq 'active' ? 'active': 'locked'; @@ -1406,14 +1416,14 @@ sub change_goto_state { # 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); + daemon_log("$session_id 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); + &daemon_log("$session_id Error: Setting gotoMode to '$state' for ".$entry->dn. "failed: ".$result->error, 1); } } diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index d5a0a6b4b..43c06a3ad 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -224,7 +224,7 @@ sub get_ip { sub import_events { if (not -e $event_dir) { - &main::daemon_log("ERROR: cannot find directory or directory is not readable: $event_dir", 1); + &main::daemon_log("G ERROR: cannot find directory or directory is not readable: $event_dir", 1); } opendir (DIR, $event_dir) or die "ERROR while loading gosa-si-events from directory $event_dir : $!\n"; @@ -235,7 +235,7 @@ sub import_events { eval{ require $event; }; if( $@ ) { - &main::daemon_log("ERROR: import of event module '$event' failed", 1); + &main::daemon_log("G ERROR: import of event module '$event' failed", 1); &main::daemon_log("$@", 1); next; } @@ -247,7 +247,7 @@ sub import_events { $event_hash->{$event_name} = $event_module; } my $events_string = join( ", ", @{$events_l}); - &main::daemon_log("INFO: GosaPackages imported events $events_string", 5); + &main::daemon_log("G INFO: GosaPackages imported events $events_string", 5); } } @@ -264,7 +264,7 @@ sub process_incoming_msg { my @msg_l; my @out_msg_l; - &main::daemon_log("DEBUG: GosaPackages: msg to process '$header'", 7); + &main::daemon_log("$session_id DEBUG: GosaPackages: msg to process '$header'", 7); if ($header =~ /^job_/) { @msg_l = &process_job_msg($msg, $msg_hash, $session_id); @@ -273,23 +273,23 @@ sub process_incoming_msg { @msg_l = &process_gosa_msg($msg, $msg_hash, $session_id); } else { - &main::daemon_log("ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix", 1); + &main::daemon_log("$session_id ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix", 1); } foreach my $out_msg ( @msg_l ) { - # keep job queue up-to-date and save result and status - if (defined ($out_msg) && $out_msg =~ /(\d+)<\/jobdb_id>/) { - my $job_id = $1; - my $sql = "UPDATE '".$main::job_queue_tn."'". - " SET status='processing'". - " WHERE id='$job_id'"; - my $res = $main::job_db->exec_statement($sql); - } +# # keep job queue up-to-date and save result and status +# if (defined ($out_msg) && $out_msg =~ /(\d+)<\/jobdb_id>/) { +# my $job_id = $1; +# my $sql = "UPDATE '".$main::job_queue_tn."'". +# " SET status='processing'". +# " WHERE id='$job_id'"; +# my $res = $main::job_db->exec_statement($sql); +# } # substitute in all outgoing msg GOSA of $server_address $out_msg =~ s/GOSA<\/source>/$server_address<\/source>/g; - + $out_msg =~ s/<\/xml>/$session_id<\/session_id><\/xml>/; if (defined $out_msg){ push(@out_msg_l, $out_msg); } @@ -310,28 +310,28 @@ sub process_gosa_msg { if( exists $event_hash->{$header} ) { # a event exists with the header as name - &main::daemon_log("INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); + &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); no strict 'refs'; @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 ($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 'done'", 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); +# &main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3); @out_msg_l = (); } elsif( $out_msg_l[0] eq 'nohandler') { - &main::daemon_log("ERROR: GosaPackages: no event handler or core function defined for '$header'", 1); + &main::daemon_log("$session_id ERROR: GosaPackages: no event handler or core function defined for '$header'", 1); @out_msg_l = (); } @@ -389,9 +389,9 @@ sub process_job_msg { my $res = $main::job_db->add_dbentry($func_dic); if (not $res == 0) { - &main::daemon_log("ERROR: GosaPackages: process_job_msg: $res", 1); + &main::daemon_log("$session_id ERROR: GosaPackages: process_job_msg: $res", 1); } else { - &main::daemon_log("INFO: GosaPackages: $header job successfully added to job queue", 5); + &main::daemon_log("$session_id INFO: GosaPackages: $header job successfully added to job queue", 5); } $out_msg = "
answer
$server_addressGOSA$res
"; } diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index 5d03cf44c..b06f3f2ef 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -390,7 +390,7 @@ sub process_incoming_msg { my $error = 0; my $host_name; my $host_key; - my @out_msg_l = (); + my @out_msg_l = ("nohandler"); # process incoming msg my $header = @{$msg_hash->{header}}[0]; @@ -399,10 +399,10 @@ sub process_incoming_msg { # skip PREFIX $header =~ s/^CLMSG_//; - &main::daemon_log("DEBUG: SIPackages: msg to process: $header", 7); + &main::daemon_log("$session_id DEBUG: SIPackages: msg to process: $header", 7); if( 0 == length @target_l){ - &main::daemon_log("ERROR: no target specified for msg $header", 1); + &main::daemon_log("$session_id ERROR: no target specified for msg $header", 1); $error++; } @@ -414,22 +414,24 @@ sub process_incoming_msg { if ($header eq 'new_key') { @out_msg_l = &new_key($msg_hash) } elsif ($header eq 'here_i_am') { - @out_msg_l = &here_i_am($msg_hash) + @out_msg_l = &here_i_am($msg_hash, $session_id) } else { if( exists $event_hash->{$header} ) { # a event exists with the header as name - &main::daemon_log("INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); + &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); no strict 'refs'; @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); } } # if delivery not possible raise error and return - if( not @out_msg_l ) { - &main::daemon_log("WARNING: SIPackages got no answer from event handler '$header'", 3); - } elsif( 0 == @out_msg_l) { - &main::daemon_log("ERROR: SIPackages: no event handler or core function defined for '$header'", 1); + if( not defined $out_msg_l[0] ) { + @out_msg_l = (); + } elsif( $out_msg_l[0] eq 'nohandler') { + &main::daemon_log("$session_id ERROR: SIPackages: no event handler or core function defined for '$header'", 1); + @out_msg_l = (); } + } else { &main::daemon_log("INFO: msg is not for gosa-si-server '$server_address', deliver it to target '$target'", 5); @@ -499,7 +501,7 @@ sub new_key { # DESCRIPTION: process this incoming message #=============================================================================== sub here_i_am { - my ($msg_hash) = @_; + my ($msg_hash, $session_id) = @_; my @out_msg_l; my $out_hash; @@ -515,16 +517,16 @@ sub here_i_am { my $db_res= $main::known_clients_db->select_dbentry( $sql_statement ); if ( 1 == keys %{$db_res} ) { - &main::daemon_log("WARNING: $source is already known as a client", 1); - &main::daemon_log("WARNING: values for $source are being overwritten", 1); + &main::daemon_log("$session_id WARNING: $source is already known as a client", 1); + &main::daemon_log("$session_id WARNING: values for $source are being overwritten", 1); $nu_clients --; } # number of actual activ clients my $act_nu_clients = $nu_clients; - &main::daemon_log("INFO: number of actual activ clients: $act_nu_clients", 5); - &main::daemon_log("INFO: number of maximal allowed clients: $max_clients", 5); + &main::daemon_log("$session_id INFO: number of actual activ clients: $act_nu_clients", 5); + &main::daemon_log("$session_id INFO: number of maximal allowed clients: $max_clients", 5); if($max_clients <= $act_nu_clients) { my $out_hash = &create_xml_hash("denied", $server_address, $source); @@ -554,7 +556,7 @@ sub here_i_am { } ); if ($res != 0) { - &main::daemon_log("ERROR: cannot add entry to known_clients: $res"); + &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $res"); return; } @@ -574,12 +576,12 @@ sub here_i_am { &add_content2xml_hash($out_hash, "timestamp", $act_timestamp); my $new_client_out = &create_xml_string($out_hash); push(@out_msg_l, $new_client_out); - &main::daemon_log("INFO: send bus msg that client '$source' has registered at server '$server_address'", 5); + &main::daemon_log("$session_id INFO: send bus msg that client '$source' has registered at server '$server_address'", 5); } # give the new client his ldap config # Workaround: Send within the registration response, if the client will get an ldap config later - my $new_ldap_config_out = &new_ldap_config($source); + my $new_ldap_config_out = &new_ldap_config($source, $session_id); if($new_ldap_config_out && (!($new_ldap_config_out =~ /error/))) { &add_content2xml_hash($out_hash, "ldap_available", "true"); } elsif($new_ldap_config_out && $new_ldap_config_out =~ /error/){ @@ -589,7 +591,7 @@ sub here_i_am { "SET status='error', result='$new_ldap_config_out' ". "WHERE status='processing' AND macaddress LIKE '$mac_address'"; my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("DEBUG: $sql_statement RESULT: $res", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement RESULT: $res", 7); } my $register_out = &create_xml_string($out_hash); push(@out_msg_l, $register_out); @@ -664,7 +666,7 @@ sub who_has_i_do { # DESCRIPTION: send to address the ldap configuration found for dn gotoLdapServer #=============================================================================== sub new_ldap_config { - my ($address) = @_ ; + my ($address, $session_id) = @_ ; my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address' OR macaddress LIKE '$address'"; my $res = $main::known_clients_db->select_dbentry( $sql_statement ); @@ -672,7 +674,7 @@ sub new_ldap_config { # check hit my $hit_counter = keys %{$res}; if( not $hit_counter == 1 ) { - &main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1); + &main::daemon_log("$session_id ERROR: more or no hit found in known_clients_db by query by '$address'", 1); } $address = $res->{1}->{hostname}; @@ -680,14 +682,14 @@ sub new_ldap_config { my $hostkey = $res->{1}->{hostkey}; if (not defined $macaddress) { - &main::daemon_log("ERROR: no mac address found for client $address", 1); + &main::daemon_log("$session_id ERROR: no mac address found for client $address", 1); return; } # Build LDAP connection &main::refresh_ldap_handle(); if( not defined $main::ldap_handle ) { - &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1); + &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); return; } @@ -698,17 +700,17 @@ sub new_ldap_config { filter => "(&(objectClass=GOhard)(macaddress=$macaddress)(gotoLdapServer=*))"); #$mesg->code && die $mesg->error; if($mesg->code) { - &main::daemon_log($mesg->error, 1); + &main::daemon_log("$session_id ".$mesg->error, 1); return; } # Sanity check if ($mesg->count != 1) { - &main::daemon_log("WARNING: client with mac address $macaddress not found/unique/active - not sending ldap config", 1); - &main::daemon_log("\tbase: $ldap_base", 1); - &main::daemon_log("\tscope: sub", 1); - &main::daemon_log("\tattrs: dn, gotoLdapServer", 1); - &main::daemon_log("\tfilter: (&(objectClass=GOhard)(macaddress=$macaddress)(gotoLdapServer=*))", 1); + &main::daemon_log("$session_id WARNING: client with mac address $macaddress not found/unique/active - not sending ldap config". + "\n\tbase: $ldap_base". + "\n\tscope: sub". + "\n\tattrs: dn, gotoLdapServer". + "\n\tfilter: (&(objectClass=GOhard)(macaddress=$macaddress)(gotoLdapServer=*))", 1); return; } @@ -735,13 +737,13 @@ sub new_ldap_config { filter => "(&(objectClass=gosaGroupOfNames)(member=$dn))"); #$mesg->code && die $mesg->error; if($mesg->code) { - &main::daemon_log($mesg->error, 1); + &main::daemon_log("$session_id ".$mesg->error, 1); return; } # Sanity check if ($mesg->count != 1) { - &main::daemon_log("WARNING: no LDAP information found for client mac $macaddress", 1); + &main::daemon_log("$session_id WARNING: no LDAP information found for client mac $macaddress", 1); return; } diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index cf409c54f..d72da5334 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -81,6 +81,9 @@ sub save_fai_log { my $macaddress = @{$msg_hash->{'macaddress'}}[0]; my $all_logs = @{$msg_hash->{$header}}[0]; + # if there is nothing to log + if( ref($all_logs) eq "HASH" ) { return; } + my $client_fai_log_dir = $main::client_fai_log_dir; if (not -d $client_fai_log_dir) { mkdir($client_fai_log_dir, 0755) @@ -123,7 +126,7 @@ sub LOGIN { ); my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash ); if ($res != 0) { - &main::daemon_log("ERROR: cannot add entry to known_clients: $error_str"); + &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str"); return; } @@ -169,10 +172,10 @@ sub CURRENTLY_LOGGED_IN { while( my($hit_id, $hit) = each(%{$db_res}) ) { $currently_logged_in_user{$hit->{'user'}} = 1; } - &main::daemon_log("DEBUG: logged in users from login_user_db: ".join(", ", keys(%currently_logged_in_user)), 7); + &main::daemon_log("$session_id DEBUG: logged in users from login_user_db: ".join(", ", keys(%currently_logged_in_user)), 7); my @logged_in_user = split(/\s+/, $login); - &main::daemon_log("DEBUG: logged in users reported from client: ".join(", ", @logged_in_user), 7); + &main::daemon_log("$session_id DEBUG: logged in users reported from client: ".join(", ", @logged_in_user), 7); foreach my $user (@logged_in_user) { my %add_hash = ( table=>$main::login_users_tn, primkey=> ['client', 'user'], @@ -182,7 +185,7 @@ sub CURRENTLY_LOGGED_IN { ); my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash ); if ($res != 0) { - &main::daemon_log("ERROR: cannot add entry to known_clients: $error_str"); + &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str"); return; } @@ -193,11 +196,11 @@ sub CURRENTLY_LOGGED_IN { # although he is not reported by client # then delete it from $login_user_db foreach my $obsolete_user (keys(%currently_logged_in_user)) { - &main::daemon_log("WARNING: user '$obsolete_user' is currently not logged ". + &main::daemon_log("$session_id WARNING: user '$obsolete_user' is currently not logged ". "in at client '$source' but still found at login_user_db", 3); my $sql_statement = "DELETE FROM $main::login_users_tn WHERE client='$source' AND user='$obsolete_user'"; my $res = $main::login_users_db->del_dbentry($sql_statement); - &main::daemon_log("WARNING: delete user '$obsolete_user' at client '$source' from login_user_db", 3); + &main::daemon_log("$session_id WARNING: delete user '$obsolete_user' at client '$source' from login_user_db", 3); } return; @@ -221,9 +224,9 @@ sub GOTOACTIVATION { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header"."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress'", 5); return; } @@ -246,9 +249,9 @@ sub PROGRESS { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET progress='$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - $content%", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - $content%", 5); return; } @@ -271,9 +274,9 @@ sub FAIREBOOT { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header "."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); return; } @@ -296,9 +299,9 @@ sub TASKSKIP { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header "."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); return; } @@ -323,20 +326,20 @@ sub TASKBEGIN { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='done', result='$header "."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); # set fai_state to localboot - &main::change_fai_state('localboot', \@{$msg_hash->{target}}); + &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id); } else { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header "."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); # -----------------------> Update hier @@ -367,9 +370,9 @@ sub TASKEND { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header "."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); # -----------------------> Update hier # finish @@ -398,9 +401,9 @@ sub TASKERROR { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header "."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); # -----------------------> Update hier # finish @@ -429,9 +432,9 @@ sub HOOK { my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header "."$content' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("DEBUG: $sql_statement", 7); + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); return; } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 31a804d10..43421356e 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -67,6 +67,13 @@ sub send_user_msg { if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; } if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; } + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + # error handling if( not @user_list && not @group_list ) { &main::daemon_log("WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3); @@ -141,6 +148,13 @@ sub recreate_fai_server_db { my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + $main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names); &main::create_fai_server_db("new_fai_server"); $main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn); @@ -157,6 +171,13 @@ sub get_login_usr_for_client { my $target = @{$msg_hash->{'target'}}[0]; my $client = @{$msg_hash->{'client'}}[0]; + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + $header =~ s/^gosa_//; my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'"; @@ -176,6 +197,14 @@ sub get_client_for_login_usr { my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; + + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + my $usr = @{$msg_hash->{'usr'}}[0]; $header =~ s/^gosa_//; @@ -194,8 +223,14 @@ sub get_client_for_login_usr { sub ping { my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg = $msg; + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + $out_msg =~ s/
gosa_/
/; - $out_msg =~ s/<\/xml>/$session_id<\/session_id><\/xml>/; my @out_msg_l = ( $out_msg ); return @out_msg_l; @@ -241,14 +276,20 @@ sub network_completition { sub detect_hardware { - my ($msg, $msg_hash) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; # just forward msg to client, but dont forget to split off 'gosa_' in header my $source = @{$msg_hash->{source}}[0]; my $target = @{$msg_hash->{target}}[0]; + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my $out_hash = &create_xml_hash("detect_hardware", $source, $target); - if( exists $msg_hash->{'jobdb_id'} ) { - &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]); + if( defined $jobdb_id ) { + &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id); } my $out_msg = &create_xml_string($out_hash); @@ -259,12 +300,19 @@ sub detect_hardware { sub trigger_reload_ldap_config { - my ($msg, $msg_hash) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; my $target = @{$msg_hash->{target}}[0]; + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + my $out_hash = &create_xml_hash("reload_ldap_config", $main::server_address, $main::server_address, $target); - if( exists $msg_hash->{'jobdb_id'} ) { - &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]); + if( defined ) { + &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id); } my $out_msg = &create_xml_string($out_hash); my @out_msg_l; @@ -274,15 +322,21 @@ sub trigger_reload_ldap_config { sub set_activated_for_installation { - my ($msg, $msg_hash) = @_; - + 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 $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target); - if( exists $msg_hash->{'jobdb_id'} ) { - &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]); + if( defined $jobdb_id ) { + &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id); } my $out_msg = &create_xml_string($out_hash); my @out_msg_l = ( $out_msg ); @@ -291,7 +345,7 @@ sub set_activated_for_installation { sub trigger_action_faireboot { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $macaddress = @{$msg_hash->{target}}[0]; my $source = @{$msg_hash->{source}}[0]; @@ -299,8 +353,8 @@ sub trigger_action_faireboot { $msg =~ s/
gosa_trigger_action_faireboot<\/header>/
trigger_action_faireboot<\/header>/; push(@out_msg_l, $msg); - &main::change_goto_state('locked', \@{$msg_hash->{target}}); - &main::change_fai_state('localboot', \@{$msg_hash->{target}}); + &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id); + &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id); # delete all jobs from jobqueue which correspond to fai my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ". @@ -312,11 +366,17 @@ sub trigger_action_faireboot { sub trigger_action_lock { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $macaddress = @{$msg_hash->{target}}[0]; my $source = @{$msg_hash->{source}}[0]; - &main::change_goto_state('locked', \@{$msg_hash->{target}}); + &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id); + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my @out_msg_l; return @out_msg_l; @@ -324,11 +384,17 @@ sub trigger_action_lock { sub trigger_action_activate { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $macaddress = @{$msg_hash->{target}}[0]; my $source = @{$msg_hash->{source}}[0]; - &main::change_goto_state('active', \@{$msg_hash->{target}}); + &main::change_goto_state('active', \@{$msg_hash->{target}}, $session_id); + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress); if( exists $msg_hash->{'jobdb_id'} ) { @@ -341,10 +407,15 @@ sub trigger_action_activate { sub trigger_action_localboot { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; $msg =~ s/
gosa_trigger_action_localboot<\/header>/
trigger_action_localboot<\/header>/; - - &main::change_fai_state('localboot', \@{$msg_hash->{target}}); + &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id); + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my @out_msg_l = ($msg); return @out_msg_l; @@ -352,10 +423,16 @@ sub trigger_action_localboot { sub trigger_action_halt { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; $msg =~ s/
gosa_trigger_action_halt<\/header>/
trigger_action_halt<\/header>/; - &main::change_fai_state('halt', \@{$msg_hash->{target}}); + &main::change_fai_state('halt', \@{$msg_hash->{target}}, $session_id); + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my @out_msg_l = ($msg); return @out_msg_l; @@ -363,10 +440,16 @@ sub trigger_action_halt { sub trigger_action_reboot { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; $msg =~ s/
gosa_trigger_action_reboot<\/header>/
trigger_action_reboot<\/header>/; - &main::change_fai_state('reboot', \@{$msg_hash->{target}}); + &main::change_fai_state('reboot', \@{$msg_hash->{target}}, $session_id); + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my @out_msg_l = ($msg); return @out_msg_l; @@ -374,10 +457,16 @@ sub trigger_action_reboot { sub trigger_action_memcheck { - my ($msg, $msg_hash) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; $msg =~ s/
gosa_trigger_action_memcheck<\/header>/
trigger_action_memcheck<\/header>/; - &main::change_fai_state('memcheck', \@{$msg_hash->{target}}); + &main::change_fai_state('memcheck', \@{$msg_hash->{target}}, $session_id); + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my @out_msg_l = ($msg); return @out_msg_l; @@ -385,10 +474,10 @@ sub trigger_action_memcheck { sub trigger_action_reinstall { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; $msg =~ s/
gosa_trigger_action_reinstall<\/header>/
trigger_action_reinstall<\/header>/; - &main::change_fai_state('reinstall', \@{$msg_hash->{target}}); + &main::change_fai_state('reinstall', \@{$msg_hash->{target}}, $session_id); my %data = ( 'macAddress' => \@{$msg_hash->{target}} ); my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); @@ -398,10 +487,10 @@ sub trigger_action_reinstall { sub trigger_action_update { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; $msg =~ s/
gosa_trigger_action_update<\/header>/
trigger_action_update<\/header>/; - &main::change_fai_state('update', \@{$msg_hash->{target}}); + &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id); my %data = ( 'macAddress' => \@{$msg_hash->{target}} ); my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); @@ -411,10 +500,17 @@ sub trigger_action_update { sub trigger_action_instant_update { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; $msg =~ s/
gosa_trigger_action_instant_update<\/header>/
trigger_action_instant_update<\/header>/; - &main::change_fai_state('update', \@{$msg_hash->{target}}); + &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id); + + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my %data = ( 'macAddress' => \@{$msg_hash->{target}} ); my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); @@ -424,10 +520,16 @@ sub trigger_action_instant_update { sub trigger_action_sysinfo { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; $msg =~ s/
gosa_trigger_action_sysinfo<\/header>/
trigger_action_sysinfo<\/header>/; - &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}); + &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}, $session_id); + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } my @out_msg_l = ($msg); return @out_msg_l; @@ -435,7 +537,15 @@ sub trigger_action_sysinfo { sub new_key_for_client { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; + + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + $msg =~ s/
gosa_new_key_for_client<\/header>/
new_key<\/header>/; my @out_msg_l = ($msg); return @out_msg_l; @@ -443,7 +553,16 @@ sub new_key_for_client { sub trigger_action_rescan { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; + + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + + $msg =~ s/
gosa_trigger_action_rescan<\/header>/
trigger_action_rescan<\/header>/; my @out_msg_l = ($msg); return @out_msg_l; @@ -451,7 +570,16 @@ sub trigger_action_rescan { sub trigger_action_wake { - my ($msg, $msg_hash) = @_; + my ($msg, $msg_hash, $session_id) = @_; + + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + + my %data = ( 'macAddress' => \@{$msg_hash->{target}} ); my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data); my @out_msg_l = ($out_msg); diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 256d75e59..55e3be017 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -244,7 +244,7 @@ sub trigger_wake { my ($msg, $msg_hash, $session_id) = @_ ; foreach (@{$msg_hash->{macAddress}}){ - &main::daemon_log("INFO: trigger wake for $_", 5); + &main::daemon_log("$session_id INFO: trigger wake for $_", 5); my $host = $_; my $ipaddr = '255.255.255.255'; my $port = getservbyname('discard', 'udp'); @@ -257,7 +257,7 @@ sub trigger_wake { if ($host =~ m/^$hwaddr_re$/) { $hwaddr = $host; } else { - &main::daemon_log("ERROR: trigger_wake called with non mac address", 1); + &main::daemon_log("$session_id ERROR: trigger_wake called with non mac address", 1); } # Generate magic sequence diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index dbe43c173..36bf5390b 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -18,7 +18,7 @@ if($sock->connected()){ # jobdb add #$data = "
gosa_network_completition
GOSAGOSAws-muc-2
"; #$data = "
job_sayHello
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; -#$data = "
job_ping
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa19700101000000
"; +$data = "
job_ping
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa19700101000000
"; # jobdb delete @@ -38,7 +38,7 @@ if($sock->connected()){ #$data = "
gosa_query_jobdb
GOSA GOSAandgt0le5
"; #$data= "
gosa_query_jobdb
GOSA GOSAping03
"; #$data= "
gosa_query_jobdb
GOSA GOSAtrigger_action_reinstall025timestamp DESC
"; -$data= "
gosa_query_jobdb
GOSA GOSA
"; +#$data= "
gosa_query_jobdb
GOSA GOSA
"; # jobdb count #$data = "
gosa_count_jobdb
GOSA GOSA
"; @@ -58,8 +58,8 @@ $data= "
gosa_query_jobdb
GOSA 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
"; #$data = "
gosa_trigger_action_faireboot
00:01:6c:9d:b9:fa GOSA
"; -#$data = "
job_trigger_action_reinstall
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa 20130101000000
"; -#$data = "
gosa_trigger_action_instant_update
00:01:6c:9d:b9:fa GOSA
"; +#$data = "
job_trigger_action_reinstall
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa 19700101000000
"; +#$data = "
job_trigger_action_instant_update
00:01:6c:9d:b9:fa GOSA 19700101000000
"; #$data = "
gosa_ping
00:01:6c:9d:b9:fa GOSA
"; -- 2.30.2