/[mon-modules]/parse_log.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /parse_log.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Sun Oct 5 17:52:04 2003 UTC revision 1.2 by dpavlin, Sun Oct 5 19:00:15 2003 UTC
# Line 11  use POSIX qw(strftime); Line 11  use POSIX qw(strftime);
11  use CGI qw/:standard *table/;  use CGI qw/:standard *table/;
12  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
13  use Data::Sorting qw(:arrays);  use Data::Sorting qw(:arrays);
14    use Time::ParseDate;
15    
16  use Data::Dumper;  use Data::Dumper;
17    
18  my $date_fmt = "%Y-%m-%d %H:%M:%S";  my $date_fmt = "%Y-%m-%d";
19    my $date_time_fmt = "%Y-%m-%d %H:%M:%S";
20    
21    my $from_date = "now - 6 months";
22    my $to_date = "now";
23    
24  # working days definition (1-7; mon=1)  # working days definition (1-7; mon=1)
25  my $wday_start = 1;  my $wday_start = 1;
# Line 22  my $wday_end = 5; Line 28  my $wday_end = 5;
28  my $whours_start = "7:00";  my $whours_start = "7:00";
29  my $whours_end = "17:00";  my $whours_end = "17:00";
30    
31  my $debug=0;  my $debug=1;
32  $debug++ if (grep(/-v/,@ARGV));  $debug++ if (grep(/-v/,@ARGV));
33  $debug++ if (grep(/-d/,@ARGV));  $debug++ if (grep(/-d/,@ARGV));
34    
   
35  my $q = new CGI;  my $q = new CGI;
36    
37  my $print_orphans = $q->param('print_orphans') || 0;  my $print_orphans = $q->param('print_orphans') || 0;
# Line 59  if ($q->param('dsort')) { Line 64  if ($q->param('dsort')) {
64  # pretty format date  # pretty format date
65  sub d {  sub d {
66          my $utime = shift || return "?";          my $utime = shift || return "?";
67          return strftime($date_fmt,localtime($utime));          return strftime($date_time_fmt,localtime($utime));
68  }  }
69  # pretty format duration  # pretty format duration
70  sub dur {  sub dur {
# Line 75  sub dur { Line 80  sub dur {
80          $s = $s % 60;          $s = $s % 60;
81    
82          $out .= $d."d " if ($d > 0);          $out .= $d."d " if ($d > 0);
83          $out .= sprintf("%02d:%02d:%02d [%d]",$h,$m,$s, $dur);          if ($debug) {
84  #       $out .= sprintf("%02d:%02d:%02d",$h,$m,$s);                  $out .= sprintf("%02d:%02d:%02d [%d]",$h,$m,$s, $dur);
85            } else {
86                    $out .= sprintf("%02d:%02d:%02d",$h,$m,$s);
87            }
88    
89          return $out;          return $out;
90  }  }
# Line 87  sub dur { Line 95  sub dur {
95  my %fail;  my %fail;
96  my %downtime;   # total downtime  my %downtime;   # total downtime
97  my %sg_filter;  # filter for service/group  my %sg_filter;  # filter for service/group
98    my %sg_count;   # count number of downtimes
99    
100  my $log_file="/home/dpavlin/mon-log/sap.log";  my $log_file="/home/dpavlin/mon-log/sap.log";
101    
# Line 111  while(<LOG>) { Line 120  while(<LOG>) {
120                                          'dur'=>dur($utime - $fail{$id}),                                          'dur'=>dur($utime - $fail{$id}),
121                                          'desc'=>$desc };                                          'desc'=>$desc };
122                                  $downtime{"$group/$service"} += ($utime - $fail{$id}),                                  $downtime{"$group/$service"} += ($utime - $fail{$id}),
123                                    $sg_count{"$group/$service"}++;
124                          }                          }
125                          $sg_filter{"$group/$service"}++;                          $sg_filter{"$group/$service"}++;
126                          delete $fail{$id};                          delete $fail{$id};
127                  } elsif ($status eq "up") {                  } elsif ($status eq "up") {
128                          if ($print_orphans) {                          if ($print_orphans && grep(m;$group/$service;,@sg_selected)) {
129                                  push @data, {                                  push @data, {
130                                          'sg'=>"$group/$service",                                          'sg'=>"$group/$service",
131                                          'to_time'=>$utime,                                          'to_time'=>$utime,
# Line 123  while(<LOG>) { Line 133  while(<LOG>) {
133                                          'to'=>d($utime),                                          'to'=>d($utime),
134                                          'dur'=>'unknown',                                          'dur'=>'unknown',
135                                          'desc'=>$desc };                                          'desc'=>$desc };
136                                    $sg_count{"$group/$service"}++;
137                          }                          }
138                          delete $fail{$id};                          delete $fail{$id};
139                          $sg_filter{"$group/$service"}++;                          $sg_filter{"$group/$service"}++;
140                  } elsif (defined($fail{$id})) {                  } elsif (defined($fail{$id})) {
141                          if ($rep_reset) {                          if ($rep_reset && grep(m;$group/$service;,@sg_selected)) {
142                                  push @data, {                                  push @data, {
143                                          'sg'=>"$group/$service",                                          'sg'=>"$group/$service",
144                                          'from_time'=>$fail{$id},                                          'from_time'=>$fail{$id},
# Line 139  while(<LOG>) { Line 150  while(<LOG>) {
150                                          'desc'=>'[failure again]'};                                          'desc'=>'[failure again]'};
151                                  $downtime{"$group/$service"} += ($utime - $fail{$id}),                                  $downtime{"$group/$service"} += ($utime - $fail{$id}),
152                                  $fail{$id} = $utime;                                  $fail{$id} = $utime;
153                                    $sg_count{"$group/$service"}++;
154                          }                          }
155                          $sg_filter{"$group/$service"}++;                          $sg_filter{"$group/$service"}++;
156                  } else {                  } else {
# Line 172  print start_form, Line 184  print start_form,
184          $q->checkbox(-name=>'print_orphans',-checked=>0,          $q->checkbox(-name=>'print_orphans',-checked=>0,
185          -label=>"show records which are not complete in this interval"),          -label=>"show records which are not complete in this interval"),
186          br,          br,
187            $q->checkbox(-name=>'use_date_limit',-checked=>1,
188            -label=>"use date limit from:"),
189            $q->textfield(-name=>'from_date',-size=>20,-default=>$from_date),
190            " to: ",
191            $q->textfield(-name=>'to_date',-size=>20,-default=>$to_date),
192            small('Using <a href="http://search.cpan.org/search?mode=module&query=Time::ParseDate">Time::ParseDate</a>'),
193            br,
194          $q->submit(-name=>'show',-value=>'Show report'),          $q->submit(-name=>'show',-value=>'Show report'),
195          )),end_table;          )),end_table;
196    
# Line 189  sub sort_link { Line 208  sub sort_link {
208          }          }
209  }  }
210    
211  print start_table({-border=>1,-cellspacing=>0,-cellpadding=>2,-width=>'100%'}),  
212          Tr(  my ($from_time,$to_time,$from_html,$to_html);
213    if ($q->param('use_date_limit')) {
214            $from_time = parsedate($q->param('from_date'), UK=>1);
215            $to_time = parsedate($q->param('to_date'), UK=>1);
216            $from_html = strftime($date_fmt,localtime($from_time));
217            $to_html = strftime($date_fmt,localtime($to_time));
218            $from_html .= " [$from_time] " if ($debug);
219            $to_html .= " [$to_time] " if ($debug);
220    }
221    
222    # sort data
223    #
224    my @sorted = sorted_array(@data, @sort);
225    #my @sorted = @data;
226    
227    print "-- sort: ",Dumper(@sort)," (data: ".@data." sorted: ".@sorted.") --\n",br if ($debug);
228    
229    print start_table({-border=>1,-cellspacing=>0,-cellpadding=>2,-width=>'100%'});
230    
231    print Tr(
232                  th("group/service"),                  th("group/service"),
233                  th({-bgcolor=>'#f0f0f0'},                  th({-bgcolor=>'#f0f0f0'},
234                          &sort_link($q,'from_time','u').' from '.                          &sort_link($q,'from_time','u').' from '.
235                          &sort_link($q,'from_time','d')                          &sort_link($q,'from_time','d'),
236                            br,$from_html
237                  ),                  ),
238                  th(                  th(
239                          &sort_link($q,'to_time','u').' to '.                          &sort_link($q,'to_time','u').' to '.
240                          &sort_link($q,'to_time','d')                          &sort_link($q,'to_time','d'),
241                            br,$to_html
242                  ),                  ),
243                  th({-bgcolor=>'#e0e0e0'},                  th({-bgcolor=>'#e0e0e0'},
244                          &sort_link($q,'dur_time','u').' duration '.                          &sort_link($q,'dur_time','u').' duration '.
245                          &sort_link($q,'dur_time','d')                          &sort_link($q,'dur_time','d')
246                  ),                  ),
247                  th("description")                  th("description")
248          );          ) if (scalar @sorted > 0);
   
 my @sorted = sorted_array(@data, @sort);  
 #my @sorted = @data;  
   
 print "-- sort: ",Dumper(@sort)," (data: ".@data." sorted: ".@sorted.") --\n";  
249    
250  foreach my $row (@sorted) {  foreach my $row (@sorted) {
251            next if ($q->param('use_date_limit') && ($row->{from_time} < $from_time || $row->{to_time} > $to_time));
252          print Tr(          print Tr(
253                  td({-align=>'left',-valign=>'center'},$row->{sg}),                  td({-align=>'left',-valign=>'center'},$row->{sg}),
254                  td({-align=>'right',-bgcolor=>'#f0f0f0'},$row->{from}),                  td({-align=>'right',-bgcolor=>'#f0f0f0'},$row->{from}),
# Line 226  foreach my $row (@sorted) { Line 262  foreach my $row (@sorted) {
262  #  #
263    
264  foreach my $sg (keys %downtime) {  foreach my $sg (keys %downtime) {
265  print Tr(th({-colspan=>3,-align=>'right'},"total for $sg:"),  print Tr(td({-colspan=>3,-align=>'right'},"total for $sg:"),
266          th({-bgcolor=>'#e0e0e0',-align=>'right'},dur($downtime{"$sg"})),          td({-bgcolor=>'#e0e0e0',-align=>'right'},dur($downtime{$sg})),
267          th("")),"\n";          td(small("in ".$sg_count{$sg}." failures"))),"\n";
268  }  }
269    
270  print end_table,  print end_table,

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.26