mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 18:38:25 +00:00
Send event log when alert rule fails (#15440)
Instead of breaking all following alerts when one has an error, just skip that one alert rule and send and eventlog detailing the error.
This commit is contained in:
parent
afc78d7890
commit
1caa2dec42
@ -31,8 +31,11 @@
|
||||
|
||||
namespace LibreNMS\Alert;
|
||||
|
||||
use App\Models\Eventlog;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use LibreNMS\Enum\AlertState;
|
||||
use LibreNMS\Enum\Severity;
|
||||
use Log;
|
||||
|
||||
class AlertRules
|
||||
@ -69,7 +72,19 @@ class AlertRules
|
||||
$rule['query'] = AlertDB::genSQL($rule['rule'], $rule['builder']);
|
||||
}
|
||||
$sql = $rule['query'];
|
||||
$qry = dbFetchRows($sql, [$device_id]);
|
||||
|
||||
// set fetch assoc
|
||||
global $PDO_FETCH_ASSOC;
|
||||
$PDO_FETCH_ASSOC = true;
|
||||
try {
|
||||
$qry = \DB::select($sql, [$device_id]);
|
||||
} catch (QueryException $e) {
|
||||
c_echo('%RError: %n' . $e->getMessage() . PHP_EOL);
|
||||
Eventlog::log("Error in alert rule {$rule['name']} ({$rule['id']}): " . $e->getMessage(), $device_id, 'alert', Severity::Error);
|
||||
continue; // skip this rule
|
||||
}
|
||||
$PDO_FETCH_ASSOC = false;
|
||||
|
||||
$cnt = count($qry);
|
||||
for ($i = 0; $i < $cnt; $i++) {
|
||||
if (isset($qry[$i]['ip'])) {
|
||||
|
Loading…
Reference in New Issue
Block a user