bad5d9fc9e166c3821eb475414f4e72da4742398
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};
43 #my $date_h;
44 #map {$date_h->{$_}++} @{$date_l};
46 if (not -d $main::client_fai_log_dir) {
47 &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1);
48 return;
49 }
51 # build out_msg
52 my $out_hash = &create_xml_hash($header, $target, $source);
54 # fetch mac directory
55 opendir(DIR, $main::client_fai_log_dir);
56 my @avail_macs = readdir(DIR);
57 closedir(DIR);
59 # goto each mac directory
60 # select all dates which matches the parameter dates
61 my %res_h;
62 foreach my $date ( @{$date_l} ) {
64 # go through all mac addresses
65 foreach my $mac (@avail_macs) {
66 if ($mac eq ".." || $mac eq ".") { next; }
68 # read all installations dates
69 my $mac_dir = File::Spec->catdir($main::client_fai_log_dir, $mac);
70 opendir(DIR, $mac_dir);
71 my @avail_dates = readdir(DIR);
72 closedir(DIR);
74 # go through all dates of one mac address
75 foreach my $avail_date (@avail_dates) {
76 if ($avail_date eq ".." || $avail_date eq ".") { next; }
77 if ($avail_date =~ /$date/i) {
78 #$mac =~ s/:/_/g;
79 &add_content2xml_hash($out_hash, $avail_date, $mac);
80 }
81 }
82 }
83 }
85 my $out_msg = &create_xml_string($out_hash);
86 return ($out_msg);
87 }
89 sub show_log_by_mac {
90 my ($msg, $msg_hash, $session_id) = @_;
91 my $header = @{$msg_hash->{header}}[0];
92 $header =~ s/gosa_//;
93 my $target = @{$msg_hash->{target}}[0];
94 my $source = @{$msg_hash->{source}}[0];
95 my $mac_l = $msg_hash->{mac};
97 if (not -d $main::client_fai_log_dir) {
98 &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1);
99 return;
100 }
102 # fetch mac directory
103 opendir(DIR, $main::client_fai_log_dir);
104 my @avail_macs = readdir(DIR);
105 closedir(DIR);
107 # build out_msg
108 my $out_hash = &create_xml_hash($header, $target, $source);
109 foreach my $mac (@{$mac_l}) {
110 foreach my $avail_mac ( @avail_macs ) {
111 if ($avail_mac eq ".." || $avail_mac eq ".") { next; }
112 if ($avail_mac =~ /$mac/i) {
113 my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
114 if (not -d $act_log_dir) { next; }
115 $avail_mac =~ s/:/_/g;
117 # fetch mac directory
118 opendir(DIR, $act_log_dir);
119 my @install_dates = readdir(DIR);
120 closedir(DIR);
121 foreach my $date (@install_dates) {
122 if ($date eq ".." || $date eq ".") { next; }
123 &add_content2xml_hash($out_hash, "mac_$avail_mac", $date);
124 }
125 }
126 }
127 }
129 my $out_msg = &create_xml_string($out_hash);
130 return ($out_msg);
131 }
134 sub show_log_by_date_and_mac {
135 my ($msg, $msg_hash, $session_id) = @_ ;
136 my $date_l = $msg_hash->{date};
137 my $mac_l = $msg_hash->{mac};
139 print STDERR "###########################################################\n";
140 print STDERR "date:".Dumper($date_l);
141 print STDERR "mac: ".Dumper($mac_l);
142 print STDERR "client_fai_log_dir: $main::client_fai_log_dir\n";
144 if (not -d $main::client_fai_log_dir) {
145 &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1);
146 return;
147 }
149 # fetch mac directory
150 opendir(DIR, $main::client_fai_log_dir);
151 my @avail_macs = readdir(DIR);
152 closedir(DIR);
154 foreach my $avail_mac (@avail_macs) {
155 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 ) {
156 next;
157 }
159 print STDERR "mac: $avail_mac\n";
160 # fetch date directory
161 my $mac_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
162 opendir(DIR, $mac_log_dir);
163 my @avail_dates = readdir(DIR);
164 closedir(DIR);
165 #print STDERR "\@avail_dates:".Dumper(@avail_dates);
166 }
168 return;
169 }
172 sub get_log_by_date {}
173 sub get_log_by_mac {}
174 sub get_log_by_date_and_mac {}
175 sub fetch_log {}
177 sub get_recent_log_by_mac {
179 }
182 sub delete_log_by_date_and_mac {
184 }
186 1;