From: rettenbe Date: Mon, 10 Mar 2008 17:07:31 +0000 (+0000) Subject: after client finish installation, logs are saved at server X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5bd4acf57d8b21c21cd9131249a9b301dc4cc6a4;p=gosa.git after client finish installation, logs are saved at server git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9624 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 14f1ed75d..e0e11bd43 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -37,6 +37,7 @@ use MIME::Base64; use XML::Simple; use Net::DNS; use File::Basename; +use File::Spec; my $event_dir = "/usr/lib/gosa-si/client/events"; use lib "/usr/lib/gosa-si/client/events"; @@ -79,6 +80,9 @@ our $prg= basename($0); # all x seconds the client reports logged_in users to gosa-si-server my $trigger_logged_in_users_report_delay = 600; +# directory where all log files from installation are stored +my $fai_log_dir = "/tmp/fai"; + %cfg_defaults = ( "general" => {"log-file" => [\$log_file, "/var/run/".$prg.".log"], @@ -978,6 +982,7 @@ sub generic_file_error { return; } + sub fifo_got_record { my $file_record = $_[ARG0]; my $header; @@ -999,10 +1004,58 @@ sub fifo_got_record { &add_content2xml_hash($clmsg_hash, "macaddress", $client_mac_address); my $clmsg = &create_xml_string($clmsg_hash); &send_msg_to_target($clmsg, $server_address, $server_key, "CLMSG_$header"); + + # if installation finished, save all log files + if ($file_record eq "TASKBEGIN finish") { + &save_fai_log($fai_log_dir); + } + return; } +sub save_fai_log { + my ($fai_log_dir) = @_ ; + my $FAI_DIR; + +print STDERR "===========================================\n"; +print STDERR "fai_log_dir: $fai_log_dir\n"; + + opendir($FAI_DIR, $fai_log_dir); + if (not defined $FAI_DIR) { + daemon_log("ERROR: can not open directory $fai_log_dir: $!", 1); + return; + } + + my @log_files = readdir($FAI_DIR); + closedir($FAI_DIR); + my @log_list; + + foreach my $log_file (@log_files) { + if( $log_file eq "." || $log_file eq ".." ) { next; } + my $log = "log_file:$log_file\n"; + $log_file = File::Spec->catfile( $fai_log_dir, $log_file ); + open(my $FILE, "<$log_file"); + if (not defined $FILE ) { + daemon_log("ERROR: can not open '$log_file': $!", 1); + next; + } + my @lines = <$FILE>; + my $log_string = join("", @lines); + $log .= &encode_base64($log_string); + push(@log_list, $log); + close ($FILE); + } + + my $all_log_string = join("\n", @log_list); + my $msg_hash = &create_xml_hash("CLMSG_save_fai_log", $client_address, $server_address, $all_log_string); + &add_content2xml_hash($msg_hash, "macaddress", $client_mac_address); + my $msg = &create_xml_string($msg_hash); + &send_msg_to_target($msg, $server_address, $server_key, "CLMSG_save_fai_log"); + +} + + sub _start { my ($kernel, $heap) = @_[KERNEL, HEAP]; $kernel->alias_set('client_session'); diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 0907860f2..a8e2bf249 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -143,6 +143,9 @@ our $messaging_tn = "messaging"; our @messaging_col_names = ('subject', 'from', 'to', 'flag', 'direction', 'delivery_time', 'message', 'timestamp', 'id INTEGER', ); my $messaging_file_name; +# path to directory to store client install log files +our $client_fai_log_dir = "/var/log/fai"; + %cfg_defaults = ( "general" => { "log-file" => [\$log_file, "/var/run/".$prg.".log"], @@ -763,6 +766,7 @@ sub get_ip { return $result; } + sub get_local_ip_for_remote_ip { my $remote_ip= shift; my $result="0.0.0.0"; @@ -897,25 +901,19 @@ 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>/ ) { my $jobdb_id = $1; if( $error ) { - # 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); + 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); + } } else { # sending msg was successful my $sql_statement = "UPDATE $job_queue_tn ". diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 0ec31d5c1..4e474d807 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -13,6 +13,7 @@ my @events = ( "LOGIN", "LOGOUT", "CURRENTLY_LOGGED_IN", + "save_fai_log", ); @EXPORT = @events; @@ -21,6 +22,7 @@ use warnings; use Data::Dumper; use GOSA::GosaSupportDaemon; use utf8; +use MIME::Base64; BEGIN {} @@ -72,6 +74,41 @@ sub read_configfile { } +sub save_fai_log { + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + my $all_logs = @{$msg_hash->{$header}}[0]; + + my $client_fai_log_dir = $main::client_fai_log_dir; + if (not -d $client_fai_log_dir) { + mkdir($client_fai_log_dir, 0755) + } + + $client_fai_log_dir = File::Spec->catfile( $client_fai_log_dir, $macaddress ); + if (not -d $client_fai_log_dir) { + mkdir($client_fai_log_dir, 0755) + } + + my $time = &get_time; + $time = substr($time, 1, 8)."_".substr($time, 8, 6); + $client_fai_log_dir = File::Spec->catfile( $client_fai_log_dir, "install-$time" ); + mkdir($client_fai_log_dir, 0755); + + my @all_logs = split(/log_file:/, $all_logs); + foreach my $log (@all_logs) { + if (length $log == 0) { next; }; + my ($log_file, $log_string) = split("\n", $log, 2); + my $client_fai_log_file = File::Spec->catfile( $client_fai_log_dir, $log_file); + open(my $LOG_FILE, ">$client_fai_log_file"); + print $LOG_FILE &decode_base64($log_string); + close($LOG_FILE); + } + return; +} + + sub LOGIN { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; @@ -267,7 +304,6 @@ sub TASKSKIP { } - sub TASKBEGIN { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 7632f70f6..3ec4b4180 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -9,7 +9,7 @@ $zahl= 1; for($count = 1; $count <= $zahl; $count++) { -$sock = new Socket_Client("127.0.0.1","20181",TRUE,1); +$sock = new Socket_Client("127.0.0.1","20081",TRUE,1); $sock->setEncryptionKey("secret-gosa-password"); if($sock->connected()){ @@ -59,8 +59,9 @@ if($sock->connected()){ #$data = "
gosa_detect_hardware
10.89.1.31:20083 10.89.1.31:20081
"; #$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 = "
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 = "
gosa_ping
00:01:6c:9d:b9:fa GOSA
";