added the ability to include an alert for each defined sensor in 'ipmi.pm'

This commit is contained in:
Jordi Sanfeliu 2017-07-31 11:18:36 +02:00
parent 70b9c740e5
commit 3f6f9d4034
4 changed files with 71 additions and 1 deletions

View File

@ -35,6 +35,7 @@
'real' (new default) and 'per_second'.
- Added the ability to include an alert for each defined sensor in 'gensens.pm'.
- Added the ability to include an alert for each defined sensor in 'hptemp.pm'.
- Added the ability to include an alert for each defined sensor in 'ipmi.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]

View File

@ -123,6 +123,7 @@ sub ipmi_init {
}
}
$config->{ipmi_hist_alerts} = ();
push(@{$config->{func_update}}, $package);
logger("$myself: Ok") if $debug;
}
@ -158,7 +159,34 @@ sub ipmi_update {
$unit = $ipmi->{units}->{$e};
foreach(@data) {
if(/^($str)\s+\|\s+(\d+\.*\d*)\s+$unit\s+/) {
$sens[$e][$e2] = $2;
my $val = $2;
$sens[$e][$e2] = $val;
# check alerts for each sensor defined
$str =~ s/ /_/;
my @al = split(',', $ipmi->{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->{ipmi_hist_alerts}->{$str} = 0;
} else {
if(!$config->{ipmi_hist_alerts}->{$str}) {
$config->{ipmi_hist_alerts}->{$str} = time;
}
if($config->{ipmi_hist_alerts}->{$str} > 0 && (time - $config->{ipmi_hist_alerts}->{$str}) >= $timeintvl) {
if(-x $script) {
logger("$myself: alert on IPMI 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->{ipmi_hist_alerts}->{$str} = time;
}
}
}
}
}
$e2++;

View File

@ -995,6 +995,45 @@ This is the type of sensor in each group. It's important to not mix different ty
This list complements the \fBdesc\fP option. It basically allows you to change the name that will appear in the graph, hiding the real name of the sensor. If no association is defined, then Monitorix will display the name specified in the \fBdesc\fP option. Note, this only works in names that don't include whitespaces.
.RE
.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.
.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.
.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
<alerts>
.br
CPU_Temp = 3600, 40, /path/to/script
.br
</alerts>
.P
Notice that the spaces in the sensor's name must be converted to underscores, since a variable can hold spaces in its name.
.P
.RE
Such alert means that if the value of the sensor CPU_Temp 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
.RE
.BI graphs_per_row
.RS
This is the number of graphs that will be put in a row.

View File

@ -245,6 +245,8 @@ secure_log_date_format = %b %e
</units>
<map>
</map>
<alerts>
</alerts>
graphs_per_row = 2
rigid = 0
limit = 100