summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiko Tyni <ntyni@iki.fi>2005-09-12 16:09:29 +0200
committerNiko Tyni <ntyni@iki.fi>2005-09-12 16:09:29 +0200
commit7fc2d592a65b39b9e4a8b9fc44f6324e291fba1e (patch)
treeb4df8c93d6ce7e2badd6544e5a419842497c4d72
parentf84dd88683a50d232722ca9f622a50a86b2531a9 (diff)
downloadsmokeping-7fc2d592a65b39b9e4a8b9fc44f6324e291fba1e.tar.gz
smokeping-7fc2d592a65b39b9e4a8b9fc44f6324e291fba1e.tar.xz
* lib/Smokeping.pm (trunk),
doc/smokeping_upgrade.pod (trunk), CHANGES (trunk), TODO (trunk): + optionally only send alerts when the state changes ('edgetrigger'). (untested yet)
-rw-r--r--CHANGES3
-rw-r--r--TODO3
-rw-r--r--doc/smokeping_upgrade.pod13
-rw-r--r--lib/Smokeping.pm51
4 files changed, 57 insertions, 13 deletions
diff --git a/CHANGES b/CHANGES
index d890fd3..e243e5b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+* optionally only send alerts when the state changes ('edgetrigger')
+ -- niko, suggested by Marc Haber <mh+smokeping-users *zugschlus.de>
+
2005/9/12 -- released version 20050912_trunk
2005/9/11 -- released version 20050911_trunk
diff --git a/TODO b/TODO
index d2dbf4b..cd6e866 100644
--- a/TODO
+++ b/TODO
@@ -16,9 +16,6 @@
only targets with host are considered
* ALERTS
- only send alerts when the state changes
- - suggested by Marc Haber,
- <http://lists.ee.ethz.ch/smokeping-users/msg01439.html>
make 'active alerts' (whatever that means, have to think
this through) visible (eg. different colour) in the CGI menu
- suggested by Cornel Badea <cornel *sbhost.ro>
diff --git a/doc/smokeping_upgrade.pod b/doc/smokeping_upgrade.pod
index 853c2ca..ee9ebb7 100644
--- a/doc/smokeping_upgrade.pod
+++ b/doc/smokeping_upgrade.pod
@@ -23,6 +23,19 @@ An official list of changes with each release can be found in the CHANGES
file in the Smokeping distribution. This document tries to complement
that with upgrading instructions etc.
+=head1 2.0 to 2.1
+
+=head2 Edge-triggered alerts
+
+The alert notifications can now optionally be sent only when the state of
+the alert changes. This means that only the first match of the alert
+generates a notification, subsequent matches don't. When the alert is
+cleared, ie. there's no match anymore, another notification is sent.
+
+This behaviour is enabled by the C<edgetrigger> variable in the C<Alerts>
+section. The old behaviour (which sends a notification on each match)
+is the default.
+
=head1 1.40 to 2.0
The biggest change with the 2.0 release is that the configuration file
diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm
index f3a243d..9b99619 100644
--- a/lib/Smokeping.pm
+++ b/lib/Smokeping.pm
@@ -1105,15 +1105,25 @@ sub update_rrds($$$$$) {
do_log "WARNING: Alert '$_' did not resolve to a Sub Ref. Skipping\n";
next;
};
- if ( &{$cfg->{Alerts}{$_}{sub}}($x) ){
- # we got a match
+ my $prevmatch = $cfg->{Alerts}{$_}{prevmatch} || 0;
+ my $match = &{$cfg->{Alerts}{$_}{sub}}($x);
+ my $edgetrigger = $cfg->{Alerts}{$_}{edgetrigger} eq 'yes';
+ my $what;
+ if ($edgetrigger and $prevmatch != $match) {
+ $what = ($prevmatch == 0 ? "was raised" : "was cleared");
+ }
+ if (not $edgetrigger and $match) {
+ $what = "is active";
+ }
+ if ($what) {
+ # send something
my $from;
my $line = "$name/$prop";
my $base = $cfg->{General}{datadir};
$line =~ s|^$base/||;
$line =~ s|/host$||;
$line =~ s|/|.|g;
- do_log("Alert $_ triggered for $line");
+ do_log("Alert $_ $what for $line");
my $urlline = $line;
$urlline = $cfg->{General}{cgiurl}."?target=".$line;
my $loss = "loss: ".join ", ",map {defined $_ ? (/^\d/ ? sprintf "%.0f%%", $_ :$_):"U" } @{$x->{loss}};
@@ -1123,11 +1133,15 @@ sub update_rrds($$$$$) {
foreach my $addr (map {$_ ? (split /\s*,\s*/,$_) : ()} $cfg->{Alerts}{to},$tree->{alertee},$cfg->{Alerts}{$_}{to}){
next unless $addr;
if ( $addr =~ /^\|(.+)/) {
- system $1,$_,$line,$loss,$rtt,$tree->{host};
+ if ($edgetrigger) {
+ system $1,$_,$line,$loss,$rtt,$tree->{host}, ($what =~/raise/);
+ } else {
+ system $1,$_,$line,$loss,$rtt,$tree->{host};
+ }
} elsif ( $addr =~ /^snpp:(.+)/ ) {
sendsnpp $1, <<SNPPALERT;
$cfg->{Alerts}{$_}{comment}
-$_ on $line
+$_ $what on $line
$loss
$rtt
SNPPALERT
@@ -1140,11 +1154,11 @@ SNPPALERT
sendmail $cfg->{Alerts}{from},$to, <<ALERT;
To: $to
From: $cfg->{Alerts}{from}
-Subject: [SmokeAlert] $_ on $line
+Subject: [SmokeAlert] $_ $what on $line
$stamp
-Got a match for alert "$_" for $urlline
+Alert "$_" $what for $urlline
Pattern
-------
@@ -1166,6 +1180,7 @@ ALERT
} else {
do_debuglog("Alert \"$_\": no match for target $name\n");
}
+ $cfg->{Alerts}{$_}{prevmatch} = $match;
}
}
}
@@ -2223,13 +2238,14 @@ A complete example
DOC
_sections => [ '/[^\s,]+/' ],
- _vars => [ qw(to from) ],
+ _vars => [ qw(to from edgetrigger) ],
_mandatory => [ qw(to from)],
to => { doc => <<DOC,
Either an email address to send alerts to, or the name of a program to
execute when an alert matches. To call a program, the first character of the
B<to> value must be a pipe symbol "|". The program will the be called
-whenever an alert matches, using the following 5 arguments:
+whenever an alert matches, using the following 5 arguments
+(except if B<edgetrigger> is 'yes'; see below):
B<name-of-alert>, B<target>, B<loss-pattern>, B<rtt-pattern>, B<hostname>.
You can also provide a comma separated list of addresses and programs.
DOC
@@ -2240,8 +2256,23 @@ DOC
_re => '.+@\S+',
_re_error => 'put an email address here',
},
+ edgetrigger => { doc => <<DOC,
+The alert notifications and/or the programs executed are normally triggered every
+time the alert matches. If this variable is set to 'yes', they will be triggered
+only when the alert's state is changed, ie. when it's raised and when it's cleared.
+Subsequent matches of the same alert will thus not trigger a notification.
+
+When this variable is set to 'yes', a notification program (see the B<to> variable
+documentation above) will get a sixth argument, B<raise>, which has the value 1 if the alert
+was just raised and 0 if it was cleared.
+DOC
+ _re => '(yes|no)',
+ _re_error =>"this must either be 'yes' or 'no'",
+ _default => 'no',
+ },
'/[^\s,]+/' => {
- _vars => [ qw(type pattern comment to) ],
+ _vars => [ qw(type pattern comment to edgetrigger) ],
+ _inherited => [ qw(edgetrigger) ],
_mandatory => [ qw(type pattern comment) ],
to => { doc => 'Similar to the "to" parameter on the top-level except that it will only be used IN ADDITION to the value of the toplevel parameter. Same rules apply.',
_re => '(\|.+|.+@\S+|snpp:)',