[PATCH] SNMP value retrieval
| From: | Johann Hanne | Date: | Tue, 14 Jan 2003 19:11:49 +0000 |
| Subject: | [PATCH] SNMP value retrieval | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-12433@lists.php.net to get a copy of this message | ||
Hi,
as promised I've created a patch which adds some functionality to the
SNMP module. It's controlled with a new function named
snmp_set_valuemethod(int method) which changes the way how SNMP values
are returned by snmpget(), snmpwalk() and snmpwalkoid(). The following
(new) constants can be passed to snmp_set_valuemethod():
- SNMP_VALUEMETHOD_LIBRARY:
Values will be retrieved with snprint_value() from the net-snmp
library, so they will be hard to parse as it may add quotes to
strings, pre-parse timeticks, etc. (old/default behaviour)
- SNMP_VALUEMETHOD_PLAIN:
Value will be processed internally depending on the value type;
no pre-parsing will occur and the values will be returned as
they are sent by the SNMP agent. Note however, that all values
(even numbers) will be strings, as most numbers will exceed
the PHP 32-bit signed limit!
- SNMP_VALUEMETHOD_OBJECT:
Values will be returned as objects with two properties named
"value" and "type"; "value" will contain the value as returned
with SNMP_VALUEMETHOD_PLAIN and "type" will contain the type
as returned by the net-snmp library, which will enable you to
do things depending on the value type returned by the SNMP
agent (the ASN_* constants from the net-snmp library are also
defined as PHP constants)
All this is achieved via a new internal C function named
php_snmp_getvalue(). The default behaviour is 100% compatible with the old
one. I've tried hard to change as less as possible in the existing source
code. However I had to introduce a global variable named
snmp_globals->valuemethod (via TSRM of course).
A new function named snmp_get_valuemethod() has also been created. It
simply returns the current method.
The patch makes it much easier to parse the returned SNMP values, as they
are no longer pre-parsed by the net-snmp library after you have set
SNMP_VALUEMETHOD_PLAIN. I've attached a simple PHP script which should
make the new functionality even clearer.
Cheers, Jonny <jonny@1409.org>