From 7fc2d592a65b39b9e4a8b9fc44f6324e291fba1e Mon Sep 17 00:00:00 2001 From: Niko Tyni Date: Mon, 12 Sep 2005 14:09:29 +0000 Subject: * lib/Smokeping.pm (trunk), doc/smokeping_upgrade.pod (trunk), CHANGES (trunk), TODO (trunk): + optionally only send alerts when the state changes ('edgetrigger'). (untested yet) --- CHANGES | 3 +++ TODO | 3 --- doc/smokeping_upgrade.pod | 13 ++++++++++++ lib/Smokeping.pm | 51 +++++++++++++++++++++++++++++++++++++---------- 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 + 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, - make 'active alerts' (whatever that means, have to think this through) visible (eg. different colour) in the CGI menu - suggested by Cornel Badea 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 variable in the C +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, <{Alerts}{$_}{comment} -$_ on $line +$_ $what on $line $loss $rtt SNPPALERT @@ -1140,11 +1154,11 @@ SNPPALERT sendmail $cfg->{Alerts}{from},$to, <{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 => < 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 is 'yes'; see below): B, B, B, B, B. 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 => < variable +documentation above) will get a sixth argument, B, 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:)', -- cgit v1.2.3-24-g4f1b