Skip to content

Commit

Permalink
fix: Clear out stale alerts (#6268)
Browse files Browse the repository at this point in the history
  • Loading branch information
laf committed Mar 25, 2017
1 parent 04beee6 commit af2930e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions alerts.php
Expand Up @@ -63,6 +63,8 @@

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";
Expand All @@ -74,6 +76,16 @@

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
Expand Down

0 comments on commit af2930e

Please sign in to comment.