function ifLabel($interface, $device = NULL) { global $config; if (!$device) { $device = device_by_id_cache($interface['device_id']); } $os = strtolower($device['os']); if (isset($config['os'][$os]['ifname'])) { $interface['label'] = $interface['ifName']; if ($interface['ifName'] == "") { $interface['label'] = $interface['ifDescr']; } else { $interface['label'] = $interface['ifName']; } } elseif (isset($config['os'][$os]['ifalias'])) { $interface['label'] = $interface['ifAlias']; } else { $interface['label'] = $interface['ifDescr']; if (isset($config['os'][$os]['ifindex'])) { $interface['label'] = $interface['label'] . " " . $interface['ifIndex']; } } if ($device['os'] == "speedtouch") { list($interface['label']) = explode("thomson", $interface['label']); } return $interface; }
function discover_new_device($hostname, $source = 'xdp') { global $config, $debug; if ($config['autodiscovery'][$source]) { echo "Discovering new host {$hostname}\n"; if (!empty($config['mydomain']) && isDomainResolves($hostname . "." . $config['mydomain'])) { if ($debug) { echo "appending " . $config['mydomain'] . "!\n"; } $dst_host = $hostname . "." . $config['mydomain']; } else { $dst_host = $hostname; } $ip = gethostbyname($dst_host); if ($debug) { echo "resolving {$dst_host} to {$ip}\n"; } if (match_network($config['autodiscovery']['ip_nets'], $ip)) { if ($debug) { echo "found {$ip} inside configured nets, adding!\n"; } $remote_device_id = addHost($dst_host); if ($remote_device_id) { $remote_device = device_by_id_cache($remote_device_id, 1); array_push($GLOBALS['devices'], $remote_device); return $remote_device_id; } } } else { if ($debug) { echo "{$source} autodiscovery disabled"; } return FALSE; } }
function discover_new_device($hostname, $device = '', $method = '', $interface = '') { global $config; if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) { $dst_host = $hostname . '.' . $config['mydomain']; } else { $dst_host = $hostname; } d_echo("discovering {$dst_host}\n"); $ip = gethostbyname($dst_host); if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { // $ip isn't a valid IP so it must be a name. if ($ip == $dst_host) { d_echo("name lookup of {$dst_host} failed\n"); log_event("{$method} discovery of " . $dst_host . " failed - Check name lookup", $device['device_id'], 'discovery'); return false; } } elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true) { // gethostbyname returned a valid $ip, was $dst_host an IP? if ($config['discovery_by_ip'] === false) { d_echo('Discovery by IP disabled, skipping ' . $dst_host); log_event("{$method} discovery of " . $dst_host . " failed - Discovery by IP disabled", $device['device_id'], 'discovery'); return false; } } d_echo("ip lookup result: {$ip}\n"); $dst_host = rtrim($dst_host, '.'); // remove trailing dot if (match_network($config['autodiscovery']['nets-exclude'], $ip)) { d_echo("{$ip} in an excluded network - skipping\n"); return false; } if (match_network($config['nets'], $ip)) { try { $remote_device_id = addHost($dst_host, '', '161', 'udp', $config['distributed_poller_group']); $remote_device = device_by_id_cache($remote_device_id, 1); echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]'; discover_device($remote_device); device_by_id_cache($remote_device_id, 1); if ($remote_device_id && is_array($device) && !empty($method)) { $extra_log = ''; $int = ifNameDescr($interface); if (is_array($int)) { $extra_log = ' (port ' . $int['label'] . ') '; } log_event('Device ' . $remote_device['hostname'] . " ({$ip}) {$extra_log} autodiscovered through {$method} on " . $device['hostname'], $remote_device_id, 'discovery'); } else { log_event("{$method} discovery of " . $remote_device['hostname'] . " ({$ip}) failed - Check ping and SNMP access", $device['device_id'], 'discovery'); } return $remote_device_id; } catch (HostExistsException $e) { // already have this device } catch (Exception $e) { log_event("{$method} discovery of " . $dst_host . " ({$ip}) failed - " . $e->getMessage()); } } else { d_echo("{$ip} not in a matched network - skipping\n"); } //end if }
function discover_new_device($hostname, $device = '', $method = '', $interface = '') { global $config, $debug; if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) { $dst_host = $hostname . '.' . $config['mydomain']; } else { $dst_host = $hostname; } if ($debug) { echo "discovering {$dst_host}\n"; } $ip = gethostbyname($dst_host); if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { // $ip isn't a valid IP so it must be a name. if ($ip == $dst_host) { if ($debug) { echo "name lookup of {$dst_host} failed\n"; } return false; } } if ($debug) { echo "ip lookup result: {$ip}\n"; } $dst_host = rtrim($dst_host, '.'); // remove trailing dot if (match_network($config['autodiscovery']['nets-exclude'], $ip)) { if ($debug) { echo "{$ip} in an excluded network - skipping\n"; } return false; } if (match_network($config['nets'], $ip)) { $remote_device_id = addHost($dst_host, '', '161', 'udp', '0', $config['distributed_poller_group']); if ($remote_device_id) { $remote_device = device_by_id_cache($remote_device_id, 1); echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]'; discover_device($remote_device); device_by_id_cache($remote_device_id, 1); if ($remote_device_id && is_array($device) && !empty($method)) { $extra_log = ''; $int = ifNameDescr($interface); if (is_array($int)) { $extra_log = ' (port ' . $int['label'] . ') '; } log_event('Device $' . $remote_device['hostname'] . " ({$ip}) {$extra_log} autodiscovered through {$method} on " . $device['hostname'], $remote_device_id, 'system'); } else { log_event("{$method} discovery of " . $remote_device['hostname'] . " ({$ip}) failed - check ping and SNMP access", $device['device_id'], 'system'); } return $remote_device_id; } } else { if ($debug) { echo "{$ip} not in a matched network - skipping\n"; } } //end if }
/** * Display neighbours. * * Display pages with device neighbours in some formats. * Examples: * print_neighbours() - display all neighbours from all devices * print_neighbours(array('pagesize' => 99)) - display 99 neighbours from all device * print_neighbours(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 neighbours from page 3 with pagination header * print_neighbours(array('pagesize' => 10, 'device' = 4)) - display 10 neighbours for device_id 4 * * @param array $vars * @return none * */ function print_neighbours($vars) { // Get neighbours array $neighbours = get_neighbours_array($vars); if (!$neighbours['count']) { // There have been no entries returned. Print the warning. print_warning('<h4>No neighbours found!</h4>'); } else { // Entries have been returned. Print the table. $list = array('device' => FALSE); if ($vars['page'] != 'device') { $list['device'] = TRUE; } if (in_array($vars['graph'], array('bits', 'upkts', 'nupkts', 'pktsize', 'percent', 'errors', 'etherlike', 'fdb_count'))) { $graph_types = array($vars['graph']); } else { $graph_types = array('bits', 'upkts', 'errors'); } $string = generate_box_open($vars['header']); $string .= '<table class="table table-striped table-hover table-condensed">' . PHP_EOL; $cols = array(array(NULL, 'class="state-marker"'), 'device_a' => 'Local Device', 'port_a' => 'Local Port', 'NONE' => NULL, 'device_b' => 'Remote Device', 'port_b' => 'Remote Port', 'protocol' => 'Protocol'); if (!$list['device']) { unset($cols[0], $cols['device_a']); } $string .= get_table_header($cols, $vars); $string .= ' <tbody>' . PHP_EOL; foreach ($neighbours['entries'] as $entry) { $string .= ' <tr class="' . $entry['row_class'] . '">' . PHP_EOL; if ($list['device']) { $string .= ' <td class="state-marker"></td>'; $string .= ' <td class="entity">' . generate_device_link($entry, NULL, array('tab' => 'ports', 'view' => 'neighbours')) . '</td>' . PHP_EOL; } $string .= ' <td><span class="entity">' . generate_port_link($entry) . '</span><br />' . $entry['ifAlias'] . '</td>' . PHP_EOL; $string .= ' <td><i class="icon-resize-horizontal text-success"></i></td>' . PHP_EOL; if (is_numeric($entry['remote_port_id']) && $entry['remote_port_id']) { $remote_port = get_port_by_id_cache($entry['remote_port_id']); $remote_device = device_by_id_cache($remote_port['device_id']); $string .= ' <td><span class="entity">' . generate_device_link($remote_device) . '</span><br />' . $remote_device['hardware'] . '</td>' . PHP_EOL; $string .= ' <td><span class="entity">' . generate_port_link($remote_port) . '</span><br />' . $remote_port['ifAlias'] . '</td>' . PHP_EOL; } else { $string .= ' <td><span class="entity">' . $entry['remote_hostname'] . '</span><br />' . $entry['remote_platform'] . '</td>' . PHP_EOL; $string .= ' <td><span class="entity">' . $entry['remote_port'] . '</span></td>' . PHP_EOL; } $string .= ' <td>' . strtoupper($entry['protocol']) . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; $string .= generate_box_close(); // Print pagination header if ($neighbours['pagination_html']) { $string = $neighbours['pagination_html'] . $string . $neighbours['pagination_html']; } // Print echo $string; } }
function add_service($device, $type, $desc, $ip = 'localhost', $param = "", $ignore = 0) { if (!is_array($device)) { $device = device_by_id_cache($device); } if (empty($ip)) { $ip = $device['hostname']; } $insert = array('device_id' => $device['device_id'], 'service_ip' => $ip, 'service_type' => $type, 'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $desc, 'service_param' => $param, 'service_ignore' => $ignore, 'service_status' => 3, 'service_message' => 'Service not yet checked'); return dbInsert($insert, 'services'); }
function discover_new_device($hostname) { global $config, $debug; if ($config['autodiscovery']['xdp']) { if (isDomainResolves($hostname . "." . $config['mydomain'])) { $dst_host = $hostname . "." . $config['mydomain']; } else { $dst_host = $hostname; } if ($debug) { echo "discovering {$dst_host}\n"; } $ip = gethostbyname($dst_host); if ($ip == $dst_host) { if ($debug) { echo "name lookup of {$dst_host} failed\n"; } return FALSE; } else { if ($debug) { echo "ip lookup result: {$ip}\n"; } } $dst_host = rtrim($dst_host, '.'); // remove trailing dot if (match_network($config['autodiscovery']['nets-exclude'], $ip)) { if ($debug) { echo "{$ip} in an excluded network - skipping\n"; } return FALSE; } if (match_network($config['nets'], $ip)) { $remote_device_id = addHost($dst_host); if ($remote_device_id) { $remote_device = device_by_id_cache($remote_device_id, 1); echo "+[" . $remote_device['hostname'] . "(" . $remote_device['device_id'] . ")]"; discover_device($remote_device); $remote_device = device_by_id_cache($remote_device_id, 1); return $remote_device_id; } } else { if ($debug) { echo "{$ip} not in a matched network - skipping\n"; } } } else { if ($debug) { echo "autodiscovery disabled - skipping\n"; } return FALSE; } }
function discover_new_device($hostname) { global $config, $debug; if (!empty($config['mydomain']) && isDomainResolves($hostname . "." . $config['mydomain'])) { $dst_host = $hostname . "." . $config['mydomain']; } else { $dst_host = $hostname; } if ($debug) { echo "discovering {$dst_host}\n"; } $ip = gethostbyname($dst_host); if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) { // $ip isn't a valid IP so it must be a name. if ($ip == $dst_host) { if ($debug) { echo "name lookup of {$dst_host} failed\n"; } return FALSE; } } if ($debug) { echo "ip lookup result: {$ip}\n"; } $dst_host = rtrim($dst_host, '.'); // remove trailing dot if (match_network($config['autodiscovery']['nets-exclude'], $ip)) { if ($debug) { echo "{$ip} in an excluded network - skipping\n"; } return FALSE; } if (match_network($config['nets'], $ip)) { $remote_device_id = addHost($dst_host, '', '161', 'udp', '0', $config['distributed_poller_group']); if ($remote_device_id) { $remote_device = device_by_id_cache($remote_device_id, 1); echo "+[" . $remote_device['hostname'] . "(" . $remote_device['device_id'] . ")]"; discover_device($remote_device); device_by_id_cache($remote_device_id, 1); return $remote_device_id; } } else { if ($debug) { echo "{$ip} not in a matched network - skipping\n"; } } }
function ifLabel($interface, $device = null) { global $config; if (!$device) { $device = device_by_id_cache($interface['device_id']); } $os = strtolower($device['os']); if (isset($config['os'][$os]['ifname'])) { $interface['label'] = $interface['ifName']; if ($interface['ifName'] == '') { $interface['label'] = $interface['ifDescr']; } else { $interface['label'] = $interface['ifName']; } } else { if (isset($config['os'][$os]['ifalias'])) { $interface['label'] = $interface['ifAlias']; } else { $interface['label'] = $interface['ifDescr']; if (isset($config['os'][$os]['ifindex'])) { $interface['label'] = $interface['label'] . ' ' . $interface['ifIndex']; } } } if ($device['os'] == 'speedtouch') { list($interface['label']) = explode('thomson', $interface['label']); } if (is_array($config['rewrite_if'])) { foreach ($config['rewrite_if'] as $src => $val) { if (stristr($interface['label'], $src)) { $interface['label'] = $val; } } } if (is_array($config['rewrite_if_regexp'])) { foreach ($config['rewrite_if_regexp'] as $reg => $val) { if (preg_match($reg . 'i', $interface['label'])) { $interface['label'] = preg_replace($reg . 'i', $val, $interface['label']); } } } return $interface; }
function generate_port_popup($port, $text = NULL, $type = NULL) { global $config; if (!isset($port['os'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } humanize_port($port); if (!$text) { $text = rewrite_ifname($port['label']); } if ($type) { $port['graph_type'] = $type; } if (!isset($port['graph_type'])) { $port['graph_type'] = 'port_bits'; } $class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); if (!isset($port['os'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } $content = generate_device_popup_header($port); $content .= generate_port_popup_header($port); $content .= '<div style="width: 700px">'; $graph_array['type'] = $port['graph_type']; $graph_array['legend'] = "yes"; $graph_array['height'] = "100"; $graph_array['width'] = "275"; $graph_array['to'] = $config['time']['now']; $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $port['port_id']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['week']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['month']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['year']; $content .= generate_graph_tag($graph_array); $content .= "</div>"; return $content; }
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage graphs * @copyright (C) 2006-2014 Adam Armstrong * */ // $cbqos = dbFetchRows("SELECT * FROM `ports_cbqos` WHERE `port_id` = ?", array($port['port_id'])); if (is_numeric($vars['id'])) { $cbqos = dbFetchRow("SELECT * FROM `ports_cbqos` WHERE `cbqos_id` = ?", array($vars['id'])); if (is_numeric($cbqos['device_id']) && ($auth || device_permitted($cbqos['device_id']))) { $device = device_by_id_cache($cbqos['device_id']); $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cbqos-" . $cbqos['policy_index'] . "-" . $cbqos['object_index'] . ".rrd"); $title = generate_device_link($device); $title .= " :: CBQoS :: " . $cbqos['policy_index'] . "-" . $cbqos['object_index']; $auth = TRUE; $graph_return['rrds'][] = $rrd_filename; } }
<?php require 'memcached.inc.php'; require 'includes/graphs/common.inc.php'; $device = device_by_id_cache($vars['id']); require 'includes/graphs/common.inc.php'; $scale_min = 0; $ds = 'threads'; $colour_area = 'F6F6F6'; $colour_line = '555555'; $colour_area_max = 'FFEE99'; // $graph_max = 100; $unit_text = 'Threads'; require 'includes/graphs/generic_simplex.inc.php';
function add_service($device, $service, $descr, $service_ip, $service_param = "", $service_ignore = 0) { if (!is_array($device)) { $device = device_by_id_cache($device); } if (empty($service_ip)) { $service_ip = $device['hostname']; } $insert = array('device_id' => $device['device_id'], 'service_ip' => $service_ip, 'service_type' => $service, 'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $descr, 'service_param' => $service_param, 'service_ignore' => $service_ignore); return dbInsert($insert, 'services'); }
/** * Humanize port. * * Returns a the $port array with processed information: * label, humans_speed, human_type, html_class and human_mac * row_class, table_tab_colour * * @param array $ports * @return array $ports * */ function humanize_port(&$port) { global $config; // Process port data to make it pretty for printing. EVOLUTION, BITCHES. // Lots of hacky shit will end up here with if (os); $device = device_by_id_cache($port['device_id']); $os = $device['os']; $port['human_speed'] = humanspeed($port['ifSpeed']); $port['human_type'] = fixiftype($port['ifType']); $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); $port['human_mac'] = formatMac($port['ifPhysAddress']); if (isset($config['os'][$os]['ifname'])) { $port['label'] = $port['ifName']; if ($port['ifName'] == "") { $port['label'] = $port['ifDescr']; } else { $port['label'] = $port['ifName']; } } elseif (isset($config['os'][$os]['ifalias'])) { $port['label'] = $port['ifAlias']; } else { $port['label'] = $port['ifDescr']; if (isset($config['os'][$os]['ifindex'])) { $port['label'] = $port['label'] . " " . $port['ifIndex']; } } if ($device['os'] == "speedtouch") { list($port['label']) = explode("thomson", $port['label']); } if ($port['ifAdminStatus'] == "down") { $port['table_tab_colour'] = "#aaaaaa"; $port['row_class'] = ""; } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "down") { $port['table_tab_colour'] = "#cc0000"; $port['row_class'] = "error"; } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "lowerLayerDown") { $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "up") { $port['table_tab_colour'] = "#194B7F"; $port['row_class'] = ""; } $port['humanized'] = TRUE; /// Set this so we can check it later. }
<?php if (is_numeric($vars['id'])) { // $auth= TRUE; $rserver = dbFetchRow('SELECT * FROM `loadbalancer_rservers` AS I, `devices` AS D WHERE I.rserver_id = ? AND I.device_id = D.device_id', array($vars['id'])); if (is_numeric($rserver['device_id']) && ($auth || device_permitted($rserver['device_id']))) { $device = device_by_id_cache($rserver['device_id']); $rrd_filename = $config['rrd_dir'] . '/' . $device['hostname'] . '/' . safename('rserver-' . $rserver['rserver_id'] . '.rrd'); $title = generate_device_link($device); $title .= ' :: Rserver :: ' . htmlentities($rserver['farm_id']); $auth = true; } }
function log_event($text, $device = NULL, $type = NULL, $reference = NULL, $severity = 6) { if (!is_array($device)) { $device = device_by_id_cache($device); } if ($device['ignore'] && $type != 'device') { return FALSE; } // Do not log events if device ignored if ($type == 'port') { if (is_array($reference)) { $port = $reference; $reference = $port['port_id']; } else { $port = get_port_by_id_cache($reference); } if ($port['ignore']) { return FALSE; } // Do not log events if interface ignored } $severity = priority_string_to_numeric($severity); // Convert named severities to numeric if ($type == 'device' && $severity == 5 || isset($_SESSION['username'])) { $severity = $severity == 6 ? 5 : $severity; // If severity default, change to notification if (isset($_SESSION['username'])) { $text .= ' (用户: ' . $_SESSION['username'] . ')'; } else { if (is_cli()) { if (is_cron()) { $text .= ' (自动运行)'; } else { $text .= ' (控制台)'; } } } } $insert = array('device_id' => $device['device_id'] ? $device['device_id'] : "NULL", 'entity_id' => is_numeric($reference) ? $reference : array('NULL'), 'entity_type' => $type ? $type : array('NULL'), 'timestamp' => array("NOW()"), 'severity' => $severity, 'message' => $text); $id = dbInsert($insert, 'eventlog'); return $id; }
function get_vlans() { // This will list all vlans for a given device global $config; $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); $hostname = $router['hostname']; $code = 500; if (empty($hostname)) { $output = $output = array('status' => 'error', 'message' => 'No hostname has been provided'); } else { include_once '../includes/functions.php'; $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); $device = null; if ($device_id) { // save the current details for returning to the client on successful delete $device = device_by_id_cache($device_id); } if ($device) { $vlans = dbFetchRows('SELECT vlan_vlan,vlan_domain,vlan_name,vlan_type,vlan_mtu FROM vlans WHERE `device_id` = ?', array($device_id)); $total_vlans = count($vlans); $code = 200; $output = array('status' => 'ok', 'count' => $total_vlans, 'vlans' => $vlans); } else { $code = 404; $output = array('status' => 'error', "Device {$hostname} not found"); } } $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
function log_event($text, $device = NULL, $type = NULL, $reference = NULL) { global $debug; if (!is_array($device)) { $device = device_by_id_cache($device); } $insert = array('host' => $device['device_id'] ? $device['device_id'] : "NULL", 'reference' => $reference ? $reference : "NULL", 'type' => $type ? $type : "NULL", 'datetime' => array("NOW()"), 'message' => $text); dbInsert($insert, 'eventlog'); }
if ($int_links_v6[$int_link]) { echo ' ', overlib_link('', '<span class="label label-success">IPv6</span>', implode("<br />", $int_links_v6[$int_link]), NULL); } if ($int_links_v4[$int_link]) { echo ' ', overlib_link('', '<span class="label label-info">IPv4</span>', implode("<br />", $int_links_v4[$int_link]), NULL); } $br = "<br />"; } } if (!isset($ports_has_ext['pseudowires']) || in_array($port['port_id'], $ports_has_ext['pseudowires'])) { foreach (dbFetchRows("SELECT * FROM `pseudowires` WHERE `port_id` = ?", array($port['port_id'])) as $pseudowire) { //`port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid` # $pw_peer_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($pseudowire['peer_device_id'])); $pw_peer_int = dbFetchRow("SELECT * FROM `ports` AS I, `pseudowires` AS P WHERE I.`device_id` = ? AND P.`cpwVcID` = ? AND P.`port_id` = I.`port_id`", array($pseudowire['peer_device_id'], $pseudowire['cpwVcID'])); # $pw_peer_int = get_port_by_id_cache($pseudowire['peer_device_id']); $pw_peer_dev = device_by_id_cache($pseudowire['peer_device_id']); if (is_array($pw_peer_int)) { humanize_port($pw_peer_int); echo $br . '<i class="oicon-arrow-switch"></i> <strong>' . generate_port_link($pw_peer_int, short_ifname($pw_peer_int['label'])) . ' on ' . generate_device_link($pw_peer_dev, short_hostname($pw_peer_dev['hostname'])) . '</strong>'; } else { echo $br . '<i class="oicon-arrow-switch"></i> <strong> VC ' . $pseudowire['cpwVcID'] . ' on ' . $pseudowire['peer_addr'] . '</strong>'; } echo ' <span class="label">' . $pseudowire['pw_psntype'] . '</span>'; echo ' <span class="label">' . $pseudowire['pw_type'] . '</span>'; $br = "<br />"; } } if (!isset($ports_has_ext['ports_pagp']) || in_array($port['ifIndex'], $ports_has_ext['ports_pagp'])) { foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? AND `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member) { humanize_port($member); $pagp[$device['device_id']][$port['ifIndex']][$member['ifIndex']] = TRUE;
* @copyright 2004-2006 T. Lechat <*****@*****.**>, Manuel Kasper <*****@*****.**>, Jonathan Watt <*****@*****.**> * @license BSD * */ include_once "../includes/defaults.inc.php"; include_once "../config.php"; include_once "../includes/definitions.inc.php"; include_once "../includes/common.inc.php"; include_once "../includes/dbFacile.php"; include_once "../includes/rewrites.inc.php"; include_once "includes/functions.inc.php"; include_once "includes/authenticate.inc.php"; include_once "../includes/snmp.inc.php"; if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) { $port = get_port_by_id($_GET['id']); $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= " :: Port " . generate_port_link($port); $auth = TRUE; } else { echo "Unauthenticad"; die; } header("Content-type: image/svg+xml"); /********** HTTP GET Based Conf ***********/ $ifnum = @$port['ifIndex']; // BSD / SNMP interface name / number $ifname = htmlentities(@$port['ifDescr']); //Interface name that will be showed on top right of graph $hostname = short_hostname($device['hostname']); if ($_GET['title']) {
$remote_device_id = discover_new_device($entry['mtxrNeighborIdentity'], 'xdp', 'MNDP', $device, $port); } // Cache remote device ID for other protocols $GLOBALS['cache']['discovery-protocols'][$entry['mtxrNeighborIdentity']] = $remote_device_id; } } else { // Try to find remote host by remote chassis mac address from DB $remote_mac = str_replace(':', '', strtolower($entry['mtxrNeighborMacAddress'])); $remote_device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `deleted` = '0' AND `ifPhysAddress` = ? LIMIT 1;", array($remote_mac)); if (!$remote_device_id) { // We can also use IP address from mtxrNeighborIpAddress to find remote device. $remote_device_id = dbFetchCell("SELECT `device_id` FROM `ports` LEFT JOIN `ipv4_addresses` on `ports`.`port_id`=`ipv4_addresses`.`port_id` WHERE `deleted` = '0' AND `ipv4_address` = ? LIMIT 1;", array($entry['mtxrNeighborIpAddress'])); } } if ($remote_device_id) { $remote_device_hostname = device_by_id_cache($remote_device_id); // Overwrite remote hostname with the one we know, for devices that we identify by sysName if ($remote_device_hostname['hostname']) { $entry['mtxrNeighborIdentity'] = $remote_device_hostname['hostname']; } } if ($remote_device_id) { // No way to find a remote port other than by MAC address, with the data we're getting from Mikrotik. Only proceed when only one remote port matches... $remote_chassis_id = strtolower(str_replace(':', '', $entry['mtxrNeighborMacAddress'])); $remote_port_ids = dbFetchRows("SELECT `port_id` FROM `ports` WHERE `ifPhysAddress` = ? AND `device_id` = ?", array($remote_chassis_id, $remote_device_id)); if (count($remote_port_ids) == 1) { $remote_port_id = $remote_port_ids[0]['port_id']; } } if (!is_bad_xdp($entry['mtxrNeighborIdentity']) && is_numeric($port['port_id']) && !empty($entry['mtxrNeighborIdentity'])) { // We format the remote MAC just like lldpRemPortId macAddress (I think) (00 11 22 33 44 55) - we don't have an actual remote port name or ifIndex or anything in this MIB.
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage graphs * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ if (is_numeric($vars['id']) && ($auth || application_permitted($vars['id']))) { $app = get_application_by_id($vars['id']); $device = device_by_id_cache($app['device_id']); $title = generate_device_link($device); $title .= $graph_subtype; $auth = TRUE; } // EOF
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; }
<?php echo '<table class="table table-striped table-condensed">'; $i = "1"; echo '<thead><th>Local Port</th> <th>Remote Port</th> <th>Remote Device</th> <th>Protocol</th> </thead>'; foreach (dbFetchRows("SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id", array($device['device_id'])) as $neighbour) { if ($bg_colour == $list_colour_b) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } echo '<tr bgcolor="' . $bg_colour . '">'; echo '<td><span style="font-weight: bold;">' . generate_port_link($neighbour) . '</span><br />' . $neighbour['ifAlias'] . '</td>'; if (is_numeric($neighbour['remote_port_id']) && $neighbour['remote_port_id']) { $remote_port = get_port_by_id($neighbour['remote_port_id']); $remote_device = device_by_id_cache($remote_port['device_id']); echo "<td>" . generate_port_link($remote_port) . "<br />" . $remote_port['ifAlias'] . "</td>"; echo "<td>" . generate_device_link($remote_device) . "<br />" . $remote_device['hardware'] . "</td>"; } else { echo "<td>" . $neighbour['remote_port'] . "</td>"; echo "<td>" . $neighbour['remote_hostname'] . "\n <br />" . $neighbour['remote_platform'] . "</td>"; } echo "<td>" . strtoupper($neighbour['protocol']) . "</td>"; echo "</tr>"; $i++; } echo "</table>";
function generate_ap_link($args, $text = null, $type = null) { global $config; $args = ifNameDescr($args); if (!$text) { $text = fixIfName($args['label']); } if ($type) { $args['graph_type'] = $type; } if (!isset($args['graph_type'])) { $args['graph_type'] = 'port_bits'; } if (!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); } $content = '<div class=list-large>' . $args['text'] . ' - ' . fixifName($args['label']) . '</div>'; if ($args['ifAlias']) { $content .= $args['ifAlias'] . '<br />'; } $content .= "<div style=\\'width: 850px\\'>"; $graph_array = array(); $graph_array['type'] = $args['graph_type']; $graph_array['legend'] = 'yes'; $graph_array['height'] = '100'; $graph_array['width'] = '340'; $graph_array['to'] = $config['time']['now']; $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $args['accesspoint_id']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['week']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['month']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['year']; $content .= generate_graph_tag($graph_array); $content .= '</div>'; $url = generate_ap_url($args); if (port_permitted($args['interface_id'], $args['device_id'])) { return overlib_link($url, $text, $content, null); } else { return fixifName($text); } }
<?php $hostname = gethostbyid($entry['host']); unset($icon); $icon = geteventicon($entry['message']); if ($icon) { $icon = '<img src="images/16/' . $icon . '" />'; } echo '<tr> <td> ' . $entry['datetime'] . ' </td>'; if (!isset($vars['device'])) { $dev = device_by_id_cache($entry['host']); echo '<td> ' . generate_device_link($dev, shorthost($dev['hostname'])) . ' </td>'; } if ($entry['type'] == 'interface') { $this_if = ifLabel(getifbyid($entry['reference'])); $entry['link'] = '<b>' . generate_port_link($this_if, makeshortif(strtolower($this_if['label']))) . '</b>'; } else { $entry['link'] = 'System'; } echo '<td>' . $entry['link'] . '</td>'; echo '<td>' . $entry['message'] . '</td> </tr>';
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage graphs * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ if (is_numeric($vars['id'])) { $sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($vars['id'])); if (is_numeric($sensor['device_id']) && ($auth || is_entity_permitted($sensor['sensor_id'], 'sensor') || device_permitted($sensor['device_id']))) { $device = device_by_id_cache($sensor['device_id']); $rrd_filename = get_rrd_path($device, get_sensor_rrd($device, $sensor)); $title = generate_device_link($device); $title .= " :: Sensors :: "; $auth = TRUE; } } // EOF
/** * 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; }
$query = mysql_query($sql); echo '<div class="container-fluid"> <div class="row"> <div class="col-md-12"> </div> </div> <div class="row"> <div class="col-md-12"> <div class="panel panel-default panel-condensed"> <div class="panel-heading"> <strong>Syslog entries</strong> </div> <table class="table table-hover table-condensed table-striped">'; foreach (dbFetchRows($sql) as $entry) { $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); include 'includes/print-syslog.inc.php'; } echo "</table>"; echo "</div>"; echo "</div>"; echo "</div>"; echo "</div>"; } else { if ($_SESSION['userlevel'] == '10') { $query = "SELECT *,DATE_FORMAT(datetime, '" . $config['dateformat']['mysql']['compact'] . "') as humandate FROM `eventlog` ORDER BY `datetime` 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 =\n P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; } $data = mysql_query($query); echo '<div class="container-fluid">
function device_by_name($name, $refresh = 0) { // FIXME - cache name > id too. return device_by_id_cache(getidbyname($name), $refresh); }