From 421cd024b76c26ee5c629b098d0dc3248d1ffcef Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Wed, 26 Jul 2017 12:22:08 +0200 Subject: [PATCH] added the ability to include an alert for each defined sensor in 'gensens.pm' --- Changes | 3 ++- lib/gensens.pm | 28 ++++++++++++++++++++++++++++ man/man5/monitorix.conf.5 | 37 +++++++++++++++++++++++++++++++++++++ monitorix.conf | 2 ++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 0671106..3497a53 100644 --- a/Changes +++ b/Changes @@ -26,13 +26,14 @@ - Added support of Postgrey (Postfix Greylisting) in 'mail.pm'. [#102] (thanks to Malte Kubat, M.Kubat AT csb-it.de) - Updated to 4.01 the HTML DOCTYPE declarations. -- Added more precision to the values in 'gensens.pm. +- Added more precision to the values in 'gensens.pm'. - Added string encoding to avoid the message 'Wide character in print at ./monitorix.cgi line ...'. [#186] - Added to force a standard locale in 'port.pm'. in order to be able for Monitorix to read the output of system commands (netstat, ...). [#186] - Added the new option 'stats_rate' in 'mail.pm' to be able to choose between 'real' (new default) and 'per_second'. +- Added the ability to include an alert for each defined sensor in 'gensens.pm'. - Fixed an undeclared global symbol "$imgfmt_lc" in 'traffacct.pm'. - Fixed the MIME type of graphs in 'emailreports.pm' and in 'traffacct.pm' to honor the 'image_format' option. [#174] diff --git a/lib/gensens.pm b/lib/gensens.pm index a0c624b..7b1eb9a 100644 --- a/lib/gensens.pm +++ b/lib/gensens.pm @@ -119,6 +119,7 @@ sub gensens_init { } } + $config->{gensens_hist_alerts} = (); push(@{$config->{func_update}}, $package); logger("$myself: Ok") if $debug; } @@ -156,6 +157,33 @@ sub gensens_update { logger("$myself: ERROR: unable to open '$gensens->{desc}->{$str}'."); } } + + # check alerts for each sensor defined + my @al = split(',', $gensens->{alerts}->{$str} || ""); + if(scalar(@al)) { + my $timeintvl = trim($al[0]); + my $threshold = trim($al[1]); + my $script = trim($al[2]); + + if(!$threshold || $val < $threshold) { + $config->{gensens_hist_alerts}->{$str} = 0; + } else { + if(!$config->{gensens_hist_alerts}->{$str}) { + $config->{gensens_hist_alerts}->{$str} = time; + } + if($config->{gensens_hist_alerts}->{$str} > 0 && (time - $config->{gensens_hist_alerts}->{$str}) >= $timeintvl) { + if(-x $script) { + logger("$myself: alert on Generic Sensor ($str): executing script '$script'."); + system($script . " " . $timeintvl . " " . $threshold . " " . $val); + } else { + logger("$myself: ERROR: script '$script' doesn't exist or don't has execution permissions."); + } + $config->{gensens_hist_alerts}->{$str} = time; + } + } + + } + $rrdata .= ":$val"; } } diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index c76a9e9..1c09798 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -880,6 +880,43 @@ With this option you can optionally rename any of the sensor names defined in th .P All names are limited to 20 characters. .RE +.P +.BI alerts +.RS +This optional list enables the alert capabilities for this graph and complements with the \fBlist\fP option. Each alert has three fields separated by comma: the \fItime interval\fP, the \fIthreshold\fP and the path to the \fIscript\fP to be executed. +.P +The \fItime interval\fP is the period of time (in seconds) that the \fIthreshold\fP needs to be exceeded before the external script is executed. +.P +The \fIthreshold\fP is the value (either temperature or HZ) that needs to be reached or exceeded within the specified time in \fItime interval\fP to execute the external script. +.P +The \fIscript\fP is the full path name of the script that will be executed by this alert. +.P +Each defined sensor has its own alert. +.P +The default Monitorix installation includes an example of a shell-script alert called \fImonitorix-alert.sh\fP which you can use as a base for your own script. +.P +The following is an example of an alert defined for the first temperature sensor: +.P +.RS + +.br + temp0 = 3600, 40, /path/to/script +.br + +.P +.RE +Such alert means that if the value of the sensor temp0 reaches or exceeds 40 during at least one hour (3600 seconds) the script in \fI/path/to/script\fP will be executed. +.P +The external script will receive the following arguments: +.P +.RS +1st - the value defined as \fItime interval\fP. +.br +2nd - the value defined as \fIthreshold\fP. +.br +3rd - the value of the sensor. +.P +.RE .SS IPMI sensor statistics (ipmi.rrd) This graph is able to monitor an unlimited number of IPMI sensors (temperatures, fans and voltages). .P diff --git a/monitorix.conf b/monitorix.conf index 0af613c..d21e921 100644 --- a/monitorix.conf +++ b/monitorix.conf @@ -220,6 +220,8 @@ secure_log_date_format = %b %e temp0 = Temperature Zone 0 cpu0 = CPU0 frequency + + rigid = 0, 0 limit = 100, 100