This commit is contained in:
HenocKA
2016-02-02 12:58:05 +01:00
107 changed files with 4982 additions and 480 deletions
+162 -1
View File
@@ -114,7 +114,7 @@ function delete_port($int_id) {
dbDelete('links', "`remote_port_id` = ?", array($int_id));
dbDelete('bill_ports', "`port_id` = ?", array($int_id));
unlink(trim($config['rrd_dir'])."/".trim($interface['hostname'])."/port-".$interface['ifIndex'].".rrd");
unlink(get_port_rrdfile_path ($interface['hostname'], $interface['port_id']));
}
function sgn($int) {
@@ -143,6 +143,15 @@ function get_sensor_rrd($device, $sensor) {
return($rrd_file);
}
function get_port_rrdfile_path ($hostname, $port_id, $suffix = '') {
global $config;
if (! empty ($suffix))
$suffix = '-' . $suffix;
return trim ($config['rrd_dir']) . '/' . safename ($hostname) . '/' . 'port-id' . safename($port_id) . safename ($suffix) . '.rrd';
}
function get_port_by_index_cache($device_id, $ifIndex) {
global $port_index_cache;
@@ -1103,3 +1112,155 @@ function ip_to_sysname($device,$ip) {
}
return $ip;
}//end ip_to_sysname
/**
* Return valid port association modes
* @param bool $no_cache No-Cache flag (optional, default false)
* @return array
*/
function get_port_assoc_modes ($no_cache = false) {
global $config;
if ($config['memcached']['enable'] && $no_cache === false) {
$assoc_modes = $config['memcached']['resource']->get (hash ('sha512', "port_assoc_modes"));
if (! empty ($assoc_modes))
return $assoc_modes;
}
$assoc_modes = Null;
foreach (dbFetchRows ("SELECT `name` FROM `port_association_mode` ORDER BY pom_id") as $row)
$assoc_modes[] = $row['name'];
if ($config['memcached']['enable'] && $no_cache === false)
$config['memcached']['resource']->set (hash ('sha512', "port_assoc_modes"), $assoc_modes, $config['memcached']['ttl']);
return $assoc_modes;
}
/**
* Validate port_association_mode
* @param string $port_assoc_mode
* @return bool
*/
function is_valid_port_assoc_mode ($port_assoc_mode) {
return in_array ($port_assoc_mode, get_port_assoc_modes ());
}
/**
* Get DB id of given port association mode name
* @param string $port_assoc_mode
* @param bool $no_cache No-Cache flag (optional, default false)
*/
function get_port_assoc_mode_id ($port_assoc_mode, $no_cache = false) {
global $config;
if ($config['memcached']['enable'] && $no_cache === false) {
$id = $config['memcached']['resource']->get (hash ('sha512', "port_assoc_mode_id|$port_assoc_mode"));
if (! empty ($id))
return $id;
}
$id = Null;
$row = dbFetchRow ("SELECT `pom_id` FROM `port_association_mode` WHERE name = ?", array ($port_assoc_mode));
if ($row) {
$id = $row['pom_id'];
if ($config['memcached']['enable'] && $no_cache === false)
$config['memcached']['resource']->set (hash ('sha512', "port_assoc_mode_id|$port_assoc_mode"), $id, $config['memcached']['ttl']);
}
return $id;
}
/**
* Get name of given port association_mode ID
* @param int $port_assoc_mode_id Port association mode ID
* @param bool $no_cache No-Cache flag (optional, default false)
* @return bool
*/
function get_port_assoc_mode_name ($port_assoc_mode_id, $no_cache = false) {
global $config;
if ($config['memcached']['enable'] && $no_cache === false) {
$name = $config['memcached']['resource']->get (hash ('sha512', "port_assoc_mode_name|$port_assoc_mode_id"));
if (! empty ($name))
return $name;
}
$name = Null;
$row = dbFetchRow ("SELECT `name` FROM `port_association_mode` WHERE pom_id = ?", array ($port_assoc_mode_id));
if ($row) {
$name = $row['name'];
if ($config['memcached']['enable'] && $no_cache === false)
$config['memcached']['resource']->set (hash ('sha512', "port_assoc_mode_name|$port_assoc_mode_id"), $name, $config['memcached']['ttl']);
}
return $name;
}
/**
* Query all ports of the given device (by ID) and build port array and
* port association maps for ifIndex, ifName, ifDescr. Query port stats
* if told to do so, too.
* @param int $device_id ID of device to query ports for
* @param bool $with_statistics Query port statistics, too. (optional, default false)
* @return array
*/
function get_ports_mapped ($device_id, $with_statistics = false) {
$ports = array();
$maps = array(
'ifIndex' => array(),
'ifName' => array(),
'ifDescr' => array(),
);
/* Query all information available for ports for this device ... */
$query = 'SELECT * FROM `ports` WHERE `device_id` = ? ORDER BY port_id';
if ($with_statistics) {
/* ... including any related ports_statistics if requested */
$query = 'SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ? ORDER BY ports.port_id';
}
// Query known ports in order of discovery to make sure the latest
// discoverd/polled port is in the mapping tables.
foreach (dbFetchRows ($query, array ($device_id)) as $port) {
// Store port information by ports port_id from DB
$ports[$port['port_id']] = $port;
// Build maps from ifIndex, ifName, ifDescr to port_id
$maps['ifIndex'][$port['ifIndex']] = $port['port_id'];
$maps['ifName'][$port['ifName']] = $port['port_id'];
$maps['ifDescr'][$port['ifDescr']] = $port['port_id'];
}
return array(
'ports' => $ports,
'maps' => $maps,
);
}
/**
* Calculate port_id of given port using given devices port information and port association mode
* @param array $ports_mapped Port information of device queried by get_ports_mapped()
* @param array $port Port information as fetched from DB
* @param string $port_association_mode Port association mode to use for mapping
* @return int port_id (or Null)
*/
function get_port_id ($ports_mapped, $port, $port_association_mode) {
// Get port_id according to port_association_mode used for this device
$port_id = Null;
/*
* Information an all ports is available through $ports_mapped['ports']
* This might come in handy sometime in the future to add you nifty new
* port mapping schema:
*
* $ports = $ports_mapped['ports'];
*/
$maps = $ports_mapped['maps'];
if (in_array ($port_association_mode, array ('ifIndex', 'ifName', 'ifDescr'))) {
$port_id = $maps[$port_association_mode][$port[$port_association_mode]];
}
return $port_id;
}
+5
View File
@@ -712,6 +712,7 @@ $config['poller_modules']['applications'] = 1;
$config['poller_modules']['cisco-asa-firewall'] = 1;
$config['poller_modules']['mib'] = 0;
$config['poller_modules']['cisco-voice'] = 1;
$config['poller_modules']['cisco-cbqos'] = 1;
$config['poller_modules']['stp'] = 1;
// List of discovery modules. Need to be in this array to be
@@ -745,6 +746,7 @@ $config['discovery_modules']['toner'] = 1;
$config['discovery_modules']['ucd-diskio'] = 1;
$config['discovery_modules']['services'] = 1;
$config['discovery_modules']['charge'] = 1;
$config['discovery_modules']['cisco-cbqos'] = 0;
$config['discovery_modules']['stp'] = 1;
$config['modules_compat']['rfc1628']['liebert'] = 1;
@@ -856,3 +858,6 @@ $config['notifications']['local'] = 'misc/notifications.rs
// Update channel (Can be 'master' or 'release')
$config['update_channel'] = 'master';
// Default port association mode
$config['default_port_association_mode'] = 'ifIndex';
+8
View File
@@ -1436,6 +1436,14 @@ $config['os'][$os]['icon'] = 'generic';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Traffic';
// EATON PDU
$os = 'eatonpdu';
$config['os'][$os]['text'] = 'Eaton PDU';
$config['os'][$os]['type'] = 'power';
$config['os'][$os]['icon'] = 'eaton';
$config['os'][$os]['over'][0]['graph'] = 'device_current';
$config['os'][$os]['over'][0]['text'] = 'Current';
// Appliances
$os = 'fortios';
$config['os'][$os]['text'] = 'FortiOS';
+184
View File
@@ -0,0 +1,184 @@
<?php
/*
* LibreNMS module to capture Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if ($device['os_group'] == 'cisco') {
$module = 'Cisco-CBQOS';
echo $module.': ';
require_once 'includes/component.php';
$component = new component();
$components = $component->getComponents($device['device_id'],array('type'=>$module));
// We only care about our device id.
$components = $components[$device['device_id']];
// Begin our master array, all other values will be processed into this array.
$tblCBQOS = array();
// Let's gather some data..
$tblcbQosServicePolicy = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.1');
$tblcbQosObjects = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.5', 2);
$tblcbQosPolicyMapCfg = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.6');
$tblcbQosClassMapCfg = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.7');
$tblcbQosMatchStmtCfg = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.8');
/*
* False == no object found - this is not an error, there is no QOS configured
* null == timeout or something else that caused an error, there may be QOS configured but we couldn't get it.
*/
if ( is_null($tblcbQosServicePolicy) || is_null($tblcbQosObjects) || is_null($tblcbQosPolicyMapCfg) || is_null($tblcbQosClassMapCfg) || is_null($tblcbQosMatchStmtCfg) ) {
// We have to error here or we will end up deleting all our QoS components.
echo "Error\n";
}
else {
// No Error, lets process things.
d_echo("QoS Objects Found:\n");
foreach ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'] as $spid => $array) {
foreach ($array as $spobj => $index) {
$result = array();
// Produce a unique reproducible index for this entry.
$result['UID'] = hash('crc32', $spid."-".$spobj);
// Now that we have a valid identifiers, lets add some more data
$result['sp-id'] = $spid;
$result['sp-obj'] = $spobj;
// Add the Type, Policy-map, Class-map, etc.
$type = $tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.3'][$spid][$spobj];
$result['qos-type'] = $type;
// Add the Parent, this lets us work out our hierarchy for display later.
$result['parent'] = $tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.4'][$spid][$spobj];
$result['direction'] = $tblcbQosServicePolicy['1.3.6.1.4.1.9.9.166.1.1.1.1.3'][$spid];
$result['ifindex'] = $tblcbQosServicePolicy['1.3.6.1.4.1.9.9.166.1.1.1.1.4'][$spid];
// Gather different data depending on the type.
switch ($type) {
case 1:
// Policy-map, get data from that table.
d_echo("\nIndex: ".$index."\n");
d_echo(" UID: ".$result['UID']."\n");
d_echo(" SPID.SPOBJ: ".$result['sp-id'].".".$result['sp-obj']."\n");
d_echo(" If-Index: ".$result['ifindex']."\n");
d_echo(" Type: 1 - Policy-Map\n");
$result['label'] = $tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.1'][$index];
if ($tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.2'][$index] != "") {
$result['label'] .= " - ".$tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.2'][$index];
}
d_echo(" Label: ".$result['label']."\n");
break;
case 2:
// Class-map, get data from that table.
d_echo("\nIndex: ".$index."\n");
d_echo(" UID: ".$result['UID']."\n");
d_echo(" SPID.SPOBJ: ".$result['sp-id'].".".$result['sp-obj']."\n");
d_echo(" If-Index: ".$result['ifindex']."\n");
d_echo(" Type: 2 - Class-Map\n");
$result['label'] = $tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.1'][$index];
if($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index] != "") {
$result['label'] .= " - ".$tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index];
}
d_echo(" Label: ".$result['label']."\n");
if ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 2) {
$result['map-type'] = 'Match-All';
}
elseif ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 3) {
$result['map-type'] = 'Match-Any';
}
else {
$result['map-type'] = 'None';
}
// Find a child, this will be a type 3
foreach ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.4'][$spid] as $id => $value) {
if ($value == $result['sp-obj']) {
// We have our child, import the match
if ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.3'][$spid][$id] == 3) {
$result['match'] = $result['map-type'].": ".$tblcbQosMatchStmtCfg['1.3.6.1.4.1.9.9.166.1.8.1.1.1'][$tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'][$spid][$id]];
d_echo(" Match: ".$result['match']."\n");
}
}
}
break;
default:
continue 2;
}
$tblCBQOS[] = $result;
}
}
/*
* Ok, we have our 2 array's (Components and SNMP) now we need
* to compare and see what needs to be added/updated.
*
* Let's loop over the SNMP data to see if we need to ADD or UPDATE any components.
*/
foreach ($tblCBQOS as $key => $array) {
$component_key = false;
// Loop over our components to determine if the component exists, or we need to add it.
foreach ($components as $compid => $child) {
if ($child['UID'] === $array['UID']) {
$component_key = $compid;
}
}
if (!$component_key) {
// The component doesn't exist, we need to ADD it - ADD.
$new_component = $component->createComponent($device['device_id'],$module);
$component_key = key($new_component);
$components[$component_key] = array_merge($new_component[$component_key], $array);
echo "+";
}
else {
// The component does exist, merge the details in - UPDATE.
$components[$component_key] = array_merge($components[$component_key], $array);
echo ".";
}
}
/*
* Loop over the Component data to see if we need to DELETE any components.
*/
foreach ($components as $key => $array) {
// Guilty until proven innocent
$found = false;
foreach ($tblCBQOS as $k => $v) {
if ($array['UID'] == $v['UID']) {
// Yay, we found it...
$found = true;
}
}
if ($found === false) {
// The component has not been found. we should delete it.
echo "-";
$component->deleteComponent($key);
}
}
// Write the Components back to the DB.
$component->setComponentPrefs($device['device_id'],$components);
echo "\n";
} // End if not error
}
+17
View File
@@ -0,0 +1,17 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.com>
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (!$os) {
if (strstr($sysObjectId, '.1.3.6.1.4.1.534.6.6.7')) {
$os = 'eatonpdu';
}
}
+55 -20
View File
@@ -9,27 +9,61 @@ $port_stats = snmpwalk_cache_oid($device, 'ifType', $port_stats, 'IF-MIB');
// End Building SNMP Cache Array
d_echo($port_stats);
// Build array of ports in the database
// FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
// -- i can make it a function, so that you don't know what it's doing.
// -- $ports_db = adamasMagicFunction($ports_db); ?
foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($device['device_id'])) as $port) {
$ports_db[$port['ifIndex']] = $port;
$ports_db_l[$port['ifIndex']] = $port['port_id'];
// By default libreNMS uses the ifIndex to associate ports on devices with ports discoverd/polled
// before and stored in the database. On Linux boxes this is a problem as ifIndexes may be
// unstable between reboots or (re)configuration of tunnel interfaces (think: GRE/OpenVPN/Tinc/...)
// The port association configuration allows to choose between association via ifIndex, ifName,
// or maybe other means in the future. The default port association mode still is ifIndex for
// compatibility reasons.
$port_association_mode = $config['default_port_association_mode'];
if ($device['port_association_mode'])
$port_association_mode = get_port_assoc_mode_name ($device['port_association_mode']);
// Build array of ports in the database and an ifIndex/ifName -> port_id map
$ports_mapped = get_ports_mapped ($device['id']);
$ports_db = $ports_mapped['ports'];
//
// Rename any old RRD files still named after the previous ifIndex based naming schema.
foreach ($ports_mapped['maps']['ifIndex'] as $ifIndex => $port_id) {
foreach (array ('', 'adsl', 'dot3') as $suffix) {
$suffix_tmp = '';
if ($suffix)
$suffix_tmp = "-$suffix";
$old_rrd_path = trim ($config['rrd_dir']) . '/' . $device['hostname'] . "/port-$ifIndex$suffix_tmp.rrd";
$new_rrd_path = get_port_rrdfile_path ($device['hostname'], $port_id, $suffix);
if (is_file ($old_rrd_path)) {
rename ($old_rrd_path, $new_rrd_path);
}
}
}
// New interface detection
foreach ($port_stats as $ifIndex => $port) {
// Check the port against our filters.
// Store ifIndex in port entry and prefetch ifName as we'll need it multiple times
$port['ifIndex'] = $ifIndex;
$ifName = $port['ifName'];
// Get port_id according to port_association_mode used for this device
$port_id = get_port_id ($ports_mapped, $port, $port_association_mode);
if (is_port_valid($port, $device)) {
if (!is_array($ports_db[$ifIndex])) {
$port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
$ports_db[$ifIndex] = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex));
echo 'Adding: '.$port['ifName'].'('.$ifIndex.')('.$ports_db[$port['ifIndex']]['port_id'].')';
// Port newly discovered?
if (! is_array($ports_db[$port_id])) {
$port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex, 'ifName' => $ifName), 'ports');
$ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $port_id));
echo 'Adding: '.$ifName.'('.$ifIndex.')('.$port_id.')';
}
else if ($ports_db[$ifIndex]['deleted'] == '1') {
dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports_db[$ifIndex]['port_id']));
$ports_db[$ifIndex]['deleted'] = '0';
// Port re-discovered after previous deletion?
else if ($ports_db[$port_id]['deleted'] == '1') {
dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports_db[$port_id]));
$ports_db[$port_id]['deleted'] = '0';
echo 'U';
}
else {
@@ -39,11 +73,13 @@ foreach ($port_stats as $ifIndex => $port) {
// We've seen it. Remove it from the cache.
unset($ports_l[$ifIndex]);
}
// Port vanished (mark as deleted)
else {
if (is_array($ports_db[$port['ifIndex']])) {
if ($ports_db[$port['ifIndex']]['deleted'] != '1') {
dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($ports_db[$ifIndex]['port_id']));
$ports_db[$ifIndex]['deleted'] = '1';
if (is_array($ports_db[$port_id])) {
if ($ports_db[$port_id]['deleted'] != '1') {
dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($ports_db[$port_id]));
$ports_db[$port_id]['deleted'] = '1';
echo '-';
}
}
@@ -68,4 +104,3 @@ echo "\n";
// Clear Variables Here
unset($port_stats);
unset($ports_db);
unset($ports_db_db);
@@ -0,0 +1,23 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.com>
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if ($device['os'] == 'eatonpdu') {
$data = snmpwalk_cache_multi_oid($device, 'outletCurrent', array(), 'EATON-EPDU-MIB');
$descr = snmpwalk_cache_multi_oid($device, 'outletName', array(), 'EATON-EPDU-MIB');
if (is_array($data)) {
$cur_oid = '.1.3.6.1.4.1.534.6.6.7.6.4.1.3.';
foreach ($data as $index => $entry) {
$i++;
discover_sensor($valid['sensor'], 'current', $device, $cur_oid.$index, $i, 'eatonpdu', $descr[$index]['outletName'], '1000', '1', null, null, null, null, $data[$index]['outletCurrent'], 'snmp', $index);
}
}
}
@@ -15,8 +15,10 @@ if ($device['os_group'] == 'cisco') {
if (is_array($temp)) {
$cur_oid = '.1.3.6.1.4.1.9.9.13.1.3.1.3.';
foreach ($temp as $index => $entry) {
$descr = ucwords($temp[$index]['ciscoEnvMonTemperatureStatusDescr']);
discover_sensor($valid['sensor'], 'temperature', $device, $cur_oid.$index, $index, 'cisco', $descr, '1', '1', null, null, $temp[$index]['ciscoEnvMonTemperatureThreshold'], null, $temp[$index]['ciscoEnvMonTemperatureStatusValue'], 'snmp', $index);
if ($temp[$index]['ciscoEnvMonTemperatureState'] != 'notPresent') {
$descr = ucwords($temp[$index]['ciscoEnvMonTemperatureStatusDescr']);
discover_sensor($valid['sensor'], 'temperature', $device, $cur_oid.$index, $index, 'cisco', $descr, '1', '1', null, null, $temp[$index]['ciscoEnvMonTemperatureThreshold'], null, $temp[$index]['ciscoEnvMonTemperatureStatusValue'], 'snmp', $index);
}
}
}
}
+66 -1
View File
@@ -112,7 +112,72 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
log_event('STP removed', $device, 'stp');
echo '-';
}
// STP port related stuff
foreach ($stp_raw as $port => $value){
if ($port) { // $stp_raw[0] ist not port related so we skip this one
$stp_port = array(
'priority' => $stp_raw[$port]['dot1dStpPortPriority'],
'state' => $stp_raw[$port]['dot1dStpPortState'],
'enable' => $stp_raw[$port]['dot1dStpPortEnable'],
'pathCost' => $stp_raw[$port]['dot1dStpPortPathCost'],
'designatedCost' => $stp_raw[$port]['dot1dStpPortDesignatedCost'],
'designatedPort' => $stp_raw[$port]['dot1dStpPortDesignatedPort'],
'forwardTransitions' => $stp_raw[$port]['dot1dStpPortForwardTransitions']
);
// set device binding
$stp_port['device_id'] = $device['device_id'];
// set port binding
$stp_port['port_id'] = dbFetchCell('SELECT port_id FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $stp_raw[$port]['dot1dStpPort']));
$dr = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedRoot']));
$dr = substr($dr, -12); //remove first two octets
$stp_port['designatedRoot'] = $dr;
$db = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedBridge']));
$db = substr($db, -12); //remove first two octets
$stp_port['designatedBridge'] = $db;
if ($device['os'] == 'pbn') {
// It seems that PBN guys don't care about ieee 802.1d :-(
// So try to find the right port with some crazy conversations
$dp_value = dechex($stp_port['priority']);
$dp_value = $dp_value.'00';
$dp_value = hexdec($dp_value);
if ($stp_raw[$port]['dot1dStpPortDesignatedPort']) {
$dp = $stp_raw[$port]['dot1dStpPortDesignatedPort'] - $dp_value;
$stp_port['designatedPort'] = $dp;
}
}
else {
// Port saved in format priority+port (ieee 802.1d-1998: clause 8.5.5.1)
$dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2); //discard the first octet (priority part)
$stp_port['designatedPort'] = hexdec($dp);
}
d_echo($stp_port);
// Write to db
if (!dbFetchCell('SELECT 1 FROM `ports_stp` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $stp_port['port_id']))) {
dbInsert($stp_port,'ports_stp');
echo '+';
}
}
}
// Delete STP ports from db if absent in SNMP query
$stp_port_db = dbFetchRows('SELECT * FROM `ports_stp` WHERE `device_id` = ?', array($device['device_id']));
//d_echo($stp_port_db);
foreach($stp_port_db as $port => $value){
$if_index = dbFetchCell('SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id']));
if ($if_index != $stp_raw[$if_index]['dot1dStpPort']){
dbDelete('ports_stp', '`device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id']));
echo '-';
}
}
}
unset($stp_raw, $stp, $stp_db);
unset($stp_raw, $stp, $stp_db, $stp_port, $stp_port_db);
echo "\n";
+25 -10
View File
@@ -239,12 +239,20 @@ function delete_device($id) {
return $ret;
}
function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0', $poller_group = '0', $force_add = '0') {
function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0', $poller_group = '0', $force_add = '0', $port_assoc_mode = 'ifIndex') {
global $config;
list($hostshort) = explode(".", $host);
// Test Database Exists
if (host_exists($host) === false) {
// Valid port assoc mode
if (! is_valid_port_assoc_mode ($port_assoc_mode)) {
if ($quiet == 0) {
print_error ("Invalid port association_mode '$port_assoc_mode'. Valid modes are: " . join (', ', get_port_assoc_modes ()));
return 0;
}
}
if ($config['addhost_alwayscheckip'] === TRUE) {
$ip = gethostbyname($host);
} else {
@@ -257,15 +265,15 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0
if (empty($snmpver)) {
// Try SNMPv2c
$snmpver = 'v2c';
$ret = addHost($host, $snmpver, $port, $transport, $quiet, $poller_group, $force_add);
$ret = addHost($host, $snmpver, $port, $transport, $quiet, $poller_group, $force_add, $port_assoc_mode);
if (!$ret) {
//Try SNMPv3
$snmpver = 'v3';
$ret = addHost($host, $snmpver, $port, $transport, $quiet, $poller_group, $force_add);
$ret = addHost($host, $snmpver, $port, $transport, $quiet, $poller_group, $force_add, $port_assoc_mode);
if (!$ret) {
// Try SNMPv1
$snmpver = 'v1';
return addHost($host, $snmpver, $port, $transport, $quiet, $poller_group, $force_add);
return addHost($host, $snmpver, $port, $transport, $quiet, $poller_group, $force_add, $port_assoc_mode);
}
else {
return $ret;
@@ -279,12 +287,12 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0
if ($snmpver === "v3") {
// Try each set of parameters from config
foreach ($config['snmp']['v3'] as $v3) {
$device = deviceArray($host, NULL, $snmpver, $port, $transport, $v3);
$device = deviceArray($host, NULL, $snmpver, $port, $transport, $v3, $port_assoc_mode);
if($quiet == '0') { print_message("Trying v3 parameters " . $v3['authname'] . "/" . $v3['authlevel'] . " ... "); }
if ($force_add == 1 || isSNMPable($device)) {
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
if (empty($snmphost) or ($snmphost == $host || $hostshort = $host)) {
$device_id = createHost ($host, NULL, $snmpver, $port, $transport, $v3, $poller_group);
$device_id = createHost ($host, NULL, $snmpver, $port, $transport, $v3, $poller_group, $port_assoc_mode);
return $device_id;
}
else {
@@ -303,14 +311,14 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0
elseif ($snmpver === "v2c" or $snmpver === "v1") {
// try each community from config
foreach ($config['snmp']['community'] as $community) {
$device = deviceArray($host, $community, $snmpver, $port, $transport, NULL);
$device = deviceArray($host, $community, $snmpver, $port, $transport, NULL, $port_assoc_mode);
if($quiet == '0') {
print_message("Trying community $community ...");
}
if ($force_add == 1 || isSNMPable($device)) {
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
if (empty($snmphost) || ($snmphost && ($snmphost == $host || $hostshort = $host))) {
$device_id = createHost ($host, $community, $snmpver, $port, $transport,array(),$poller_group);
$device_id = createHost ($host, $community, $snmpver, $port, $transport,array(),$poller_group, $port_assoc_mode);
return $device_id;
}
else {
@@ -382,12 +390,18 @@ next;
}
}
function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp', $v3) {
function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp', $v3, $port_assoc_mode = 'ifIndex') {
$device = array();
$device['hostname'] = $host;
$device['port'] = $port;
$device['transport'] = $transport;
/* Get port_assoc_mode id if neccessary
* We can work with names of IDs here */
if (! is_int ($port_assoc_mode))
$port_assoc_mode = get_port_assoc_mode_id ($port_assoc_mode);
$device['port_association_mode'] = $port_assoc_mode;
$device['snmpver'] = $snmpver;
if ($snmpver === "v2c" or $snmpver === "v1") {
$device['community'] = $community;
@@ -554,7 +568,7 @@ function getpollergroup($poller_group='0') {
}
}
function createHost($host, $community = NULL, $snmpver, $port = 161, $transport = 'udp', $v3 = array(), $poller_group='0') {
function createHost($host, $community = NULL, $snmpver, $port = 161, $transport = 'udp', $v3 = array(), $poller_group='0', $port_assoc_mode = 'ifIndex') {
global $config;
$host = trim(strtolower($host));
@@ -569,6 +583,7 @@ function createHost($host, $community = NULL, $snmpver, $port = 161, $transport
'snmpver' => $snmpver,
'poller_group' => $poller_group,
'status_reason' => '',
'port_association_mode' => $port_assoc_mode,
);
$device = array_merge($device, $v3);
+22 -47
View File
@@ -168,10 +168,10 @@ if ($config['enable_bgp']) {
$peerrrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('bgp-'.$peer['bgpPeerIdentifier'].'.rrd');
if (!is_file($peerrrd)) {
$create_rrd = 'DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000
DS:bgpPeerInUpdates:COUNTER:600:U:100000000000
DS:bgpPeerOutTotal:COUNTER:600:U:100000000000
DS:bgpPeerInTotal:COUNTER:600:U:100000000000
$create_rrd = 'DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000
DS:bgpPeerInUpdates:COUNTER:600:U:100000000000
DS:bgpPeerOutTotal:COUNTER:600:U:100000000000
DS:bgpPeerInTotal:COUNTER:600:U:100000000000
DS:bgpPeerEstablished:GAUGE:600:0:U '.$config['rrd_rra'];
rrdtool_create($peerrrd, $create_rrd);
@@ -294,45 +294,6 @@ if ($config['enable_bgp']) {
unset($cbgp_data);
}//end if
if ($device['os'] == 'junos') {
// Missing: cbgpPeerAdminLimit cbgpPeerPrefixThreshold cbgpPeerPrefixClearThreshold cbgpPeerSuppressedPrefixes cbgpPeerWithdrawnPrefixes
$safis['unicast'] = 1;
$safis['multicast'] = 2;
if (!isset($peerIndexes)) {
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
foreach ($j_bgp as $index => $entry) {
switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
case 'ipv4':
$ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
$j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
break;
case 'ipv6':
$ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
$ip6 = Net_IPv6::compress($ip6);
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo "PANIC: Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
break;
}
}
}//end if
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
$cbgpPeerAcceptedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesAccepted'];
$cbgpPeerDeniedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesRejected'];
$cbgpPeerAdvertisedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi.".$safis[$safi]]['jnxBgpM2PrefixOutPrefixes'];
unset($j_prefixes);
unset($j_bgp);
unset($j_peerIndexes);
}//end if
// FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE!
$update = 'UPDATE bgpPeers_cbgp SET';
$peer['c_update']['AcceptedPrefixes'] = $cbgpPeerAcceptedPrefixes;
@@ -344,14 +305,28 @@ if ($config['enable_bgp']) {
$peer['c_update']['SuppressedPrefixes'] = $cbgpPeerSuppressedPrefixes;
$peer['c_update']['WithdrawnPrefixes'] = $cbgpPeerWithdrawnPrefixes;
$oids = array(
'AcceptedPrefixes',
'DeniedPrefixes',
'AdvertisedPrefixes',
'SuppressedPrefixes',
'WithdrawnPrefixes',
);
foreach ($oids as $oid) {
$peer['c_update'][$oid.'_delta'] = $peer['c_update'][$oid] - $peer_afi[$oid];
$peer['c_update'][$oid.'_prev'] = $peer_afi[$oid];
}
dbUpdate($peer['c_update'], 'bgpPeers_cbgp', '`device_id` = ? AND bgpPeerIdentifier = ? AND afi = ? AND safi = ?', array($device['device_id'], $peer['bgpPeerIdentifier'], $afi, $safi));
$cbgp_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('cbgp-'.$peer['bgpPeerIdentifier'].".$afi.$safi.rrd");
if (!is_file($cbgp_rrd)) {
$rrd_create = 'DS:AcceptedPrefixes:GAUGE:600:U:100000000000
DS:DeniedPrefixes:GAUGE:600:U:100000000000
DS:AdvertisedPrefixes:GAUGE:600:U:100000000000
DS:SuppressedPrefixes:GAUGE:600:U:100000000000
$rrd_create = 'DS:AcceptedPrefixes:GAUGE:600:U:100000000000
DS:DeniedPrefixes:GAUGE:600:U:100000000000
DS:AdvertisedPrefixes:GAUGE:600:U:100000000000
DS:SuppressedPrefixes:GAUGE:600:U:100000000000
DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 '.$config['rrd_rra'];
rrdtool_create($cbgp_rrd, $rrd_create);
}
+72
View File
@@ -0,0 +1,72 @@
<?php
/*
* LibreNMS module to capture Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if ($device['os_group'] == "cisco") {
$module = 'Cisco-CBQOS';
require_once 'includes/component.php';
$component = new component();
$options['filter']['type'] = array('=',$module);
$options['filter']['disabled'] = array('=',0);
$options['filter']['ignore'] = array('=',0);
$components = $component->getComponents($device['device_id'],$options);
// We only care about our device id.
$components = $components[$device['device_id']];
// Only collect SNMP data if we have enabled components
if (count($components > 0)) {
// Let's gather the stats..
$tblcbQosClassMapStats = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.15.1.1', 2);
// Loop through the components and extract the data.
foreach ($components as $key => $array) {
$type = $array['qos-type'];
// Get data from the class table.
if ($type == 2) {
// Let's make sure the rrd is setup for this class.
$filename = "port-".$array['ifindex']."-cbqos-".$array['sp-id']."-".$array['sp-obj'].".rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename);
if (!file_exists ($rrd_filename)) {
rrdtool_create ($rrd_filename, " DS:postbits:COUNTER:600:0:U DS:bufferdrops:COUNTER:600:0:U DS:qosdrops:COUNTER:600:0:U" . $config['rrd_rra']);
}
// Let's print some debugging info.
d_echo("\n\nComponent: ".$key."\n");
d_echo(" Class-Map: ".$array['label']."\n");
d_echo(" SPID.SPOBJ: ".$array['sp-id'].".".$array['sp-obj']."\n");
d_echo(" PostBytes: 1.3.6.1.4.1.9.9.166.1.15.1.1.10.".$array['sp-id'].".".$array['sp-obj']." = ".$tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.10'][$array['sp-id']][$array['sp-obj']]."\n");
d_echo(" BufferDrops: 1.3.6.1.4.1.9.9.166.1.15.1.1.21.".$array['sp-id'].".".$array['sp-obj']." = ".$tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.21'][$array['sp-id']][$array['sp-obj']]."\n");
d_echo(" QOSDrops: 1.3.6.1.4.1.9.9.166.1.15.1.1.17.".$array['sp-id'].".".$array['sp-obj']." = ".$tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.17'][$array['sp-id']][$array['sp-obj']]."\n");
$rrd['postbytes'] = $tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.10'][$array['sp-id']][$array['sp-obj']];
$rrd['bufferdrops'] = $tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.21'][$array['sp-id']][$array['sp-obj']];
$rrd['qosdrops'] = $tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.17'][$array['sp-id']][$array['sp-obj']];
// Update rrd
rrdtool_update ($rrd_filename, $rrd);
// Clean-up after yourself!
unset($filename, $rrd_filename);
}
} // End foreach components
echo $module." ";
} // end if count components
// Clean-up after yourself!
unset($type, $components, $component, $options, $module);
}
+15
View File
@@ -0,0 +1,15 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.com>
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
$hardware = trim(snmp_get($device, 'partNumber.0', '-Ovq', 'EATON-EPDU-MIB'), '"');
$version = trim(snmp_get($device, 'firmwareVersion.0', '-Ovq', 'EATON-EPDU-MIB'), '"');
$serial = trim(snmp_get($device, 'serialNumber.0', '-Ovq', 'EATON-EPDU-MIB'), '"');
+6 -6
View File
@@ -39,11 +39,11 @@
// adslAturPerfESs.1 = 0 seconds
// adslAturPerfValidIntervals.1 = 0
// adslAturPerfInvalidIntervals.1 = 0
if (isset($port_stats[$port['ifIndex']]['adslLineCoding'])) {
if (isset($port_stats[$port_id]['adslLineCoding'])) {
// Check to make sure Port data is cached.
$this_port = &$port_stats[$port['ifIndex']];
$this_port = &$port_stats[$port_id];
$rrdfile = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('port-'.$port['ifIndex'].'-adsl.rrd');
$rrdfile = get_port_rrdfile_path ($device['hostname'], $port_id, 'adsl');
$rrd_create = ' --step 300';
$rrd_create .= ' DS:AtucCurrSnrMgn:GAUGE:600:0:635';
@@ -130,8 +130,8 @@ if (isset($port_stats[$port['ifIndex']]['adslLineCoding'])) {
$this_port[$oid] = ($this_port[$oid] / 10);
}
if (dbFetchCell('SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = ?', array($port['port_id'])) == '0') {
dbInsert(array('port_id' => $port['port_id']), 'ports_adsl');
if (dbFetchCell('SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = ?', array($port_id)) == '0') {
dbInsert(array('port_id' => $port_id), 'ports_adsl');
}
$port['adsl_update'] = array('port_adsl_updated' => array('NOW()'));
@@ -141,7 +141,7 @@ if (isset($port_stats[$port['ifIndex']]['adslLineCoding'])) {
$port['adsl_update'][$oid] = $data;
}
dbUpdate($port['adsl_update'], 'ports_adsl', '`port_id` = ?', array($port['port_id']));
dbUpdate($port['adsl_update'], 'ports_adsl', '`port_id` = ?', array($port_id));
if ($this_port['adslAtucCurrSnrMgn'] > '1280') {
$this_port['adslAtucCurrSnrMgn'] = 'U';
+5 -4
View File
@@ -1,13 +1,14 @@
<?php
if ($port_stats[$port['ifIndex']] &&
if ($port_stats[$port_id] &&
$port['ifType'] == 'ethernetCsmacd' &&
isset($port_stats[$port['ifIndex']]['dot3StatsIndex'])) {
isset($port_stats[$port_id]['dot3StatsIndex'])) {
// Check to make sure Port data is cached.
$this_port = &$port_stats[$port[ifIndex]];
$this_port = &$port_stats[$port_id];
// TODO: remove legacy check?
$old_rrdfile = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('etherlike-'.$port['ifIndex'].'.rrd');
$rrdfile = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('port-'.$port['ifIndex'].'-dot3.rrd');
$rrd_file = get_port_rrdfile_path ($device['hostname'], $port_id, 'dot3');
$rrd_create = $config['rrd_rra'];
+4 -5
View File
@@ -35,14 +35,13 @@ $peth_oids = array(
'pethMainPseConsumptionPower',
);
if ($port_stats[$port['ifIndex']]
if ($port_stats[$port_id]
&& $port['ifType'] == 'ethernetCsmacd'
&& isset($port_stats[$port['ifIndex']]['dot3StatsIndex'])) {
&& isset($port_stats[$port_id]['dot3StatsIndex'])) {
// Check to make sure Port data is cached.
$this_port = &$port_stats[$port['ifIndex']];
$rrdfile = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('port-'.$port['ifIndex'].'-poe.rrd');
$this_port = &$port_stats[$port_id];
$rrdfile = get_port_rrdfile_path ($device['hostname'], $port_id, 'poe');
if (!file_exists($rrdfile)) {
$rrd_create .= $config['rrd_rra'];
+76 -35
View File
@@ -191,50 +191,91 @@ $polled = time();
// End Building SNMP Cache Array
d_echo($port_stats);
// Build array of ports in the database
// FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
// -- i can make it a function, so that you don't know what it's doing.
// -- $ports = adamasMagicFunction($ports_db); ?
// select * doesn't do what we want if multiple tables have the same column name -- last one wins :/
$ports_db = dbFetchRows('SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?', array($device['device_id']));
// By default libreNMS uses the ifIndex to associate ports on devices with ports discoverd/polled
// before and stored in the database. On Linux boxes this is a problem as ifIndexes may be
// unstable between reboots or (re)configuration of tunnel interfaces (think: GRE/OpenVPN/Tinc/...)
// The port association configuration allows to choose between association via ifIndex, ifName,
// or maybe other means in the future. The default port association mode still is ifIndex for
// compatibility reasons.
$port_association_mode = $config['default_port_association_mode'];
if ($device['port_association_mode'])
$port_association_mode = get_port_assoc_mode_name ($device['port_association_mode']);
foreach ($ports_db as $port) {
$ports[$port['ifIndex']] = $port;
// Query known ports and mapping table in order of discovery to make sure
// the latest discoverd/polled port is in the mapping tables.
$ports_mapped = get_ports_mapped ($device['device_id'], true);
$ports = $ports_mapped['ports'];
//
// Rename any old RRD files still named after the previous ifIndex based naming schema.
foreach ($ports_mapped['maps']['ifIndex'] as $ifIndex => $port_id) {
foreach (array ('', 'adsl', 'dot3') as $suffix) {
$suffix_tmp = '';
if ($suffix)
$suffix_tmp = "-$suffix";
$old_rrd_path = trim ($config['rrd_dir']) . '/' . $device['hostname'] . "/port-$ifIndex$suffix_tmp.rrd";
$new_rrd_path = get_port_rrdfile_path ($device['hostname'], $port_id, $suffix);
if (is_file ($old_rrd_path)) {
rename ($old_rrd_path, $new_rrd_path);
}
}
}
// New interface detection
foreach ($port_stats as $ifIndex => $port) {
// Store ifIndex in port entry and prefetch ifName as we'll need it multiple times
$port['ifIndex'] = $ifIndex;
$ifName = $port['ifName'];
// Get port_id according to port_association_mode used for this device
$port_id = get_port_id ($ports_mapped, $port, $port_association_mode);
if (is_port_valid($port, $device)) {
echo 'valid';
if (!is_array($ports[$port['ifIndex']])) {
$port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
// Port newly discovered?
if (! $ports[$port_id]) {
$port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex, 'ifName' => $ifName), 'ports');
dbInsert(array('port_id' => $port_id), 'ports_statistics');
$ports[$port['ifIndex']] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id));
echo 'Adding: '.$port['ifName'].'('.$ifIndex.')('.$ports[$port['ifIndex']]['port_id'].')';
$ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id));
echo 'Adding: '.$ifName.'('.$ifIndex.')('.$port_id.')';
// print_r($ports);
}
else if ($ports[$ifIndex]['deleted'] == '1') {
dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id']));
$ports[$ifIndex]['deleted'] = '0';
}
if ($ports[$ifIndex]['ports_statistics_port_id'] === null) {
// in case the port was created before we created the table
dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics');
}
}
else {
if ($ports[$port['ifIndex']]['deleted'] != '1') {
dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id']));
$ports[$ifIndex]['deleted'] = '1';
}
}
}
// End New interface detection
// Port re-discovered after previous deletion?
else if ($ports[$port_id]['deleted'] == 1) {
dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($port_id));
$ports[$port_id]['deleted'] = '0';
}
if ($ports[$port_id]['ports_statistics_port_id'] === null) {
// in case the port was created before we created the table
dbInsert(array('port_id' => $port_id), 'ports_statistics');
}
// Assure stable mapping
$port_stats[$ifIndex]['port_id'] = $port_id;
$ports[$port_id]['ifIndex'] = $ifIndex;
}
// Port vanished (mark as deleted)
else {
if ($ports[$port_id]['deleted'] != '1') {
dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($port_id));
$ports[$port_id]['deleted'] = '1';
}
}
} // End new interface detection
echo "\n";
// Loop ports in the DB and update where necessary
foreach ($ports as $port) {
echo 'Port '.$port['ifDescr'].'('.$port['ifIndex'].') ';
$port_id = $port['port_id'];
echo 'Port ' . $port['ifName'] . ': ' . $port['ifDescr'] . '(' . $port['ifIndex'] . ') ';
if ($port_stats[$port['ifIndex']] && $port['disabled'] != '1') {
// Check to make sure Port data is cached.
$this_port = &$port_stats[$port['ifIndex']];
@@ -477,7 +518,7 @@ foreach ($ports as $port) {
}
// Update RRDs
$rrdfile = $host_rrd.'/port-'.safename($port['ifIndex'].'.rrd');
$rrdfile = get_port_rrdfile_path ($device['hostname'], $port_id);
if (!is_file($rrdfile)) {
rrdtool_create(
$rrdfile,
@@ -576,9 +617,9 @@ foreach ($ports as $port) {
// Update Database
if (count($port['update'])) {
$updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id']));
$updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port_id));
// do we want to do something else with this?
$updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port['port_id']));
$updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port_id));
d_echo("$updated updated");
}
@@ -588,7 +629,7 @@ foreach ($ports as $port) {
echo 'Port Deleted';
// Port missing from SNMP cache.
if ($port['deleted'] != '1') {
dbUpdate(array('deleted' => '1'), 'ports', '`device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $port['ifIndex']));
dbUpdate(array('deleted' => '1'), 'ports', '`device_id` = ? AND `port_id` = ?', array($device['device_id'], $port_id));
}
}
else {
@@ -599,7 +640,7 @@ foreach ($ports as $port) {
// Clear Per-Port Variables Here
unset($this_port);
}//end foreach
} //end port update
// Clear Variables Here
unset($port_stats);
+54 -1
View File
@@ -39,6 +39,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
// read the 802.1D subtree
$stp_raw = snmpwalk_cache_oid($device, 'dot1dStp', array(), 'RSTP-MIB');
d_echo($stp_raw);
$stp = array(
'protocolSpecification' => $stp_raw[0]['dot1dStpProtocolSpecification'],
'priority' => $stp_raw[0]['dot1dStpPriority'],
@@ -121,7 +122,59 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
dbUpdate($stp,'stp','device_id = ?', array($device['device_id']));
echo '.';
}
// STP port related stuff
foreach ($stp_raw as $port => $value){
if ($port) { // $stp_raw[0] ist not port related so we skip this one
$stp_port = array(
'priority' => $stp_raw[$port]['dot1dStpPortPriority'],
'state' => $stp_raw[$port]['dot1dStpPortState'],
'enable' => $stp_raw[$port]['dot1dStpPortEnable'],
'pathCost' => $stp_raw[$port]['dot1dStpPortPathCost'],
'designatedCost' => $stp_raw[$port]['dot1dStpPortDesignatedCost'],
'designatedPort' => $stp_raw[$port]['dot1dStpPortDesignatedPort'],
'forwardTransitions' => $stp_raw[$port]['dot1dStpPortForwardTransitions']
);
// set device binding
$stp_port['device_id'] = $device['device_id'];
// set port binding
$stp_port['port_id'] = dbFetchCell('SELECT port_id FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $stp_raw[$port]['dot1dStpPort']));
$dr = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedRoot']));
$dr = substr($dr, -12); //remove first two octets
$stp_port['designatedRoot'] = $dr;
$db = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedBridge']));
$db = substr($db, -12); //remove first two octets
$stp_port['designatedBridge'] = $db;
if ($device['os'] == 'pbn') {
// It seems that PBN guys don't care about ieee 802.1d :-(
// So try to find the right port with some crazy conversations
$dp_value = dechex($stp_port['priority']);
$dp_value = $dp_value.'00';
$dp_value = hexdec($dp_value);
if ($stp_raw[$port]['dot1dStpPortDesignatedPort']) {
$dp = $stp_raw[$port]['dot1dStpPortDesignatedPort'] - $dp_value;
$stp_port['designatedPort'] = $dp;
}
}
else {
// Port saved in format priority+port (ieee 802.1d-1998: clause 8.5.5.1)
$dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2); //discard the first octet (priority part)
$stp_port['designatedPort'] = hexdec($dp);
}
//d_echo($stp_port);
// Update db
dbUpdate($stp_port,'ports_stp','`device_id` = ? AND `port_id` = ?', array($device['device_id'], $stp_port['port_id']));
echo '.';
}
}
}
unset($stp_raw, $stp, $stp_db);
unset($stp_raw, $stp, $stp_db, $stp_port);
echo "\n";
+66
View File
@@ -1274,4 +1274,70 @@ function register_mibs($device, $mibs, $included_by)
}
echo "\n";
} // register_mibs
/**
* SNMPWalk_array_num - performs a numeric SNMPWalk and returns an array containing $count indexes
* One Index:
* From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0
* To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27.18']['655360'] = 0
* Two Indexes:
* From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0
* To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27']['18']['655360'] = 0
* And so on...
* Think snmpwalk_cache_*_oid but for numeric data.
*
* Why is this useful?
* Some SNMP data contains a single index (eg. ifIndex in IF-MIB) and some is dual indexed
* (eg. PolicyIndex/ObjectsIndex in CISCO-CLASS-BASED-QOS-MIB).
* The resulting array allows us to easily access the top level index we want and iterate over the data from there.
*
* @param $device
* @param $OID
* @param int $indexes
* @internal param $string
* @return array
*/
function snmpwalk_array_num($device,$oid,$indexes=1) {
$array = array();
$string = snmp_walk($device, $oid, '-Osqn');
if ( $string === false) {
// False means: No Such Object.
return false;
}
if ($string == "") {
// Empty means SNMP timeout or some such.
return null;
}
// Let's turn the string into something we can work with.
foreach (explode("\n", $string) as $line) {
if ($line[0] == '.') {
// strip the leading . if it exists.
$line = substr($line,1);
}
list($key, $value) = explode(' ', $line, 2);
$prop_id = explode('.', $key);
$value = trim($value);
// if we have requested more levels that exist, set to the max.
if ($indexes > count($prop_id)) {
$indexes = count($prop_id)-1;
}
for ($i=0;$i<$indexes;$i++) {
// Pop the index off.
$index = array_pop($prop_id);
$value = array($index => $value);
}
// Rebuild our key
$key = implode('.',$prop_id);
// Add the entry to the master array
$array = array_replace_recursive($array,array($key => $value));
}
return $array;
}