From 8e6a401ce24a3c479bc2f24fe0f594b44d8aba1f Mon Sep 17 00:00:00 2001 From: Niko Tyni Date: Wed, 12 Jul 2006 17:32:39 +0000 Subject: * pass 'prevmatch' to alert matcher plugins. -- niko, from Dylan Vanderhoof (add to trunk as well) --- CHANGES | 2 ++ lib/Smokeping.pm | 6 ++++++ lib/Smokeping/matchers/base.pm | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 84eb968..c9367ec 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +* pass 'prevmatch' to alert matcher plugins. + -- niko, from Dylan Vanderhoof * fix subject in tSmoke 'morning' emails. --niko, from Jean-Philippe Luiggi diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm index 49fdea8..9ff2578 100644 --- a/lib/Smokeping.pm +++ b/lib/Smokeping.pm @@ -1142,6 +1142,12 @@ sub update_rrds($$$$$) { next; }; my $prevmatch = $tree->{prevmatch}{$_} || 0; + + # add the current state of an edge triggered alert to the + # data passed into a matcher, which allows for somewhat + # more intelligent alerting due to state awareness. + $x->{prevmatch} = $prevmatch; + my $match = &{$cfg->{Alerts}{$_}{sub}}($x) || 0; # Avgratio returns undef my $edgetrigger = $cfg->{Alerts}{$_}{edgetrigger} eq 'yes'; my $what; diff --git a/lib/Smokeping/matchers/base.pm b/lib/Smokeping/matchers/base.pm index 130634f..0d69bcd 100644 --- a/lib/Smokeping/matchers/base.pm +++ b/lib/Smokeping/matchers/base.pm @@ -80,7 +80,7 @@ sub Desc ($) { =head2 Test Run the matcher and return true or false. The Test method is called -with a hash of two arrays giving it access to both rtt and loss values. +with a hash containing two arrays giving it access to both rtt and loss values. my $data=shift; my @rtt = @{$data->{rtt}}; @@ -93,6 +93,11 @@ The arrays are ordered from old to new. There may be more than the expected number of elements in this array. Address them with $x[-1] to $x[-max]. +There's also a key called 'prevmatch' in the hash. It contains the +value returned by the previous call of the 'Test' method. This allows +for somewhat more intelligent alerting due to state awareness. + + my $prevmatch = $data->{prevmatch}; =cut -- cgit v1.2.3-24-g4f1b