function getDates($dayofmonth, $months = 0) { $dayofmonth = zeropad($dayofmonth); $year = date('Y'); $month = date('m'); if (date('d') > $dayofmonth) { // Billing day is past, so it is next month $date_end = date_create($year . '-' . $month . '-' . $dayofmonth); $date_start = date_create($year . '-' . $month . '-' . $dayofmonth); date_add($date_end, date_interval_create_from_date_string('1 month')); } else { // Billing day will happen this month, therefore started last month $date_end = date_create($year . '-' . $month . '-' . $dayofmonth); $date_start = date_create($year . '-' . $month . '-' . $dayofmonth); date_sub($date_start, date_interval_create_from_date_string('1 month')); } if ($months > 0) { date_sub($date_start, date_interval_create_from_date_string($months . ' month')); date_sub($date_end, date_interval_create_from_date_string($months . ' month')); } // date_sub($date_start, date_interval_create_from_date_string('1 month')); date_sub($date_end, date_interval_create_from_date_string('1 day')); $date_from = date_format($date_start, 'Ymd') . '000000'; $date_to = date_format($date_end, 'Ymd') . '235959'; date_sub($date_start, date_interval_create_from_date_string('1 month')); date_sub($date_end, date_interval_create_from_date_string('1 month')); $last_from = date_format($date_start, 'Ymd') . '000000'; $last_to = date_format($date_end, 'Ymd') . '235959'; $return = array(); $return['0'] = $date_from; $return['1'] = $date_to; $return['2'] = $last_from; $return['3'] = $last_to; return $return; }
function snmp_cache_cip($oid, $device, $array, $mib = 0) { global $config; $cmd = ($device['snmpver'] == 'v1' ? $config['snmpwalk'] : $config['snmpbulkwalk']) . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . ":" . $device['port'] . " "; if ($mib) { $cmd .= "-m {$mib} "; } $cmd .= $oid; $data = trim(shell_exec($cmd)); $device_id = $device['device_id']; #echo("Caching: $oid\n"); foreach (explode("\n", $data) as $entry) { list($this_oid, $this_value) = split("=", $entry); $this_oid = trim($this_oid); $this_value = trim($this_value); $this_oid = substr($this_oid, 30); list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode(".", $this_oid); $h_a = zeropad(dechex($a)); $h_b = zeropad(dechex($b)); $h_c = zeropad(dechex($c)); $h_d = zeropad(dechex($d)); $h_e = zeropad(dechex($e)); $h_f = zeropad(dechex($f)); $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}"; if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; } if ($mac && $dir) { $array[$device_id][$ifIndex][$mac][$oid][$dir] = $this_value; } } return $array; }
function getDates($dayofmonth, $months = 0) { $dayofmonth = zeropad($dayofmonth); $year = date('Y'); $month = date('m'); if (date('d') >= $dayofmonth) { $date_end = date_create($year . '-' . $month . '-' . $dayofmonth); $date_start = date_create($year . '-' . $month . '-' . $dayofmonth); date_add($date_end, date_interval_create_from_date_string('1 月')); } else { // Billing day will happen this month, therefore started last month $date_end = date_create($year . '-' . $month . '-' . $dayofmonth); $date_start = date_create($year . '-' . $month . '-' . $dayofmonth); date_sub($date_start, date_interval_create_from_date_string('1 月')); } if ($months > 0) { date_sub($date_start, date_interval_create_from_date_string($months . ' 月')); date_sub($date_end, date_interval_create_from_date_string($months . ' 月')); } # date_sub($date_start, date_interval_create_from_date_string('1 月')); date_sub($date_end, date_interval_create_from_date_string('1 天')); $date_from = date_format($date_start, 'Ymd') . "000000"; $date_to = date_format($date_end, 'Ymd') . "235959"; date_sub($date_start, date_interval_create_from_date_string('1 月')); date_sub($date_end, date_interval_create_from_date_string('1 月')); $last_from = date_format($date_start, 'Ymd') . "000000"; $last_to = date_format($date_end, 'Ymd') . "235959"; $return['0'] = $date_from; $return['1'] = $date_to; $return['2'] = $last_from; $return['3'] = $last_to; return $return; }
function getHEXRGB($string) { $matches = null; $returnValue = preg_match('/rgba?\\(\\s*(?<red>[0-9A-F]{1,3})\\s*,\\s*(?<green>[0-9A-F]{1,3})\\s*,\\s*(?<blue>[0-9A-F]{1,3})/is', $string, $matches); if ($returnValue) { return zeropad(dechex(intval($matches["red"])), 2) . zeropad(dechex(intval($matches["green"])), 2) . zeropad(dechex(intval($matches["blue"])), 2); } return trim($string, "#"); }
function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0) { global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); if (!isset($device['transport'])) { $device['transport'] = 'udp'; } if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; } else { $snmpcommand = $config['snmpbulkwalk']; } $cmd = $snmpcommand; $cmd .= snmp_gen_auth($device); $cmd .= ' -O snQ'; if ($mib) { $cmd .= " -m {$mib}"; } $cmd .= mibdir(null); $cmd .= isset($timeout) ? ' -t ' . $timeout : ''; $cmd .= isset($retries) ? ' -r ' . $retries : ''; $cmd .= ' ' . $device['transport'] . ':' . $device['hostname'] . ':' . $device['port'] . ' ' . $oid; if (!$debug) { $cmd .= ' 2>/dev/null'; } $data = trim(external_exec($cmd)); // echo("Caching: $oid\n"); foreach (explode("\n", $data) as $entry) { list($this_oid, $this_value) = preg_split('/=/', $entry); $this_oid = trim($this_oid); $this_value = trim($this_value); $this_oid = substr($this_oid, 30); list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode('.', $this_oid); $h_a = zeropad(dechex($a)); $h_b = zeropad(dechex($b)); $h_c = zeropad(dechex($c)); $h_d = zeropad(dechex($d)); $h_e = zeropad(dechex($e)); $h_f = zeropad(dechex($f)); $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}"; if ($dir == '1') { $dir = 'input'; } else { if ($dir == '2') { $dir = 'output'; } } if ($mac && $dir) { $array[$ifIndex][$mac][$oid][$dir] = $this_value; } } //end foreach return $array; }
// Copyright (c) 1986-2011 by Cisco Systems, Inc. // Compiled Thu 22-Dec-11 00:46 by prod_rel_team // mtxrNeighborPlatform.1 = STRING: cisco WS-C2960G-48TC-L // mtxrNeighborIdentity.1 = STRING: switch.example.com // mtxrNeighborSoftwareID.1 = STRING: // mtxrNeighborInterfaceID.1 = INTEGER: 2 $mtxr_array = snmpwalk_cache_oid($device, "mtxrNeighbor", array(), "MIKROTIK-MIB", NULL, OBS_SNMP_ALL | OBS_SNMP_CONCAT); if ($mtxr_array) { if (OBS_DEBUG > 1) { print_vars($mtxr_array); } foreach ($mtxr_array as $key => $entry) { // Need to straighten out the MAC first for use later. Mikrotik does not pad the numbers! (i.e. 0:12:23:3:5c:6b) // FIXME move this to a smarter function? list($a, $b, $c, $d, $e, $f) = explode(':', $entry['mtxrNeighborMacAddress'], 6); $entry['mtxrNeighborMacAddress'] = zeropad($a) . ':' . zeropad($b) . ':' . zeropad($c) . ':' . zeropad($d) . ':' . zeropad($e) . ':' . zeropad($f); $ifIndex = $entry['mtxrNeighborInterfaceID']; // Get the port using BRIDGE-MIB $port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", array($device['device_id'], $ifIndex)); $remote_device_id = FALSE; $remote_port_id = 0; if (is_valid_hostname($entry['mtxrNeighborIdentity'])) { if (isset($GLOBALS['cache']['discovery-protocols'][$entry['mtxrNeighborIdentity']])) { // This hostname already checked, skip discover $remote_device_id = $GLOBALS['cache']['discovery-protocols'][$entry['mtxrNeighborIdentity']]; } else { $remote_device = dbFetchRow("SELECT `device_id`, `hostname` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIdentity'])); $remote_device_id = $remote_device['device_id']; // If we don't know this device, try to discover it, as long as it's not matching our exclusion filters if (!$remote_device_id && !is_bad_xdp($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborPlatform'])) { $remote_device_id = discover_new_device($entry['mtxrNeighborIdentity'], 'xdp', 'MNDP', $device, $port);
/** * @dataProvider providerZeropad */ public function testZeropad($value, $result) { $this->assertSame($result, zeropad($value)); }
function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0) { $cmd = gen_snmpwalk_cmd($device, $oid, ' -OsnQ', $mib); $data = trim(external_exec($cmd)); // echo("Caching: $oid\n"); foreach (explode("\n", $data) as $entry) { list($this_oid, $this_value) = preg_split('/=/', $entry); $this_oid = trim($this_oid); $this_value = trim($this_value); $this_oid = substr($this_oid, 30); list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode('.', $this_oid); $h_a = zeropad(dechex($a)); $h_b = zeropad(dechex($b)); $h_c = zeropad(dechex($c)); $h_d = zeropad(dechex($d)); $h_e = zeropad(dechex($e)); $h_f = zeropad(dechex($f)); $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}"; if ($dir == '1') { $dir = 'input'; } elseif ($dir == '2') { $dir = 'output'; } if ($mac && $dir) { $array[$ifIndex][$mac][$oid][$dir] = $this_value; } } //end foreach return $array; }
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage discovery * @copyright (C) 2006-2014 Adam Armstrong * */ // This could do with a rewrite. echo " S5-CHASSIS-MIB "; # Get major version number of running firmware $fw_major_version = Null; preg_match("/[0-9]\\.[0-9]/", $device['version'], $fw_major_version); $fw_major_version = $fw_major_version[0]; # Temperature info only known to be present in firmware 6.1 or higher if ($fw_major_version >= 6.1) { $temps = snmp_walk($device, "1.3.6.1.4.1.45.1.6.3.7.1.1.5.5", "-Osqn"); $scale = 0.5; foreach (explode("\n", $temps) as $i => $t) { $t = explode(" ", $t); $oid = $t[0]; $val = trim($t[1]); discover_sensor($valid['sensor'], 'temperature', $device, $oid, zeropad($i + 1), 'avaya-ers', "Unit " . ($i + 1) . " temperature", $scale, $val * $scale); } } // EOF
<?php $mac_list = array(); // Disabled because we can do this better in poller now without performance hit if ($device['os_group'] == "cisco" && FALSE) { echo "Cisco MAC Accounting : "; $datas = snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacSwitchedBytes", "-OUqsX", "NS-ROOT-MIB"); foreach (explode("\n", $datas) as $data) { list(, $ifIndex, $dir, $mac, ) = parse_oid2($data); list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $mac); $ah_a = zeropad($a_a); $ah_b = zeropad($a_b); $ah_c = zeropad($a_c); $ah_d = zeropad($a_d); $ah_e = zeropad($a_e); $ah_f = zeropad($a_f); $clean_mac = "{$ah_a}{$ah_b}{$ah_c}{$ah_d}{$ah_e}{$ah_f}"; $mac_list[$ifIndex . '_' . $clean_mac] = array('ifIndex' => $ifIndex, 'mac' => $clean_mac); } foreach ($mac_list as $mac_entry) { $port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device['device_id'], $mac_entry['ifIndex'])); if ($port) { echo $port['ifDescr'] . ' (' . $mac_entry['ifIndex'] . ') -> ' . $mac_entry['mac']; if (dbFetchCell("SELECT COUNT(*) from `mac_accounting` WHERE `port_id` = ? AND `mac` = ?", array($port['port_id'], $mac_entry['mac']))) { echo "."; } else { $ma_id = dbInsert(array('port_id' => $port['port_id'], 'device_id' => $device['device_id'], 'mac' => $mac_entry['mac']), 'mac_accounting'); dbInsert(array('ma_id' => $ma_id), 'mac_accounting-state'); echo "+"; } } else {
function char2hex($c) { return zeropad(dechex(ord($c)), 2); }
<?php if ($device['os'] == 'avaya-ers') { // Get major version number of running firmware $fw_major_version = null; preg_match('/[0-9]\\.[0-9]/', $device['version'], $fw_major_version); $fw_major_version = $fw_major_version[0]; // Temperature info only known to be present in firmware 6.1 or higher if ($fw_major_version >= 6.1) { $temps = snmp_walk($device, '1.3.6.1.4.1.45.1.6.3.7.1.1.5.5', '-Osqn'); foreach (explode("\n", $temps) as $i => $t) { $t = explode(' ', $t); $oid = $t[0]; $val = $t[1]; // Sensors are reported as 2 * value $val = trim($val) / 2; discover_sensor($valid['sensor'], 'temperature', $device, $oid, zeropad($i + 1), 'avaya-ers', 'Unit ' . ($i + 1) . ' temperature', '2', '1', null, null, null, null, $val); } } }
function convert_color($color) { $out = ''; // We only accept color in #rgb, #rrggbb, and rgb(r,g,b) formats if (preg_match('/#(\\[0-9a-f])([0-9a-f])([0-9a-f])/i', $color, $matches)) { $out = '#' . $matches[1] . $matches[1] . $matches[2] . $matches[2] . $matches[3] . $matches[3]; } else { if (preg_match('/#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i', $color, $matches)) { $out = '#' . $matches[1] . $matches[2] . $matches[3]; } else { if (preg_match('/rgb\\((\\d+),\\s?(\\d+),\\s?(\\d+)\\)/', $color, $matches)) { $out = '#' . zeropad(dechex($matches[1]), 2) . zeropad(dechex($matches[2]), 2) . zeropad(dechex($matches[3]), 2); } } } return $out; }
<?php if ($device['os'] == 'avaya-ers') { // Processor information only know to work with 5500 and 5600 switches if (preg_match('/5[56][0-9][0-9]/', $device['sysDescr'])) { $procs = snmp_walk($device, '.1.3.6.1.4.1.45.1.6.3.8.1.1.6', '-Osqn'); foreach (explode("\n", $procs) as $i => $t) { $t = explode(' ', $t); $oid = $t[0]; $val = $t[1]; discover_processor($valid['processor'], $device, $oid, zeropad($i + 1), 'avaya-ers', 'Unit ' . ($i + 1) . ' processor', '1', $val, $i, null); } } }
$datas = shell_exec($config['snmpbulkwalk'] . " -m CISCO-IP-STAT-MIB -Oqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " cipMacSwitchedBytes"); #echo("$datas\n"); #echo("done\n"); foreach (explode("\n", $datas) as $data) { list($oid) = explode(" ", $data); $oid = str_replace(".1.3.6.1.4.1.9.9.84.1.2.1.1.4.", "", $oid); list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $oid); $oid = "{$a_a}.{$a_b}.{$a_c}.{$a_d}.{$a_e}.{$a_f}"; unset($interface); $interface = mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "' AND ifIndex = '" . $if . "'")); $ah_a = zeropad(dechex($a_a)); $ah_b = zeropad(dechex($a_b)); $ah_c = zeropad(dechex($a_c)); $ah_d = zeropad(dechex($a_d)); $ah_e = zeropad(dechex($a_e)); $ah_f = zeropad(dechex($a_f)); $mac = "{$ah_a}:{$ah_b}:{$ah_c}:{$ah_d}:{$ah_e}:{$ah_f}"; $mac_cisco = "{$ah_a}{$ah_b}.{$ah_c}{$ah_d}.{$ah_e}{$ah_f}"; $mac_cisco = $mac_table[$if][$mac]['ciscomac']; $clean_mac = $mac_table[$if][$mac]['cleanmac']; $ip = $mac_table[$if][$mac]['ip']; if ($ip && $interface) { $new_mac = str_replace(":", "", $mac); #echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip"); if (mysql_result(mysql_query("SELECT COUNT(*) from mac_accounting WHERE interface_id = '" . $interface['interface_id'] . "' AND mac = '{$clean_mac}'"), 0)) { #$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND `mac` = '$clean_mac'"; #mysql_query($sql); #if(mysql_affected_rows()) { echo(" UPDATED!"); } #echo($sql); echo "."; } else {
if (OBS_DEBUG && count($sessions_db)) { print_vars($sessions_db); } $radios_db = dbFetchRows("SELECT `wifi_radio_id`, `radio_number`,`ap_number`, `wifi_accesspoints`.`device_id` FROM `wifi_accesspoints`, `wifi_radios` WHERE `wifi_radios`.`radio_ap` = wifi_accesspoints.`wifi_accesspoint_id` AND wifi_accesspoints.`device_id` = ?", array($device['device_id'])); foreach ($radios_db as $radio_db) { $radios_sorted_db[$radio_db['ap_number']][$radio_db['radio_number']] = $radio_db; } $sessions_array = snmpwalk_cache_multi_oid($device, "trpzClSessClientSessionTable", $sessions_array, "TRAPEZE-NETWORKS-CLIENT-SESSION-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX); if (OBS_DEBUG > 1 && count($sessions_array)) { print_vars($sessions_array); } $timestamp = date('Y-m-d H:i:s', strtotime("now")); // Goes through the SNMP sessions data foreach ($sessions_array as $index => $session) { list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $index); $clean_mac = zeropad(dechex($a_a)) . zeropad(dechex($a_b)) . zeropad(dechex($a_c)) . zeropad(dechex($a_d)) . zeropad(dechex($a_e)) . zeropad(dechex($a_f)); // Mapping OIDs<>DB $db_oids = array('trpzClSessClientSessSessionId' => 'session_id', 'trpzClSessClientSessUsername' => 'username', 'trpzClSessClientSessIpAddress' => 'ipv4_addr', 'trpzClSessClientSessSsid' => 'ssid', 'trpzClSessClientSessSessionState' => 'state'); $new_index = $clean_mac; foreach ($db_oids as $db_oid => $db_value) { $db_insert[$db_value] = $session[$db_oid]; } $db_insert['device_id'] = $device['device_id']; $db_insert['mac_addr'] = $clean_mac; $db_insert['uptime'] = timeticks_to_sec($session['trpzClSessClientSessTimeStamp']); // FIXME. There timestamp, not timetick! $db_insert['timestamp'] = $timestamp; if ($session['trpzClSessClientSessRadioNum'] == "radio-1") { $radio_number = '1'; } else { if ($session['trpzClSessClientSessradioNum'] == "radio-2") {
} else { // In principle the such shouldn't be. continue; } $if = $matches[1]; $port_id = $interface[$if]; if ($ip & $port_id) { if ($matches[3] === '' && $matches[4] === '') { // Convert IPv4 to fake MAC for 6to4 tunnels //ipNetToPhysicalPhysAddress[27][ipv6]["20:02:c0:58:63:01:00:00:00:00:00:00:00:00:00:00"] 0:0:c0:58 $matches[3] = 'ff'; $matches[4] = 'fe'; } $mac = zeropad($matches[3]); for ($i = 4; $i <= 8; $i++) { $mac .= ':' . zeropad($matches[$i]); } $clean_mac = str_replace(':', '', $mac); $mac_table[$if][$ip_version][$ip] = $clean_mac; if (isset($old_table[$if][$ip_version][$ip])) { $old_mac = $old_table[$if][$ip_version][$ip]; if ($clean_mac != $old_mac && $clean_mac != '00:00:00:00:00:00' && $old_mac != '00:00:00:00:00:00') { print_debug("Changed MAC address for {$ip} from " . format_mac($old_mac) . " to " . format_mac($clean_mac)); log_event("MAC changed: {$ip} : " . format_mac($old_mac) . " -> " . format_mac($clean_mac), $device, "port", $port_id); dbUpdate(array('mac_address' => $clean_mac), 'ip_mac', 'port_id = ? AND ip_address = ?', array($port_id, $ip)); echo "U"; } else { echo "."; } } else { $params = array('port_id' => $port_id, 'mac_address' => $clean_mac, 'ip_address' => $ip, 'ip_version' => $ip_version);
dbUpdate($vlan_update, 'vlans', 'vlan_id = ?', array($vlans_db[$vtpdomain_id][$vlan_id]['vlan_id'])); $module_stats[$vlan_id]['V'] = 'U'; } elseif (is_array($vlans_db[$vtpdomain_id][$vlan_id])) { $module_stats[$vlan_id]['V'] = '.'; //echo("."); } else { dbInsert(array('device_id' => $device['device_id'], 'vlan_domain' => $vtpdomain_id, 'vlan_vlan' => $vlan_id, 'vlan_name' => $vlan['dot1qVlanStaticName'], 'vlan_type' => array('NULL')), 'vlans'); $module_stats[$vlan_id]['V'] = '+'; } $device['vlans'][$vtpdomain_id][$vlan_id] = $vlan_id; //Set Q-BRIDGE ports Vlan table (not work on FTOS for now) if ($device['os'] != 'ftos') { $parts = explode(' ', $vlan['dot1qVlanStaticEgressPorts']); $binary = ''; foreach ($parts as $part) { $binary .= zeropad(decbin($part), 8); } $length = strlen($binary); for ($i = 0; $i < $length; $i++) { if ($binary[$i]) { $port = get_port_by_index_cache($device, $i); if (isset($ports_vlans_db[$port['port_id']][$vlan_id])) { $ports_vlans[$port['port_id']][$vlan_id] = $ports_vlans_db[$port['port_id']][$vlan_id]['port_vlan_id']; $module_stats[$vlan_id]['P'] = '.'; } else { $db_w = array('device_id' => $device['device_id'], 'port_id' => $port['port_id'], 'vlan' => $vlan_id); $id = dbInsert($db_w, 'ports_vlans'); $module_stats[$vlan_id]['P'] = '+'; $ports_vlans[$port['port_id']][$vlan_id] = $id; } }
$this_port['ifOutUcastPkts'] = $airos_stats[1]['txValidUnicastFrames']; $ports['update']['ifInOctets'] = $airos_stats[1]['rxOctetsOK']; $ports['update']['ifOutOctets'] = $airos_stats[1]['txOctetsOK']; $ports['update']['ifInErrors'] = $airos_stats[1]['rxErroredFrames']; $ports['update']['ifOutErrors'] = $airos_stats[1]['txErroredFrames']; $ports['update']['ifInBroadcastPkts'] = $airos_stats[1]['rxValidBroadcastFrames']; $ports['update']['ifOutBroadcastPkts'] = $airos_stats[1]['txValidBroadcastFrames']; $ports['update']['ifInMulticastPkts'] = $airos_stats[1]['rxValidMulticastFrames']; $ports['update']['ifOutMulticastPkts'] = $airos_stats[1]['txValidMulticastFrames']; $ports['update']['ifInUcastPkts'] = $airos_stats[1]['rxValidUnicastFrames']; $ports['update']['ifOutUcastPkts'] = $airos_stats[1]['txValidUnicastFrames']; } // rewrite the ifPhysAddress if (strpos($this_port['ifPhysAddress'], ':')) { list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(':', $this_port['ifPhysAddress']); $this_port['ifPhysAddress'] = zeropad($a_a) . zeropad($a_b) . zeropad($a_c) . zeropad($a_d) . zeropad($a_e) . zeropad($a_f); } if (is_numeric($this_port['ifHCInBroadcastPkts']) && is_numeric($this_port['ifHCOutBroadcastPkts']) && is_numeric($this_port['ifHCInMulticastPkts']) && is_numeric($this_port['ifHCOutMulticastPkts'])) { echo 'HC '; $this_port['ifInBroadcastPkts'] = $this_port['ifHCInBroadcastPkts']; $this_port['ifOutBroadcastPkts'] = $this_port['ifHCOutBroadcastPkts']; $this_port['ifInMulticastPkts'] = $this_port['ifHCInMulticastPkts']; $this_port['ifOutMulticastPkts'] = $this_port['ifHCOutMulticastPkts']; } // Overwrite ifSpeed with ifHighSpeed if it's over 1G if (is_numeric($this_port['ifHighSpeed']) && ($this_port['ifSpeed'] > '1000000000' || $this_port['ifSpeed'] == 0)) { echo 'HighSpeed '; $this_port['ifSpeed'] = $this_port['ifHighSpeed'] * 1000000; } // Overwrite ifDuplex with dot3StatsDuplexStatus if it exists if (isset($this_port['dot3StatsDuplexStatus'])) {
function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0) { global $config; if (is_numeric($device['timeout']) && $device['timeout'] > 0) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries']) && $device['retries'] > 0) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } if (!isset($device['transport'])) { $device['transport'] = "udp"; } if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; } else { $snmpcommand = $config['snmpbulkwalk']; } $cmd = $snmpcommand; $cmd .= snmp_gen_auth($device); $cmd .= " -O snQ"; if ($mib) { $cmd .= " -m {$mib}"; } $cmd .= mibdir(null); if (isset($timeout)) { $cmd .= " -t " . $timeout; } if (isset($retries)) { $cmd .= " -r " . $retries; } $cmd .= " " . $device['transport'] . ":" . $device['hostname'] . ":" . $device['port'] . " " . $oid; if (!$debug) { $cmd .= " 2>/dev/null"; } $data = trim(external_exec($cmd)); $device_id = $device['device_id']; #echo("Caching: $oid\n"); foreach (explode("\n", $data) as $entry) { list($this_oid, $this_value) = preg_split("/=/", $entry); $this_oid = trim($this_oid); $this_value = trim($this_value); $this_oid = substr($this_oid, 30); list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode(".", $this_oid); $h_a = zeropad(dechex($a)); $h_b = zeropad(dechex($b)); $h_c = zeropad(dechex($c)); $h_d = zeropad(dechex($d)); $h_e = zeropad(dechex($e)); $h_f = zeropad(dechex($f)); $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}"; if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; } if ($mac && $dir) { $array[$ifIndex][$mac][$oid][$dir] = $this_value; } } return $array; }
function snmpwalk_cache_cip($device, $oid, $array, $mib = NULL, $mibdir = NULL) { $data = snmp_walk($device, $oid, "-OsnQ", $mib, $mibdir); foreach (explode("\n", $data) as $entry) { list($this_oid, $this_value) = preg_split("/=/", $entry); $this_oid = trim($this_oid); $this_value = trim($this_value); $this_oid = substr($this_oid, 30); list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode(".", $this_oid); $h_a = zeropad(dechex($a)); $h_b = zeropad(dechex($b)); $h_c = zeropad(dechex($c)); $h_d = zeropad(dechex($d)); $h_e = zeropad(dechex($e)); $h_f = zeropad(dechex($f)); $mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}"; if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; } if ($mac && $dir) { $array[$ifIndex][$mac][$oid][$dir] = $this_value; } } return $array; }
foreach (snmpwalk_cache_oid($device, 'dot1dBasePortIfIndex', $port_stats, 'BRIDGE-MIB') as $dot1dbaseport => $data) { $dot1dBasePort_table[$dot1dbaseport] = $port_ifIndex_table[$data['dot1dBasePortIfIndex']]; } foreach (explode("\n", $dot1qTpFdbEntry_table) as $text) { list($oid, $value) = explode(' ', $text); preg_match('/(\\w+)\\[(\\d+)\\]\\[([a-f0-9:]+)\\]/', $text, $oid); if (!empty($value)) { if (isset($fakejunipervlans[$oid[2]])) { // if we have a translated vlan id for juniper, use it $vlan = $fakejunipervlans[$oid[2]]; } else { $vlan = $oid[2]; } $mac = ''; foreach (explode(':', $oid[3]) as $m) { $mac .= zeropad($m); } if (strlen($mac) === 12 && is_numeric($vlan) && $mac != '000000000000') { $fdbs[$vlan][$mac][$oid[1]] = $value; } } } } } if (count($fdbs)) { if (OBS_DEBUG > 1) { print_vars($fdbs); } //echo(str_pad('Vlan', 8) . ' | ' . str_pad('MAC',12) . ' | ' . 'Port (dot1d|ifIndex)' .' | '. str_pad('Status',16) . "\n". //str_pad('', 90, '-')."\n"); }
} $oids = trim($oids); if ($oids) { echo "Areca Harddisk "; } foreach (explode("\n", $oids) as $data) { $data = trim($data); if ($data) { list($oid, $descr) = explode(" ", $data, 2); $split_oid = explode('.', $oid); $temperature_id = $split_oid[count($split_oid) - 1]; $temperature_oid = "1.3.6.1.4.1.18928.1.1.2.14.1.2.{$temperature_id}"; $temperature = snmp_get($device, $temperature_oid, "-Oqv", ""); $descr = "Hard disk {$temperature_id}"; if ($temperature != -128) { discover_sensor($valid['sensor'], 'temperature', $device, $temperature_oid, zeropad($temperature_id), $type, $descr, 1, 1, NULL, NULL, NULL, NULL, $temperature); } } } $oids = snmp_walk($device, "1.3.6.1.4.1.18928.1.2.2.1.10.1.2", "-OsqnU", ""); if ($debug) { echo $oids . "\n"; } if ($oids) { echo "Areca Controller "; } $precision = 1; foreach (explode("\n", $oids) as $data) { $data = trim($data); if ($data) { list($oid, $descr) = explode(" ", $data, 2);
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage discovery * @copyright (C) 2006-2014 Adam Armstrong * */ // This could do with a rewrite. echo " S5-CHASSIS-MIB "; # Get major version number of running firmware $fw_major_version = Null; preg_match("/[0-9]\\.[0-9]/", $device['version'], $fw_major_version); $fw_major_version = $fw_major_version[0]; # Temperature info only known to be present in firmware 6.1 or higher if ($fw_major_version >= 6.1) { $temps = snmp_walk($device, "1.3.6.1.4.1.45.1.6.3.7.1.1.5.5", "-Osqn"); foreach (explode("\n", $temps) as $i => $t) { $t = explode(" ", $t); $oid = $t[0]; $val = $t[1]; # Sensors are reported as 2 * value $val = trim($val) / 2; discover_sensor($valid['sensor'], 'temperature', $device, $oid, zeropad($i + 1), 'avaya-ers', "Unit " . ($i + 1) . " temperature", 2, 1, NULL, NULL, NULL, NULL, $val); } } // EOF
function datetime_preset($preset) { $begin_fmt = 'Y-m-d 00:00:00'; $end_fmt = 'Y-m-d 23:59:59'; switch ($preset) { case 'sixhours': $from = date('Y-m-d H:i:00', strtotime('-6 hours')); $to = date('Y-m-d H:i:59'); break; case 'today': $from = date($begin_fmt); $to = date($end_fmt); break; case 'yesterday': $from = date($begin_fmt, strtotime('-1 day')); $to = date($end_fmt, strtotime('-1 day')); break; case 'tweek': $from = date('l') == 'Monday' ? date($begin_fmt) : date($begin_fmt, strtotime('last Monday')); $to = date('l') == 'Sunday' ? date($end_fmt) : date($end_fmt, strtotime('next Sunday')); break; case 'lweek': $from = date($begin_fmt, strtotime('-6 days')); $to = date($end_fmt); break; case 'tmonth': $tmonth = date('Y-m'); $from = $tmonth . '-01 00:00:00'; $to = date($end_fmt, strtotime($tmonth . ' next month - 1 hour')); break; case 'lmonth': $from = date($begin_fmt, strtotime('previous month + 1 day')); $to = date($end_fmt); break; case 'tquarter': case 'lquarter': $quarter = ceil(date('m') / 3); // Current quarter if ($preset == 'lquarter') { $quarter = $quarter - 1; // Previous quarter } $year = date('Y'); if ($quarter < 1) { $year -= 1; $quarter = 4; } $tmonth = $quarter * 3; $fmonth = $tmonth - 2; $from = $year . '-' . zeropad($fmonth) . '-01 00:00:00'; $to = date('Y-m-t 23:59:59', strtotime($year . '-' . $tmonth . '-01')); break; case 'tyear': $from = date('Y-01-01 00:00:00'); $to = date('Y-12-31 23:59:59'); break; case 'lyear': $from = date($begin_fmt, strtotime('previous year + 1 day')); $to = date($end_fmt); break; } return array('from' => $from, 'to' => $to); }
function snmp2ipv6($ipv6_snmp) { $ipv6 = explode('.', $ipv6_snmp); for ($i = 0; $i <= 15; $i++) { $ipv6[$i] = zeropad(dechex($ipv6[$i])); } for ($i = 0; $i <= 15; $i += 2) { $ipv6_2[] = $ipv6[$i] . $ipv6[$i + 1]; } return implode(':', $ipv6_2); }
$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); $ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); $ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); foreach (explode("\n", $ipNetToMedia_data) as $data) { list($oid, $mac) = explode(' ', $data); list($if, $first, $second, $third, $fourth) = explode('.', $oid); $ip = $first . '.' . $second . '.' . $third . '.' . $fourth; if ($ip != '...') { $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); $m_a = zeropad($m_a); $m_b = zeropad($m_b); $m_c = zeropad($m_c); $m_d = zeropad($m_d); $m_e = zeropad($m_e); $m_f = zeropad($m_f); $md_a = hexdec($m_a); $md_b = hexdec($m_b); $md_c = hexdec($m_c); $md_d = hexdec($m_d); $md_e = hexdec($m_e); $md_f = hexdec($m_f); $mac = "{$m_a}:{$m_b}:{$m_c}:{$m_d}:{$m_e}:{$m_f}"; $mac_table[$if][$mac]['ip'] = $ip; $mac_table[$if][$mac]['ciscomac'] = "{$m_a}{$m_b}.{$m_c}{$m_d}.{$m_e}{$m_f}"; $clean_mac = $m_a . $m_b . $m_c . $m_d . $m_e . $m_f; $mac_table[$if][$mac]['cleanmac'] = $clean_mac; $port_id = $interface['port_id']; $mac_table[$port_id][$clean_mac] = 1; if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { // Commented below, no longer needed but leaving for reference.
$oids = trim($oids); if ($oids) { echo 'Areca Harddisk '; } foreach (explode("\n", $oids) as $data) { $data = trim($data); if ($data) { list($oid, $descr) = explode(' ', $data, 2); $split_oid = explode('.', $oid); $temperature_id = $split_oid[count($split_oid) - 1]; $temperature_oid = "1.3.6.1.4.1.18928.1.1.2.14.1.2.{$temperature_id}"; $temperature = snmp_get($device, $temperature_oid, '-Oqv', ''); $descr = "Hard disk {$temperature_id}"; if ($temperature != -128) { // -128 = not measured/present discover_sensor($valid['sensor'], 'temperature', $device, $temperature_oid, zeropad($temperature_id), 'areca', $descr, '1', '1', null, null, null, null, $temperature); } } } $oids = snmp_walk($device, '1.3.6.1.4.1.18928.1.2.2.1.10.1.2', '-OsqnU', ''); d_echo($oids . "\n"); if ($oids) { echo 'Areca Controller '; } $precision = 1; $type = 'areca'; foreach (explode("\n", $oids) as $data) { $data = trim($data); if ($data) { list($oid, $descr) = explode(' ', $data, 2); $split_oid = explode('.', $oid);
function ipv62snmp($ipv6) { $ipv6_split = array(); $ipv6_ex = explode(':', Net_IPv6::uncompress($ipv6)); for ($i = 0; $i < 8; $i++) { $ipv6_ex[$i] = zeropad($ipv6_ex[$i], 4); } $ipv6_ip = implode('', $ipv6_ex); for ($i = 0; $i < 32; $i += 2) { $ipv6_split[] = hexdec(substr($ipv6_ip, $i, 2)); } return implode('.', $ipv6_split); }
dbUpdate($vlan_update, 'vlans', 'vlan_id = ?', array($vlans_db[$vtpdomain_id][$vlan_id]['vlan_id'])); $module_stats[$vlan_id]['V'] = 'U'; } elseif (is_array($vlans_db[$vtpdomain_id][$vlan_id])) { $module_stats[$vlan_id]['V'] = '.'; //echo("."); } else { dbInsert(array('device_id' => $device['device_id'], 'vlan_domain' => $vtpdomain_id, 'vlan_vlan' => $vlan_id, 'vlan_name' => $vlan['dot1qVlanStaticName'], 'vlan_type' => array('NULL')), 'vlans'); $module_stats[$vlan_id]['V'] = '+'; } $device['vlans'][$vtpdomain_id][$vlan_id] = $vlan_id; //Set Q-BRIDGE ports Vlan table (not work on FTOS for now) if ($device['os'] != 'ftos') { $parts = explode(' ', $vlan['dot1qVlanStaticEgressPorts']); $binary = ''; foreach ($parts as $part) { $binary .= zeropad(base_convert($part, 16, 2), 8); } $length = strlen($binary); for ($i = 0; $i < $length; $i++) { if ($binary[$i]) { $port = get_port_by_index_cache($device, $i + $vlan_ifindex_min); if (isset($ports_vlans_db[$port['port_id']][$vlan_id])) { $ports_vlans[$port['port_id']][$vlan_id] = $ports_vlans_db[$port['port_id']][$vlan_id]['port_vlan_id']; $module_stats[$vlan_id]['P'] = '.'; } else { $db_w = array('device_id' => $device['device_id'], 'port_id' => $port['port_id'], 'vlan' => $vlan_id); $id = dbInsert($db_w, 'ports_vlans'); $module_stats[$vlan_id]['P'] = '+'; $ports_vlans[$port['port_id']][$vlan_id] = $id; } }