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

This commit is contained in:
Jordi Sanfeliu 2017-07-28 13:02:10 +02:00
parent 861f1630cb
commit 6fd3320faf
3 changed files with 43 additions and 0 deletions

View File

@ -34,6 +34,7 @@
- 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'.
- Added the ability to include an alert for each defined sensor in 'hptemp.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

@ -132,10 +132,44 @@ sub hptemp_init {
}
}
$config->{hptemp_hist_alerts} = ();
push(@{$config->{func_update}}, $package);
logger("$myself: Ok") if $debug;
}
sub hptemp_alerts {
my $myself = (caller(0))[3];
my $config = (shift);
my $sensor = (shift);
my $val = (shift);
my $hptemp = $config->{hptemp};
my @al = split(',', $hptemp->{alerts}->{$sensor} || "");
if(scalar(@al)) {
my $timeintvl = trim($al[0]);
my $threshold = trim($al[1]);
my $script = trim($al[2]);
if(!$threshold || $val < $threshold) {
$config->{hptemp_hist_alerts}->{$sensor} = 0;
} else {
if(!$config->{hptemp_hist_alerts}->{$sensor}) {
$config->{hptemp_hist_alerts}->{$sensor} = time;
}
if($config->{hptemp_hist_alerts}->{$sensor} > 0 && (time - $config->{hptemp_hist_alerts}->{$sensor}) >= $timeintvl) {
if(-x $script) {
logger("$myself: alert on HP Temp ($sensor): executing script '$script'.");
system($script . " " . $timeintvl . " " . $threshold . " " . $val);
} else {
logger("$myself: ERROR: script '$script' doesn't exist or don't has execution permissions.");
}
$config->{hptemp_hist_alerts}->{$sensor} = time;
}
}
}
}
sub hptemp_update {
my $myself = (caller(0))[3];
my ($package, $config, $debug) = @_;
@ -165,6 +199,8 @@ sub hptemp_update {
chomp($temp);
$temp =~ s/C//;
push(@hptemp1, map {$_ eq "---" ? 0 : $_} ($temp));
# check alerts for each sensor defined
hptemp_alerts($config, $str, $temp);
}
}
foreach my $t (split(',', ($hptemp->{graph_1} || ""))) {
@ -174,6 +210,8 @@ sub hptemp_update {
chomp($temp);
$temp =~ s/C//;
push(@hptemp2, map {$_ eq "---" ? 0 : $_} ($temp));
# check alerts for each sensor defined
hptemp_alerts($config, $str, $temp);
}
}
foreach my $t (split(',', ($hptemp->{graph_2} || ""))) {
@ -183,6 +221,8 @@ sub hptemp_update {
chomp($temp);
$temp =~ s/C//;
push(@hptemp3, map {$_ eq "---" ? 0 : $_} ($temp));
# check alerts for each sensor defined
hptemp_alerts($config, $str, $temp);
}
}
}

View File

@ -172,6 +172,8 @@ secure_log_date_format = %b %e
graph_0 = 2, 3
graph_1 = 1, 6
graph_2 = 16, 18, 19, 20, 21, 22
<alerts>
</alerts>
</hptemp>