diff --git a/includes/common.php b/includes/common.php index cfdd0c6863..d434ab67cc 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1324,6 +1324,36 @@ function str_i_contains($haystack, $needles) return false; } + /** + * Get alert_rules sql filter by minimal severity + * + * @param string|int $min_severity + * @param string $alert_rules_name + * @return string + */ + +function get_sql_filter_min_severity($min_severity, $alert_rules_name) +{ + $alert_severities = array( + // alert_rules.status is enum('ok','warning','critical') + 'ok' => 1, + 'warning' => 2, + 'critical' => 3, + 'ok only' => 4, + 'warning only' => 5, + 'critical only' => 6, + ); + if (is_numeric($min_severity)) { + $min_severity_id = $min_severity; + } elseif (!empty($min_severity)) { + $min_severity_id = $alert_severities[$min_severity]; + } + if (isset($min_severity_id)) { + return " AND `$alert_rules_name`.`severity` " . ($min_severity_id > 3 ? "" : ">") . "= " . ($min_severity_id > 3 ? $min_severity_id - 3 : $min_severity_id); + } + return ""; +} + if (!function_exists('ends_with')) { /** * Determine if a given string ends with a given substring. diff --git a/includes/html/pages/alert-log.inc.php b/includes/html/pages/alert-log.inc.php index d585fb2a41..664a37fb24 100644 --- a/includes/html/pages/alert-log.inc.php +++ b/includes/html/pages/alert-log.inc.php @@ -17,6 +17,26 @@ $param = array(); $pagetitle[] = 'Alert Log'; +$alert_states = array( + // divined from librenms/alerts.php + 'Any' => -1, + 'Ok (recovered)' => 0, + 'Alert' => 1, +// 'Acknowledged' => 2, + 'Worse' => 3, + 'Better' => 4, +); + +$alert_severities = array( + // alert_rules.status is enum('ok','warning','critical') + 'Any' => '', + 'Ok, warning and critical' => 1, + 'Warning and critical' => 2, + 'Critical' => 3, + 'OK' => 4, + 'Warning' => 5 +); + echo '