コード例 #1
0
ファイル: common.php プロジェクト: RomanBogachev/observium
function deviceUptime($device, $format = "long")
{
    if ($device['status'] == 0) {
        $since = time() - strtotime($device['last_polled']);
        return "Down " . formatUptime($since, $format);
    } else {
        return formatUptime($device['uptime'], $format);
    }
}
コード例 #2
0
ファイル: services.inc.php プロジェクト: awlx/librenms
        echo $service['service_id'];
        ?>
' name='edit-service'><i class='fa fa-pencil' aria-hidden='true'></i></button>
                    <button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-service_id='<?php 
        echo $service['service_id'];
        ?>
' name='delete-service'><i class='fa fa-trash' aria-hidden='true'></i></button>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="col-sm-8"><?php 
        echo nl2br(trim($service['service_message']));
        ?>
</div>
                <div class="col-sm-4"><?php 
        echo formatUptime(time() - $service['service_changed']);
        ?>
</div>
            </div>
<?php 
        if ($vars['view'] == 'details') {
            // if we have a script for this check, use it.
            $check_script = $config['install_dir'] . '/includes/services/check_' . strtolower($service['service_type']) . '.inc.php';
            if (is_file($check_script)) {
                include $check_script;
                // If we have a replacement DS use it.
                if (isset($check_ds)) {
                    $service['service_ds'] = $check_ds;
                }
            }
            $graphs = json_decode($service['service_ds'], true);
コード例 #3
0
ファイル: jt.php プロジェクト: CumulusNetworks/cldemo-archive
foreach (dbFetchRows($sql) as $service) {
    if (device_permitted($service['device_id'])) {
        echo "<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>\n      <strong>" . generate_device_link($service, shorthost($service['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Service Down</span><br />\n      <strong>" . $service['service_type'] . "</strong><br />\n      <span class=body-date-1>" . truncate($interface['ifAlias'], 15) . "</span>\n      </center></div>";
    }
}
$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id";
foreach (dbFetchRows($sql) as $peer) {
    if (device_permitted($peer['device_id'])) {
        echo "<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>\n      <strong>" . generate_device_link($peer, shorthost($peer['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>BGP Down</span><br />\n      <strong>" . $peer['bgpPeerIdentifier'] . "</strong><br />\n      <span class=body-date-1>AS" . $peer['bgpPeerRemoteAs'] . " " . truncate($peer['astext'], 10) . "</span>\n      </div>";
    }
}
if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
    $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'";
    foreach (dbFetchRows($sql) as $device) {
        if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") {
            echo "<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ddffdd;'>\n        <strong>" . generate_device_link($device, shorthost($device['hostname'])) . "</strong><br />\n        <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #090;'>Device<br />Rebooted</span><br />\n        <span class=body-date-1>" . formatUptime($device['attrib_value']) . "</span>\n        </div>";
        }
    }
}
echo "\n\n        <div style='clear: both;'>{$errorboxes}</div> <div style='margin: 0px; clear: both;'>\n\n<h3>Recent Syslog Messages</h3>\n\n";
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20";
echo "<table cellspacing=0 cellpadding=2 width=100%>";
foreach (dbFetchRows($sql) as $entry) {
    include "includes/print-syslog.inc.php";
}
echo "</table>";
echo "</div>\n\n   </td>\n   <td bgcolor=#e5e5e5 width=470 valign=top>";
// this stuff can be customised to show whatever you want....
if ($_SESSION['userlevel'] >= '5') {
    $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias";
    unset($seperator);
コード例 #4
0
ファイル: default.php プロジェクト: greggcz/librenms
        generate_front_box('bgp-down', generate_device_link($peer, shorthost($peer['hostname'])) . "<br />\n    <span class=bgp-down>BGP Down</span>\n    <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) {
    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'];
    } 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'];
    }
    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>');
        ++$count_boxes;
    }
}
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\n  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>';
}
echo '</div>';
echo '</div>';
echo '</div>';
echo '
  </div>
  </div>
';
if ($config['vertical_summary']) {
コード例 #5
0
                 $temp_output[] = '
                 <a href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'])) . '" title="' . $device['hostname'] . " - " . formatUptime($device['uptime']) . '">
                 <div class="device-availability ' . $deviceState . '" style="width:' . $config['webui']['availability_map_direct_tile_size'] . 'px;">
                     <span class="availability-label label ' . $deviceLabel . ' label-font-border">' . $deviceState . '</span>
                     <span class="device-icon">' . $deviceIcon . '</span><br>
                     <span class="small">' . shorthost(ip_to_sysname($device, $device['hostname'])) . '</span>
                 </div>
                 </a>';
             } else {
                 $temp_output[] = '
                 <a href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'])) . '" title="' . $device['hostname'] . " - " . formatUptime($device['uptime']) . '">
                     <span class="label ' . $deviceLabel . ' widget-availability label-font-border">' . $deviceState . '</span>
                 </a>';
             }
         } else {
             $temp_output[] = '<a href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'])) . '" title="' . $device['hostname'] . " - " . formatUptime($device['uptime']) . '"><div class="' . $deviceLabelOld . '" style="width:' . $compact_tile . 'px;"></div></a>';
         }
     }
 }
 if (($mode == 1 || $mode == 2) && $config['show_services'] != 0) {
     $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `S`.`service_ignore`, `S`.`service.disabled`, `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id` ORDER BY ' . $serviceOrderBy . ';';
     $services = dbFetchRows($service_query);
     if (count($services) > 0) {
         foreach ($services as $service) {
             if ($service['service_disabled'] == '1') {
                 $serviceState = "disabled";
                 $serviceLabel = "blackbg";
                 $serviceDisabledCount++;
             } else {
                 if ($service['service_ignore'] == '1') {
                     $serviceState = "ignored";
コード例 #6
0
    }
}
print_debug("{$uptime_msg} ({$uptime} seconds)");
if (is_numeric($uptime)) {
    // Notify only if current uptime less than one month (eg if changed from sysUpTime to snmpEngineTime)
    if ($uptime < $device['uptime'] && $uptime < 2628000) {
        notify($device, "Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.");
        log_event('Device rebooted after ' . formatUptime($device['uptime']), $device, 'reboot', $device['uptime']);
    }
    $uptime_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd";
    if (!is_file($uptime_rrd)) {
        rrdtool_create($uptime_rrd, "DS:uptime:GAUGE:600:0:U ");
    }
    rrdtool_update($uptime_rrd, "N:" . $uptime);
    $graphs['uptime'] = TRUE;
    print_message("Uptime: " . formatUptime($uptime));
    $update_array['uptime'] = $uptime;
    $cache['devices']['uptime'][$device['device_id']]['uptime'] = $uptime;
    $cache['devices']['uptime'][$device['device_id']]['polled'] = $polled;
}
$poll_device['sysLocation'] = str_replace("\"", "", $poll_device['sysLocation']);
// Rewrite sysLocation if there is a mapping array (database too?)
if (!empty($poll_device['sysLocation'])) {
    $poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
}
$poll_device['sysContact'] = str_replace("\"", "", $poll_device['sysContact']);
if ($poll_device['sysLocation'] == "not set") {
    $poll_device['sysLocation'] = "";
}
if ($poll_device['sysContact'] == "not set") {
    $poll_device['sysContact'] = "";
コード例 #7
0
      </td>
      <td style="width: 7%">
        ' . $row['last_polled_timetaken'] . 's
      </td>
      <td>' . format_timestamp($row['last_polled']) . ' </td>
      <td>' . formatUptime($config['time']['now'] - strtotime($row['last_polled']), 'shorter') . ' ago</td>';
    // Discovery times
    echo '
      <td style="width: 12%;">
        <div class="progress progress-' . $proc['color']['discovery'] . ' active" style="margin-bottom: 5px;"><div class="bar" style="text-align: right; width: ' . $proc['time']['discovery'] . '%;"></div></div>
      </td>
      <td style="width: 7%">
        ' . $row['last_discovered_timetaken'] . 's
      </td>
      <td>' . format_timestamp($row['last_discovered']) . '</td>
      <td>' . formatUptime($config['time']['now'] - strtotime($row['last_discovered']), 'shorter') . ' ago</td>

    </tr>
';
}
// Calculate root mean square
$proc['avg2']['poller'] = sqrt($proc['avg2']['poller'] / $devices['count']);
$proc['avg2']['poller'] = round($proc['avg2']['poller'], 2);
$proc['avg2']['discovery'] = sqrt($proc['avg2']['discovery'] / $devices['count']);
$proc['avg2']['discovery'] = round($proc['avg2']['discovery'], 2);
echo '    <tr>
      <th colspan="4" style="text-align: right;">所有设备的总时间(平均每设备):</th>
      <th colspan="3" style="text-align: left;">' . $cache['devices']['timers']['polling'] . 's (' . $proc['avg2']['poller'] . 's)</th>
      <th></th>
      <th colspan="3" style="text-align: left;">' . $cache['devices']['timers']['discovery'] . 's (' . $proc['avg2']['discovery'] . 's)</th>
    </tr>
コード例 #8
0
ファイル: system.inc.php プロジェクト: REAP720801/librenms
$snmpEngineTime = (int) snmp_get($device, "snmpEngineTime.0", "-OUqv", "SNMP-FRAMEWORK-MIB");
if (!is_numeric($snmpEngineTime)) {
    $snmpEngineTime = 0;
}
if (is_numeric($uptime)) {
    if ($uptime < $device['uptime'] && $uptime >= $snmpEngineTime) {
        notify($device, "Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.");
        log_event('Device rebooted after ' . formatUptime($device['uptime']), $device, 'reboot', $device['uptime']);
    }
    $uptime_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd";
    if (!is_file($uptime_rrd)) {
        rrdtool_create($uptime_rrd, "DS:uptime:GAUGE:600:0:U " . $config['rrd_rra']);
    }
    rrdtool_update($uptime_rrd, "N:" . $uptime);
    $graphs['uptime'] = TRUE;
    echo "Uptime: " . formatUptime($uptime) . "\n";
    $update_array['uptime'] = $uptime;
}
$poll_device['sysLocation'] = str_replace("\"", "", $poll_device['sysLocation']);
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
$poll_device['sysLocation'] = trim($poll_device['sysLocation'], "\\");
// Rewrite sysLocation if there is a mapping array (database too?)
if (!empty($poll_device['sysLocation']) && is_array($config['location_map'])) {
    $poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
}
$poll_device['sysContact'] = str_replace("\"", "", $poll_device['sysContact']);
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
$poll_device['sysContact'] = trim($poll_device['sysContact'], "\\");
if ($poll_device['sysLocation'] == "not set") {
    $poll_device['sysLocation'] = "";
}
コード例 #9
0
/**
 * Check all alerts for a device to see if they should be notified or not
 *
 * @param array device
 * @return NULL
 */
function process_alerts($device)
{
    global $config, $alert_rules, $alert_assoc;
    echo "Processing alerts for " . $device['hostname'] . PHP_EOL;
    $alert_table = cache_device_alert_table($device['device_id']);
    $sql = "SELECT * FROM  `alert_table`";
    $sql .= " LEFT JOIN  `alert_table-state` ON  `alert_table`.`alert_table_id` =  `alert_table-state`.`alert_table_id`";
    $sql .= " WHERE  `device_id` =  ?";
    foreach (dbFetchRows($sql, array($device['device_id'])) as $entry) {
        echo 'Alert: ' . $entry['alert_table_id'] . ' Status: ' . $entry['alert_status'] . ' ';
        // If the alerter is now OK and has previously alerted, send an recovery notice.
        if ($entry['alert_status'] == '1' && $entry['has_alerted'] == '1') {
            $alert = $alert_rules[$entry['alert_test_id']];
            $state = json_decode($entry['state'], TRUE);
            $conditions = json_decode($alert['conditions'], TRUE);
            $entity = get_entity_by_id_cache($entry['entity_type'], $entry['entity_id']);
            $graphs = "";
            $metric_text = "";
            foreach ($state['metrics'] as $metric => $value) {
                $metric_text .= $metric . " = " . $value . PHP_EOL . "<br />";
            }
            // FIXME De-dup this shit soon.
            // - adama
            $message = '
<head>
    <title>Observium Alert</title>
<style>
.observium{ width:100%; max-width: 500px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; border:1px solid #DDDDDD; background-color:#FAFAFA;
 font-size: 13px; color: #777777; }
.header{ font-weight: bold; font-size: 16px; padding: 5px; color: #555555; }
.red { color: #cc0000; }
#deviceinfo tr:nth-child(odd) { background: #ffffff; }
</style>
<style type="text/css"></style></head>
<body>
<table class="observium">
  <tbody>
    <tr>
      <td>
        <table class="observium" id="deviceinfo">
  <tbody>
    <tr><td class="header">RECOVERY</td><td><a style="float: right;" href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $entry['alert_table_id'])) . '">Modify</a></td></tr>
    <tr><td><b>Alert</b></font></td><td class="red">' . $alert['alert_message'] . '</font></td></tr>
    <tr><td><b>Entity</b></font></td><td>' . generate_entity_link($entry['entity_type'], $entry['entity_id'], $entity['entity_name']) . '</font></td></tr>';
            if (strlen($entity['entity_descr']) > 0) {
                $message .= '<tr><td><b>Descr</b></font></td><td>' . $entity['entity_descr'] . '</font>';
            }
            $message .= '
    <tr><td><b>Metrics</b></font></td><td>' . $metric_text . '</font></td></tr>
    <tr><td><b>Duration</b></font></td><td>' . formatUptime(time() - $entry['last_failed']) . '</font></td></tr>
    <tr><td colspan="2" class="header">Device</td></tr>
    <tr><td><b>Device</b></font></td><td>' . generate_device_link($device) . '</font></td></tr>
    <tr><td><b>Hardware</b></font></td><td>' . $device['hardware'] . '</font></td></tr>
    <tr><td><b>Operating System</b></font></td><td>' . $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'] . '</font></td></tr>
    <tr><td><b>Location</b></font></td><td>' . htmlspecialchars($device['location']) . '</font></td></tr>
    <tr><td><b>Uptime</b></font></td><td>' . deviceUptime($device) . '</font></td></tr>
  </tbody></table>
</td></tr>
<tr><td>
<center>' . $graphs . '</center></td></tr>
</tbody></table>
</body>
</html>';
            alert_notify($device, "RECOVER: [" . $device['hostname'] . "] [" . $alert['entity_type'] . "] [" . $entity['entity_name'] . "] " . $alert['alert_message'], $message);
            $update_array['last_recovered'] = time();
            $update_array['has_alerted'] = 0;
            dbUpdate($update_array, 'alert_table-state', '`alert_table_id` = ?', array($entry['alert_table_id']));
        }
        if ($entry['alert_status'] == '0') {
            echo 'Alert tripped. ';
            // Has this been alerted more frequently than the alert interval in the config?
            /// FIXME -- this should be configurable per-entity or per-checker
            if (time() - $entry['last_alerted'] < $config['alerts']['interval'] && !isset($GLOBALS['spam'])) {
                $entry['suppress_alert'] = TRUE;
            }
            // Check if alert has ignore_until set.
            if (is_numeric($entry['ignore_until']) && $entry['ignore_until'] > time()) {
                $entry['suppress_alert'] = TRUE;
            }
            if ($entry['suppress_alert'] != TRUE) {
                echo 'Requires notification. ';
                $alert = $alert_rules[$entry['alert_test_id']];
                $state = json_decode($entry['state'], TRUE);
                $conditions = json_decode($alert['conditions'], TRUE);
                $entity = get_entity_by_id_cache($entry['entity_type'], $entry['entity_id']);
                $condition_text = "";
                foreach ($state['failed'] as $failed) {
                    $condition_text .= $failed['metric'] . " " . $failed['condition'] . " " . $failed['value'] . " (" . $state['metrics'][$failed['metric']] . ")<br />";
                }
                $graphs = "";
                $metric_text = "";
                foreach ($state['metrics'] as $metric => $value) {
                    $metric_text .= $metric . " = " . $value . PHP_EOL . "<br />";
                }
                if (is_array($config['entities'][$entry['entity_type']]['graph'])) {
                    // We can draw a graph for this type/metric pair!
                    $graph_array = $config['entities'][$entry['entity_type']]['graph'];
                    foreach ($graph_array as $key => $val) {
                        // Check to see if we need to do any substitution
                        if (substr($val, 0, 1) == "@") {
                            $nval = substr($val, 1);
                            echo " replaced " . $val . " with " . $entity[$nval] . " from entity. " . PHP_EOL . "<br />";
                            $graph_array[$key] = $entity[$nval];
                        }
                    }
                    print_r($graph_array);
                    $image_data_uri = generate_alert_graph($graph_array);
                    print_r(strlen($image_data_uri));
                    $graphs .= '<img src="' . $image_data_uri . '">' . "<br />";
                    unset($graph_array);
                }
                #$css = data_uri($config['html_dir'].'/css/bootstrap-mini.css' ,'text/css');
                $message = '
<head>
    <title>Observium Alert</title>
<style>
.observium{ width:100%; max-width: 500px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; border:1px solid #DDDDDD; background-color:#FAFAFA;
 font-size: 13px; color: #777777; }
.header{ font-weight: bold; font-size: 16px; padding: 5px; color: #555555; }
.red { color: #cc0000; }
#deviceinfo tr:nth-child(odd) { background: #ffffff; }
</style>
<style type="text/css"></style></head>
<body>
<table class="observium">
  <tbody>
    <tr>
      <td>
        <table class="observium" id="deviceinfo">
  <tbody>
    <tr><td class="header">ALERT</td><td><a style="float: right;" href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $entry['alert_table_id'])) . '">Modify</a></td></tr>
    <tr><td><b>Alert</b></font></td><td class="red">' . $alert['alert_message'] . '</font></td></tr>
    <tr><td><b>Entity</b></font></td><td>' . generate_entity_link($entry['entity_type'], $entry['entity_id'], $entity['entity_name']) . '</font></td></tr>';
                if (strlen($entity['entity_descr']) > 0) {
                    $message .= '<tr><td><b>Descr</b></font></td><td>' . $entity['entity_descr'] . '</font>';
                }
                $message .= '
    <tr><td><b>Conditions</b></font></td><td>' . $condition_text . '</font></td></tr>
    <tr><td><b>Metrics</b></font></td><td>' . $metric_text . '</font></td></tr>
    <tr><td><b>Duration</b></font></td><td>' . formatUptime(time() - $entry['last_failed']) . '</font></td></tr>
    <tr><td colspan="2" class="header">Device</td></tr>
    <tr><td><b>Device</b></font></td><td>' . generate_device_link($device) . '</font></td></tr>
    <tr><td><b>Hardware</b></font></td><td>' . $device['hardware'] . '</font></td></tr>
    <tr><td><b>Operating System</b></font></td><td>' . $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'] . '</font></td></tr>
    <tr><td><b>Location</b></font></td><td>' . htmlspecialchars($device['location']) . '</font></td></tr>
    <tr><td><b>Uptime</b></font></td><td>' . deviceUptime($device) . '</font></td></tr>
  </tbody></table>
</td></tr>
<tr><td>
<center>' . $graphs . '</center></td></tr>
</tbody></table>
</body>
</html>';
                alert_notify($device, "ALERT: [" . $device['hostname'] . "] [" . $alert['entity_type'] . "] [" . $entity['entity_name'] . "] " . $alert['alert_message'], $message);
                $update_array['last_alerted'] = time();
                $update_array['has_alerted'] = 1;
                dbUpdate($update_array, 'alert_table-state', '`alert_table_id` = ?', array($entry['alert_table_id']));
            } else {
                echo "No notification required. " . (time() - $entry['last_alerted']);
            }
        } elseif ($entry['alert_status'] == '1') {
            echo "Status: OK. ";
        } else {
            echo "Unknown status.";
        }
        echo PHP_EOL;
    }
}
コード例 #10
0
ファイル: bgp-peers.inc.php プロジェクト: skive/observium
         $vendor_oid = $vendor_oids[$device['os']][str_replace('bgp', 'vendor_', $bgp_oid)];
         ${$bgp_oid} = $vendor_peers[$peer_ip][$vendor_oid];
     }
     print_debug("Peer: {$peer_ip} (State = {$bgpPeerState} AdminStatus = {$bgpPeerAdminStatus})");
 }
 // FIXME I left the eventlog code for now, as soon as alerts send an entry to the eventlog this can go.
 if ($bgpPeerFsmEstablishedTime) {
     if (!(is_array($config['alerts']['bgp']['whitelist']) && !in_array($peer['bgpPeerRemoteAs'], $config['alerts']['bgp']['whitelist'])) && ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState'])) {
         if ($peer['bgpPeerState'] == $bgpPeerState) {
             log_event('BGP Session flapped: ' . $remote_ip . ' (AS' . $peer['bgpPeerRemoteAs'] . '), time ' . formatUptime($bgpPeerFsmEstablishedTime) . ' ago', $device, 'bgpPeer', $peer['bgpPeer_id']);
         } else {
             if ($bgpPeerState == "established") {
                 log_event('BGP Session Up: ' . $remote_ip . ' (AS' . $peer['bgpPeerRemoteAs'] . '), time ' . formatUptime($bgpPeerFsmEstablishedTime) . ' ago', $device, 'bgpPeer', $peer['bgpPeer_id']);
             } else {
                 if ($peer['bgpPeerState'] == "established") {
                     log_event('BGP Session Down: ' . $remote_ip . ' (AS' . $peer['bgpPeerRemoteAs'] . '), time ' . formatUptime($bgpPeerFsmEstablishedTime) . ' ago.', $device, 'bgpPeer', $peer['bgpPeer_id']);
                 }
             }
         }
     }
 }
 check_entity('bgp_peer', $peer, array('bgpPeerState' => $bgpPeerState, 'bgpPeerAdminStatus' => $bgpPeerAdminStatus, 'bgpPeerFsmEstablishedTime' => $bgpPeerFsmEstablishedTime));
 $polled = time();
 $polled_period = $polled - $peer['bgpPeer_polled'];
 if ($debug) {
     echo "[ polled {$polled} -> period {$polled_period} ]";
 }
 $peer_rrd = 'bgp-' . $peer_ip . '.rrd';
 $create_rrd = "DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 \\\n        DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 \\\n        DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 \\\n        DS:bgpPeerInTotal:COUNTER:600:U:100000000000 \\\n        DS:bgpPeerEstablished:GAUGE:600:0:U ";
 rrdtool_create($device, $peer_rrd, $create_rrd);
 rrdtool_update($device, "{$peer_rrd}", "N:{$bgpPeerOutUpdates}:{$bgpPeerInUpdates}:{$bgpPeerOutTotalMessages}:{$bgpPeerInTotalMessages}:{$bgpPeerFsmEstablishedTime}");
コード例 #11
0
ファイル: devices.inc.php プロジェクト: Rosiak/librenms
    $hostname = generate_device_link($device);
    if (extension_loaded('mbstring')) {
        $location = mb_substr($device['location'], 0, 32, 'utf8');
    } else {
        $location = substr($device['location'], 0, 32);
    }
    if ($subformat == 'detail') {
        $platform = $device['hardware'] . '<br>' . $device['features'];
        $os = $device['os_text'] . '<br>' . $device['version'];
        $uptime = formatUptime($device['uptime'], 'short');
        $hostname .= '<br>' . $device['sysName'];
        if (empty($port_count)) {
            $port_count = 0;
            $col_port = '';
        }
        if ($port_count) {
            $col_port = '<img src="images/icons/port.png" align="absmiddle"> ' . $port_count . '<br>';
        }
        if ($sensor_count) {
            $col_port .= '<img src="images/icons/sensors.png" align="absmiddle"> ' . $sensor_count;
        }
    } else {
        $platform = $device['hardware'];
        $os = $device['os_text'] . ' ' . $device['version'];
        $uptime = formatUptime($device['uptime'], 'short');
    }
    $response[] = array('extra' => $extra, 'msg' => $msg, 'list_type' => $subformat, 'icon' => $image, 'hostname' => $hostname, 'ports' => $col_port, 'hardware' => $platform, 'os' => $os, 'uptime' => $uptime, 'location' => $location, 'actions' => $actions);
}
//end foreach
$output = array('current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total);
echo _json_encode($output);
コード例 #12
0
    // Reset RSS/Atom key
    if ($vars['atom_key'] == "toggle") {
        if (set_user_pref($user_id, 'atom_key', md5(strgen()))) {
            print_success('RSS/Atom key updated.');
            $prefs = get_user_prefs($user_id);
        } else {
            print_error('Error generating RSS/Atom key.');
        }
    }
    // Reset API key
    if ($vars['api_key'] == "toggle") {
        if (set_user_pref($user_id, 'api_key', md5(strgen()))) {
            print_success('API key updated.');
            $prefs = get_user_prefs($user_id);
        } else {
            print_error('Error generating API key.');
        }
    }
}
$atom_key_updated = isset($prefs['atom_key']['updated']) ? formatUptime(time() - strtotime($prefs['atom_key']['updated']), 'shorter') . ' ago' : 'Never';
$api_key_updated = isset($prefs['api_key']['updated']) ? formatUptime(time() - strtotime($prefs['api_key']['updated']), 'shorter') . ' ago' : 'Never';
$filename = $config['html_dir'] . '/pages/preferences/' . $vars['section'] . '.inc.php';
if (is_file($filename)) {
    $vars = get_vars('POST');
    // Note, on edit pages use only method POST!
    include $filename;
} else {
    print_error('<h4>Page does not exist</h4>
The requested page does not exist. Please correct the URL and try again.');
}
// EOF
コード例 #13
0
ファイル: status.inc.php プロジェクト: Natolumin/observium
function get_status_array($status)
{
    // Mike: I know that there are duplicated variables, but later will remove global
    global $config, $cache;
    $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1)));
    $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1)));
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D', 'hide_ignored' => TRUE));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I', 'hide_ignored' => TRUE));
    // Show Device Status
    if ($status['devices']) {
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= 'WHERE D.`status` = 0' . $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            // Since reboot event more complicated than just device uptime less than some time
            //$query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning'];
            $query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`last_rebooted` > ?';
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query, array($config['time']['now'] - $config['uptime_warning'] - 10));
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['neighbours']) {
        $status['neighbours'] = $status['neighbours'] && !$status['ports'];
        // Disable 'neighbours' if 'ports' already enabled
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['neighbours']) {
            $query .= 'INNER JOIN `neighbours` as L ON I.`port_id` = L.`port_id` ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
        $query .= "WHERE D.`status` = 1 AND D.ignore = 0 AND I.ignore = 0 AND I.deleted = 0 AND I.`ifAdminStatus` = 'up' AND (I.`ifOperStatus` = 'lowerLayerDown' OR I.`ifOperStatus` = 'down') ";
        if ($status['neighbours']) {
            $query .= ' AND L.`active` = 1 ';
        }
        $query .= $query_port_permitted;
        $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) ';
        if ($status['neighbours']) {
            $query .= 'GROUP BY L.`port_id` ';
        }
        $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC ';
        $entries = dbFetchRows($query);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > $max_count) {
                // Limit to 200 ports on overview page
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports']['errored'] as $port_id) {
            if (in_array($port_id, $cache['ports']['ignored'])) {
                continue;
            }
            // Skip ignored ports
            $port = get_port_by_id($port_id);
            $device = device_by_id_cache($port['device_id']);
            humanize_port($port);
            if ($port['ifInErrors_delta']) {
                $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']);
            }
            if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                $port['string'] .= ', ';
            }
            if ($port['ifOutErrors_delta']) {
                $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']);
            }
            $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => $port['string'], 'location' => $device['location']);
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.`device_id` = D.`device_id` ';
        $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0";
        $query .= $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            $query = 'SELECT * FROM `bgpPeers` AS B ';
            $query .= 'LEFT JOIN `devices` AS D ON B.`device_id` = D.`device_id` ';
            $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` ';
            $query .= "WHERE D.`status` = 1 AND (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' ";
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $peer) {
                humanize_bgp($peer);
                $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']);
                $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE;
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Return boxes array
    return $boxes;
}
コード例 #14
0
ファイル: events.inc.php プロジェクト: skive/observium
/**
 * Display events.
 *
 * Display pages with device/port/system events on some formats.
 * Examples:
 * print_events() - display last 10 events from all devices
 * print_events(array('pagesize' => 99)) - display last 99 events from all device
 * print_events(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_events(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_events(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_events($vars)
{
    // Get events array
    $events = get_events_array($vars);
    if (!$events['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No eventlog entries found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'port' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'eventlog') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['port']) || empty($vars['port'])) {
            $list['port'] = TRUE;
        }
        $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$events['short']) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['port']) {
                $string .= '      <th>Entity</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            $icon = geteventicon($entry['message']);
            if ($icon) {
                $icon = '<img src="images/16/' . $icon . '" />';
            }
            $string .= '  <tr>' . PHP_EOL;
            if ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= overlib_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td style="width: 160px">';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'eventlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['port']) {
                if ($entry['type'] == 'port') {
                    $this_if = get_port_by_id_cache($entry['reference']);
                    $entry['link'] = '<span class="entity">' . generate_port_link($this_if, short_ifname($this_if['label'])) . '</span>';
                } else {
                    $entry['link'] = ucfirst($entry['type']);
                }
                if (!$events['short']) {
                    $string .= '    <td>' . $entry['link'] . '</td>' . PHP_EOL;
                }
            }
            if ($events['short']) {
                $string .= '    <td class="syslog">' . $entry['link'] . ' ';
            } else {
                $string .= '    <td>';
            }
            $string .= htmlspecialchars($entry['message']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}
コード例 #15
0
$data = snmp_get_multi($device, $oids, "-OQUst", "SNMPv2-MIB:CISCO-CONFIG-MAN-MIB", mib_dirs(array("cisco")));
$config_age = $data[0];
foreach ($config_age as $key => $val) {
    $config_age[$key] = $val / 100;
}
$RunningLastChanged = $config_age['sysUpTime'] - $config_age['ccmHistoryRunningLastChanged'];
$RunningLastChangedTS = time() - $RunningLastChanged;
$RunningLastSaved = $config_age['sysUpTime'] - $config_age['ccmHistoryRunningLastSaved'];
$RunningLastSavedTS = time() - $RunningLastSaved;
$StartupLastChanged = $config_age['sysUpTime'] - $config_age['ccmHistoryStartupLastChanged'];
$StartupLastChangedTS = time() - $StartupLastChanged;
$sysUptimeTS = time() - $config_age['sysUpTime'];
echo 'sysUptime : ' . format_unixtime($sysUptimeTS) . ' | ' . formatUptime($config_age['sysUpTime']) . PHP_EOL;
echo 'Running   : ' . format_unixtime($RunningLastChangedTS) . ' | ' . formatUptime($RunningLastChanged) . PHP_EOL;
echo 'Saved     : ' . format_unixtime($RunningLastSavedTS) . ' | ' . formatUptime($RunningLastSaved) . PHP_EOL;
echo 'Startup   : ' . format_unixtime($StartupLastChangedTS) . ' | ' . formatUptime($StartupLastChanged) . PHP_EOL;
# 7200 and IOS-XE (ASR1k)
if (preg_match('/^Cisco IOS Software, .+? Software \\([^\\-]+-([^\\-]+)-\\w\\),.+?Version ([^, ]+)/', $poll_device['sysDescr'], $regexp_result)) {
    $features = $regexp_result[1];
    $version = $regexp_result[2];
} elseif (preg_match('/Cisco Internetwork Operating System Software\\s+IOS \\(tm\\) [^ ]+ Software \\([^\\-]+-([^\\-]+)-\\w\\),.+?Version ([^, ]+)/', $poll_device['sysDescr'], $regexp_result)) {
    $features = $regexp_result[1];
    $version = $regexp_result[2];
} elseif (is_array($entPhysical)) {
    if ($entPhysical['entPhysicalContainedIn'] === '0') {
        if (!empty($entPhysical['entPhysicalSoftwareRev'])) {
            $version = $entPhysical['entPhysicalSoftwareRev'];
        }
        if (!empty($entPhysical['entPhysicalModelName'])) {
            $hardware = $entPhysical['entPhysicalModelName'];
        } else {
コード例 #16
0
 $graph_type = "bgp_updates";
 $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&amp;type=" . $graph_type . "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'] . "&amp;width=500&amp;height=150";
 $peeraddresslink = "<span class=list-large><a href='device/device=" . $peer['device_id'] . "/tab=routing/proto=bgp/' onmouseover=\"return overlib('<img src=\\'{$peer_daily_url}\\'>', LEFT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\">" . $peer['bgpPeerIdentifier'] . "</a></span>";
 echo '<tr class="bgp"' . ($peer['alert'] ? ' bordercolor="#cc0000"' : '') . ($peer['disabled'] ? ' bordercolor="#cccccc"' : '') . ">";
 unset($sep);
 foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) {
     $afi = $afisafi['afi'];
     $safi = $afisafi['safi'];
     $this_afisafi = $afi . $safi;
     $peer['afi'] .= $sep . $afi . "." . $safi;
     $sep = "<br />";
     $peer['afisafi'][$this_afisafi] = 1;
     // Build a list of valid AFI/SAFI for this peer
 }
 unset($sep);
 echo "  <td></td>\n            <td width=150>" . $localaddresslink . "<br />" . generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')) . "</td>\n            <td width=30><b>&#187;</b></td>\n            <td width=150>" . $peeraddresslink . "</td>\n            <td width=50><b>{$peer_type}</b></td>\n            <td width=50>" . $peer['afi'] . "</td>\n            <td><strong>AS" . $peer['bgpPeerRemoteAs'] . "</strong><br />" . $peer['astext'] . "</td>\n            <td><strong><span style='color: {$admin_col};'>" . $peer['bgpPeerAdminStatus'] . "</span><br /><span style='color: {$col};'>" . $peer['bgpPeerState'] . "</span></strong></td>\n            <td>" . formatUptime($peer['bgpPeerFsmEstablishedTime']) . "<br />\n                Updates <img src='images/16/arrow_down.png' align=absmiddle /> " . format_si($peer['bgpPeerInUpdates']) . "\n                        <img src='images/16/arrow_up.png' align=absmiddle /> " . format_si($peer['bgpPeerOutUpdates']) . "</td></tr>";
 unset($invalid);
 switch ($vars['graph']) {
     case 'prefixes_ipv4unicast':
     case 'prefixes_ipv4multicast':
     case 'prefixes_ipv4vpn':
     case 'prefixes_ipv6unicast':
     case 'prefixes_ipv6multicast':
         list(, $afisafi) = explode("_", $vars['graph']);
         if (isset($peer['afisafi'][$afisafi])) {
             $peer['graph'] = 1;
         }
     case 'updates':
         $graph_array['type'] = "bgp_" . $vars['graph'];
         $graph_array['id'] = $peer['bgpPeer_id'];
 }
コード例 #17
0
/**
 * Display syslog messages.
 *
 * Display pages with device syslog messages.
 * Examples:
 * print_syslogs() - display last 10 syslog messages from all devices
 * print_syslogs(array('pagesize' => 99)) - display last 99 syslog messages from all device
 * print_syslogs(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 syslog messages from page 3 with pagination header
 * print_syslogs(array('pagesize' => 10, 'device' = 4)) - display last 10 syslog messages for device_id 4
 * print_syslogs(array('short' => TRUE)) - show small block with last syslog messages
 *
 * @param array $vars
 * @return none
 *
 */
function print_syslogs($vars)
{
    // Short events? (no pagination, small out)
    $short = isset($vars['short']) && $vars['short'];
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1;
    $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10;
    $start = $pagesize * $pageno - $pagesize;
    $priorities = $GLOBALS['config']['syslog']['priorities'];
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            $cond = array();
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= ' AND `device_id` = ?';
                    $param[] = $value;
                    break;
                case 'priority':
                    if (!is_array($value)) {
                        $value = array($value);
                    }
                    foreach ($value as $k => $v) {
                        // Rewrite priority strings to numbers
                        $value[$k] = priority_string_to_numeric($v);
                    }
                    // Do not break here, it's true!
                // Do not break here, it's true!
                case 'program':
                    if (!is_array($value)) {
                        $value = array($value);
                    }
                    foreach ($value as $v) {
                        $cond[] = '?';
                        $param[] = $v === '[[EMPTY]]' ? '' : $v;
                    }
                    $where .= " AND `{$var}` IN (";
                    $where .= implode(', ', $cond);
                    $where .= ')';
                    break;
                case 'message':
                    foreach (explode(',', $value) as $val) {
                        $param[] = '%' . $val . '%';
                        $cond[] = '`msg` LIKE ?';
                    }
                    $where .= 'AND (';
                    $where .= implode(' OR ', $cond);
                    $where .= ')';
                    break;
                case 'timestamp_from':
                    $where .= ' AND `timestamp` > ?';
                    $param[] = $value;
                    break;
                case 'timestamp_to':
                    $where .= ' AND `timestamp` < ?';
                    $param[] = $value;
                    break;
            }
        }
    }
    // Show events only for permitted devices
    $query_permitted = generate_query_permitted();
    $query = 'FROM `syslog` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`seq`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY `seq` DESC ';
    $query .= "LIMIT {$start},{$pagesize}";
    // Query syslog messages
    $entries = dbFetchRows($query, $param);
    // Query syslog count
    if ($pagination && !$short) {
        $count = dbFetchCell($query_count, $param);
    } else {
        $count = count($entries);
    }
    if (!$count) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No syslog entries found!</h4>
Check that the syslog daemon and Observium configuration options are set correctly, that your devices are configured to send syslog to Observium and that there are no firewalls blocking the messages.

See <a href="http://www.observium.org/wiki/Category:Documentation" target="_blank">documentation</a> and <a href="http://www.observium.org/wiki/Configuration_Options#Syslog_Settings" target="_blank">configuration options</a> for more information.');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'priority' => TRUE);
        // For now (temporarily) priority always displayed
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'syslog') {
            $list['device'] = TRUE;
        }
        if ($short || !isset($vars['priority']) || empty($vars['priority'])) {
            $list['priority'] = TRUE;
        }
        $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$short) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['priority']) {
                $string .= '      <th>Priority</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries as $entry) {
            $string .= '  <tr>';
            if ($short) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= overlib_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td width="160">';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'syslog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['priority']) {
                if (!$short) {
                    $string .= '    <td style="color: ' . $priorities[$entry['priority']]['color'] . '; white-space: nowrap;">' . nicecase($priorities[$entry['priority']]['name']) . ' (' . $entry['priority'] . ')</td>' . PHP_EOL;
                }
            }
            $entry['program'] = empty($entry['program']) ? '[[EMPTY]]' : $entry['program'];
            if ($short) {
                $string .= '    <td class="syslog">';
                $string .= '<strong style="color: ' . $priorities[$entry['priority']]['color'] . ';">' . $entry['program'] . '</strong> : ';
            } else {
                $string .= '    <td>';
                $string .= '<strong>' . $entry['program'] . '</strong> : ';
            }
            $string .= htmlspecialchars($entry['msg']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>' . PHP_EOL;
        // Print pagination header
        if ($pagination && !$short) {
            $string = pagination($vars, $count) . $string . pagination($vars, $count);
        }
        // Print syslog
        echo $string;
    }
}
コード例 #18
0
ファイル: bgpPeer.inc.php プロジェクト: kyrisu/observernms
     if ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState']) {
         if ($device['sysContact']) {
             $email = $device['sysContact'];
         } else {
             $email = $config['email_default'];
         }
         if ($peer['bgpPeerState'] == $bgpPeerState) {
             mail($email, "BGP Session flapped: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session flapped " . formatUptime($bgpPeerFsmEstablishedTime) . " ago.\n\nHostname : " . $device['hostname'] . "\nPeer IP  : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' (' . $peer['astext'] . ')', $config['email_headers']);
             eventlog('BGP Session Flap: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
         } else {
             if ($bgpPeerState == "established") {
                 mail($email, "BGP Session up: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session up since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP  : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' (' . $peer['astext'] . ')', $config['email_headers']);
                 eventlog('BGP Session Up: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
             } else {
                 if ($peer['bgpPeerState'] == "established") {
                     mail($email, "BGP Session down: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session down since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP  : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' (' . $peer['astext'] . ')', $config['email_headers']);
                     eventlog('BGP Session Down: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
                 }
             }
         }
     }
 }
 $peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("bgp-" . $peer['bgpPeerIdentifier'] . ".rrd");
 if (!is_file($peerrrd)) {
     $create_rrd = "DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerInTotal:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerEstablished:GAUGE:600:0:U \\\n      RRA:AVERAGE:0.5:1:600 \\\n      RRA:AVERAGE:0.5:6:700 \\\n      RRA:AVERAGE:0.5:24:775 \\\n      RRA:AVERAGE:0.5:288:797 \\\n      RRA:MAX:0.5:1:600 \\\n      RRA:MAX:0.5:6:700 \\\n      RRA:MAX:0.5:24:775 \\\n      RRA:MAX:0.5:288:797";
     rrdtool_create($peerrrd, $create_rrd);
 }
 rrdtool_update("{$peerrrd}", "N:{$bgpPeerOutUpdates}:{$bgpPeerInUpdates}:{$bgpPeerOutTotalMessages}:{$bgpPeerInTotalMesages}:{$bgpPeerFsmEstablishedTime}");
 $update = "UPDATE bgpPeers SET bgpPeerState = '{$bgpPeerState}', bgpPeerAdminStatus = '{$bgpPeerAdminStatus}', ";
 $update .= "bgpPeerFsmEstablishedTime = '{$bgpPeerFsmEstablishedTime}', bgpPeerInUpdates = '{$bgpPeerInUpdates}' , bgpLocalAddr = '{$bgpLocalAddr}' , bgpPeerOutUpdates = '{$bgpPeerOutUpdates}'";
 $update .= " WHERE `device_id` = '" . $device['device_id'] . "' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "'";
コード例 #19
0
ファイル: bgp.inc.php プロジェクト: skive/observium
     $afi = $afisafi['afi'];
     $safi = $afisafi['safi'];
     $this_afisafi = $afi . $safi;
     $peer['afi'] .= $sep . $afi . "." . $safi;
     $sep = "<br />";
     $peer['afisafi'][$this_afisafi] = 1;
     // Build a list of valid AFI/SAFI for this peer
 }
 $graph_type = "bgp_updates";
 $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&amp;type=" . $graph_type . "&amp;from=" . $config['time']['day'] . "&amp;to=" . $config['time']['now'] . "&amp;width=500&amp;height=150";
 $peeraddresslink = "<span class=entity-title><a onmouseover=\"return overlib('<img src=\\'{$peer_daily_url}\\'>', LEFT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\">" . $peer['human_remoteip'] . "</a></span>";
 echo '<tr class="' . $peer['html_row_class'] . '">';
 echo '
      <td style="width: 1px; background-color: ' . $peer['table_tab_colour'] . '; margin: 0px; padding: 0px"></td>
      <td style="width: 1px;"></td>';
 echo "   <td>" . $peeraddresslink . "<br />" . $peername . "</td>\n           <td><strong>" . $peer['peer_type'] . "</strong></td>\n           <td style='font-size: 10px; font-weight: bold; line-height: 10px;'>" . (isset($peer['afi']) ? $peer['afi'] : '') . "</td>\n           <td><strong>AS" . $peer['bgpPeerRemoteAs'] . "</strong><br />" . $peer['astext'] . "</td>\n           <td><strong><span class='" . $peer['admin_class'] . "'>" . $peer['bgpPeerAdminStatus'] . "</span><br /><span class='" . $peer['state_class'] . "'>" . $peer['bgpPeerState'] . "</span></strong></td>\n           <td>" . formatUptime($peer['bgpPeerFsmEstablishedTime']) . "<br />\n               Updates <i class='oicon-arrow_down'></i> " . format_si($peer['bgpPeerInUpdates']) . "\n                       <i class='oicon-arrow_up'></i> " . format_si($peer['bgpPeerOutUpdates']) . "</td>\n          </tr>";
 unset($invalid);
 switch ($vars['view']) {
     case 'prefixes_ipv4unicast':
     case 'prefixes_ipv4multicast':
     case 'prefixes_vpnv4unicast':
     case 'prefixes_ipv6unicast':
     case 'prefixes_ipv6multicast':
         list(, $afisafi) = explode("_", $vars['view']);
         if (isset($peer['afisafi'][$afisafi])) {
             $peer['graph'] = 1;
         }
         // FIXME no break??
     // FIXME no break??
     case 'updates':
         $graph_array['type'] = "bgp_" . $vars['view'];
コード例 #20
0
ファイル: demo.php プロジェクト: kyrisu/observernms
}
$sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND D.status = '1' AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
while ($interface = mysql_fetch_array($sql)) {
    echo "<div style='border: solid 2px #D0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>\n      <center><strong>" . generatedevicelink($interface, shorthost($interface['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Port Down</span> \n      <strong>" . generateiflink($interface, makeshortif($interface['ifDescr'])) . "</strong> <br />\n      <span class=body-date-1>" . truncate($interface['ifAlias'], 20) . "</span>\n      </center></div>";
}
$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND  D.status = '1' AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'");
while ($service = mysql_fetch_array($sql)) {
    echo "<div style='border: solid 2px #D0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>\n      <center><strong>" . generatedevicelink($service, shorthost($service['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Service Down</span> \n      <strong>" . $service['service_type'] . "</strong><br />\n      <span class=body-date-1>" . truncate($interface['ifAlias'], 20) . "</span>\n      </center></div>";
}
$sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE  D.status = '1' AND bgpPeerState != 'established' AND B.device_id = D.device_id");
while ($peer = mysql_fetch_array($sql)) {
    echo "<div style='border: solid 2px #d0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>\n      <center><strong>" . generatedevicelink($peer, shorthost($peer['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>BGP Down</span> \n      <strong>" . $peer['bgpPeerIdentifier'] . "</strong> <br />\n      <span class=body-date-1>AS" . $peer['bgpPeerRemoteAs'] . " " . truncate($peer['astext'], 10) . "</span>\n      </center></div>";
}
$sql = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND `uptime` < '84600'");
while ($device = mysql_fetch_array($sql)) {
    echo "<div style='border: solid 2px #d0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ddffdd; margin: 4px;'>\n      <center><strong>" . generatedevicelink($device, shorthost($device['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #090;'>Device<br />Rebooted</span><br /> \n      <span class=body-date-1>" . formatUptime($device['uptime']) . "</span>\n      </center></div>";
}
echo "\n\n\t<div style='clear: both;'>{$errorboxes}</div> <div style='margin: 4px; clear: both;'>  \n\n<h3>Recent Syslog Messages</h3>\n\n";
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog AS S, devices AS D \n        WHERE S.device_id = D.device_id ORDER BY timestamp DESC LIMIT 20";
$query = mysql_query($sql);
echo "<table cellspacing=0 cellpadding=2 width=100%>";
while ($entry = mysql_fetch_array($query)) {
    include "includes/print-syslog.inc";
}
echo "</table>";
echo "</div>\n\n   </td>\n   <td bgcolor=#e5e5e5 width=275 valign=top>";
/// this stuff can be customised to show whatever you want....
#if($_SESSION['userlevel'] >= '5') {
echo "<a onmouseover=\"return overlib('<img src=\\'graph.php?type=bits&if=36" . "&from=" . $day . "&to=" . $now . "&width=400&height=150\\'>', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\"  >" . "<div style='font-size: 18px; font-weight: bold;'>Alpha Traffic</div>" . "<img src='graph.php?type=bits&if=36" . "&from=" . $day . "&to=" . $now . "&width=200&height=100'></a>";
echo "<div style='clear: both; margin-top: 10px;'></div>";
echo "<a onmouseover=\"return overlib('<img src=\\'graph.php?type=hrstorage&id=54" . "&from=" . $day . "&to=" . $now . "&width=400&height=150\\'>', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\"  >" . "<div style='font-size: 18px; font-weight: bold;'>Alpha Storage</div>" . "<img src='graph.php?type=hrstorage&id=54" . "&from=" . $day . "&to=" . $now . "&width=200&height=100'></a>";
コード例 #21
0
ファイル: logalert.inc.php プロジェクト: Natolumin/observium
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function print_logalert_log($vars)
{
    global $config;
    foreach (dbFetchRows("SELECT * FROM `syslog_rules` ORDER BY `la_name`") as $la) {
        $syslog_rules[$la['la_id']] = $la;
    }
    $entries = get_logalert_log($vars);
    if (!$entries['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No logging alert entries found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'alert_log') {
            $list['device'] = TRUE;
        }
        if (!isset($vars['la_id']) || empty($vars['la_id'])) {
            $list['la_id'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$entries['short']) {
            $cols = array();
            $cols[] = array(NULL, 'class="state-marker"');
            $cols['date'] = array('Date', 'style="width: 140px"');
            if ($list['device']) {
                $cols['device'] = array('Device', 'style="width: 150px;"');
            }
            if ($list['la_id']) {
                $cols['la_id'] = array('Alert Rule', 'style="width: 150px;"');
            }
            $cols[] = array('Program', 'style="width: 80px"');
            $cols[] = 'Message';
            $cols[] = array('Notified', 'style="width: 40px"');
            $string .= get_table_header($cols);
            // , $vars); // Actually sorting is disabled now
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries['entries'] as $entry) {
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($entries['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td>';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'alertlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['la_id']) {
                $string .= '<td><strong><a href="' . generate_url(array('page' => 'syslog_rules', 'la_id' => $entry['la_id'])) . '">' . (is_array($syslog_rules[$entry['la_id']]) ? $syslog_rules[$entry['la_id']]['la_name'] : 'Rule Deleted') . '</td>' . PHP_EOL;
            }
            $string .= '<td>' . (strlen($entry['program']) ? '<span class="label">' . $entry['program'] . '</span> ' : '') . '</td>' . PHP_EOL;
            $string .= '<td>' . escape_html($entry['message']) . '</td>' . PHP_EOL;
            if (!$vars['short']) {
                //$string .= '<td>' . escape_html($entry['log_type']) . '</td>' . PHP_EOL;
                $string .= '<td style="text-align: right">' . ($entry['notified'] == '1' ? '<span class="label label-success">YES</span>' : ($entry['notified'] == '-1' ? '<span class="label label-suppressed">NO</span>' : '<span class="label">NO</span>')) . '</td>' . PHP_EOL;
            }
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
    }
    // Print pagination header
    if ($entries['pagination_html']) {
        $string = $entries['pagination_html'] . $string . $entries['pagination_html'];
    }
    // Print events
    echo $string;
}
コード例 #22
0
ファイル: IRCBot.php プロジェクト: arrmo/librenms
 private function _device($params)
 {
     $params = explode(' ', $params);
     $hostname = $params[0];
     $device = dbFetchRow('SELECT * FROM `devices` WHERE `hostname` = ?', array($hostname));
     if (!$device) {
         return $this->respond('Error: Bad or Missing hostname, use .listdevices to show all devices.');
     }
     if ($this->user['level'] < 5 && !in_array($device['device_id'], $this->user['devices'])) {
         return $this->respond('Error: Permission denied.');
     }
     $status = $device['status'] ? 'Up ' . formatUptime($device['uptime']) : 'Down';
     $status .= $device['ignore'] ? '*Ignored*' : '';
     $status .= $device['disabled'] ? '*Disabled*' : '';
     return $this->respond($device['os'] . ' ' . $device['version'] . ' ' . $device['features'] . ' ' . $status);
 }
コード例 #23
0
ファイル: core.inc.php プロジェクト: awlx/librenms
}
//end if
if ($device["os"] != "edgeswitch") {
    if ($snmp_uptime > $uptime && is_numeric($snmp_uptime)) {
        $uptime = $snmp_uptime;
        d_echo('hrSystemUptime or sysUpTime looks like to have rolled, using snmpEngineTime instead');
    }
}
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']);
    }
    $tags = array('rrd_def' => 'DS:uptime:GAUGE:600:0:U');
    data_update($device, 'uptime', $tags, $uptime);
    $graphs['uptime'] = true;
    echo 'Uptime: ' . formatUptime($uptime) . "\n";
    $update_array['uptime'] = $uptime;
}
//end if
$poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']);
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
$poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\');
// Rewrite sysLocation if there is a mapping array (database too?)
if (!empty($poll_device['sysLocation']) && (is_array($config['location_map']) || is_array($config['location_map_regex']))) {
    $poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
}
$poll_device['sysContact'] = str_replace('"', '', $poll_device['sysContact']);
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
$poll_device['sysContact'] = trim($poll_device['sysContact'], '\\');
foreach (array('sysLocation', 'sysContact') as $elem) {
    if ($poll_device[$elem] == 'not set') {
コード例 #24
0
ファイル: sla.inc.php プロジェクト: Natolumin/observium
function generate_sla_row($sla, $vars)
{
    global $config;
    humanize_sla($sla);
    $table_cols = "8";
    $graph_array = array();
    $graph_array['to'] = $config['time']['now'];
    $graph_array['id'] = $sla['sla_id'];
    $graph_array['type'] = $sla['graph_type'];
    $graph_array['legend'] = "no";
    $graph_array['width'] = 80;
    $graph_array['height'] = 20;
    $graph_array['bg'] = 'ffffff00';
    $graph_array['from'] = $config['time']['day'];
    if ($sla['rtt_event'] && $sla['rtt_sense']) {
        $mini_graph = generate_graph_tag($graph_array);
    } else {
        // Do not show "Draw Error" minigraph
        $mini_graph = '';
    }
    $out = '<tr class="' . $sla['row_class'] . '"><td class="state-marker"></td>';
    if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
        $out .= '<td class="entity">' . generate_device_link($sla) . '</td>';
        $table_cols++;
    }
    $out .= '<td class="entity">' . generate_entity_link('sla', $sla) . '</td>';
    $out .= '<td>' . $sla['sla_owner'] . '</td>';
    $out .= '<td>' . $sla['rtt_label'] . '</td>';
    $out .= '<td>' . generate_entity_link('sla', $sla, $mini_graph, NULL, FALSE) . '</td>';
    $out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, formatUptime($config['time']['now'] - $sla['rtt_last_change'], 'short-2') . ' ago', format_unixtime($sla['rtt_last_change'])) . '</td>';
    $out .= '<td style="text-align: right;"><strong><span class="' . $sla['rtt_class'] . '">' . $sla['rtt_event'] . '</span></strong></td>';
    $out .= '<td style="text-align: right;"><strong><span class="' . $sla['rtt_class'] . '">' . $sla['rtt_sense'] . '</span></strong></td>';
    $out .= '<td><span class="' . $sla['sla_class'] . '">' . $sla['human_value'] . $sla['human_unit'] . '</span></td>';
    $out .= '</tr>';
    if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $sla['sla_id']) {
        // If id set in vars, display only specific graphs
        $graph_array = array();
        $graph_array['type'] = $sla['graph_type'];
        $graph_array['id'] = $sla['sla_id'];
        $out .= '<tr class="' . $sla['row_class'] . '">';
        $out .= '  <td class="state-marker"></td>';
        $out .= '  <td colspan="' . $table_cols . '">';
        $out .= generate_graph_row($graph_array, TRUE);
        $out .= '  </td>';
        $out .= '</tr>';
    }
    return $out;
}
コード例 #25
0
function get_status_array($status)
{
    // Mike: I know that there are duplicated variables, but later will remove global
    global $config, $cache;
    $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1)));
    $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1)));
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D'));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    // Show Device Status
    if ($status['devices']) {
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= 'WHERE D.`status` = 0' . $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning'];
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['links']) {
        // warning about deprecated option: $config['warn']['ifdown']
        if (isset($config['warn']['ifdown']) && !$config['warn']['ifdown']) {
            print_warning("<strong>Config option obsolete</strong>\n                    Please note that config option <strong>\$config['warn']['ifdown']</strong> is now obsolete.\n                    Use options: <strong>\$config['frontpage']['device_status']['ports']</strong> and <strong>\$config['frontpage']['device_status']['errors']</strong>\n                    To remove this message, delete <strong>\$config['warn']['ifdown']</strong> from configuration file.");
        }
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['links'] && !$status['ports']) {
            $query .= 'INNER JOIN `links` as L ON I.`port_id` = L.`local_port_id` ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
        $query .= "WHERE I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up' ";
        if ($status['links'] && !$status['ports']) {
            $query .= ' AND L.`active` = 1 ';
        }
        $query .= $query_port_permitted;
        $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) ';
        $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC ';
        $entries = dbFetchRows($query);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > $max_count) {
                // Limit to 200 ports on overview page
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports']['errored'] as $port_id) {
            $port = get_port_by_id($port_id);
            $device = device_by_id_cache($port['device_id']);
            humanize_port($port);
            if ($port['ifInErrors_delta']) {
                $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']);
            }
            if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                $port['string'] .= ', ';
            }
            if ($port['ifOutErrors_delta']) {
                $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']);
            }
            $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => $port['string'], 'location' => $device['location']);
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.device_id = D.device_id ';
        $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0";
        $query .= $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'LEFT JOIN `bgpPeers` AS B ON B.`device_id` = D.`device_id` ';
            $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` ';
            $query .= "WHERE (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' ";
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $peer) {
                $peer_ip = strstr($peer['bgpPeerRemoteAddr'], ':') ? Net_IPv6::compress($peer['bgpPeerRemoteAddr']) : $peer['bgpPeerRemoteAddr'];
                $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE;
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Return boxes array
    return $boxes;
}
コード例 #26
0
ファイル: default.php プロジェクト: kyrisu/observernms
}
if ($_SESSION['userlevel'] == '10') {
    $sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
} else {
    $sql = mysql_query("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 bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
}
while ($peer = mysql_fetch_array($sql)) {
    generate_front_box("alert", "<center><strong>" . generatedevicelink($peer, shorthost($peer['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>BGP Down</span> \n      <span style='" . (strstr($peer['bgpPeerIdentifier'], ':') ? 'font-size: 10px' : '') . "'><strong>" . $peer['bgpPeerIdentifier'] . "</strong></span><br />\n      <span title='" . $peer['astext'] . "' class=body-date-1>AS" . $peer['bgpPeerRemoteAs'] . " " . truncate($peer['astext'], 10) . "</span>\n      </center>");
}
if ($_SESSION['userlevel'] == '10') {
    $sql = mysql_query("SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime < '84600' AND D.ignore = 0");
} else {
    $sql = mysql_query("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 < '84600' AND D.ignore = 0");
}
while ($device = mysql_fetch_array($sql)) {
    generate_front_box("info", "<center><strong>" . generatedevicelink($device, shorthost($device['hostname'])) . "</strong><br />\n      <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #009;'>Device<br />Rebooted</span><br />\n      <span class=body-date-1>" . formatUptime($device['uptime'], 'short') . "</span>\n      </center>");
}
if ($config['enable_syslog']) {
    ## Open Syslog Div
    echo "<div style='margin: 4px; clear: both; padding: 5px;'>  \n    <h3>Recent Syslog Messages</h3>\n  ";
    if ($_SESSION['userlevel'] == '10') {
        $sql = "SELECT *,DATE_FORMAT(timestamp, '%D %b %T') as date  FROM `syslog` ORDER BY `timestamp` DESC LIMIT 0,15";
    } else {
        $sql = "SELECT *,DATE_FORMAT(timestamp, '%D %b %T') as date  FROM `syslog` AS E, devices_perms AS P WHERE\n    E.device_id = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `timestamp` DESC LIMIT 0,15";
    }
    $query = mysql_query($sql);
    echo "<table cellspacing=0 cellpadding=2 width=100%>";
    while ($entry = mysql_fetch_array($query)) {
        $entry = array_merge($entry, device_by_id_cache($entry['device_id']));
        include "includes/print-syslog.inc";
    }
コード例 #27
0
ファイル: bgp.inc.php プロジェクト: n-st/librenms
 foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) {
     $afi = $afisafi['afi'];
     $safi = $afisafi['safi'];
     $this_afisafi = $afi . $safi;
     $peer['afi'] .= $sep . $afi . '.' . $safi;
     $sep = '<br />';
     $peer['afisafi'][$this_afisafi] = 1;
     // Build a list of valid AFI/SAFI for this peer
 }
 unset($sep);
 echo '  <td></td>
     <td width=150>' . $localaddresslink . '<br />' . generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')) . '</td>
     <td width=30><b>&#187;</b></td>
     <td width=150>' . $peeraddresslink . "</td>\n            <td width=50><b>{$peer_type}</b></td>\n            <td width=50>" . $peer['afi'] . '</td>
     <td><strong>AS' . $peer['bgpPeerRemoteAs'] . '</strong><br />' . $peer['astext'] . "</td>\n            <td><strong><span style='color: {$admin_col};'>" . $peer['bgpPeerAdminStatus'] . "</span><br /><span style='color: {$col};'>" . $peer['bgpPeerState'] . '</span></strong></td>
     <td>' . formatUptime($peer['bgpPeerFsmEstablishedTime']) . "<br />\n            Updates <img src='images/16/arrow_down.png' align=absmiddle /> " . format_si($peer['bgpPeerInUpdates']) . "\n            <img src='images/16/arrow_up.png' align=absmiddle /> " . format_si($peer['bgpPeerOutUpdates']) . '</td></tr>';
 unset($invalid);
 switch ($vars['graph']) {
     case 'prefixes_ipv4unicast':
     case 'prefixes_ipv4multicast':
     case 'prefixes_ipv4vpn':
     case 'prefixes_ipv6unicast':
     case 'prefixes_ipv6multicast':
         list(, $afisafi) = explode('_', $vars['graph']);
         if (isset($peer['afisafi'][$afisafi])) {
             $peer['graph'] = 1;
         }
     case 'updates':
         $graph_array['type'] = 'bgp_' . $vars['graph'];
         $graph_array['id'] = $peer['bgpPeer_id'];
 }
コード例 #28
0
        <td>Location</td>
        <td>' . $device['location'] . '</td>
      </tr>';
    if (get_dev_attrib($device, 'override_sysLocation_bool') && !empty($device['real_location'])) {
        echo '<tr>
        <td>SNMP Location</td>
        <td>' . $device['real_location'] . '</td>
      </tr>';
    }
}
$loc = parse_location($device['location']);
if (!is_array($loc)) {
    $loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device['location']));
}
if (is_array($loc)) {
    echo '<tr>
        <td>Lat / Lng</td>
        <td>[' . $loc['lat'] . ',' . $loc['lng'] . ']</td>
    </tr>';
}
if ($uptime) {
    echo '<tr>
        <td>Uptime</td>
        <td>' . formatUptime($uptime) . '</td>
      </tr>';
}
echo '</table>
      </div>
      </div>
      </div>
      </div>';
コード例 #29
0
if ($device['ignore'] == '1') {
    $class = 'bg-warning';
    if ($device['status'] == '1') {
        $class = 'bg-success';
    }
}
if ($device['disabled'] == '1') {
    $class = 'bg-info';
}
$type = strtolower($device['os']);
if ($device['os'] == 'ios') {
    formatCiscoHardware($device, true);
}
$device['os_text'] = $config['os'][$device['os']]['text'];
echo '  <tr>
          <td class="' . $class . ' "></td>
          <td>' . $image . '</td>
          <td><span style="font-size: 15px;">' . generate_device_link($device) . '</span></td>';
echo '<td>';
if ($port_count) {
    echo ' <img src="images/icons/port.png" align=absmiddle /> ' . $port_count;
}
echo '<br />';
if ($sensor_count) {
    echo ' <img src="images/icons/sensors.png" align=absmiddle /> ' . $sensor_count;
}
echo '</td>';
echo '    <td>' . $device['hardware'] . ' ' . $device['features'] . '</td>';
echo '    <td>' . formatUptime($device['uptime'], 'short') . ' <br />';
echo '    ' . truncate($device['location'], 32, '') . '</td>';
echo ' </tr>';
コード例 #30
0
 /**
  * @dataProvider providerFormatUptime
  */
 public function testFormatUptime($value, $format, $result)
 {
     $this->assertSame($result, formatUptime($value, $format));
 }