diff --git a/Changes b/Changes index bdd4ebf..053d25d 100644 --- a/Changes +++ b/Changes @@ -36,6 +36,7 @@ - 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'. +- Added alert capabilities to 'lmsens.pm'. [#171] - 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/lmsens.pm b/lib/lmsens.pm index e0b8497..7e84ce6 100644 --- a/lib/lmsens.pm +++ b/lib/lmsens.pm @@ -156,10 +156,44 @@ sub lmsens_init { } } + $config->{lmsens_hist_alerts} = (); push(@{$config->{func_update}}, $package); logger("$myself: Ok") if $debug; } +sub lmsens_alerts { + my $myself = (caller(0))[3]; + my $config = (shift); + my $sensor = (shift); + my $val = (shift); + + my $lmsens = $config->{lmsens}; + my @al = split(',', $lmsens->{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->{lmsens_hist_alerts}->{$sensor} = 0; + } else { + if(!$config->{lmsens_hist_alerts}->{$sensor}) { + $config->{lmsens_hist_alerts}->{$sensor} = time; + } + if($config->{lmsens_hist_alerts}->{$sensor} > 0 && (time - $config->{lmsens_hist_alerts}->{$sensor}) >= $timeintvl) { + if(-x $script) { + logger("$myself: alert on LM-Sensor ($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->{lmsens_hist_alerts}->{$sensor} = time; + } + } + } +} + sub lmsens_update { my $myself = (caller(0))[3]; my ($package, $config, $debug) = @_; @@ -203,6 +237,8 @@ sub lmsens_update { $value = $1; } $mb[$n] = int($value); + # check alerts for each sensor defined + lmsens_alerts($config, $str, $value); } } for($n = 0; $n < 4; $n++) { @@ -220,6 +256,8 @@ sub lmsens_update { $value = $1; } $cpu[$n] = int($value); + # check alerts for each sensor defined + lmsens_alerts($config, $str, $value); } } for($n = 0; $n < 9; $n++) { @@ -234,6 +272,8 @@ sub lmsens_update { } my ($value, undef) = split(' ', $tmp); $fan[$n] = int($value); + # check alerts for each sensor defined + lmsens_alerts($config, $str, $value); } } for($n = 0; $n < 16; $n++) { @@ -251,6 +291,8 @@ sub lmsens_update { $value = $1; } $core[$n] = int($value); + # check alerts for each sensor defined + lmsens_alerts($config, $str, $value); } } for($n = 0; $n < 12; $n++) { @@ -265,6 +307,8 @@ sub lmsens_update { } my ($value, undef) = split(' ', $tmp); $volt[$n] = $value; + # check alerts for each sensor defined + lmsens_alerts($config, $str, $value); } } } @@ -296,12 +340,16 @@ sub lmsens_update { if(int($value) > 0) { $gpu[$n] = int($value); } + # check alerts for each sensor defined + lmsens_alerts($config, $str, $value); } } } } if($lmsens->{list}->{$str} eq "ati") { $gpu[$n] = get_ati_data($n); + # check alerts for each sensor defined + lmsens_alerts($config, $str, $gpu[$n]); } } } diff --git a/monitorix.conf b/monitorix.conf index 1e93679..7995f60 100644 --- a/monitorix.conf +++ b/monitorix.conf @@ -200,6 +200,8 @@ secure_log_date_format = %b %e + +