diff options
Diffstat (limited to 'perl-install')
-rwxr-xr-x | perl-install/standalone/logdrake | 101 |
1 files changed, 52 insertions, 49 deletions
diff --git a/perl-install/standalone/logdrake b/perl-install/standalone/logdrake index 442e5595b..c9ffc68f1 100755 --- a/perl-install/standalone/logdrake +++ b/perl-install/standalone/logdrake @@ -24,7 +24,7 @@ use lib qw(/usr/lib/libDrakX); use standalone; #- warning, standalone must be loaded very first, for 'explanations' use common; use interactive; -use any; +use ugtk qw(:helpers :wrappers); use my_gtk qw(:helpers :wrappers); $::isInstall and die "Not supported during install.\n"; @@ -39,41 +39,41 @@ if ($::isEmbedded) { } #- parse arguments list. -for (@ARGV) { +foreach (@ARGV) { /^--explain=(.*)$/ and do { $::isExplain = ($::Explain) = $1; $::isFile = 1; $::File = "/var/log/explanations"; next }; /^--file=(.*)$/ and do { $::isFile = ($::File) = $1; next }; /^--word=(.*)$/ and do { $::isWord = ($::Word) = $1; next }; /^--alert$/ and do { alert_config(); quit() }; } -$::isTail = 1 if ($::isFile); -$| = 1 if ($::isTail); +$::isTail = 1 if $::isFile; +n$| = 1 if $::isTail; my $h = chomp_(`hostname -s`); my $my_win = my_gtk->new('logdrake'); unless ($::isEmbedded) { $my_win->{rwindow}->set_title(N("logdrake")); - $my_win->{window}->border_width (5); + $my_win->{window}->border_width(5); $my_win->{rwindow}->set_policy(1, 1, 1); } $my_win->{window}->signal_connect(delete_event => \&quit); #$my_win->{window}->set_default_size(540,460); my $cal = gtkset_sensitive(new Gtk::Calendar(),0); -my (undef,undef,undef,$mday) = localtime(time); +my (undef,undef,undef,$mday) = localtime(time()); $cal->select_day($mday); my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my $cal_mode = 0; -my $cal_butt = gtksignal_connect(new Gtk::CheckButton(N("Show only for the selected day")), clicked =>sub{ $cal_mode =!$cal_mode; gtkset_sensitive($cal,$cal_mode) }); +my $cal_butt = gtksignal_connect(new Gtk::CheckButton(N("Show only for the selected day")), clicked => sub { $cal_mode = !$cal_mode; gtkset_sensitive($cal,$cal_mode) }); ### menus definition # the menus are not shown # but they provides shiny shortcut like C-q my @menu_items = ( { path => N("/_File"), type => '<Branch>' }, - { path => N("/File/_New"), accelerator => N("<control>N"), callback => \&print_hello }, - { path => N("/File/_Open"), accelerator => N("<control>O"),callback => \&print_hello }, - { path => N("/File/_Save"), accelerator => N("<control>S"),callback => \&save }, + { path => N("/File/_New"), accelerator => N("<control>N"), ncallback => \&print_hello }, + { path => N("/File/_Open"), accelerator => N("<control>O"), callback => \&print_hello }, + { path => N("/File/_Save"), accelerator => N("<control>S"), callback => \&save }, { path => N("/File/Save _As") }, { path => N("/File/-"),type => '<Separator>' }, { path => N("/File/_Quit"), accelerator => N("<control>Q"), callback => \&quit }, @@ -168,7 +168,7 @@ gtkadd($my_win->{window}, gtkpack_(new Gtk::HBox(0,0), 1, gtkadd(gtkset_border_width(new Gtk::Frame(N("Choose file")),2), gtkpack (gtkset_border_width(new Gtk::VBox(0,0),0), - map { ${ "b_". $_ } = gtksignal_connect(new Gtk::CheckButton($files{ $_ }{desc}), clicked => sub{ $refcount_search++; gtkset_sensitive($yy,$refcount_search) }) } keys %files, + map { ${ "b_". $_ } = gtksignal_connect(new Gtk::CheckButton($files{$_}{desc}), clicked => sub{ $refcount_search++; gtkset_sensitive($yy,$refcount_search) }) } keys %files, ) ), 0, gtkadd(gtkset_border_width(new Gtk::Frame(N("Calendar")),2), @@ -205,7 +205,7 @@ use strict; $::isFile and gtkset_usize($log_text,400,500); $my_win->{window}->realize; $my_win->{window}->show_all(); -search() if ($::isFile); +search() if $::isFile; $my_win->main; sub quit { my_gtk->exit(0) } @@ -220,7 +220,7 @@ sub search { parse_file($::File); } else { foreach (keys %files) { - parse_file($files{ $_ }{file}) if ${ $::{ "b_". $_ }}->active + parse_file($files{$_}{fnile}) if ${ $::{"b_" . $_} n}->active }; } $log_text->thaw(); @@ -234,7 +234,7 @@ sub parse_file { my $i = 0; gtkadd(my $win_pb = (gtkset_modal new Gtk::Window(), 1), gtkpack(new Gtk::VBox(5,0), - " " . N("please wait, parsing file: %s", $files{ $_ }{desc}) . " ", + " " . N("please wait, parsing file: %s", $files{$_}{desc}) . " ", my $pbar = new Gtk::ProgressBar() ) ); @@ -246,21 +246,21 @@ sub parse_file { $ey =~ s/ OR /\|/; $ey =~ s/^\*$//; $en =~ s/^\*$/.*/; - $ey = $ey .($::Word) if ($::isWord); + $ey = $ey . $::Word if $::isWord; if ($cal_mode) { my ($year, $month, $day) = $cal->get_date(); $ey = $months[$month]."\\s{1,2}$day\\s.*$ey.*\n"; } - my @all = catMaybeCompressed ($file); + my @all = catMaybeCompressed($file); if ($::isExplain) { my (@t, $t); while (@all) { $t = pop @all; - next if ($t =~ /logdrake/); - last if !($t =~ /$::Explain/); + next if $t =~ /logdrake/; + last if $t !~ /$::Explain/; push @t, $t; } @all = reverse @t; @@ -274,14 +274,16 @@ sub parse_file { Gtk->main_iteration while Gtk->events_pending; } - if (($en eq "") and /$ey/i) { logcolorize($_); next } - if ((! /$en/i) and /$ey/i) { logcolorize($_); next } - if ((! /$en/i) and ($ey eq "")) { logcolorize($_); next } + if ($en eq "" and /$ey/i) { logcolorize($_); next } + if (! /$en/i and /$ey/i) { logcolorize($_); next } + if (! /$en/i and $ey eq "") { logcolorize($_); next } } $win_pb->destroy(); if ($::isTail) { + local *F; open F, $file or die "E: $!"; + local $_; while (<F>) {}; #to prevent to output the file twice.. $log_text->set_point($log_text->get_length()); my $timer = Gtk->timeout_add(1000, \&input_callback); @@ -304,48 +306,48 @@ sub logcolorize { my @rec = split; log_output($cyan,$timestamp,$b); # date & time if any... - $::isExplain or log_output(($rec[0] eq $h) ? $blue : $col,"$rec[0] ",$b); # hostname + $::isExplain or log_output($rec[0] eq $h ? $blue : $col, "$rec[0] ",$b); # hostname if ($rec[1] eq "last") { - log_output($green," last message repeated ",$n); + log_output($green, " last message repeated ",$n); log_output($green, $rec[4], $b); - log_output($green," times\n",$n); + log_output($green, " times\n",$n); return; } # Extract PID if present if ($rec[1] =~ /\[(\d+)\]\:/) { my($pid) = $1; - $rec[1] =~s/\[$1\]\:// ; - log_output ($green, $rec[1] ."[",$n); + $rec[1] =~ s/\[$1\]\://; + log_output ($green, $rec[1] . "[", $n); log_output ($black, $pid,$b); log_output ($green, "]: ",$n); } else { - log_output($green, $rec[1] ." ",$n); + log_output($green, $rec[1] . " ", $n); } - for my $therest (2 .. $#rec) { + foreach my $therest (2 .. $#rec) { $col = $cyan; # Check for keywords to highlight - foreach (@word_good) { $col = $col_good if ($_ eq $rec[$therest]) } - foreach (@word_warn) { $col = $col_warn if ($_ eq $rec[$therest]) } - foreach (@word_bad) { $col = $col_bad if ($_ eq $rec[$therest]) } - foreach (@word_note) { $col = $col_note if ($_ eq $rec[$therest]) } + foreach (@word_good) { $col = $col_good if $_ eq $rec[$therest] } + foreach (@word_warn) { $col = $col_warn if $_ eq $rec[$therest] } + foreach (@word_bad) { $col = $col_bad if $_ eq $rec[$therest] } + foreach (@word_note) { $col = $col_note if $_ eq $rec[$therest] } # Watch for words that indicate entire lines should be highlighted - #foreach (@line_good) { $col = $col_good if ($_ eq $rec[$therest]) } - #foreach (@line_warn) { $col = $col_warn if ($_ eq $rec[$therest]) } - #foreach (@line_bad) { $col = $col_bad if ($_ eq $rec[$therest]) } + #foreach (@line_good) { $col = $col_good if $_ eq $rec[$therest] } + #foreach (@line_warn) { $col = $col_warn if $_ eq $rec[$therest] } + #foreach (@line_bad) { $col = $col_bad if $_ eq $rec[$therest] } - log_output($col,"$rec[$therest] ",$n); + log_output($col, "$rec[$therest] ", $n); } - log_output($black,"\n",$n); + log_output($black, "\n",$n); } sub log_output { - $log_text->insert($_[2],$_[0], undef,$_[1]); + $log_text->insert($_[2], $_[0], undef, $_[1]); } @@ -391,20 +393,20 @@ my $initdir = "/etc/init.d"; webmin => N("Webmin Service"), xinetd => N("Xinetd Service") }; - my @installed_d = (); + my @installed_d; foreach my $serv (keys %$service) { -e "$initdir/$serv" && push (@installed_d,$serv); } $in->ask_from(N("service setting"), N("You will receive an alert if one of the selected services is no more running"), - [ map { { label => "$_", val => \${ $_ }, type => "bool", text => "$service->{ $_ }" } } @installed_d + [ map { { label => $_, val => \${ $_ }, type => "bool", text => "$service->{ $_ }" } } @installed_d ]) or goto begin; $cron .= "#- check services\n"; my $r; foreach (@installed_d) { - if(!-e "/var/lock/subsys/$_") { $r .= "Service $_ ($service->{$_} is not running\n" }; + $r .= "Service $_ ($service->{$_} is not running\n" unless -e "/var/lock/subsys/$_"; # $cron .= "$r" if ${ $_ }; # take a look at this, don't know what is done here } @@ -419,7 +421,7 @@ my $initdir = "/etc/init.d"; $cron .= sprintf(<<'EOF', $load); #- load my ($load) = split ' ', first(cat_("/proc/loadavg")); -$r .= "Load is huge: $load\n" if ($load > %s); +$r .= "Load is huge: $load\n" if $load > %s; EOF @@ -430,14 +432,15 @@ EOF N("Please enter your email address below "), [ { label => "" }, - { label => "Email", val => \$email}, + { label => "Email", val => \$email }, ]) or goto step_load; $cron .= q(#- report it); $cron .= q( -$email = ) . "'" . "$email" . "'" . ";\n\n"; +$email = ) . "'$email';\n\n"; $cron .= q( +local *F; open F, '|/usr/sbin/sendmail -oi -t'; print F @@ -447,10 +450,10 @@ To: ), "$email\n"; print F $r; # EOF); - output "$cron_hourly", $cron; + output $cron_hourly, $cron; chmod 0755, $cron_hourly; - print ("whole cron is ****** $cron *******\n"); + print "whole cron is ****** $cron *******\n"; undef $::isWizard; if (defined $::WizardWindow) { @@ -466,7 +469,7 @@ print F $r; sub save { - $::isWizard=0; - $yy = $in->ask_file(N("Save as.."),"/root") or return; - output($yy,$log_text->get_chars(0,$log_text->get_length())); + $::isWizard = 0; + $yy = $in->ask_file(N("Save as.."), "/root") or return; + output($yy, $log_text->get_chars(0, $log_text->get_length())); } |