From e6affacc914e6ebdb0062ee8bea3a50d37367c54 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 25 Mar 2008 16:43:26 +0000 Subject: [PATCH] new event module logHandling.pm git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9978 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/modules/GosaPackages.pm | 6 +- gosa-si/server/events/clMessages.pm | 2 +- gosa-si/server/events/logHandling.pm | 146 +++++++++++++++++++++++++++ gosa-si/tests/client.php | 23 ++--- 4 files changed, 157 insertions(+), 20 deletions(-) create mode 100644 gosa-si/server/events/logHandling.pm diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index b616de5ba..7e50aef02 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -229,8 +229,8 @@ sub import_events { while (defined (my $event = readdir (DIR))) { if( $event eq "." || $event eq ".." ) { next; } - if( $event eq "siTriggered.pm" ) { next; } # SI specific events not needed in GosaPackages.pm - if( $event eq "clMessages.pm" ) { next; } # SI specific events not needed in GosaPackages.pm + if( $event eq "siTriggered.pm" ) { next; } # SI specific events not needed in GosaPackages.pm + if( $event eq "clMessages.pm" ) { next; } # SI specific events not needed in GosaPackages.pm eval{ require $event; }; if( $@ ) { @@ -246,7 +246,7 @@ sub import_events { $event_hash->{$event_name} = $event_module; } my $events_string = join( ", ", @{$events_l}); - &main::daemon_log("G DEBUG: GosaPackages imported events $events_string", 8); + &main::daemon_log("G DEBUG: GosaPackages from '$1' imported events $events_string", 8); } } diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 698dad28e..c606822f5 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -95,7 +95,7 @@ sub save_fai_log { my $time = &get_time; $time = substr($time, 0, 8)."_".substr($time, 8, 6); - $client_fai_log_dir = File::Spec->catfile( $client_fai_log_dir, "install-$time" ); + $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); diff --git a/gosa-si/server/events/logHandling.pm b/gosa-si/server/events/logHandling.pm new file mode 100644 index 000000000..8b9af8f74 --- /dev/null +++ b/gosa-si/server/events/logHandling.pm @@ -0,0 +1,146 @@ +package logHandling; +use Exporter; +@ISA = qw(Exporter); +my @events = ( + "get_events", +# "show_log_by_mac", +# "show_log_by_date", +# "show_log_by_date_and_mac", +# "get_log_by_date", +# "get_log_by_mac", +# "get_log_by_date_and_mac", +# "get_recent_log_by_mac", +# "delete_log_by_date_and_mac", + ); +@EXPORT = @events; + +use strict; +use warnings; +use GOSA::GosaSupportDaemon; +use Data::Dumper; +use File::Spec; + +BEGIN {} + +END {} + +### Start ###################################################################### + +#&main::read_configfile($main::cfg_file, %cfg_defaults); + +sub get_events { + return \@events +} + +sub show_log_by_date { + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{header}}[0]; + $header =~ s/gosa_//; + my $target = @{$msg_hash->{target}}[0]; + my $source = @{$msg_hash->{source}}[0]; + + my $date_l = $msg_hash->{date}; + + if (not -d $main::client_fai_log_dir) { + &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); + return; + } + + # build out_msg + my $out_hash = &create_xml_hash($header, $target, $source); + + # fetch mac directory + opendir(DIR, $main::client_fai_log_dir); + my @avail_macs = readdir(DIR); + closedir(DIR); + +} + +sub show_log_by_mac { + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{header}}[0]; + $header =~ s/gosa_//; + my $target = @{$msg_hash->{target}}[0]; + my $source = @{$msg_hash->{source}}[0]; + my $mac_l = $msg_hash->{mac}; + + if (not -d $main::client_fai_log_dir) { + &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); + return; + } + + # build out_msg + my $out_hash = &create_xml_hash($header, $target, $source); + foreach my $mac (@{$mac_l}) { + my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $mac); + if (not -d $act_log_dir) { next; } + $mac =~ s/:/_/g; + + # fetch mac directory + opendir(DIR, $act_log_dir); + my @install_dates = readdir(DIR); + closedir(DIR); + foreach my $date (@install_dates) { + if ($date eq ".." || $date eq ".") { next; } + &add_content2xml_hash($out_hash, "mac_$mac", $date); + } + } + + my $out_msg = &create_xml_string($out_hash); + return ($out_msg); +} + + +sub show_log_by_date_and_mac { + my ($msg, $msg_hash, $session_id) = @_ ; + my $date_l = $msg_hash->{date}; + my $mac_l = $msg_hash->{mac}; + + print STDERR "###########################################################\n"; + print STDERR "date:".Dumper($date_l); + print STDERR "mac: ".Dumper($mac_l); + print STDERR "client_fai_log_dir: $main::client_fai_log_dir\n"; + + if (not -d $main::client_fai_log_dir) { + &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); + return; + } + + # fetch mac directory + opendir(DIR, $main::client_fai_log_dir); + my @avail_macs = readdir(DIR); + closedir(DIR); + + foreach my $avail_mac (@avail_macs) { + if (not $avail_mac =~ /^([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 ) { + next; + } + + print STDERR "mac: $avail_mac\n"; + # fetch date directory + my $mac_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac); + opendir(DIR, $mac_log_dir); + my @avail_dates = readdir(DIR); + closedir(DIR); + #print STDERR "\@avail_dates:".Dumper(@avail_dates); + } + + return; +} + + +sub get_log_by_date {} +sub get_log_by_mac {} +sub get_log_by_date_and_mac {} +sub fetch_log {} + +sub get_recent_log_by_mac { + +} + + +sub delete_log_by_date_and_mac { + +} + +1; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 5b81853b0..e3d7a1d7d 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -28,7 +28,7 @@ if($sock->connected()){ #$data = "
gosa_gen_smb_hash
GOSAGOSAtester
"; # Reload ldap config -$data = "
gosa_trigger_reload_ldap_config
GOSA00:01:6c:9d:b9:fa
"; +#$data = "
gosa_trigger_reload_ldap_config
GOSA00:01:6c:9d:b9:fa
"; # jobdb update #$data = "
gosa_update_status_jobdb_entry
GOSA GOSA 1 19700101000000
"; @@ -63,21 +63,6 @@ $data = "
gosa_trigger_reload_ldap_config
GOSA
gosa_send_user_msg
GOSA GOSA cajus.pollmeier kaffeepause
"; +################ +# logHandling.pm +$data = "
gosa_show_log_by_mac
GOSA GOSA 00:01:6c:9d:b9:fa
"; + + + $sock->write($data); $answer = "nothing"; $answer = $sock->read(); -- 2.30.2