* Observium * * This file is part of Observium. * * @package observium * @subpackage graphs * @copyright (C) 2006-2014 Adam Armstrong * */ // Generate a list of ports and then call the multi_bits grapher to generate from the list $i = 0; foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE `port_descr_type` = 'cust' AND `port_descr_descr` = ? AND D.device_id = I.device_id", array($vars['id'])) as $port) { $rrd_filename = get_port_rrdfilename($port, NULL, TRUE); if (is_file($rrd_filename)) { $rrd_list[$i]['filename'] = $rrd_filename; $rrd_list[$i]['descr'] = $port['hostname'] . "-" . $port['ifDescr']; $rrd_list[$i]['descr_in'] = short_hostname($port['hostname']); $rrd_list[$i]['descr_out'] = short_ifname($port['ifDescr'], NULL, FALSE); // Options sets for skip htmlentities $i++; } } $units = 'b'; $total_units = 'B'; $colours_in = 'greens'; $multiplier = "8"; $colours_out = 'blues'; $nototal = 1; $ds_in = "INOCTETS"; $ds_out = "OUTOCTETS"; include "includes/graphs/generic_multi_bits_separated.inc.php";
if ($port_id) { $vars['id'] = $port_id; } } elseif (!empty($vars['ifalias'])) { // Get port by ifAlias $port_id = get_port_id_by_ifAlias($device['device_id'], $vars['ifalias']); if ($port_id) { $vars['id'] = $port_id; } } } elseif (!empty($vars['circuit'])) { // Get port by circuit id $port_id = get_port_id_by_customer(array('circuit' => $vars['circuit'])); if ($port_id) { $vars['id'] = $port_id; } } } if (is_numeric($vars['id']) && ($auth || port_permitted($vars['id']))) { $port = get_port_by_id($vars['id']); $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= " :: Port <b>" . generate_port_link($port) . "</b>"; $title_array = array(); $title_array[] = array('text' => $device['hostname'], 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id']))); $title_array[] = array('text' => 'Ports', 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'ports'))); $title_array[] = array('text' => rewrite_ifname($port['label']), 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']))); $graph_title = short_hostname($device['hostname']) . " :: " . strtolower(short_ifname($port['ifDescr'], NULL, FALSE)); $auth = TRUE; $rrd_filename = get_port_rrdfilename($port, NULL, TRUE); }
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; }
function generate_port_row($port, $vars = array()) { global $config, $cache; $device = device_by_id_cache($port['device_id']); humanize_port($port); if (!isset($vars['view'])) { $vars['view'] = "basic"; } // Populate $port_adsl if the port has ADSL-MIB data if (!isset($cache['ports_option']['ports_adsl']) || in_array($port['port_id'], $cache['ports_option']['ports_adsl'])) { $port_adsl = dbFetchRow("SELECT * FROM `ports_adsl` WHERE `port_id` = ?", array($port['port_id'])); } // Populate $port['tags'] with various tags to identify port statuses and features // Port Errors if ($port['ifInErrors_delta'] > 0 || $port['ifOutErrors_delta'] > 0) { $port['tags'] .= generate_port_link($port, '<span class="label label-important">Errors</span>', 'port_errors'); } // Port Deleted if ($port['deleted'] == '1') { $port['tags'] .= '<a href="' . generate_url(array('page' => 'deleted-ports')) . '"><span class="label label-important">Deleted</span></a>'; } // Port CBQoS if (isset($cache['ports_option']['ports_cbqos'])) { if (in_array($port['port_id'], $cache['ports_option']['ports_cbqos'])) { $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'cbqos')) . '"><span class="label label-info">CBQoS</span></a>'; } } else { if (dbFetchCell("SELECT COUNT(*) FROM `ports_cbqos` WHERE `port_id` = ?", array($port['port_id']))) { $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'cbqos')) . '"><span class="label label-info">CBQoS</span></a>'; } } // Port MAC Accounting if (isset($cache['ports_option']['mac_accounting'])) { if (in_array($port['port_id'], $cache['ports_option']['mac_accounting'])) { $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'macaccounting')) . '"><span class="label label-info">MAC</span></a>'; } } else { if (dbFetchCell("SELECT COUNT(*) FROM `mac_accounting` WHERE `port_id` = ?", array($port['port_id']))) { $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'macaccounting')) . '"><span class="label label-info">MAC</span></a>'; } } // Populated formatted versions of port rates. $port['bps_in'] = formatRates($port['ifInOctets_rate'] * 8); $port['bps_out'] = formatRates($port['ifOutOctets_rate'] * 8); $port['pps_in'] = format_si($port['ifInUcastPkts_rate']) . "pps"; $port['pps_out'] = format_si($port['ifOutUcastPkts_rate']) . "pps"; $string = ''; if ($vars['view'] == "basic" || $vars['view'] == "graphs") { $table_cols = '8'; $string .= '<tr class="' . $port['row_class'] . '"> <td class="state-marker"></td> <td style="width: 1px;"></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; // Increment table columns by one to make sure graph line draws correctly $string .= ' <td style="width: 200px;"><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br /> <span class="em">' . escape_html(truncate($port['location'], 32, "")) . '</span></td>'; } $string .= ' <td><span class="entity">' . generate_port_link($port, rewrite_ifname($port['port_label'])) . ' ' . $port['tags'] . '</span><br /> <span class="em">' . escape_html(truncate($port['ifAlias'], 50, '')) . '</span></td>' . '<td style="width: 110px;"> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . formatRates($port['in_rate']) . '</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . formatRates($port['out_rate']) . '</span><br /></td>' . '<td style="width: 90px;"> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . $port['ifInOctets_perc'] . '%</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . $port['ifOutOctets_perc'] . '%</span><br /></td>' . '<td style="width: 110px;"><i class="icon-circle-arrow-down" style="' . $port['pps_in_style'] . '"></i> <span class="small" style="' . $port['pps_in_style'] . '">' . format_bi($port['ifInUcastPkts_rate']) . 'pps</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['pps_out_style'] . '"></i> <span class="small" style="' . $port['pps_out_style'] . '">' . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span></td>' . '<td style="width: 110px;"><small>' . $port['human_speed'] . '<br />' . $port['ifMtu'] . '</small></td> <td ><small>' . $port['human_type'] . '<br />' . $port['human_mac'] . '</small></td> </tr>'; } else { if ($vars['view'] == "details" || $vars['view'] == "detail") { $table_cols = '9'; $string .= '<tr class="' . $port['row_class'] . '"'; if ($vars['tab'] != "port") { $string .= ' onclick="openLink(\'' . generate_port_url($port) . '\')" style="cursor: pointer;"'; } $string .= '>'; $string .= ' <td class="state-marker"></td> <td style="width: 1px;"></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; // Increment table columns by one to make sure graph line draws correctly $string .= ' <td width="200"><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br /> <span class="em">' . escape_html(truncate($port['location'], 32, "")) . '</span></td>'; } $string .= ' <td style="min-width: 250px;">'; $string .= ' <span class="entity-title"> ' . generate_port_link($port) . ' ' . $port['tags'] . ' </span><br /><span class="small">' . escape_html($port['ifAlias']) . '</span>'; if ($port['ifAlias']) { $string .= '<br />'; } unset($break); if (!isset($cache['ports_option']['ipv4_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv4_addresses'])) { foreach (dbFetchRows("SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip) { $string .= $break . generate_popup_link('ip', $ip['ipv4_address'] . '/' . $ip['ipv4_prefixlen'], NULL, 'small'); $break = "<br />"; } } if (!isset($cache['ports_option']['ipv6_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv6_addresses'])) { foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip6) { $string .= $break . generate_popup_link('ip', $ip6['ipv6_address'] . '/' . $ip6['ipv6_prefixlen'], NULL, 'small'); $break = "<br />"; } } //$string .= '</span>'; $string .= '</td>'; // Print port graph thumbnails $string .= '<td style="width: 147px;">'; $port['graph_type'] = "port_bits"; $graph_array = array(); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $port['port_id']; $graph_array['type'] = $port['graph_type']; $graph_array['width'] = 100; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; $graph_array['from'] = $config['time']['day']; $string .= generate_port_link($port, generate_graph_tag($graph_array)); $port['graph_type'] = "port_upkts"; $graph_array['type'] = $port['graph_type']; $string .= generate_port_link($port, generate_graph_tag($graph_array)); $port['graph_type'] = "port_errors"; $graph_array['type'] = $port['graph_type']; $string .= generate_port_link($port, generate_graph_tag($graph_array)); $string .= '</td>'; $string .= '<td style="width: 100px; white-space: nowrap;">'; if ($port['ifOperStatus'] == "up" || $port['ifOperStatus'] == "monitoring") { // Colours generated by humanize_port $string .= '<i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . formatRates($port['in_rate']) . '</span><br /> <i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . formatRates($port['out_rate']) . '</span><br /> <i class="icon-circle-arrow-down" style="' . $port['pps_in_style'] . '"></i> <span class="small" style="' . $port['pps_in_style'] . '">' . format_bi($port['ifInUcastPkts_rate']) . 'pps</span><br /> <i class="icon-circle-arrow-up" style="' . $port['pps_out_style'] . '"></i> <span class="small" style="' . $port['pps_out_style'] . '">' . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span>'; } $string .= '</td><td style="width: 110px;">'; if ($port['ifType'] && $port['ifType'] != "") { $string .= '<span class="small">' . $port['human_type'] . '</span>'; } else { $string .= '-'; } $string .= '<br />'; if ($port['ifSpeed']) { $string .= '<span class="small">' . humanspeed($port['ifSpeed']) . '</span>'; } if ($port['ifDuplex'] && $port['ifDuplex'] != "unknown") { $string .= '<span class="small"> (' . str_replace("Duplex", "", $port['ifDuplex']) . ')</span>'; } $string .= '<br />'; if ($port['ifMtu'] && $port['ifMtu'] != "") { $string .= '<span class="small">MTU ' . $port['ifMtu'] . '</span>'; } else { $string .= '<span class="small">Unknown MTU</span>'; } // if ($ifHardType && $ifHardType != "") { $string .= '<span class="small">" . $ifHardType . "</span>"); } else { $string .= '-'; } //$string .= '<br />'; // Set VLAN data if the port has ifTrunk populated if ($port['ifTrunk']) { if ($port['ifVlan']) { // Native VLAN if (!isset($cache['ports_vlan'])) { $native_state = dbFetchCell('SELECT `state` FROM `ports_vlans` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $port['port_id'])); $native_name = dbFetchCell('SELECT `vlan_name` FROM vlans WHERE `device_id` = ? AND `vlan_vlan` = ?;', array($device['device_id'], $port['ifVlan'])); } else { $native_state = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['state']; $native_name = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['vlan_name']; } switch ($native_state) { case 'blocking': $class = 'text-danger'; break; case 'forwarding': $class = 'text-success'; break; default: $class = 'muted'; } if (empty($native_name)) { $native_name = 'VLAN' . str_pad($port['ifVlan'], 4, '0', STR_PAD_LEFT); } $native_tooltip = 'NATIVE: <strong class=' . $class . '>' . $port['ifVlan'] . ' [' . $native_name . ']</strong><br />'; } if (!isset($cache['ports_vlan'])) { $vlans = dbFetchRows('SELECT * FROM `ports_vlans` AS PV LEFT JOIN vlans AS V ON PV.`vlan` = V.`vlan_vlan` AND PV.`device_id` = V.`device_id` WHERE PV.`port_id` = ? AND PV.`device_id` = ? ORDER BY PV.`vlan`;', array($port['port_id'], $device['device_id'])); } else { $vlans = $cache['ports_vlan'][$port['port_id']]; } $vlans_count = count($vlans); $rel = $vlans_count || $native_tooltip ? 'tooltip' : ''; // Hide tooltip for empty $string .= '<p class="small"><a class="label label-info" data-rel="' . $rel . '" data-tooltip="<div class=\'small\' style=\'max-width: 320px; text-align: justify;\'>' . $native_tooltip; if ($vlans_count) { $string .= 'ALLOWED: '; $vlans_aggr = array(); foreach ($vlans as $vlan) { if ($vlans_count > 20) { // Aggregate VLANs $vlans_aggr[] = $vlan['vlan']; } else { // List VLANs switch ($vlan['state']) { case 'blocking': $class = 'text-danger'; break; case 'forwarding': $class = 'text-success'; break; default: $class = 'muted'; } if (empty($vlan['vlan_name'])) { 'VLAN' . str_pad($vlan['vlan'], 4, '0', STR_PAD_LEFT); } $string .= '<strong class=' . $class . '>' . $vlan['vlan'] . ' [' . $vlan['vlan_name'] . ']</strong><br />'; } } if ($vlans_count > 20) { // End aggregate VLANs $string .= '<strong>' . range_to_list($vlans_aggr, ', ') . '</strong>'; } } $string .= '</div>">' . $port['ifTrunk'] . '</a></p>'; } else { if ($port['ifVlan']) { if (!isset($cache['ports_vlan'])) { $native_state = dbFetchCell('SELECT `state` FROM `ports_vlans` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $port['port_id'])); $native_name = dbFetchCell('SELECT `vlan_name` FROM vlans WHERE `device_id` = ? AND `vlan_vlan` = ?;', array($device['device_id'], $port['ifVlan'])); } else { $native_state = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['state']; $native_name = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['vlan_name']; } switch ($native_state) { case 'blocking': $class = 'label-error'; break; case 'forwarding': $class = 'label-success'; break; default: $class = ''; } $rel = $native_name ? 'tooltip' : ''; // Hide tooltip for empty $string .= '<br /><span data-rel="' . $rel . '" class="label ' . $class . '" data-tooltip="<strong class=\'small\'>' . $port['ifVlan'] . ' [' . $native_name . ']</strong>">VLAN ' . $port['ifVlan'] . '</span>'; } else { if ($port['ifVrf']) { $vrf_name = dbFetchCell("SELECT `vrf_name` FROM `vrfs` WHERE `vrf_id` = ?", array($port['ifVrf'])); $string .= '<br /><span class="label label-success" data-rel="tooltip" data-tooltip="VRF">' . $vrf_name . '</span>'; } } } $string .= '</td>'; // If the port is ADSL, print ADSL port data. if ($port_adsl['adslLineCoding']) { $string .= '<td style="width: 200px;"><span class="small">'; $string .= '<span class="label">' . $port_adsl['adslLineCoding'] . '</span> <span class="label">' . rewrite_adslLineType($port_adsl['adslLineType']) . '</span>'; $string .= '<br />'; $string .= 'SYN <i class="icon-circle-arrow-down green"></i> ' . formatRates($port_adsl['adslAtucChanCurrTxRate']) . ' <i class="icon-circle-arrow-up blue"></i> ' . formatRates($port_adsl['adslAturChanCurrTxRate']); $string .= '<br />'; //$string .= 'Max:'.formatRates($port_adsl['adslAtucCurrAttainableRate']) . '/'. formatRates($port_adsl['adslAturCurrAttainableRate']); //$string .= '<br />'; $string .= 'ATN <i class="icon-circle-arrow-down green"></i> ' . $port_adsl['adslAtucCurrAtn'] . 'dBm <i class="icon-circle-arrow-up blue"></i> ' . $port_adsl['adslAturCurrAtn'] . 'dBm'; $string .= '<br />'; $string .= 'SNR <i class="icon-circle-arrow-down green"></i> ' . $port_adsl['adslAtucCurrSnrMgn'] . 'dB <i class="icon-circle-arrow-up blue"></i> ' . $port_adsl['adslAturCurrSnrMgn'] . 'dB'; $string .= '</span>'; } else { // Otherwise print normal port data $string .= '<td style="width: 150px;"><span class="small">'; if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") { $string .= $port['human_mac']; } else { $string .= '-'; } $string .= '<br />' . $port['ifLastChange'] . '</span>'; } $string .= '</td>'; $string .= '<td style="min-width: 200px" class="small">'; if (strpos($port['port_label'], "oopback") === FALSE && !$graph_type) { unset($br); // Populate links array for ports with direct links if (!isset($cache['ports_option']['neighbours']) || in_array($port['port_id'], $cache['ports_option']['neighbours'])) { foreach (dbFetchRows('SELECT * FROM `neighbours` WHERE `port_id` = ?', array($port['port_id'])) as $neighbour) { // print_r($link); if ($neighbour['remote_port_id']) { $int_links[$neighbour['remote_port_id']] = $neighbour['remote_port_id']; $int_links_phys[$neighbour['remote_port_id']] = 1; } else { $int_links_unknown[] = $neighbour; } } } else { } // Populate links array for devices which share an IPv4 subnet if (!isset($cache['ports_option']['ipv4_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv4_addresses'])) { foreach (dbFetchColumn('SELECT DISTINCT(`ipv4_network_id`) FROM `ipv4_addresses` LEFT JOIN `ipv4_networks` USING(`ipv4_network_id`) WHERE `port_id` = ? AND `ipv4_network` NOT IN (?);', array($port['port_id'], $config['ignore_common_subnet'])) as $network_id) { $sql = 'SELECT N.*, P.`port_id`, P.`device_id` FROM `ipv4_addresses` AS A, `ipv4_networks` AS N, `ports` AS P WHERE A.`port_id` = P.`port_id` AND P.`device_id` != ? AND A.`ipv4_network_id` = ? AND N.`ipv4_network_id` = A.`ipv4_network_id` AND P.`ifAdminStatus` = "up"'; $params = array($device['device_id'], $network_id); foreach (dbFetchRows($sql, $params) as $new) { if ($cache['devices']['id'][$new['device_id']]['disabled'] && !$config['web_show_disabled']) { continue; } $int_links[$new['port_id']] = $new['port_id']; $int_links_v4[$new['port_id']][] = $new['ipv4_network']; } } } // Populate links array for devices which share an IPv6 subnet if (!isset($cache['ports_option']['ipv6_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv6_addresses'])) { foreach (dbFetchColumn("SELECT DISTINCT(`ipv6_network_id`) FROM `ipv6_addresses`\n LEFT JOIN `ipv6_networks` USING(`ipv6_network_id`)\n WHERE `port_id` = ? AND `ipv6_network` NOT IN (?);", array($port['port_id'], $config['ignore_common_subnet'])) as $network_id) { $sql = "SELECT N.*, P.`port_id`, P.`device_id` FROM `ipv6_addresses` AS A, `ipv6_networks` AS N, `ports` AS P\n WHERE A.`port_id` = P.`port_id` AND P.device_id != ?\n AND A.`ipv6_network_id` = ? AND N.`ipv6_network_id` = A.`ipv6_network_id`\n AND P.`ifAdminStatus` = 'up' AND A.`ipv6_origin` != 'linklayer' AND A.`ipv6_origin` != 'wellknown'"; $params = array($device['device_id'], $network_id); foreach (dbFetchRows($sql, $params) as $new) { if ($cache['devices']['id'][$new['device_id']]['disabled'] && !$config['web_show_disabled']) { continue; } $int_links[$new['port_id']] = $new['port_id']; $int_links_v6[$new['port_id']][] = $new['ipv6_network']; } } } // Output contents of links array foreach ($int_links as $int_link) { $link_if = get_port_by_id_cache($int_link); if (!device_permitted($link_if['device_id'])) { continue; } // Skip not permitted links $link_dev = device_by_id_cache($link_if['device_id']); $string .= $br; if ($int_links_phys[$int_link]) { $string .= '<a data-alt="Directly connected" class="oicon-connect"></a> '; } else { $string .= '<a data-alt="Same subnet" class="oicon-network-hub"></a> '; } $string .= '<b>' . generate_port_link($link_if, $link_if['port_label_short']) . ' on ' . generate_device_link($link_dev, short_hostname($link_dev['hostname'])) . '</b>'; ## FIXME -- do something fancy here. if ($int_links_v6[$int_link]) { $string .= ' ' . overlib_link('', '<span class="label label-success">IPv6</span>', implode("<br />", $int_links_v6[$int_link]), NULL); } if ($int_links_v4[$int_link]) { $string .= ' ' . overlib_link('', '<span class="label label-info">IPv4</span>', implode("<br />", $int_links_v4[$int_link]), NULL); } $br = "<br />"; } // Output content of unknown links array (where ports don't exist in our database, or they weren't matched) foreach ($int_links_unknown as $int_link) { // FIXME -- Expose platform and version here. $string .= '<a data-alt="Directly connected" class="oicon-plug-connect"></a> '; $string .= '<b><i>' . short_ifname($int_link['remote_port']) . '</i></b> on '; $string .= '<i><b>' . generate_tooltip_link(NULL, $int_link['remote_hostname'], '<div class="small" style="max-width: 500px;"><b>' . $int_link['remote_platform'] . '</b><br />' . $int_link['remote_version'] . '</div>') . '</b></i>'; $string .= '<br />'; } } if (!isset($cache['ports_option']['pseudowires']) || in_array($port['port_id'], $cache['ports_option']['pseudowires'])) { foreach (dbFetchRows("SELECT * FROM `pseudowires` WHERE `port_id` = ?", array($port['port_id'])) as $pseudowire) { //`port_id`,`peer_device_id`,`peer_ldp_id`,`pwID`,`pwIndex` # $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.`pwID` = ? AND P.`port_id` = I.`port_id`", array($pseudowire['peer_device_id'], $pseudowire['pwID'])); # $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); $string .= $br . '<i class="oicon-arrow-switch"></i> <strong>' . generate_port_link($pw_peer_int, $pw_peer_int['port_label_short']) . ' on ' . generate_device_link($pw_peer_dev, short_hostname($pw_peer_dev['hostname'])) . '</strong>'; } else { $string .= $br . '<i class="oicon-arrow-switch"></i> <strong> VC ' . $pseudowire['pwID'] . ' on ' . $pseudowire['peer_addr'] . '</strong>'; } $string .= ' <span class="label">' . $pseudowire['pwPsnType'] . '</span>'; $string .= ' <span class="label">' . $pseudowire['pwType'] . '</span>'; $br = "<br />"; } } if (!isset($cache['ports_option']['ports_pagp']) || in_array($port['ifIndex'], $cache['ports_option']['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; $string .= $br . '<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($member) . ' [PAgP]</strong>'; $br = "<br />"; } } if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) { $pagp[$device['device_id']][$port['pagpGroupIfIndex']][$port['ifIndex']] = TRUE; $parent = dbFetchRow("SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?", array($port['pagpGroupIfIndex'], $device['device_id'])); humanize_port($parent); $string .= $br . '<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($parent) . ' [PAgP]</strong>'; $br = "<br />"; } if (!isset($cache['ports_option']['ports_stack_low']) || in_array($port['ifIndex'], $cache['ports_option']['ports_stack_low'])) { foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $higher_if) { if ($higher_if['port_id_high']) { if ($pagp[$device['device_id']][$higher_if['port_id_high']][$port['ifIndex']]) { continue; } // Skip if same PAgP port $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']); if (is_array($this_port)) { $string .= $br . '<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($this_port) . '</strong>'; $br = "<br />"; } } } } if (!isset($cache['ports_option']['ports_stack_high']) || in_array($port['ifIndex'], $cache['ports_option']['ports_stack_high'])) { foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_high` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $lower_if) { if ($lower_if['port_id_low']) { if ($pagp[$device['device_id']][$port['ifIndex']][$lower_if['port_id_low']]) { continue; } // Skip if same PAgP ports $this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low']); if (is_array($this_port)) { $string .= $br . '<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($this_port) . '</strong>'; $br = "<br />"; } } } } unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br); $string .= '</td></tr>'; } } // End Detailed View // If we're showing graphs, generate the graph and print the img tags if ($vars['graph'] == "etherlike") { $graph_file = get_port_rrdfilename($port, "dot3", TRUE); } else { $graph_file = get_port_rrdfilename($port, NULL, TRUE); } if ($vars['graph'] && is_file($graph_file)) { $string .= '<tr><td colspan="' . $table_cols . '">'; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $port['port_id']; $graph_array['type'] = 'port_' . $vars['graph']; $string .= generate_graph_row($graph_array); $string .= '</td></tr>'; } return $string; }
/** * 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; } }
/** * 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; }
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; }
/** * Display pseudowires. * * Display pages with device pseudowires in some formats. * Examples: * print_pseudowires() - display all pseudowires from all devices * print_pseudowires(array('pagesize' => 99)) - display 99 pseudowires from all device * print_pseudowires(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 pseudowires from page 3 with pagination header * print_pseudowires(array('pagesize' => 10, 'device' = 4)) - display 10 pseudowires for device_id 4 * * @param array $vars * @return none * */ function print_pseudowires($vars) { // Get pseudowires array $events = get_pseudowires_array($vars); if (!$events['count']) { // There have been no entries returned. Print the warning. print_warning('<h4>No pseudowires 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 = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL; $cols = array('id' => 'PW ID', 'type' => array('Type', 'style="width: 5%;"'), 'device_a' => 'Local Device', 'port_a' => 'Local Port', 'NONE' => NULL, 'device_b' => 'Remote Device', 'port_b' => 'Remote Port'); if (!$list['device']) { unset($cols['device_a']); } $string .= get_table_header($cols); //, $vars); // Currently sorting is not available $string .= ' <tbody>' . PHP_EOL; foreach ($events['entries'] as $entry) { $string .= ' <tr>' . PHP_EOL; $string .= ' <td style="font-size: 18px; padding: 4px; width: 5%;">' . $entry['pwID'] . '</td>' . PHP_EOL; $string .= ' <td>' . strtoupper($entry['pwPsnType']) . '<br />' . nicecase($entry['pwType']) . '</td>' . PHP_EOL; if ($list['device']) { $local_dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity">' . generate_device_link($local_dev, short_hostname($local_dev['hostname']), array('tab' => 'pseudowires')) . '</td>' . PHP_EOL; } $local_if = get_port_by_id_cache($entry['port_id']); $string .= ' <td class="entity">' . generate_port_link($local_if) . '<br />' . $local_if['ifAlias']; if ($vars['view'] == "minigraphs") { $string .= '<br />'; if ($local_if) { $local_if['width'] = "150"; $local_if['height'] = "30"; $local_if['from'] = $GLOBALS['config']['time']['day']; $local_if['to'] = $GLOBALS['config']['time']['now']; foreach ($graph_types as $graph_type) { $local_if['graph_type'] = "port_" . $graph_type; $string .= generate_port_thumbnail($local_if, FALSE); } } } $string .= '</td>' . PHP_EOL; $string .= ' <td style="width: 3%;"><i class="oicon-arrow_right"></i></td>' . PHP_EOL; if (is_numeric($entry['peer_port_id'])) { $peer_if = get_port_by_id_cache($entry['peer_port_id']); $peer_dev = device_by_id_cache($peer_if['device_id']); $string .= ' <td class="entity">' . generate_device_link($peer_dev, short_hostname($peer_dev['hostname']), array('tab' => 'pseudowires')) . '</br>' . $entry['peer_addr'] . '</td>' . PHP_EOL; $string .= ' <td class="entity">' . generate_port_link($peer_if) . '<br />' . $peer_if['ifAlias']; if ($vars['view'] == "minigraphs") { $string .= '<br />'; if ($peer_if) { $peer_if['width'] = "150"; $peer_if['height'] = "30"; $peer_if['from'] = $GLOBALS['config']['time']['day']; $peer_if['to'] = $GLOBALS['config']['time']['now']; foreach ($graph_types as $graph_type) { $peer_if['graph_type'] = "port_" . $graph_type; $string .= generate_port_thumbnail($peer_if, FALSE); } } } $string .= '</td>' . PHP_EOL; } else { // Show only peer address (and PTR name) $string .= ' <td class="entity">' . $entry['peer_rdns'] . '<br />' . $entry['peer_addr'] . '</td>' . PHP_EOL; $string .= ' <td class="entity"><br />' . $entry['pwRemoteIfString'] . '</td>' . PHP_EOL; } } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($events['pagination_html']) { $string = $events['pagination_html'] . $string . $events['pagination_html']; } // Print echo $string; } }
/** * Display events. * * Display pages with alert logs in multiple formats. * Examples: * print_alert_log() - display last 10 events from all devices * print_alert_log(array('pagesize' => 99)) - display last 99 events from all device * print_alert_log(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header * print_alert_log(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4 * print_alert_log(array('short' => TRUE)) - show small block with last events * * @param array $vars * @return none * */ function print_alert_log($vars) { global $alert_rules, $config; // This should be set outside, but do it here if it isn't if (!is_array($alert_rules)) { $alert_rules = cache_alert_rules(); } // Get events array $events = get_alert_log($vars); if (!$events['count']) { if (!$vars['no_empty_message']) { // There have been no entries returned. Print the warning. print_message('<h4>No alert log entries found!</h4>', FALSE); } } else { // Entries have been returned. Print the table. $list = array('device' => FALSE, 'entity' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'alert_log') { $list['device'] = TRUE; } if ($events['short'] || !isset($vars['entity']) || empty($vars['entity'])) { $list['entity'] = TRUE; } if (!isset($vars['alert_test_id']) || empty($vars['alert_test_id']) || $vars['page'] == 'alert_check' || TRUE) { $list['alert_test_id'] = TRUE; } if (!isset($vars['entity_type']) || empty($vars['entity_type']) || $vars['page'] == 'alert_check' || TRUE) { $list['entity_type'] = TRUE; } $string = generate_box_open($vars['header']); $string .= '<table class="table table-striped table-hover table-condensed-more">' . PHP_EOL; if (!$events['short']) { $cols = array(); $cols[] = array(NULL, 'class="state-marker"'); $cols['date'] = array('Date', 'style="width: 160px"'); if ($list['device']) { $cols['device'] = 'Device'; } if ($list['alert_test_id']) { $cols['alert_test_id'] = 'Alert Check'; } if ($list['entity']) { $cols['entity'] = 'Entity'; } $cols[] = 'Message'; $cols['status'] = 'Status'; $cols['notified'] = array('Notified', 'style="width: 40px"'); $string .= get_table_header($cols); // , $vars); // Actually sorting is disabled now } $string .= ' <tbody>' . PHP_EOL; foreach ($events['entries'] as $entry) { $alert_rule = $alert_rules[$entry['alert_test_id']]; // Functionize? // Set colours and classes based on the status of the alert if ($entry['log_type'] == 'OK') { $entry['class'] = "green"; $entry['html_row_class'] = "success"; } else { if ($entry['log_type'] == 'RECOVER_NOTIFY') { $entry['class'] = "green"; $entry['html_row_class'] = "info"; } else { if ($entry['log_type'] == 'ALERT_NOTIFY') { $entry['class'] = "red"; $entry['html_row_class'] = "error"; } elseif ($entry['log_type'] == 'FAIL') { $entry['class'] = "red"; $entry['html_row_class'] = "error"; } elseif ($entry['log_type'] == 'FAIL_DELAYED') { $entry['class'] = "purple"; $entry['html_row_class'] = "warning"; } elseif ($entry['log_type'] == 'FAIL_SUPPRESSED') { $entry['class'] = "purple"; $entry['html_row_class'] = "suppressed"; } elseif ($entry['log_type'] == 'RECOVER_SUPPRESSED') { $entry['class'] = "purple"; $entry['html_row_class'] = "suppressed"; } else { // Anything else set the colour to grey and the class to disabled. $entry['class'] = "gray"; $entry['html_row_class'] = "disabled"; } } } $string .= ' <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL; $string .= '<td class="state-marker"></td>' . PHP_EOL; if ($events['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['alert_test_id']) { $string .= ' <td class="entity"><a href="' . generate_url(array('page' => 'alert_check', 'alert_test_id' => $alert_rule['alert_test_id'])) . '">' . escape_html($alert_rule['alert_name']) . '</a></td>'; } if ($list['entity']) { $string .= ' <td class="entity">'; if ($list['entity_type']) { $string .= '<i class="' . $config['entities'][$entry['entity_type']]['icon'] . '"></i> '; } if ($events['short']) { $string .= ' ' . generate_entity_link($entry['entity_type'], $entry['entity_id'], NULL, NULL, NULL, TRUE) . '</td>' . PHP_EOL; } else { $string .= ' ' . generate_entity_link($entry['entity_type'], $entry['entity_id']) . '</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'] ? '<span class="label label-success">YES</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 ($events['pagination_html']) { $string = $events['pagination_html'] . $string . $events['pagination_html']; } // Print events echo $string; } }
/** * 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) { global $config; // Get events array $events = get_events_array($vars); if (!$events['count']) { // There have been no entries returned. Print the warning. print_warning('<h4>没有发现事件内容!</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['entity'] = 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 class="state-marker"></th>' . PHP_EOL; $string .= ' <th>日期</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>设备</th>' . PHP_EOL; } if ($list['entity']) { $string .= ' <th>单位</th>' . PHP_EOL; } $string .= ' <th>信息</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 . '" />'; } switch ($entry['severity']) { case "0": // Emergency // Emergency case "1": // Alert // Alert case "2": // Critical // Critical case "3": // Error $entry['html_row_class'] = "error"; break; case "4": // Warning $entry['html_row_class'] = "warning"; break; case "5": // Notification $entry['html_row_class'] = "recovery"; break; case "6": // Informational $entry['html_row_class'] = "up"; break; case "7": // Debugging $entry['html_row_class'] = "suppressed"; break; default: } $string .= ' <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL; $string .= '<td class="state-marker"></td>' . 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['entity']) { if ($entry['entity_type'] == 'device' && !$entry['entity_id']) { $entry['entity_id'] = $entry['device_id']; } if ($entry['entity_type'] == 'port') { $this_if = get_port_by_id_cache($entry['entity_id']); $entry['link'] = '<span class="entity"><i class="' . $config['entities']['port']['icon'] . '"></i> ' . generate_port_link($this_if, short_ifname($this_if['label'])) . '</span>'; } else { if (!empty($config['entities'][$entry['entity_type']]['icon'])) { $entry['link'] = '<i class="' . $config['entities'][$entry['entity_type']]['icon'] . '"></i> ' . generate_entity_link($entry['entity_type'], $entry['entity_id']); } else { $entry['link'] = nicecase($entry['entity_type']); } } if (!$events['short']) { $string .= ' <td>' . $entry['link'] . '</td>' . PHP_EOL; } } if ($events['short']) { $string .= ' <td class="syslog">'; if (strpos($entry['message'], $entry['link']) !== 0) { $string .= $entry['link'] . ' '; } } else { $string .= ' <td>'; } $string .= escape_html($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; } }
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage graphs * @copyright (C) 2006-2014 Adam Armstrong * */ include "includes/graphs/device/auth.inc.php"; if ($auth && is_numeric($_GET['mod']) && is_numeric($_GET['chan'])) { $entity = dbFetchRow("SELECT * FROM entPhysical WHERE device_id = ? AND entPhysicalIndex = ?", array($device['device_id'], $_GET['mod'])); $title .= " :: " . $entity['entPhysicalName']; $title .= " :: Fabric " . $_GET['chan']; $graph_title = short_hostname($device['hostname']) . "::" . $entity['entPhysicalName'] . "::Fabric" . $_GET['chan']; $rrd_filename = get_rrd_path($device, "c6kxbar-" . $_GET['mod'] . "-" . $_GET['chan'] . ".rrd"); }
echo '<tr class="' . $peer['html_row_class'] . '">'; unset($sep); foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerRemoteAddr = ?", array($peer['device_id'], $peer['bgpPeerRemoteAddr'])) 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 style="width: 1px; background-color: ' . $peer['table_tab_colour'] . '; margin: 0px; padding: 0px"></td> <td style="width: 1px;"></td>'; echo "\n <td style='width: 150px;'>" . $localaddresslink . "<br />" . generate_device_link($peer, short_hostname($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')) . "</td>\n <td style='width: 30px;'><b>»</b></td>\n <td style='width: 150px;'>" . $peeraddresslink . "<br />" . $peername . "</td>\n <td style='width: 50px;'><b>" . $peer['peer_type'] . "</b></td>\n <td style='width: 50px;'><small>" . $peer['afi'] . "</small></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></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']; }
echo '<table class="table table-bordered table-striped">'; $i = "1"; foreach (dbFetchRows("SELECT * FROM `vrfs` GROUP BY `mplsVpnVrfRouteDistinguisher`") as $vrf) { if ($i % 2) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } echo "<tr valign=top bgcolor='{$bg_colour}'>"; echo "<td width=240><a class=entity href='routing/vrf/" . $vrf['mplsVpnVrfRouteDistinguisher'] . "/" . $_GET['optc'] . "/'>" . $vrf['vrf_name'] . "</a><br /><span class=small>" . $vrf['mplsVpnVrfDescription'] . "</span></td>"; echo "<td width=100 class=small>" . $vrf['mplsVpnVrfRouteDistinguisher'] . "</td>"; #echo("<td width=200 class=small>" . $vrf['mplsVpnVrfDescription'] . "</td>"); echo '<td><table class="table table-striped table-bordered table-condensed">'; $x = 1; foreach ($vrf_devices[$vrf['mplsVpnVrfRouteDistinguisher']] as $device) { echo '<tr><td width=150><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'])) . '</span>'; if ($device['vrf_name'] != $vrf['vrf_name']) { echo "<a href='#' onmouseover=\" return overlib('Expected Name : " . $vrf['vrf_name'] . "<br />Configured : " . $device['vrf_name'] . "', CAPTION, '<span class=entity-title>VRF Inconsistency</span>' ,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\"> <img align=absmiddle src=images/16/exclamation.png></a>"; } echo "</td><td>"; unset($seperator); foreach ($ports[$device['vrf_id']][$device['device_id']] as $port) { $port = array_merge($device, $port); switch ($_GET['optc']) { case 'bits': case 'upkts': case 'nupkts': case 'errors': $port['width'] = "130"; $port['height'] = "30"; $port['from'] = $config['time']['day'];
echo '<div class="row"><div class="col-md-12">'; echo '<h4>' . generate_link(nicecase($app_type), array('page' => 'apps', 'app' => $app_type)) . '</h4>'; $app_devices = array_sort_by($app_types[$app_type], 'hostname', SORT_ASC, SORT_STRING); foreach ($app_devices as $app) { $graph_type = $config['app'][$app['app_type']]['top'][0]; $graph_array['type'] = "application_" . $app['app_type'] . "_" . $graph_type; $graph_array['id'] = $app['app_id']; $graph_array_zoom['type'] = "application_" . $app['app_type'] . "_" . $graph_type; $graph_array_zoom['id'] = $app['app_id']; $link_array = $graph_array; $link_array['page'] = "device"; $link_array['device'] = $app['device_id']; $link_array['tab'] = "apps"; $link_array['app'] = $app['app_type']; unset($link_array['height'], $link_array['width']); $overlib_url = generate_url($link_array); $overlib_link = '<span style="float:left; margin-left: 10px; font-weight: bold;">' . short_hostname($app['hostname']) . "</span>"; if (!empty($app['app_instance'])) { $overlib_link .= '<span style="float:right; margin-right: 10px; font-weight: bold;">' . $app['app_instance'] . "</span>"; $app['content_add'] = '(' . $app['app_instance'] . ')'; } $overlib_link .= "<br/>"; $overlib_link .= generate_graph_tag($graph_array); $overlib_content = generate_overlib_content($graph_array, $app['hostname'] . " - " . $app['app_type'] . $app['content_add']); echo "<div style='display: block; padding: 1px; padding-top: 3px; margin: 2px; min-width: " . $width_div . "px; max-width:" . $width_div . "px; min-height:165px; max-height:165px;\n text-align: center; float: left; background-color: #f5f5f5;'>"; echo overlib_link($overlib_url, $overlib_link, $overlib_content); echo "</div>"; } echo '</div></div>'; } // EOF
/** * 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; } }
/** * 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']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $pageno = $vars['pageno']; $pagesize = $vars['pagesize']; $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 .= generate_query_values($value, 'device_id'); break; case 'priority': if (!is_array($value)) { $value = explode(',', $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': $where .= generate_query_values($value, $var); break; case 'message': $where .= generate_query_values($value, 'msg', '%LIKE%'); 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(*) ' . $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="' . OBSERVIUM_URL . '/wiki/Category:Documentation" target="_blank">documentation</a> and <a href="' . OBSERVIUM_URL . '/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 = generate_box_open($vars['header']); $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; $string .= ' <th class="state-marker"></th>' . PHP_EOL; # $string .= ' <th></th>' . 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) { switch ($entry['priority']) { case "0": // Emergency // Emergency case "1": // Alert // Alert case "2": // Critical // Critical case "3": // Error $entry['html_row_class'] = "error"; break; case "4": // Warning $entry['html_row_class'] = "warning"; break; case "5": // Notification $entry['html_row_class'] = "recovery"; break; case "6": // Informational $entry['html_row_class'] = "up"; break; case "7": // Debugging $entry['html_row_class'] = "suppressed"; break; default: } $string .= ' <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL; $string .= '<td class="state-marker"></td>' . PHP_EOL; if ($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 width="130">'; $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; width: 95px;"><span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . nicecase($priorities[$entry['priority']]['name']) . ' (' . $entry['priority'] . ')</span></td>' . PHP_EOL; } } $entry['program'] = empty($entry['program']) ? '[[EMPTY]]' : $entry['program']; if ($short) { $string .= ' <td class="syslog">'; $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '"><strong>' . $entry['program'] . '</strong></span> '; } else { $string .= ' <td>'; $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . $entry['program'] . '</span>'; } $string .= escape_html($entry['msg']) . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>' . PHP_EOL; $string .= generate_box_close(); // Print pagination header if ($pagination && !$short) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print syslog echo $string; } }
$sql = 'SELECT * FROM `bgpPeers` AS B LEFT JOIN `bgpPeers-state` AS S ON B.bgpPeer_id = S.bgpPeer_id WHERE `device_id` = ? ' . $where . ' ORDER BY `bgpPeerRemoteAs`, `bgpPeerRemoteAddr`'; foreach (dbFetchRows($sql, array($device['device_id'])) as $peer) { $peer['bgpLocalAs'] = $device['bgpLocalAs']; humanize_bgp($peer); $has_macaccounting = dbFetchCell("SELECT COUNT(*) FROM mac_accounting AS M\n LEFT JOIN `ip_mac` AS I ON M.mac = I.mac_address\n WHERE I.ip_address = ?", array($peer['bgpPeerRemoteAddr'])); unset($peerhost, $peername); $ip_version = strstr($peer['bgpPeerRemoteAddr'], ':') ? 'ipv6' : 'ipv4'; $peerhost = dbFetchRow('SELECT * FROM ' . $ip_version . '_addresses AS A LEFT JOIN ports AS I ON A.port_id = I.port_id LEFT JOIN devices AS D ON I.device_id = D.device_id WHERE A.' . $ip_version . '_address = ?', array($peer['bgpPeerRemoteAddr'])); if ($peerhost['device_id']) { $peername = generate_device_link($peerhost, short_hostname($peerhost['hostname']), array('tab' => 'routing', 'proto' => 'bgp')); $peer['remote_id'] = $peerhost['device_id']; } else { $peername = $peer['reverse_dns']; } unset($sep); foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerRemoteAddr = ?", array($device['device_id'], $peer['bgpPeerRemoteAddr'])) 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 } $graph_type = "bgp_updates";
/** * Display bgp peers. * * Display pages with BGP Peers. * Examples: * print_bgp() - display all bgp peers from all devices * print_bgp(array('pagesize' => 99)) - display 99 bgp peers from all device * print_bgp(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 bgp peers from page 3 with pagination header * print_bgp(array('pagesize' => 10, 'device' = 4)) - display 10 bgp peers for device_id 4 * * @param array $vars * @return none * */ function print_bgp_table($vars) { // Get bgp peers array $entries = get_bgp_array($vars); //r($entries); if (!$entries['count']) { // There have been no entries returned. Print the warning. print_warning('<h4>No BGP peers found!</h4>'); } else { // Entries have been returned. Print the table. $list = array('device' => FALSE); if ($vars['page'] != 'device') { $list['device'] = TRUE; } switch ($vars['graph']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': case 'macaccounting_bits': case 'macaccounting_pkts': case 'updates': $table_class = 'table-striped-two'; $list['graph'] = TRUE; break; default: $table_class = 'table-striped'; $list['graph'] = FALSE; } $string = generate_box_open(); $string .= '<table class="table ' . $table_class . ' table-hover table-condensed ">' . PHP_EOL; $cols = array(array(NULL, 'class="state-marker"'), array(NULL, 'style="width: 1px;"'), 'device' => array('Local address', 'style="width: 150px;"'), array(NULL, 'style="width: 20px;"'), 'peer_ip' => array('Peer address', 'style="width: 150px;"'), 'type' => array('Type', 'style="width: 50px;"'), array('Family', 'style="width: 50px;"'), 'peer_as' => 'Remote AS', 'state' => 'State', 'Uptime / Updates'); //if (!$list['device']) { unset($cols['device']); } $string .= get_table_header($cols, $vars); $string .= ' <tbody>' . PHP_EOL; foreach ($entries['entries'] as $peer) { $local_dev = device_by_id_cache($peer['device_id']); $local_as = $list['device'] ? ' (AS' . $peer['bgpLocalAs'] . ')' : ''; $local_name = generate_device_link($local_dev, short_hostname($local_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp')); $local_ip = generate_device_link($local_dev, $peer['human_localip'] . $local_as, array('tab' => 'routing', 'proto' => 'bgp')); $peer_as = 'AS' . $peer['bgpPeerRemoteAs']; if ($peer['peer_device_id']) { $peer_dev = device_by_id_cache($peer['peer_device_id']); $peer_name = generate_device_link($peer_dev, short_hostname($peer_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp')); } else { $peer_name = $peer['reverse_dns']; } $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']); $peer_afis =& $entries['afisafi'][$peer['device_id']][$peer['bgpPeerRemoteAddr']]; $peer_afis_html = array(); foreach ($peer_afis as $peer_afi) { $peer_afi_html = '<span class="label-group">'; switch ($peer_afi['afi']) { case 'ipv4': case 'ipv4z': $afi_class = 'success'; break; case 'ipv6': case 'ipv6z': $afi_class = 'primary'; break; default: $afi_class = 'default'; } switch ($peer_afi['safi']) { case 'unicast': $safi_class = 'delayed'; break; case 'multicast': $safi_class = 'warning'; break; case 'vpn': $safi_class = 'suppressed'; break; default: $safi_class = 'default'; } $peer_afi_html .= '<span class="label label-' . $afi_class . '">' . $peer_afi['afi'] . '</span>'; $peer_afi_html .= '<span class="label label-' . $safi_class . '">' . $peer_afi['safi'] . '</span>'; $peer_afi_html .= '</span>'; $peer_afis_html[] = $peer_afi_html; } $string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL; $string .= ' <td class="state-marker"></td>' . PHP_EOL; $string .= ' <td></td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap" class="entity">' . $local_ip . '<br />' . $local_name . '</td>' . PHP_EOL; $string .= ' <td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap" class="entity">' . $peer_ip . '<br />' . $peer_name . '</td>' . PHP_EOL; $string .= ' <td><span class="label label-' . $peer['peer_type_class'] . '">' . $peer['peer_type'] . '</span></td>' . PHP_EOL; $string .= ' <td>' . implode('<br />', $peer_afis_html) . '</td>' . PHP_EOL; $string .= ' <td><strong>' . $peer_as . '</strong><br />' . $peer['astext'] . '</td>' . PHP_EOL; $string .= ' <td><strong><span class=" label label-' . $peer['admin_class'] . '">' . $peer['bgpPeerAdminStatus'] . '</span><br /><span class="label label-' . $peer['state_class'] . '">' . $peer['bgpPeerState'] . '</span></strong></td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap">' . formatUptime($peer['bgpPeerFsmEstablishedTime']) . '<br /> Updates: <i class="icon-circle-arrow-down text-success"></i> ' . format_si($peer['bgpPeerInUpdates']) . ' <i class="icon-circle-arrow-up text-primary"></i> ' . format_si($peer['bgpPeerOutUpdates']) . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; // Graphs $peer_graph = FALSE; switch ($vars['graph']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': $afisafi = preg_replace('/prefixes_(ipv[46])(\\w+)/', '$1.$2', $vars['graph']); // prefixes_ipv6unicast ->> ipv6.unicast if (isset($peer_afis[$afisafi]) && $peer['bgpPeer_id']) { $graph_array['type'] = 'bgp_' . $vars['graph']; $graph_array['id'] = $peer['bgpPeer_id']; $peer_graph = TRUE; } break; case 'updates': if ($peer['bgpPeer_id']) { $graph_array['type'] = 'bgp_updates'; $graph_array['id'] = $peer['bgpPeer_id']; $peer_graph = TRUE; } break; case 'macaccounting_bits': case 'macaccounting_pkts': //FIXME. I really still not know it works or not? -- mike // This part copy-pasted from old code as is $acc = dbFetchRow("SELECT * FROM `mac_accounting` AS M\n LEFT JOIN `ip_mac` AS I ON M.mac = I.mac_address\n LEFT JOIN `ports` AS P ON P.port_id = M.port_id\n LEFT JOIN `devices` AS D ON D.device_id = P.device_id\n WHERE I.ip_address = ?", array($peer['bgpPeerRemoteAddr'])); $database = get_rrd_path($device, "cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); if (is_array($acc) && is_file($database)) { $peer_graph = TRUE; $graph_array['id'] = $acc['ma_id']; $graph_array['type'] = $vars['graph']; } break; } if ($peer_graph) { $graph_array['to'] = $config['time']['now']; $string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL; $string .= ' <td class="state-marker"></td><td colspan="10" style="white-space: nowrap">' . PHP_EOL; $string .= generate_graph_row($graph_array); $string .= ' </td>' . PHP_EOL . ' </tr>' . PHP_EOL; } else { if ($list['graph']) { // Empty row for correct view class table-striped-two $string .= ' <tr class="' . $peer['html_row_class'] . '"><td class="state-marker"></td><td colspan="10"></td></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 echo $string; } }
$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']) { $ifname = $_GET['title']; } /********* Other conf *******/ $scale_type = "follow"; //Autoscale default setup : "up" = only increase scale; "follow" = increase and decrease scale according to current graphed datas $nb_plot = 240; //NB plot in graph if (is_numeric($_GET['interval'])) { $time_interval = $_GET['interval']; } else { $time_interval = 1; //Refresh time Interval } $fetch_link = "data.php?id=" . $_GET['id'];
echo '>'; if ($vars['sort'] == $col['sort']) { echo $col['head'] . ' *'; } else { echo '<a href="' . generate_url($vars, array('sort' => $col['sort'])) . '">' . $col['head'] . '</a>'; } echo "</th>"; } echo " </tr></thead>"; $ports_disabled = 0; $ports_down = 0; $ports_up = 0; $ports_total = 0; foreach ($ports as $port) { $device = device_by_id_cache($port['device_id']); #&$GLOBALS['cache']['devices']['id'][$port['device_id']]; $ports_total++; humanize_port($port); if ($port['in_errors'] > 0 || $port['out_errors'] > 0) { $error_img = generate_port_link($port, "<img src='images/16/chart_curve_error.png' alt='接口错误' border=0>", errors); } else { $error_img = ""; } $port['bps_in'] = formatRates($port['ifInOctets_rate'] * 8); $port['bps_out'] = formatRates($port['ifOutOctets_rate'] * 8); $port['pps_in'] = format_si($port['ifInUcastPkts_rate']) . "pps"; $port['pps_out'] = format_si($port['ifOutUcastPkts_rate']) . "pps"; echo "<tr class='ports " . $port['row_class'] . "'>\n <td style='background-color: " . $port['table_tab_colour'] . ";'></td>\n <td></td>\n <td><span class=entity>" . generate_device_link($device, short_hostname($device['hostname'], "20")) . "</span><br />\n <span class=em>" . truncate($port['location'], 32, "") . "</span></td>\n\n <td><span class=entity>" . generate_port_link($port, rewrite_ifname($port['label'])) . " " . $error_img . "</span><br />\n <span class=em>" . truncate($port['ifAlias'], 50, '') . "</span></td>" . '<td> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . formatRates($port['in_rate']) . '</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . formatRates($port['out_rate']) . '</span><br /></td>' . '<td> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . $port['ifInOctets_perc'] . '%</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . $port['ifOutOctets_perc'] . '%</span><br /></td>' . '<td><i class="icon-circle-arrow-down" style="' . $port['pps_in_style'] . '"></i> <span class="small" style="' . $port['pps_in_style'] . '">' . format_bi($port['ifInUcastPkts_rate']) . 'pps</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['pps_out_style'] . '"></i> <span class="small" style="' . $port['pps_out_style'] . '">' . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span></td>' . "<td>" . $port['human_speed'] . "<br />" . $port['ifMtu'] . "</td>\n <td >" . $port['human_type'] . "<br />" . $port['human_mac'] . "</td>\n </tr>\n"; } echo '</td></tr></table>'; echo pagination($vars, count($ports));
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; echo $br . '<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($member) . ' [PAgP]</strong>'; $br = "<br />"; }
if (empty($ports[$port['ifvrf']][$port['device_id']])) { $ports[$port['ifvrf']][$port['device_id']][0] = $port; } else { array_push($ports[$port['ifvrf']][$port['device_id']], $port); } } echo '<table class="table table-bordered table-striped">'; foreach (dbFetchRows("SELECT * FROM `vrfs` GROUP BY `mplsVpnVrfRouteDistinguisher`") as $vrf) { echo '<tr>'; echo '<td style="width: 240px;"><a class="entity" href="' . generate_url($link_array, array('vrf' => $vrf['mplsVpnVrfRouteDistinguisher'])) . '">' . $vrf['vrf_name'] . '</a><br /><span class="small">' . $vrf['mplsVpnVrfDescription'] . '</span></td>'; echo '<td style="width: 100px;" class="small">' . $vrf['mplsVpnVrfRouteDistinguisher'] . '</td>'; #echo('<td style="width: 200px;" class="small">' . $vrf['mplsVpnVrfDescription'] . '</td>'); echo '<td><table class="table table-striped table-bordered table-condensed">'; $x = 1; foreach ($vrf_devices[$vrf['mplsVpnVrfRouteDistinguisher']] as $device) { echo '<tr><td style="width: 150px;"><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'])) . '</span>'; if ($device['vrf_name'] != $vrf['vrf_name']) { echo "<a href='#' onmouseover=\" return overlib('要求的名称 : " . $vrf['vrf_name'] . "<br />配置 : " . $device['vrf_name'] . "', CAPTION, '<span class=entity-title>VRF不一致</span>' ,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\"> <img align=absmiddle src=images/16/exclamation.png></a>"; } echo "</td><td>"; unset($seperator); foreach ($ports[$device['vrf_id']][$device['device_id']] as $port) { $port = array_merge($device, $port); switch ($vars['graph']) { case 'bits': case 'upkts': case 'nupkts': case 'errors': $port['width'] = "130"; $port['height'] = "30"; $port['from'] = $config['time']['day'];