SNMP PHP

SNMP, the Simple Network Management Protocol, is a protocol for Internet network management. It was first described in RFC 1089. One place to start learning about SNMP is SNMP Research. To use these functions under UNIX, you must have the UCD SNMP libraries. You can find them. Documentation at this site is more specific to the library PHP uses. I've attempted to follow their examples by translating them into equivalent PHP code.

At the time of this writing, no SNMP extension for Windows was available for PHP4. Presumably, the name would be php_snmp.dll. PHP3's library was called php3_snmp.dll. It did not use the UCD SNMP libraries and was available under Windows NT only. You can activate an extension with the dl function or with the extension directive in php.ini.

Mike Jackson, Rasmus Lerdorf, and Steven Lawrance have contributed to the SNMP extension.

boolean snmp_get_quick_print()
The snmp_get_quick_print function returns the status of the UCD SNMP library's quick_print setting. Consequently, this function is unavailable o Windows users. The quick_print setting controls how verbose object values are. By default, quick_print is FALSE, and values include types and other information. The UCD SNMP manual provides more information.

snmp_set_quick_print(boolean on)
The snmp_set_quick_print function sets the value of the UCD SNMP library's quick_print setting. Consequently, this function is unavailable to Windows users. See the description of snmp_get_quick_print for a brief description of the quick_print setting.

string snmpget(string host, string community, string object, integer timeout, integer retries)
The snmpget function returns the value of the specified object. The host may be numerical or named. You must also specify the community and the object. Optionally, you may supply a timeout in seconds and a number of times to retry a connection.

<?
//find out how long the system has been up
//should return something like
//Timeticks: (586731977) 67 days, 21:48:39.77
if($snmp = snmpget("ucd-snmp.ucdavis.edu",
"demopublic", "system.sysUpTime.0"))
{
print($snmp);
}
else
{
print("snmpget failed!");
}
?>

boolean snmpset(string host, string community, string object, string type, string value, integer timeout, integer retries)
The snmpset function sets the value of the specified object. The host may be numerical or named. You must also specify the community and the object. The type argument is a one-character string. Optionally, you may supply a timeout in seconds and a number of times to retry a connection.

<?
//show current value of the demo string
$snmp = snmpget("ucd-snmp.ucdavis.edu",
"demopublic", "ucdDemoPublicString.0");
print("$snmp (original value) <BR> ");
//set it to something else
snmpset("ucd-snmp.ucdavis.edu",
"demopublic", "ucdDemoPublicString.0",
"s", "Core PHP Programming");
//see current value of the demo string
$snmp = snmpget("ucd-snmp.ucdavis.edu",
"demopublic", "ucdDemoPublicString.0");
print("$snmp (new value)<BR> ");
?>

snmprealwalk
This function is an alias to snmpwalk.

array snmpwalk(string host, string community, string object, integer timeout, integer retries)
The snmpwalk function returns an array of all objects in the tree that starts at the specified object. You can use an empty string for the object parameter to get all objects. Optionally, you may supply a timeout in seconds and a number of times to retry a connection.

SNMP-Types

<?
//get all the SNMP objects
$snmp = snmpwalk("ucd-snmp.ucdavis.edu",
"demopublic", "");
reset($snmp);
while(list($key, $value) = each($snmp))
{
print($value . "<BR> ");
}
?>

array snmpwalkoid(string host, string community, string object, integer timeout, integer retries)
The snmpwalkoid function is an alias to snmpwalk.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics