mirror of https://github.com/mikaku/Monitorix.git
Improved the alerting system in 'ambsens.pm'
From now on, the alerts accepts a forth parameter that specifies when the alert will be triggered. This parameter accepts two values: 'above' or 'below', being the 'above' the default value if it's not specified, in order to keep backwards compatibility. This way, if some value in the graph is 'above' or 'below' from the threshold during more time than specified in the timeout value, the alert will be triggered. The manpage has also been updated to reflect this new feature. #221
This commit is contained in:
parent
bfb6ccac1f
commit
49ef3a3528
2
Changes
2
Changes
|
@ -27,6 +27,8 @@
|
|||
- Added in 'ipmi.pm' the ability to save negative values. [#218]
|
||||
- Added the ability in the alerts of 'gensens.pm' to specify when the alert will
|
||||
be triggered 'above' or 'below' the threshold. [#221]
|
||||
- Added the ability in the alerts of 'ambsens.pm' to specify when the alert will
|
||||
be triggered 'above' or 'below' the threshold. [#221]
|
||||
- Drop entropy support for FreeBSD in 'system.pm'. [#226]
|
||||
- Added Exim support in 'mail.pm'. [#96]
|
||||
- Added an autocheck to control the responsiveness of the HTTP built-in server,
|
||||
|
|
|
@ -159,22 +159,37 @@ sub ambsens_update {
|
|||
my $timeintvl = trim($al[0]);
|
||||
my $threshold = trim($al[1]);
|
||||
my $script = trim($al[2]);
|
||||
|
||||
if(!$threshold || $val < $threshold) {
|
||||
$config->{ambsens_hist_alerts}->{$str} = 0;
|
||||
} else {
|
||||
if(!$config->{ambsens_hist_alerts}->{$str}) {
|
||||
$config->{ambsens_hist_alerts}->{$str} = time;
|
||||
}
|
||||
if($config->{ambsens_hist_alerts}->{$str} > 0 && (time - $config->{ambsens_hist_alerts}->{$str}) >= $timeintvl) {
|
||||
if(-x $script) {
|
||||
logger("$myself: alert on Ambient Sensor ($str): executing script '$script'.");
|
||||
system($script . " " . $timeintvl . " " . $threshold . " " . $val);
|
||||
my $when = lc(trim($al[3] || ""));
|
||||
my @range = split('-', $threshold);
|
||||
$when = "above" if !$when; # 'above' is the default
|
||||
$threshold = 0 if !$threshold;
|
||||
if(scalar(@range) == 1) {
|
||||
if($when eq "above" && $val < $threshold) {
|
||||
$config->{ambsens_hist_alerts}->{$str} = 0;
|
||||
} elsif($when eq "below" && $val > $threshold) {
|
||||
$config->{ambsens_hist_alerts}->{$str} = 0;
|
||||
} else {
|
||||
if($when eq "above" || $when eq "below") {
|
||||
if(!$config->{ambsens_hist_alerts}->{$str}) {
|
||||
$config->{ambsens_hist_alerts}->{$str} = time;
|
||||
}
|
||||
if($config->{ambsens_hist_alerts}->{$str} > 0 && (time - $config->{ambsens_hist_alerts}->{$str}) >= $timeintvl) {
|
||||
if(-x $script) {
|
||||
logger("$myself: alert on Ambient 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->{ambsens_hist_alerts}->{$str} = time;
|
||||
}
|
||||
} else {
|
||||
logger("$myself: ERROR: script '$script' doesn't exist or don't has execution permissions.");
|
||||
logger("$myself: ERROR: invalid when value '$when'");
|
||||
}
|
||||
$config->{ambsens_hist_alerts}->{$str} = time;
|
||||
}
|
||||
} elsif(scalar(@range) == 2) {
|
||||
logger("$myself: range values are not supported yet.");
|
||||
} else {
|
||||
logger("$myself: ERROR: invalid threshold value '$threshold'");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1152,14 +1152,16 @@ This list complements the \fBdesc\fP option. It basically allows you to change t
|
|||
.P
|
||||
.BI alerts
|
||||
.RS
|
||||
This optional list enables the alert capabilities for this graph and complements with the \fBdesc\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.
|
||||
This optional list enables the alert capabilities for this graph and complements with the \fBlist\fP option. Each alert has four fields separated by comma: the \fItime interval\fP, the \fIthreshold\fP, the path to the \fIscript\fP to be executed and \fIwhen\fP the alert must be triggered. the last field is optional.
|
||||
.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 temperature that needs to be reached or exceeded within the specified time in \fItime interval\fP to execute the external script.
|
||||
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
|
||||
The \fIwhen\fP value specifies when the alert must be triggered (\fIabove\fP or \fIbelow\fP) the threshold, being \fIabove\fP the default value when it's not specified.
|
||||
.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.
|
||||
|
@ -1169,12 +1171,16 @@ The following is an example of an alert defined for the first temperature sensor
|
|||
.RS
|
||||
<alerts>
|
||||
.br
|
||||
at1 = 3600, 40, /path/to/script.sh
|
||||
temp0 = 3600, 40, /path/to/script.sh, above
|
||||
.br
|
||||
temp1 = 3600, 10, /path/to/script.sh, below
|
||||
.br
|
||||
</alerts>
|
||||
.P
|
||||
.RE
|
||||
Such alert means that if the value of the sensor \fIat1\fP reaches or exceeds 40 during at least one hour (3600 seconds) the script in \fI/path/to/script.sh\fP will be executed.
|
||||
The first alert means that if the value of the sensor temp0 exceeds above 40 during at least one hour (3600 seconds) the script in \fI/path/to/script.sh\fP will be executed.
|
||||
.P
|
||||
The second alert means that if the value of the sensor temp1 exceeds below 10 during at least one hour (3600 seconds) the script in \fI/path/to/script.sh\fP will be executed.
|
||||
.P
|
||||
The external script will receive the following arguments:
|
||||
.P
|
||||
|
@ -1184,6 +1190,8 @@ The external script will receive the following arguments:
|
|||
2nd - the value defined as \fIthreshold\fP.
|
||||
.br
|
||||
3rd - the value of the sensor.
|
||||
.br
|
||||
4th - the direction or when that alert was triggered by (above or below).
|
||||
.P
|
||||
.RE
|
||||
.RE
|
||||
|
|
Loading…
Reference in New Issue