mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fix: Clear out stale alerts (#6268)
This commit is contained in:
12
alerts.php
12
alerts.php
@ -63,6 +63,8 @@ if (isset($options['d'])) {
|
||||
|
||||
if (!defined('TEST') && $config['alert']['disable'] != 'true') {
|
||||
echo 'Start: '.date('r')."\r\n";
|
||||
echo "ClearStaleAlerts():" . PHP_EOL;
|
||||
ClearStaleAlerts();
|
||||
echo "RunFollowUp():\r\n";
|
||||
RunFollowUp();
|
||||
echo "RunAlerts():\r\n";
|
||||
@ -74,6 +76,16 @@ if (!defined('TEST') && $config['alert']['disable'] != 'true') {
|
||||
|
||||
unlink($config['install_dir'].'/.alerts.lock');
|
||||
|
||||
function ClearStaleAlerts()
|
||||
{
|
||||
$sql = "SELECT `alerts`.`id` AS `alert_id`, `devices`.`hostname` AS `hostname` FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE `alerts`.`state`!=0 AND `devices`.`hostname` IS NULL";
|
||||
foreach (dbFetchRows($sql) as $alert) {
|
||||
if (empty($alert['hostname']) && isset($alert['alert_id'])) {
|
||||
dbDelete('alerts', '`id` = ?', array($alert['alert_id']));
|
||||
echo "Stale-alert: #{$alert['alert_id']}" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-Validate Rule-Mappings
|
||||
|
Reference in New Issue
Block a user