Extracting port names from D-Link switches - feature parity
![](https://secure.gravatar.com/avatar/1280ab8004c08ad36f83942837b1423e.jpg?s=120&d=mm&r=g)
In observium we cannot, AFAIUI from the UI, overwrite the various switch port names. Observium relies on the port names getting set ‘right’ on the agent side.
However - having control over the name is useful e.g. for peering/ transit link regex()ing and what not.
Unfortunately not all switches allow for this (for some reason, it seems to be mostly enterprise POE switches). One vendor that does not allow this is D-Link; their ifNames are hardcoded to Slot/0, Port0.0 or the empty string on some (most recent?) product lines.
However they do allow the editing of the sysPortDescString in their private enterprise MIB (through config, API, SNMP or the web interface).
Below is a small file diff that makes this possible. It is a bit inefficient; as doing it at discovery time is not enough; ifName is watched by the port poller —and I cannot see an easy place to make a ‘note’ of the expensively found OID.
But may be of use as a starting point for some.
Dw.
beeb $ svn diff Index: observium/includes/polling/ports/companysystems.inc.php =================================================================== --- observium/includes/polling/ports/companysystems.inc.php (nonexistent) +++ observium/includes/polling/ports/companysystems.inc.php (working copy) @@ -0,0 +1,89 @@ +<?php + +/** + * companySystem - various D-Link switches have an extra sysPortDescString + * which unlike ifName/ifName can be configured (i.e. are not hardcoded + * to Slot0/0, the Emptry String or Port0.0). + * + * Here we discover them; and if set - add them to the ifName. + * + * Unfortunately - D-Link does use a different MIB for every product (even + * though the structure is pretty much identical). The path is contructed: + * + * enterprises.d-link.dlink-products.$series.$model.$type.companySystem.... + * + * with values such as dlink-DGS12XXSeriesProd.dgs-1210-28p.dgs-1210-28pcx + * for the series, model and type. + * + * Under companySystem we are after the field + * + * sysPortDescriptionTable.sysPortDescriptionEntry.sysPortDescString.<index> + * + * @package observium + * @subpackage discovery + * @copyright (C) 2013 dirkx + * + */ + +echo(" D-Link companySystem-MIB"); + +# We do a bit of a trick - and rely on the fact that the companySystem is first. # And use that to ‘tell’ us enough to get the MIB of that specific product. +# +# This way we discover the series/model/type without having to do a 35 Mbyte +# SNMP walk of the whole device. +# +# Unfortunately that does mean we have to use 'all'; which slows down +# polling (but we have to do it during polling; as any ifName set during +# discovery is uncerimouniously wacked on the next poll, with an alert +# to boot). The alternative would be to hardcode the 60-odd OID's for +# D-Link in this file. +# +# So we do this in two steps - one to check if there is any +# D-Link stuff - and then the actual more expensive pass. +# +$topoid = ".1.3.6.1.4.1.171"; +$str= snmp_get($device, $topoid,NULL,NULL,NULL,NULL, TRUE); // a getnext call + +if ($str) { + // pretty sure this is a D-Link switch of some description now. + // So do the more expensive pass. + // + + $topoid = '.iso.org.dod.internet.private.enterprises.d-link'; + $str= snmp_get($device, $topoid,NULL,'all',NULL,NULL, TRUE); // // a getnext call + + $cnt = 0; + if ($str) { + // Deconstruct the reply - to extract the actual per-product + // MIB name. + // + // DGS-1210-28P-CX::sysSwitchName.0 = STRING: 24x PoE Switch DLink + // + list($field, $skipEq, $skipStr, $name) = split(' ',$str,4); + list($mib, $skipField) = split('::', $field); + + $portOids = snmpwalk_cache_multi_oid($device, "sysPortDescString", array(), $mib); + + //Note that we are assuming that index = ifIndex (which seems to be the standard on D-Link kit). + // + foreach ($portOids as $ifIndex => $entry) + { + $descr = $entry[ sysPortDescString ]; + + if ($descr) { + $port = $port_stats[ $ifIndex ]; + $name = $port['ifName']; + + if (strlen($name)) { + $descr = "$descr ($name)"; + }; + $port_stats[$ifIndex]['ifName'] = $descr; + $cnt++; + }; + }; + }; + }; +if ($cnt) { + echo "[$cnt]"; +}; +
Property changes on: companysystems.inc.php ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property
participants (1)
-
Dirk-Willem van Gulik