mirror of
https://github.com/webmin/webmin.git
synced 2026-06-20 19:30:30 +01:00
Finished off monitor history project
This commit is contained in:
@@ -48,18 +48,21 @@ elsif (!$st->{'check'}) {
|
||||
elsif ($st->{'errors'} && $_[1]->{'errors'} == 1) {
|
||||
# Errors found, and failing on any errors
|
||||
return { 'up' => 0,
|
||||
'value' => $st->{'errors'},
|
||||
'desc' => &text('monitor_errorsfound', $st->{'errors'}) };
|
||||
}
|
||||
elsif ($st->{'errors'} && $_[1]->{'errors'} == 2 &&
|
||||
$st->{'errors'} > $lasterrors{$_[1]->{'drive'}}) {
|
||||
# Errors found and have increased
|
||||
return { 'up' => 0,
|
||||
'value' => $st->{'errors'},
|
||||
'desc' => &text('monitor_errorsinced', $st->{'errors'},
|
||||
$lasterrors{$_[1]->{'drive'}}) };
|
||||
}
|
||||
else {
|
||||
# All OK!
|
||||
return { 'up' => 1 };
|
||||
return { 'up' => 1,
|
||||
'value' => $st->{'errors'} };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,3 +79,4 @@ Enhanced the free memory monitor to be able to check virtual memory as well.
|
||||
Update the SSL certificate monitor to check alternate names as well when looking for hostname mismatches.
|
||||
---- Changes since 1.590 ----
|
||||
Commands run when a monitor goes up or down can now access details of the monitor via environment variables starting with STATUS_
|
||||
A history of the status of each monitor's scheduled checks is now logged for 30 days, and can be viewed on the Edit Monitor page. This also includes the value associated with the monitor (such as free disk space), if any.
|
||||
|
||||
@@ -7,19 +7,22 @@ local %change;
|
||||
&read_file("$module_config_directory/change", \%change);
|
||||
local $t = $change{$_[0]->{'file'}};
|
||||
local @st = stat($_[0]->{'file'});
|
||||
local $rv;
|
||||
local $up;
|
||||
if ($t && $st[9] != $t) {
|
||||
$rv = { 'up' => 0 };
|
||||
$up = 0;
|
||||
}
|
||||
elsif (!$t) {
|
||||
$rv = { 'up' => -1 };
|
||||
$up = -1;
|
||||
}
|
||||
else {
|
||||
$rv = { 'up' => 1 };
|
||||
$up = 1;
|
||||
}
|
||||
$change{$_[0]->{'file'}} = $st[9];
|
||||
&write_file("$module_config_directory/change", \%change);
|
||||
return $rv;
|
||||
return { 'up' => $up,
|
||||
'value' => $st[9],
|
||||
'nice_value' => &make_date($st[9]),
|
||||
};
|
||||
}
|
||||
|
||||
sub show_change_dialog
|
||||
|
||||
@@ -24,6 +24,8 @@ if ($m) {
|
||||
'desc' => &text('consume_high',
|
||||
&nice_size($diff*1024)) };
|
||||
}
|
||||
$rv->{'value'} = $diff*1024;
|
||||
$rv->{'nice_value'} = &nice_size($diff*1024);
|
||||
}
|
||||
$consume{$_[0]->{'fs'}} = "$sp[1] $now";
|
||||
&write_file("$module_config_directory/consume", \%consume);
|
||||
|
||||
@@ -251,6 +251,8 @@ if (!$in{'type'}) {
|
||||
if (@history) {
|
||||
print &ui_hidden_table_start($text{'mon_header4'}, "width=100%", 2,
|
||||
"history", defined($in{'all'}) || defined($in{'changes'}));
|
||||
|
||||
# Build links to switch to changes-only mode or show all history
|
||||
@links = ( );
|
||||
if ($in{'changes'}) {
|
||||
push(@links, "<a href='edit_mon.cgi?id=$in{'id'}&changes=0&".
|
||||
@@ -267,10 +269,26 @@ if (@history) {
|
||||
if ($in{'changes'}) {
|
||||
@history = grep { $_->{'old'} ne $_->{'new'} } @history;
|
||||
}
|
||||
|
||||
# Check if any history events have a value
|
||||
$anyvalue = 0;
|
||||
foreach $h (@history) {
|
||||
foreach my $hv (split(/\//, $h->{'value'})) {
|
||||
my ($vhost, $v) = split(/=/, $hv, 2);
|
||||
if ($v ne '') {
|
||||
$anyvalue++;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Show history table
|
||||
$links = &ui_links_row(\@links);
|
||||
$table = &ui_columns_start([ $text{'mon_hwhen'},
|
||||
$text{'mon_hold'},
|
||||
$text{'mon_hnew'} ]);
|
||||
$table = &ui_columns_start([
|
||||
$text{'mon_hwhen'},
|
||||
$text{'mon_hold'},
|
||||
$text{'mon_hnew'},
|
||||
$anyvalue ? ( $text{'mon_hvalue'} ) : ( ) ]);
|
||||
foreach $h (reverse(@history)) {
|
||||
my @cols = ( &make_date($h->{'time'}) );
|
||||
foreach my $s ($h->{'old'}, $h->{'new'}) {
|
||||
@@ -289,7 +307,17 @@ if (@history) {
|
||||
}
|
||||
push(@cols, join(" ", @ups));
|
||||
}
|
||||
push(@cols, $h->{'value_show'} || $h->{'value'});
|
||||
if ($anyvalue) {
|
||||
my @vlist;
|
||||
my @values = split(/\//, $h->{'value'});
|
||||
my @nice_values = split(/\//, $h->{'nice_value'});
|
||||
for(my $i=0; $i<@values; $i++) {
|
||||
my ($vhost, $v) = split(/=/, $values[$i], 2);
|
||||
my ($_, $nv) = split(/=/, $nice_values[$i], 2);
|
||||
push(@vlist, $nv || $v);
|
||||
}
|
||||
push(@cols, join(" ", @vlist));
|
||||
}
|
||||
$table .= &ui_columns_row(\@cols);
|
||||
}
|
||||
$table .= &ui_columns_end();
|
||||
|
||||
@@ -11,6 +11,8 @@ else {
|
||||
@files = ( $_[0]->{'file'} );
|
||||
}
|
||||
my $allup = 1;
|
||||
my @allfiles;
|
||||
my @allsizes;
|
||||
foreach my $f (@files) {
|
||||
local @st = stat($f);
|
||||
local $size;
|
||||
@@ -33,6 +35,7 @@ foreach my $f (@files) {
|
||||
$allup = 0;
|
||||
push(@allfiles, $f);
|
||||
}
|
||||
push(@allsizes, $size) if (defined($size));
|
||||
}
|
||||
my $desc;
|
||||
if (@files > 1 && @allfiles) {
|
||||
@@ -44,8 +47,13 @@ if (@files > 1 && @allfiles) {
|
||||
$desc = &text('file_elarge', $desc);
|
||||
}
|
||||
}
|
||||
return { 'up' => $up,
|
||||
'desc' => $desc };
|
||||
my $rv = { 'up' => $up,
|
||||
'desc' => $desc };
|
||||
if (@allsizes == 1) {
|
||||
$rv->{'value'} = $allsizes[0];
|
||||
$rv->{'nice_value'} = &nice_size($allsizes[0]);
|
||||
}
|
||||
return $rv;
|
||||
}
|
||||
|
||||
sub show_file_dialog
|
||||
|
||||
@@ -8,11 +8,13 @@ if (!@u) {
|
||||
return { 'up' => -1 }
|
||||
}
|
||||
elsif ($u[$_[0]->{'time'}] >= $_[0]->{'max'}) {
|
||||
return { 'up' => 0 }
|
||||
return { 'up' => 0,
|
||||
'value' => $u[$_[0]->{'time'}] };
|
||||
}
|
||||
else {
|
||||
return { 'up' => 1,
|
||||
'desc' => "Load is $u[$_[0]->{'time'}]" };
|
||||
'desc' => "Load is $u[$_[0]->{'time'}]",
|
||||
'value' => $u[$_[0]->{'time'}] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,12 @@ elsif ($m eq "postfix") {
|
||||
}
|
||||
if (@qfiles > $_[0]->{'size'}) {
|
||||
return { 'up' => 0,
|
||||
'value' => scalar(@qfiles),
|
||||
'desc' => "<font color=#ff0000>".&text('mailq_toomany', scalar(@qfiles))."</font>" };
|
||||
}
|
||||
else {
|
||||
return { 'up' => 1,
|
||||
'value' => scalar(@qfiles),
|
||||
'desc' => &text('mailq_ok', scalar(@qfiles)) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,14 @@ if ($@) {
|
||||
}
|
||||
elsif ($mem[1] < $_[0]->{'min'}) {
|
||||
return { 'up' => 0,
|
||||
'value' => $mem[1]*1024,
|
||||
'nice_value' => &nice_size($mem[1]*1024),
|
||||
'desc' => &text('memory_freelow', &nice_size($mem[1]*1024)) };
|
||||
}
|
||||
elsif ($mem[2] && $mem[3] < $_[0]->{'minswap'}) {
|
||||
return { 'up' => 0,
|
||||
'value' => $mem[3]*1024,
|
||||
'nice_value' => &nice_size($mem[3]*1024),
|
||||
'desc' => &text('memory_freelowswap',
|
||||
&nice_size($mem[3]*1024)) };
|
||||
}
|
||||
@@ -25,6 +29,8 @@ else {
|
||||
push(@desc, &text('memory_freeswap', &nice_size($mem[2]*1024)));
|
||||
}
|
||||
return { 'up' => 1,
|
||||
'value' => $mem[1]*1024,
|
||||
'nice_value' => &nice_size($mem[1]*1024),
|
||||
'desc' => join(", ", @desc) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@ foreach $serv (@services) {
|
||||
# Check for a status change or failure on each monitored host,
|
||||
# and perform the appropriate action
|
||||
$newstats = { };
|
||||
$newvalues = { };
|
||||
$newvalues_nice = { };
|
||||
foreach $r (@remotes) {
|
||||
# Work out the hostname
|
||||
local $host = $r eq "*" ? $thishost : $r;
|
||||
@@ -191,6 +193,8 @@ foreach $serv (@services) {
|
||||
}
|
||||
}
|
||||
$newstats->{$r} = $up;
|
||||
$newvalues->{$r} = $stat->{'value'};
|
||||
$newvalues_nice->{$r} = $stat->{'nice_value'};
|
||||
|
||||
if ($serv->{'email'} && $thisemail) {
|
||||
# If this service has an extra email address specified,
|
||||
@@ -225,9 +229,13 @@ foreach $serv (@services) {
|
||||
}
|
||||
|
||||
# Log the status
|
||||
$newstatus = join(" ", map { "$_=$newstats->{$_}" } @remotes);
|
||||
$newstatus_str = join(" ", map { "$_=$newstats->{$_}" } @remotes);
|
||||
$newvalues_str = join("/", map { "$_=$newvalues->{$_}" } @remotes);
|
||||
$newvalues_nice_str = join("/", map { "$_=$newvalues_nice->{$_}" } @remotes);
|
||||
%history = ( 'time' => $nowunix,
|
||||
'new' => $newstatus,
|
||||
'new' => $newstatus_str,
|
||||
'value' => $newvalues_str,
|
||||
'nice_value' => $newvalues_nice_str,
|
||||
'by' => $by );
|
||||
if (defined($oldstatus{$serv->{'id'}})) {
|
||||
$history{'old'} = $oldstatus{$serv->{'id'}};
|
||||
@@ -235,7 +243,7 @@ foreach $serv (@services) {
|
||||
&add_history($serv, \%history);
|
||||
|
||||
# Update old status hash
|
||||
$oldstatus{$serv->{'id'}} = $newstatus;
|
||||
$oldstatus{$serv->{'id'}} = $newstatus_str;
|
||||
}
|
||||
|
||||
# Close oldstatus and fails files
|
||||
|
||||
@@ -11,11 +11,15 @@ if (!@st) {
|
||||
}
|
||||
elsif ($st[9] < time()-$_[0]->{'diff'}) {
|
||||
# File hasn't been changed lately
|
||||
return { 'up' => 0 };
|
||||
return { 'up' => 0,
|
||||
'value' => $st[9],
|
||||
'nice_value' => &make_date($st[9]) };
|
||||
}
|
||||
else {
|
||||
# File has been changed lately
|
||||
return { 'up' => 1 };
|
||||
return { 'up' => 1,
|
||||
'value' => $st[9],
|
||||
'nice_value' => &make_date($st[9]) };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,20 @@ foreach $p (&foreign_call("proc", "list_processes")) {
|
||||
local $thresh = $_[0]->{'thresh'} || 1;
|
||||
if ($_[0]->{'not'}) {
|
||||
if ($count >= $thresh) {
|
||||
return { 'up' => 0 };
|
||||
return { 'up' => 0, 'value' => $count };
|
||||
}
|
||||
else {
|
||||
return { 'up' => 1 };
|
||||
return { 'up' => 1, 'value' => $count };
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($count >= $thresh) {
|
||||
return { 'up' => 1, 'desc' => &text('proc_pid',
|
||||
join(" ", @found)) };
|
||||
return { 'up' => 1,
|
||||
'desc' => &text('proc_pid', join(" ", @found)),
|
||||
'value' => $count };
|
||||
}
|
||||
else {
|
||||
return { 'up' => 0 };
|
||||
return { 'up' => 0, 'value' => $count };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@ return { 'up' => 1 } if (!$sens);
|
||||
if ($_[0]->{'mode'} == 0) {
|
||||
return $sens->{'alarm'} ? { 'up' => 0 } : { 'up' => 1 };
|
||||
}
|
||||
elsif ($_[0]->{'mode'} == 1) {
|
||||
return $sens->{'value'} < $_[0]->{'min'} ? { 'up' => 0 }
|
||||
: { 'up' => 1 };
|
||||
}
|
||||
elsif ($_[0]->{'mode'} == 2) {
|
||||
return $sens->{'value'} > $_[0]->{'max'} ? { 'up' => 0 }
|
||||
: { 'up' => 1 };
|
||||
else {
|
||||
local $up;
|
||||
if ($_[0]->{'mode'} == 1) {
|
||||
$up = $sens->{'value'} < $_[0]->{'min'} ? 0 : 1;
|
||||
}
|
||||
elsif ($_[0]->{'mode'} == 2) {
|
||||
$up = $sens->{'value'} > $_[0]->{'max'} ? 0 : 1;
|
||||
}
|
||||
return { 'up' => $up,
|
||||
'value' => $sens->{'value'} };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ if ($m) {
|
||||
local $pc = $sp[1] * 100.0 / $sp[0];
|
||||
if ($pc < $1) {
|
||||
return { 'up' => 0,
|
||||
'value' => $pc,
|
||||
'nice_value' => $pc.'%',
|
||||
'desc' => &text('space_perr', int($pc)) };
|
||||
}
|
||||
}
|
||||
@@ -27,6 +29,8 @@ if ($m) {
|
||||
# Compare absolute size
|
||||
if ($sp[1] < $_[0]->{'min'}) {
|
||||
return { 'up' => 0,
|
||||
'value' => $sp[1]*1024,
|
||||
'nice_value' => &nice_size($sp[1]*1024),
|
||||
'desc' => &text('space_merr',
|
||||
&nice_size($sp[1]*1024)) };
|
||||
}
|
||||
@@ -37,11 +41,14 @@ if ($m) {
|
||||
local @isp = &mount::inode_space($m->[2], $m->[0]);
|
||||
if ($isp[1] < $_[0]->{'inode'}) {
|
||||
return { 'up' => 0,
|
||||
'value' => $isp[1],
|
||||
'desc' => &text('space_ierr', $isp[1]) };
|
||||
}
|
||||
}
|
||||
|
||||
return { 'up' => 1,
|
||||
'value' => $sp[1]*1024,
|
||||
'nice_value' => &nice_size($sp[1]*1024),
|
||||
'desc' => &text('space_desc', &nice_size($sp[1]*1024)) };
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user