Working examples for all retrieval functions done:
* snmp3_get
- returns single value as string
* snmp3_getnext
- returns single value as string or null if no more values
* snmp3_walk
- returns array of values
* snmp3_real_walk
- returns associative array of OID/value pairs
Argument list for all above functions:
Code:
retval snmp3_NNNNN(string host,
string sec_name,
string sec_level,
string auth_protocol,
string auth_passphrase,
string priv_protocol,
string priv_passphrase,
string object_id
[, int timeout
[, int retries]]
)
Where:
* Host can be just hostname/IP or hostname/IP:port
- e.g. 192.168.1.2;165
* sec_level is one of 'noAuthNoPriv', 'authNoPriv', or 'authPriv'
- If noAuthNoPriv, don't need auth_protocol or auth_passphrase
or priv_protocol or priv_passphrase
- if authNoPriv, don't need priv_protocol or priv_passphrase
- if authPriv, need all four
* Passphrases are the ASCII passphrases, the routines will *not* accept hex encoded phrases
* auth_protocol is one of 'MD5' (default) or 'SHA'
* priv_protocol is one of 'DES' (default) , 'AES128', 'AES192', 'AES256'
- I know from my own experience Net-SNMP agents as of 5.1.2 only work with DES
Working code (passphrases etc not the real ones in use):
Code:
#!/usr/local/bin/php
<?
$auth_key = 'My user key';
$priv_key = 'PDU encrypt key';
$user = 'myusername';
# Host with optional :port
$host = '192.168.1.2:164';
# Want both user authentication and PDU encryption
$level = 'authPriv';
# For passphrase encryption
$auth_protocol = 'MD5';
# PDU encryption
$priv_protocol = 'DES';
# Number of users on system
$oid1 = '.1.3.6.1.2.1.25.1.5.0';
# Disk use and memory use - for walk
$oid2 = '.1.3.6.1.2.1.25.2.3.1';
# Single value
$get = snmp3_get($host,
$user,
$level,
$auth_protocol,
$auth_key,
$priv_protocol,
$priv_key,
$oid1);
print $get;
# Walk, return values in array
$walk = array();
$walk = snmp3_walk($host,
$user,
$level,
$auth_protocol,
$auth_key,
$priv_protocol,
$priv_key,
$oid2);
foreach ($walk as $value) {
print "$value\n";
}
# Walk, get OID/value pairs back
$real_walk = array();
$real_walk = snmp3_real_walk($host,
$user,
$level,
$auth_protocol,
$auth_key,
$priv_protocol,
$priv_key,
$oid2);
foreach ($real_walk as $oid => $value) {
print "$oid: $value\n";
}
?>
Let me know if you would like more information than what I have provided