Here is a example using snmprealwalk() to make a simple dump to a textfile. The script filters out some things that atleast I don't need.
To get more verbose output comment out "$walk = snmp_nice_array($walk);" and/or change "snmp_set_quick_print(1);" to "snmp_set_quick_print(0);". Example with most information. Array ( [system.sysORTable.sysOREntry.sysORID.1] => system.sysORTable.sysOREntry.sysORID.1 = OID: ifMIB [system.sysORTable.sysOREntry.sysORID.2] => system.sysORTable.sysOREntry.sysORID.2 = OID: .iso.org.dod.internet.snmpV2.snmpModules.snmpMIB [system.sysORTable.sysOREntry.sysORID.3] => system.sysORTable.sysOREntry.sysORID.3 = OID: tcpMIB [system.sysORTable.sysOREntry.sysORID.4] => system.sysORTable.sysOREntry.sysORID.4 = OID: ip ) ( ) // Kdr (oo) /------\/ / | || * ||---|| ~~ ~~ ------------------------------------------------------------------------ ---- <?php $file = "dump.txt"; // file to save all things to. $host = "127.0.0.1"; // SNMP host. $community = "public"; // SNMP community name. $object = ""; // SNMP Object, empty to get all. $fp = fopen($file,"w+"); // Open file. /* Function that removes objectname in value from a snmprealwalk result */ function snmp_nice_array ($array) { foreach($array as $key => $value) { $value = preg_replace("/^$key /","",$value); $array[$key] = $value; } return $array; } snmp_set_quick_print(1); // Less information. $walk = snmprealwalk($host,$community,$object); // Fetch the data. /* Example of what $walk might contain now. Array ( [system.sysORTable.sysOREntry.sysORID.1] => system.sysORTable.sysOREntry.sysORID.1 ifMIB [system.sysORTable.sysOREntry.sysORID.2] => system.sysORTable.sysOREntry.sysORID.2 .iso.org.dod.internet.snmpV2.snmpModules.snmpMIB [system.sysORTable.sysOREntry.sysORID.3] => system.sysORTable.sysOREntry.sysORID.3 tcpMIB [system.sysORTable.sysOREntry.sysORID.4] => system.sysORTable.sysOREntry.sysORID.4 ip ) */ $walk = snmp_nice_array($walk); // Run the result thru snmp_nice_array(). /* Example of what $walk might contain after snmp_nice_array(). Array ( [system.sysORTable.sysOREntry.sysORID.1] => ifMIB [system.sysORTable.sysOREntry.sysORID.2] => .iso.org.dod.internet.snmpV2.snmpModules.snmpMIB [system.sysORTable.sysOREntry.sysORID.3] => tcpMIB [system.sysORTable.sysOREntry.sysORID.4] => ip ) */ foreach($walk as $key => $value) fputs($fp,"$key = $value\n"); // Write data to file. /* Example of what the file might contain. system.sysORTable.sysOREntry.sysORID.1 = ifMIB system.sysORTable.sysOREntry.sysORID.2 = .iso.org.dod.internet.snmpV2.snmpModules.snmpMIB system.sysORTable.sysOREntry.sysORID.3 = tcpMIB system.sysORTable.sysOREntry.sysORID.4 = ip */ fclose($fp); // Close file. ?> ------------------------------------------------------------------------ ---- > Hi > > I would like to collect data from snmpget and log it. > Anyone have a idea how to do this? > > // maas, Sweden -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php