Here's a patch of my version of mon, which I tweaked to fix this 
problem.  This patch also includes a a fix to make mon tell you when it 
has reach a max number of alerts and will send no more.

-hal

Hutchison, Stuart wrote:

> Hello,
> I have a remote watch script to successfully sending named mon traps to the
> daemon, but the daemon then alerts on every trap rather than following the
> alertevery directive in the mon.cf section. Is the following piece of mon.cf
> correct? Current versions are: mon 0.38.18, Mon::Client v1.31 (modified for
> NT4).
> --
> watch systemsKM
>     service signals
>         description KM signal status
>         period wd {Sun-Sat}
>             # comp_alerts
>             alert file.alert -d /var/log/mon systemsKM.log
>             alert qpage.alert shutchis
>             alertevery 1h summary
>             alert mail.alert shutchis
>             upalert mail.alert shutchis
>             upalert qpage.alert shutchis
> --
> regards,
> Stuart Hutchison
> Unix Administrator
> Sherritt International Corp
> (780) 992-7083
> [EMAIL PROTECTED]
> 
> 

--- /tmp/mon-0.99.2/mon Sat Sep  8 09:42:05 2001
+++ /opt/mon/bin/mon    Mon Nov  5 16:41:41 2001
@@ -490,7 +490,7 @@
 sub do_startup_alerts {
     foreach my $group (keys %watch) {
        foreach my $service (keys %{$watch{$group}}) {
-           do_alert ($group, $service, "", 0, $FL_STARTUPALERT);
+           do_alert($group, $service, "", 0, $FL_STARTUPALERT);
        }
     }
 }
@@ -574,11 +574,20 @@
            #
            # alert only numalerts
            #
-           if ($pref->{"numalerts"} &&
-                    $pref->{"_alert_sent"} >= $pref->{"numalerts"})
-           {
+         if ($pref->{"numalerts"}) {
+           if ($pref->{"_alert_sent"} == ($pref->{"numalerts"} - 1)) {
+             my @lines = split("\n", $output);
+             my $sum = shift(@lines);
+             $sum = "[LAST OF " . $pref->{"numalerts"} . "] $sum";
+             unshift(@lines, "THIS IS ALERT #" .
+                     ($pref->{"_alert_sent"} + 1) . ". " . 
+                     "NO MORE ALERTS WILL BE SENT DURING THE " . 
+                     "CURRENT PERIOD.\n");
+             $output = join("\n", $sum, @lines);
+           } elsif ($pref->{"_alert_sent"} >= $pref->{"numalerts"}) {
                next;
            }
+         }
 
            #
            # only alert once every "alertevery" seconds, unless
@@ -3949,13 +3958,19 @@
     }
     #### else just fall through and send alert
 
+    #TRAPALERT
+    if (!$noalert) {
     do_alert (
            $trap{"grp"},
            $trap{"svc"},
            $trap{"sum"} . $trap{"dtl"},
            $trap{"sta"},
            $FL_TRAP | $flags,
-    ) unless ($noalert);
+              );      
+      my $sref = \%{$watch{$group}->{$service}};
+      $sref->{"_failure_output"} = $trap{"sum"} . $trap{"dtl"};
+      
+    }
 
     if( defined($sref->{"_intended"}) )
     {

Reply via email to