Honour 'Disable all alerting for this host'

Fixes some redundancy in macros (parentesis)
This commit is contained in:
f0o
2015-05-18 10:23:25 +00:00
parent b8b9ef7abe
commit 4c10cb625b
3 changed files with 12 additions and 7 deletions

View File

@@ -84,6 +84,9 @@ function IsRuleValid($device,$rule) {
*/ */
function IssueAlert($alert) { function IssueAlert($alert) {
global $config; 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? $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); $obj = DescribeAlert($alert);
if( is_array($obj) ) { if( is_array($obj) ) {
@@ -101,6 +104,7 @@ function IssueAlert($alert) {
} }
echo "\r\n"; echo "\r\n";
} }
return true;
} }
/** /**
@@ -312,6 +316,7 @@ function DescribeAlert($alert) {
$i = 0; $i = 0;
$device = dbFetchRow("SELECT hostname FROM devices WHERE device_id = ?",array($alert['device_id'])); $device = dbFetchRow("SELECT hostname FROM devices WHERE device_id = ?",array($alert['device_id']));
$obj['hostname'] = $device['hostname']; $obj['hostname'] = $device['hostname'];
$obj['device_id'] = $alert['device_id'];
$extra = $alert['details']; $extra = $alert['details'];
if( $alert['state'] >= 1 ) { if( $alert['state'] >= 1 ) {
$obj['title'] = 'Alert for device '.$device['hostname'].' Alert-ID #'.$alert['id']; $obj['title'] = 'Alert for device '.$device['hostname'].' Alert-ID #'.$alert['id'];

View File

@@ -162,7 +162,7 @@ function RunMacros($rule,$x=1) {
krsort($config['alert']['macros']['rule']); krsort($config['alert']['macros']['rule']);
foreach( $config['alert']['macros']['rule'] as $macro=>$value ) { foreach( $config['alert']['macros']['rule'] as $macro=>$value ) {
if( !strstr($macro," ") ) { if( !strstr($macro," ") ) {
$rule = str_replace('%macros.'.$macro,$value,$rule); $rule = str_replace('%macros.'.$macro,'('.$value.')',$rule);
} }
} }
if( strstr($rule,"%macros") ) { if( strstr($rule,"%macros") ) {

View File

@@ -215,14 +215,14 @@ $config['alert'] = array(
'past_60m' => 'DATE_SUB(NOW(),INTERVAL 60 MINUTE)', 'past_60m' => 'DATE_SUB(NOW(),INTERVAL 60 MINUTE)',
//Device Macros //Device Macros
'device' => '(%devices.disabled = "0" && %devices.ignore = "0")', 'device' => '%devices.disabled = "0" && %devices.ignore = "0"',
'device_up' => '(%devices.status = "1" && %macros.device)', 'device_up' => '%devices.status = "1" && %macros.device',
'device_down' => '(%devices.status = "0" && %macros.device)', 'device_down' => '%devices.status = "0" && %macros.device',
//Port Macros //Port Macros
'port' => '(%ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0")', 'port' => '%ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0"',
'port_up' => '(%ports.ifOperStatus = "up" && %ports.ifAdminStatus = "up" && %macros.port)', 'port_up' => '%ports.ifOperStatus = "up" && %ports.ifAdminStatus = "up" && %macros.port',
'port_down' => '(%ports.ifOperStatus = "down" && %ports.ifAdminStatus != "down" && %macros.port)', 'port_down' => '%ports.ifOperStatus = "down" && %ports.ifAdminStatus != "down" && %macros.port',
'port_usage_perc' => '((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100', 'port_usage_perc' => '((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100',
//Misc Macros //Misc Macros