Code

new event module logHandling.pm
[gosa.git] / gosa-si / server / events / logHandling.pm
1 package logHandling;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5     "get_events",
6 #    "show_log_by_mac",
7 #    "show_log_by_date",
8 #    "show_log_by_date_and_mac",
9 #    "get_log_by_date",
10 #    "get_log_by_mac",
11 #    "get_log_by_date_and_mac",
12 #    "get_recent_log_by_mac",
13 #    "delete_log_by_date_and_mac",
14     );
15 @EXPORT = @events;
17 use strict;
18 use warnings;
19 use GOSA::GosaSupportDaemon;
20 use Data::Dumper;
21 use File::Spec;
23 BEGIN {}
25 END {}
27 ### Start ######################################################################
29 #&main::read_configfile($main::cfg_file, %cfg_defaults);
31 sub get_events {
32     return \@events
33 }
35 sub show_log_by_date {
36     my ($msg, $msg_hash, $session_id) = @_;
37     my $header = @{$msg_hash->{header}}[0];
38     $header =~ s/gosa_//;
39     my $target = @{$msg_hash->{target}}[0];
40     my $source = @{$msg_hash->{source}}[0];
42     my $date_l =  $msg_hash->{date};
44     if (not -d $main::client_fai_log_dir) {
45         &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); 
46         return;
47     }
49     # build out_msg
50     my $out_hash = &create_xml_hash($header, $target, $source);
51     
52     # fetch mac directory
53     opendir(DIR, $main::client_fai_log_dir); 
54     my @avail_macs = readdir(DIR);
55     closedir(DIR);   
56    
57 }
59 sub show_log_by_mac {
60     my ($msg, $msg_hash, $session_id) = @_;
61     my $header = @{$msg_hash->{header}}[0];
62     $header =~ s/gosa_//;
63     my $target = @{$msg_hash->{target}}[0];
64     my $source = @{$msg_hash->{source}}[0];
65     my $mac_l = $msg_hash->{mac};
67     if (not -d $main::client_fai_log_dir) {
68         &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); 
69         return;
70     }
72     # build out_msg
73     my $out_hash = &create_xml_hash($header, $target, $source);
74     foreach my $mac (@{$mac_l}) {
75         my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $mac);
76         if (not -d $act_log_dir) { next; }
77         $mac =~ s/:/_/g;
79         # fetch mac directory
80         opendir(DIR, $act_log_dir); 
81         my @install_dates = readdir(DIR);
82         closedir(DIR);   
83         foreach my $date (@install_dates) {
84             if ($date eq ".." || $date eq ".") { next; }
85             &add_content2xml_hash($out_hash, "mac_$mac", $date);
86         }
87     }
89     my $out_msg = &create_xml_string($out_hash);
90     return ($out_msg);
91 }
94 sub show_log_by_date_and_mac {
95     my ($msg, $msg_hash, $session_id) = @_ ;
96     my $date_l = $msg_hash->{date};
97     my $mac_l = $msg_hash->{mac};
99     print STDERR "###########################################################\n"; 
100     print STDERR "date:".Dumper($date_l); 
101     print STDERR "mac: ".Dumper($mac_l); 
102     print STDERR "client_fai_log_dir: $main::client_fai_log_dir\n"; 
104     if (not -d $main::client_fai_log_dir) {
105         &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); 
106         return;
107     }
109     # fetch mac directory
110     opendir(DIR, $main::client_fai_log_dir); 
111     my @avail_macs = readdir(DIR);
112     closedir(DIR);   
113     
114     foreach my $avail_mac (@avail_macs) {
115         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 ) { 
116             next; 
117         }
119         print STDERR "mac: $avail_mac\n"; 
120         # fetch date directory
121         my $mac_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
122         opendir(DIR, $mac_log_dir); 
123         my @avail_dates = readdir(DIR);
124         closedir(DIR);
125         #print STDERR "\@avail_dates:".Dumper(@avail_dates); 
126     }
128     return;
132 sub get_log_by_date {}
133 sub get_log_by_mac {}
134 sub get_log_by_date_and_mac {}
135 sub fetch_log {}
137 sub get_recent_log_by_mac {
142 sub delete_log_by_date_and_mac {
146 1;