From 4c10cb625b7a25f47f143e87f7deb973091ddba4 Mon Sep 17 00:00:00 2001 From: f0o Date: Mon, 18 May 2015 10:23:25 +0000 Subject: [PATCH] Honour 'Disable all alerting for this host' Fixes some redundancy in macros (parentesis) --- alerts.php | 5 +++++ includes/alerts.inc.php | 2 +- includes/defaults.inc.php | 12 ++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/alerts.php b/alerts.php index d7b4f8d55..56fd4ffdd 100755 --- a/alerts.php +++ b/alerts.php @@ -84,6 +84,9 @@ function IsRuleValid($device,$rule) { */ function IssueAlert($alert) { global $config; + if( dbFetchCell('SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = ?',array($alert['device_id'])) == "1" ) { + return true; + } $default_tpl = "%title\r\nSeverity: %severity\r\n{if %state == 0}Time elapsed: %elapsed\r\n{/if}Timestamp: %timestamp\r\nUnique-ID: %uid\r\nRule: {if %name}%name{else}%rule{/if}\r\n{if %faults}Faults:\r\n{foreach %faults} #%key: %value.string\r\n{/foreach}{/if}Alert sent to: {foreach %contacts}%value <%key> {/foreach}"; //FIXME: Put somewhere else? $obj = DescribeAlert($alert); if( is_array($obj) ) { @@ -101,6 +104,7 @@ function IssueAlert($alert) { } echo "\r\n"; } + return true; } /** @@ -312,6 +316,7 @@ function DescribeAlert($alert) { $i = 0; $device = dbFetchRow("SELECT hostname FROM devices WHERE device_id = ?",array($alert['device_id'])); $obj['hostname'] = $device['hostname']; + $obj['device_id'] = $alert['device_id']; $extra = $alert['details']; if( $alert['state'] >= 1 ) { $obj['title'] = 'Alert for device '.$device['hostname'].' Alert-ID #'.$alert['id']; diff --git a/includes/alerts.inc.php b/includes/alerts.inc.php index 34426a04c..ea6b94b73 100644 --- a/includes/alerts.inc.php +++ b/includes/alerts.inc.php @@ -162,7 +162,7 @@ function RunMacros($rule,$x=1) { krsort($config['alert']['macros']['rule']); foreach( $config['alert']['macros']['rule'] as $macro=>$value ) { if( !strstr($macro," ") ) { - $rule = str_replace('%macros.'.$macro,$value,$rule); + $rule = str_replace('%macros.'.$macro,'('.$value.')',$rule); } } if( strstr($rule,"%macros") ) { diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index dca985947..eeebfd7d1 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -215,14 +215,14 @@ $config['alert'] = array( 'past_60m' => 'DATE_SUB(NOW(),INTERVAL 60 MINUTE)', //Device Macros - 'device' => '(%devices.disabled = "0" && %devices.ignore = "0")', - 'device_up' => '(%devices.status = "1" && %macros.device)', - 'device_down' => '(%devices.status = "0" && %macros.device)', + 'device' => '%devices.disabled = "0" && %devices.ignore = "0"', + 'device_up' => '%devices.status = "1" && %macros.device', + 'device_down' => '%devices.status = "0" && %macros.device', //Port Macros - 'port' => '(%ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0")', - 'port_up' => '(%ports.ifOperStatus = "up" && %ports.ifAdminStatus = "up" && %macros.port)', - 'port_down' => '(%ports.ifOperStatus = "down" && %ports.ifAdminStatus != "down" && %macros.port)', + 'port' => '%ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0"', + 'port_up' => '%ports.ifOperStatus = "up" && %ports.ifAdminStatus = "up" && %macros.port', + 'port_down' => '%ports.ifOperStatus = "down" && %ports.ifAdminStatus != "down" && %macros.port', 'port_usage_perc' => '((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100', //Misc Macros