Add on-timeout command
authorJamie Cameron <jcameron@webmin.com>
Tue, 4 May 2010 18:13:47 +0000 (11:13 -0700)
committerJamie Cameron <jcameron@webmin.com>
Tue, 4 May 2010 18:13:47 +0000 (11:13 -0700)
status/CHANGELOG
status/edit_mon.cgi
status/lang/en
status/monitor.pl
status/monitor.pl.bak [deleted file]
status/save_mon.cgi

index 5d7b152..0b5dbe3 100644 (file)
@@ -72,3 +72,4 @@ Added an option to the Disk Space monitor to alert based on percentage free, as
 Put back the option to use Cingular as an SMS carrier.
 ---- Changes since 1.510 ----
 The Check File or Directory monitor can now use a pattern like /tmp/* to check sizes for all files in a directory.
+Added a monitor-level option to run a command if the monitor times out.
index 7fa1d8e..bdb88f6 100755 (executable)
@@ -204,6 +204,10 @@ print &ui_table_row($text{'mon_onup'},
                    &ui_textbox("onup", $serv->{'onup'}, 60),
                    undef, \@tds);
 
+print &ui_table_row($text{'mon_ontimeout'},
+                   &ui_textbox("ontimeout", $serv->{'ontimeout'}, 60),
+                   undef, \@tds);
+
 print &ui_table_row(" ", "<font size=-1>$text{'mon_oninfo'}</font>",
                    undef, \@tds);
 
index c0d2e0b..da6daec 100644 (file)
@@ -95,6 +95,7 @@ mon_timeout=Timed out
 mon_not=Not installed
 mon_ondown=If monitor goes down, run command
 mon_onup=If monitor comes up, run command
+mon_ontimeout=If monitor times out, run command
 mon_clone=Module to monitor
 mon_err=Failed to save monitor
 mon_edesc=Missing description
index 2806ddd..23d6de8 100755 (executable)
@@ -150,6 +150,8 @@ foreach $serv (@services) {
                        elsif ($up == -3) {
                                # Monitor function timed out
                                $suffix = "timed";
+                               $out = &run_on_command($serv,
+                                                      $serv->{'ontimeout'});
                                }
                        }
                elsif ($warn == 2 && $up == 0) {
diff --git a/status/monitor.pl.bak b/status/monitor.pl.bak
deleted file mode 100755 (executable)
index f83423f..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/usr/local/bin/perl
-# monitor.pl
-# Check all the monitors and send email if something is down
-
-$no_acl_check++;
-require './status-lib.pl';
-
-# Check if the monitor should be run now
-@tm = localtime(time());
-@hours = split(/\s+/, $config{'sched_hours'});
-!@hours || &indexof($tm[2], @hours) >= 0 || exit;
-@days = split(/\s+/, $config{'sched_days'});
-!@days || &indexof($tm[6], @days) >= 0 || exit;
-
-# Check for services that are down
-&read_file("$module_config_directory/oldstatus", \%oldstatus);
-$now = localtime(time());
-$host = &get_system_hostname();
-foreach $serv (&list_services()) {
-       if ($serv->{'nosched'}) {
-               delete($oldstatus{$serv->{'id'}});
-               next;
-               }
-       $stat = &service_status($serv);
-       $o = $oldstatus{$serv->{'id'}};
-       if ($config{'sched_warn'} == 0 && $stat->{'up'} == 0 && $o) {
-               # Service has just gone down
-               $email .= "Monitor on $host for '$serv->{'desc'}'\n".
-                "has detected that the service is down at $now\n\n";
-               $subj = "$serv->{'desc'} down on $host";
-               $pager_msg .= "$host: '$serv->{'desc'}' is down $now! ";
-               if ($serv->{'ondown'}) {
-                       system("($serv->{'ondown'}) >/dev/null 2>&1");
-                       }
-               }
-       elsif ($config{'sched_warn'} == 1 && $stat->{'up'} != $o &&
-              (defined($o) || $stat->{'up'} == 0)) {
-               # Service has changed status
-               if ($stat->{'up'} == 0) {
-                       $email .= "Monitor on $host for '$serv->{'desc'}'\n".
-                        "has detected that the service is down at $now\n\n";
-                       $subj = "$serv->{'desc'} down on $host";
-                       $pager_msg .= "$host: '$serv->{'desc'}' is down $now! ";
-                       if ($serv->{'ondown'}) {
-                               system("($serv->{'ondown'}) >/dev/null 2>&1");
-                               }
-                       }
-               elsif ($stat->{'up'} == 1) {
-                       $email .= "Monitor on $host for '$serv->{'desc'}'\n".
-                        "has detected that the service is back up at $now\n\n";
-                       $subj = "$serv->{'desc'} back up on $host";
-                       $pager_msg .= "$host: '$serv->{'desc'}' is back up $now! ";
-                       if ($serv->{'onup'}) {
-                               system("($serv->{'onup'}) >/dev/null 2>&1");
-                               }
-                       }
-               }
-       $oldstatus{$serv->{'id'}} = $stat->{'up'};
-       if ($config{'sched_single'} && $email) {
-               # Force the sending of one email per report
-               &send_status_email($email, $subj);
-               undef($email);
-               }
-       }
-&write_file("$module_config_directory/oldstatus", \%oldstatus);
-
-# Send the email if necessary
-if ($email) {
-       &send_status_email($email, 'Service monitor');
-       &send_status_pager($pager_msg);
-       }
-
-# send_status_email(text, subject)
-sub send_status_email
-{
-return if (!$config{'sched_email'});
-local %sconfig = &foreign_config("sendmail");
-if ($config{'sched_from'}) {
-       open(MAIL, "|$sconfig{'sendmail_path'} -t -f$config{'sched_from'} >/dev/null 2>&1");
-       print MAIL "From: $config{'sched_from'}\n";
-       }
-else {
-       open(MAIL, "|$sconfig{'sendmail_path'} -t >/dev/null 2>&1");
-       print MAIL "From: webmin\n";
-       }
-print MAIL "To: $config{'sched_email'}\n";
-print MAIL "Subject: $_[1]\n";
-print MAIL "\n";
-print MAIL $_[0];
-print MAIL "\n";
-close(MAIL);
-}
-
-# send_status_pager(text)
-sub send_status_pager
-{
-  return if (!$config{'sched_pager'});
-  return if (!&has_command($config{'pager_cmd'}));
-  local $msg = $_[0];
-  $msg =~ s/\\/\\\\/g;
-  $msg =~ s/\'/\\\'/g;
-  system("$config{'pager_cmd'} $config{'sched_pager'} '$msg'  >/dev/null 2>&1 </dev/null");
-}
-
index 4172aef..9579fd5 100755 (executable)
@@ -73,6 +73,7 @@ else {
        $serv->{'notify'} = join(" ", split(/\0/, $in{'notify'}));
        $serv->{'ondown'} = $in{'ondown'};
        $serv->{'onup'} = $in{'onup'};
+       $serv->{'ontimeout'} = $in{'ontimeout'};
        $serv->{'runon'} = $in{'runon'};
        $serv->{'clone'} = $in{'clone'};
        $in{'fails'} =~ /^\d+$/ || &error($text{'mon_efails'});