fix: Ignore meraki bad_uptime #4691

This commit is contained in:
crcro
2016-10-08 20:48:11 +03:00
committed by Neil Lathwood
parent c0d7ad44b0
commit 80497f5295
2 changed files with 44 additions and 44 deletions

View File

@@ -33,25 +33,25 @@ $count_boxes = 0;
// Device down boxes
if (is_admin() === true || is_read() === true) {
$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT " . $config['front_page_down_box_limit'];
} else {
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '0' AND D.ignore = '0' LIMIT".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0' LIMIT" . $config['front_page_down_box_limit'];
}
foreach (dbFetchRows($sql) as $device) {
generate_front_box(
'device-down',
generate_device_link($device, shorthost($device['hostname'])).'<br />
generate_device_link($device, shorthost($device['hostname'])) . '<br />
<span class=list-device-down>Device Down</span> <br />
<span class=body-date-1>'.truncate($device['location'], 20).'</span>'
<span class=body-date-1>' . truncate($device['location'], 20) . '</span>'
);
++$count_boxes;
}
if (is_admin() === true || is_read() === true) {
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT " . $config['front_page_down_box_limit'];
} else {
$sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT " . $config['front_page_down_box_limit'];
}
// These things need to become more generic, and more manageable across different frontpages... rewrite inc :>
@@ -62,11 +62,11 @@ if ($config['warn']['ifdown']) {
$interface = ifNameDescr($interface);
generate_front_box(
'alert alert-danger',
generate_device_link($interface, shorthost($interface['hostname']))."<br />
generate_device_link($interface, shorthost($interface['hostname'])) . "<br />
<span class=\"interface-updown\">Port Down</span><br />
<!-- <img src='graph.php?type=bits&amp;if=".$interface['port_id'].'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now']."&amp;width=100&amp;height=32' /> -->
".generate_port_link($interface, truncate(makeshortif($interface['label']), 13, '')).' <br />
'.($interface['ifAlias'] ? '<span class="body-date-1">'.truncate($interface['ifAlias'], 20, '').'</span>' : '')
<!-- <img src='graph.php?type=bits&amp;if=" . $interface['port_id'] . '&amp;from=' . $config['time']['day'] . '&amp;to=' . $config['time']['now'] . "&amp;width=100&amp;height=32' /> -->
" . generate_port_link($interface, truncate(makeshortif($interface['label']), 13, '')) . ' <br />
' . ($interface['ifAlias'] ? '<span class="body-date-1">' . truncate($interface['ifAlias'], 20, '') . '</span>' : '')
);
++$count_boxes;
}
@@ -77,20 +77,20 @@ if ($config['warn']['ifdown']) {
FIXME service permissions? seem nonexisting now.. */
// Service down boxes
if (is_admin() === true || is_read() === true) {
$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = '2' AND D.ignore = '0' AND S.service_ignore = '0' LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = '2' AND D.ignore = '0' AND S.service_ignore = '0' LIMIT " . $config['front_page_down_box_limit'];
$param[] = '';
} else {
$sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '2' LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '2' LIMIT " . $config['front_page_down_box_limit'];
$param[] = $_SESSION['user_id'];
}
foreach (dbFetchRows($sql, $param) as $service) {
generate_front_box(
'service-down',
generate_device_link($service, shorthost($service['hostname'])).'<br />
generate_device_link($service, shorthost($service['hostname'])) . '<br />
<span class=service-down>Service Down</span>
'.$service['service_type'].'<br />
<span class=body-date-1>'.truncate($interface['ifAlias'], 20).'</span>'
' . $service['service_type'] . '<br />
<span class=body-date-1>' . truncate($interface['ifAlias'], 20) . '</span>'
);
++$count_boxes;
}
@@ -98,37 +98,37 @@ foreach (dbFetchRows($sql, $param) as $service) {
// BGP neighbour down boxes
if (isset($config['enable_bgp']) && $config['enable_bgp']) {
if (is_admin() === true || is_read() === true) {
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT " . $config['front_page_down_box_limit'];
} else {
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT " . $config['front_page_down_box_limit'];
}
foreach (dbFetchRows($sql) as $peer) {
generate_front_box(
'bgp-down',
generate_device_link($peer, shorthost($peer['hostname']))."<br />
generate_device_link($peer, shorthost($peer['hostname'])) . "<br />
<span class=bgp-down>BGP Down</span>
<span class='".(strstr($peer['bgpPeerIdentifier'], ':') ? 'front-page-bgp-small' : 'front-page-bgp-normal')."'>".$peer['bgpPeerIdentifier'].'</span><br />
<span class=body-date-1>AS'.truncate($peer['bgpPeerRemoteAs'].' '.$peer['astext'], 14, '').'</span>'
<span class='" . (strstr($peer['bgpPeerIdentifier'], ':') ? 'front-page-bgp-small' : 'front-page-bgp-normal') . "'>" . $peer['bgpPeerIdentifier'] . '</span><br />
<span class=body-date-1>AS' . truncate($peer['bgpPeerRemoteAs'] . ' ' . $peer['astext'], 14, '') . '</span>'
);
++$count_boxes;
}
}
// Device rebooted boxes
if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0 && $config['os'][$os]['bad_uptime'] !== true) {
if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0 && $config['os'][$device['os']]['bad_uptime'] !== true) {
if (is_admin() === true || is_read() === true) {
$sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT " . $config['front_page_down_box_limit'];
} else {
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit'];
$sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT " . $config['front_page_down_box_limit'];
}
foreach (dbFetchRows($sql) as $device) {
generate_front_box(
'device-rebooted',
generate_device_link($device, shorthost($device['hostname'])).'<br />
<span class=device-rebooted>Device Rebooted</span><br />
<span class=body-date-1>'.formatUptime($device['uptime'], 'short').'</span>'
generate_device_link($device, shorthost($device['hostname'])) . '<br />
<span class=device-rebooted>Device Rebooted</span><br />
<span class=body-date-1>' . formatUptime($device['uptime'], 'short') . '</span>'
);
++$count_boxes;
}
@@ -136,7 +136,7 @@ if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $c
if ($count_boxes == 0) {
echo "<h5>Nothing here yet</h5><p class=welcome>This is where status notifications about devices and services would normally go. You might have none
because you run such a great network, or perhaps you've just started using ".$config['project_name'].". If you're new to ".$config['project_name'].', you might
because you run such a great network, or perhaps you've just started using " . $config['project_name'] . ". If you're new to " . $config['project_name'] . ', you might
want to start by adding one or more devices in the Devices menu.</p>';
}
@@ -166,7 +166,7 @@ echo '
';
if ($config['enable_syslog']) {
$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20";
$sql = "SELECT *, DATE_FORMAT(timestamp, '" . $config['dateformat']['mysql']['compact'] . "') AS date from syslog ORDER BY timestamp DESC LIMIT 20";
echo '<div class="container-fluid">
<div class="row">
@@ -197,11 +197,11 @@ if ($config['enable_syslog']) {
echo '</div>';
} else {
if (is_admin() === true || is_read() === true) {
$query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15";
$query = "SELECT *,DATE_FORMAT(datetime, '" . $config['dateformat']['mysql']['compact'] . "') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15";
$alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15';
} else {
$query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = ".$_SESSION['user_id'].' ORDER BY `datetime` DESC LIMIT 0,15';
$alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = '.$_SESSION['user_id'].' ORDER BY `time_logged` DESC LIMIT 0,15';
$query = "SELECT *,DATE_FORMAT(datetime, '" . $config['dateformat']['mysql']['compact'] . "') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . ' ORDER BY `datetime` DESC LIMIT 0,15';
$alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = ' . $_SESSION['user_id'] . ' ORDER BY `time_logged` DESC LIMIT 0,15';
}
echo '<div class="container-fluid">
@@ -222,7 +222,7 @@ if ($config['enable_syslog']) {
include 'includes/print-alerts.inc.php';
}
echo '</table>
echo '</table>
</div>
</div>
<div class="col-md-6 column">

View File

@@ -14,32 +14,32 @@
unset($poll_device);
$snmpdata = snmp_get_multi($device, 'sysUpTime.0 sysLocation.0 sysContact.0 sysName.0 sysObjectID.0', '-OQnUst', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$snmpdata = snmp_get_multi($device, 'sysUpTime.0 sysLocation.0 sysContact.0 sysName.0 sysObjectID.0', '-OQnUst', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$poll_device = $snmpdata[0];
$poll_device['sysName'] = strtolower($poll_device['sysName']);
$poll_device['sysName'] = strtolower($poll_device['sysName']);
$poll_device['sysDescr'] = snmp_get($device, 'sysDescr.0', '-OvQ', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$poll_device['sysDescr'] = snmp_get($device, 'sysDescr.0', '-OvQ', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
if (!empty($agent_data['uptime'])) {
list($uptime) = explode(' ', $agent_data['uptime']);
$uptime = round($uptime);
$uptime = round($uptime);
echo "Using UNIX Agent Uptime ($uptime)\n";
}
if (empty($uptime)) {
$snmp_data = snmp_get_multi($device, 'snmpEngineTime.0 hrSystemUptime.0', '-OQnUst', 'HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$uptime_data = $snmp_data[0];
$snmp_uptime = (integer) $uptime_data['snmpEngineTime'];
$snmp_uptime = (integer)$uptime_data['snmpEngineTime'];
$hrSystemUptime = $uptime_data['hrSystemUptime'];
if (!empty($hrSystemUptime) && !strpos($hrSystemUptime, 'No') && ($device['os'] != 'windows')) {
// Move uptime into agent_uptime
$agent_uptime = $uptime;
$uptime = floor($hrSystemUptime / 100);
echo 'Using hrSystemUptime ('.$uptime."s)\n";
echo 'Using hrSystemUptime (' . $uptime . "s)\n";
} else {
$uptime = floor($poll_device['sysUpTime'] / 100);
echo 'Using SNMP Agent Uptime ('.$uptime."s)\n ";
echo 'Using SNMP Agent Uptime (' . $uptime . "s)\n ";
}//end if
}//end if
@@ -50,9 +50,9 @@ if ($device["os"] != "edgeswitch") {
}
}
if (is_numeric($uptime) && $config['os'][$os]['bad_uptime'] !== true) {
if (is_numeric($uptime) && ($config['os'][$device['os']]['bad_uptime'] !== true)) {
if ($uptime < $device['uptime']) {
log_event('Device rebooted after '.formatUptime($device['uptime']), $device, 'reboot', $device['uptime']);
log_event('Device rebooted after ' . formatUptime($device['uptime']), $device, 'reboot', $device['uptime']);
}
$tags = array(
@@ -62,7 +62,7 @@ if (is_numeric($uptime) && $config['os'][$os]['bad_uptime'] !== true) {
$graphs['uptime'] = true;
echo 'Uptime: '.formatUptime($uptime)."\n";
echo 'Uptime: ' . formatUptime($uptime) . "\n";
$update_array['uptime'] = $uptime;
}//end if
@@ -93,13 +93,13 @@ foreach (array('sysLocation', 'sysContact') as $elem) {
foreach (array('sysContact', 'sysObjectID', 'sysName', 'sysDescr') as $elem) {
if ($poll_device[$elem] && $poll_device[$elem] != $device[$elem]) {
$update_array[$elem] = $poll_device[$elem];
log_event("$elem -> ".$poll_device[$elem], $device, 'system');
log_event("$elem -> " . $poll_device[$elem], $device, 'system');
}
}
if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'] && $device['override_sysLocation'] == 0) {
$update_array['location'] = $poll_device['sysLocation'];
log_event('Location -> '.$poll_device['sysLocation'], $device, 'system');
log_event('Location -> ' . $poll_device['sysLocation'], $device, 'system');
}
if ($config['geoloc']['latlng'] === true) {