diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index d90bf4ff0a..253c90cc0b 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -321,6 +321,8 @@ __devices.location__ = The devices location. __devices.status__ = The status of the device, 1 = up, 0 = down. +__devices.status_reason__ = The reason the device was detected as down (icmp or snmp). + __devices.ignore__ = If the device is ignored this will be set to 1. __devices.disabled__ = If the device is disabled this will be set to 1. diff --git a/html/includes/table/devices.inc.php b/html/includes/table/devices.inc.php index e89e0b6dbe..25cf21bd51 100644 --- a/html/includes/table/devices.inc.php +++ b/html/includes/table/devices.inc.php @@ -94,7 +94,7 @@ foreach (dbFetchRows($sql, $param) as $device) { if ($device['status'] == '0') { $extra = "danger"; - $msg = "down"; + $msg = $device['status_reason']; } else { $extra = "success"; $msg = "up"; diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 03ec28b0a4..6af89c3b99 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -144,21 +144,23 @@ function poll_device($device, $options) $device['pingable'] = $ping_response['result']; $ping_time = $ping_response['last_ping_timetaken']; $response = array(); + $status_reason = ''; if ($device['pingable']) { $device['snmpable'] = isSNMPable($device); if ($device['snmpable']) { $status = "1"; + $response['status_reason'] = ''; } else { echo("SNMP Unreachable"); $status = "0"; - $response['status'] = 'snmp'; + $response['status_reason'] = 'snmp'; } } else { echo("Unpingable"); $status = "0"; - $response['status'] = 'icmp'; + $response['status_reason'] = 'icmp'; } if ($device['status'] != $status) @@ -166,11 +168,11 @@ function poll_device($device, $options) $poll_update .= $poll_separator . "`status` = '$status'"; $poll_separator = ", "; - dbUpdate(array('status' => $status), 'devices', 'device_id=?', array($device['device_id'])); + dbUpdate(array('status' => $status,'status_reason' => $response['status_reason']), 'devices', 'device_id=?', array($device['device_id'])); dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => "Device is " .($status == '1' ? 'up' : 'down')), 'alerts'); log_event('Device status changed to ' . ($status == '1' ? 'Up' : 'Down'), $device, ($status == '1' ? 'up' : 'down')); - notify($device, "Device ".($status == '1' ? 'Up' : 'Down').": " . $device['hostname'], "Device ".($status == '1' ? 'up' : 'down').": " . $device['hostname'] . " " . $response['status']); + notify($device, "Device ".($status == '1' ? 'Up' : 'Down').": " . $device['hostname'], "Device ".($status == '1' ? 'up' : 'down').": " . $device['hostname'] . " " . $response['status_reason']); } if ($status == "1") diff --git a/sql-schema/056.sql b/sql-schema/056.sql index f8617ab98f..a434a7d68d 100644 --- a/sql-schema/056.sql +++ b/sql-schema/056.sql @@ -1,3 +1,5 @@ CREATE TABLE IF NOT EXISTS `device_perf` ( `id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `timestamp` datetime NOT NULL, `xmt` float NOT NULL, `rcv` float NOT NULL, `loss` float NOT NULL, `min` float NOT NULL, `max` float NOT NULL, `avg` float NOT NULL, KEY `id` (`id`,`device_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; insert into config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.macros.rule.packet_loss_15m','(%macros.past_15m && %device_perf.loss)','(%macros.past_15m && %device_perf.loss)','Packet loss over the last 15 minutes','alerting',0,'macros',0,1,0); insert into config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.macros.rule.packet_loss_5m','(%macros.past_5m && %device_perf.loss)','(%macros.past_5m && %device_perf.loss)','Packet loss over the last 5 minutes','alerting',0,'macros',0,1,0); +ALTER TABLE `devices` ADD `status_reason` VARCHAR( 50 ) NOT NULL AFTER `status` ; +UPDATE `devices` SET `status_reason`='down' WHERE `status`=0;