-
Notifications
You must be signed in to change notification settings - Fork 58
SNMP Class
This page describes the SNMP class and its various functions. See also the phpDoc documentation.
It should be read in conjunction with the example, Using MIBS and Caching.
In general, these methods all front snmp2_get()
and ``snmp2_real_walk()` of the PHP SNMP extension and then parse their output (or the equivalent v1 and v3 functions).
-
get()
- get a scalar value for a given OID; -
walk1d()
- get a list of values by walking a given OID. This should be a penultimate OID such that the resulting values all of the same kind (such as interface types). The associatative array returned is indexed with the last OID index.
For example, a snmpwalk()
on .1.3.6.1.2.1.2.2.1.7
which is interface administrative states may yield:
.1.3.6.1.2.1.2.2.1.7.1 = INTEGER: 1
.1.3.6.1.2.1.2.2.1.7.2 = INTEGER: 1
.1.3.6.1.2.1.2.2.1.7.3 = INTEGER: 1
.1.3.6.1.2.1.2.2.1.7.7 = INTEGER: 2
.1.3.6.1.2.1.2.2.1.7.1661 = INTEGER: 2
.1.3.6.1.2.1.2.2.1.7.4337 = INTEGER: 1
For which walk1d()
would return an array:
[1] => 1
[2] => 1
[3] => 1
[7] => 2
[1661] => 2
[4337] => 1
-
subOidWalk()
is similar towalk1d
but the array is indexed by a given OID index position rather than the last position.
For example, walking CDP capability OIDs may yield:
.1.3.6.1.4.1.9.9.23.1.2.1.1.9.10101.5 = Hex-STRING: 00 00 00 01
.1.3.6.1.4.1.9.9.23.1.2.1.1.9.10105.2 = Hex-STRING: 00 00 00 01
.1.3.6.1.4.1.9.9.23.1.2.1.1.9.10108.4 = Hex-STRING: 00 00 00 01
and we are interested in the penultimate index (which is the interface ID) rather than the last index. As such, subOidWalk( $oid, 15 )
returns:
[10101] => ...
[10105] => ...
[10108] => ...
Typically SNMP returns strings which need to be parsed. parseSnmpValue()
takes care of this and throws an exception if it comes up against a type it does not recognise.
Translating return values can be done via translate()
and you'll find an example for this in Writing MIBs.