NYCPHP Meetup

NYPHP.org

[nycphp-talk] [ot] Web tree command available?

John Lacey jlacey at att.net
Sun Jul 4 13:26:46 EDT 2004


Jon Baer wrote:

>> Yep ... I have a few sensors laying around which speak SNMP (v1) and 
>> I have the MIB so I was thinking of a web interface for it, but it 
>> seems like a generic idea would be nice to have.
>>

Here's the short version:

The tests were run on a win2k pro box with sp2.   The SNMP service must 
be installed and running.  You don't need the SNMP Trap service running 
for the tests, but I started it anyway, since I might mess with that later.

To set up a quickie test environment, I used XAMPP  
http://www.apachefriends.org/en/xampp-windows.html
If you scroll down, you'll find the php5xampp-dev package.  Naturally, I 
went into the php.ini file and uncommented the snmp extension.  With the 
windows version, phpinfo() shows UCD-SNMP (ver. 4.2.3)  --  *nix will 
use net-snmp, as you know.

- snmp_read_mib() is still causing a fatal error (no such function...) 
when debugging with Zend Studio ver. 3.5, so I moved on...  After 
testing a few things, I believe the purpose of this function is to read 
in custom MIB descriptions on the fly (else, you must restart apache) so 
you can use names instead of numbers.  If you're using just standard 
MIBs, like RMON for the sensors, you won't need to call 
snmp_read_mib().  You mention SNMPv1 sensors, but the RMON MIB is 
SNMPv2.  Are they custom sensors, and not RMON probes?

This is important if you want to use names instead of numbers in the PHP 
code:  (the numbers cause brain damage)
- on my c: drive, I created a c:\usr\mibs directory.
- copy all the contents of the "extras/mibs" directory  -- there are 
over 50 [.txt] files; some are not MIBs, bit it's easier to copy them all
- after doing this, you must restart Apache which apparently causes the 
MIB descriptions to be loaded into the active MIB tree
- this will allow the syntax:  $sysdesc = snmpget('localhost', 'public', 
'system.sysDescr.0');
- instead of having to use:   $sysdesc = snmpget('localhost', 'public', 
'.1.3.6.1.2.1.1.1.0');
- note: 'system.sysDescr.0' and all the other names are case-sensitive
- if you want to see names/numbers for the "system" stuff, just display 
SNMPv2-MIB.txt


The following is a test script I hacked on to get things running -- 
lotsa trial and error.  The SNMP community name "public" should work 
fine here.  On a real network, if you don't change your community names 
to non-default values, well, shame on you.

<?php
// filename mibtest.php

// I made this call to verify snmp_mib_read() worked, and didn't use it 
again
// snmp_read_mib('c:\php5xampp-dev\htdocs\mib\mycustom-MIB.txt') or 
die('bad mib read');

// the following two calls should yield the same results
// note the period at the beginning of the ObjectID for the numbered 
system description -- very important
$sysdesc = snmpget('localhost', 'public', '.1.3.6.1.2.1.1.1.0');
echo $sysdesc;
echo '<br /><br />';
$sysdesc = snmpget('localhost', 'public', 'system.sysDescr.0');
echo $sysdesc;


echo '<br /><br />';
// snmpwalk didn't work here
// NULL says to return ALL object ids beginning at the root
$arr = snmprealwalk('localhost', 'public', NULL);
echo $arr['system.sysName.0'];

// snmpwalk didn't work here
// uncomment these and you'll see a crapload of stuff
//$arr = snmpwalkoid('localhost', 'public', NULL);
// print_r($arr);

echo '<br /><br />';
$sysname = snmpget('localhost', 'public', 'system.sysName.0');
echo $sysname;

// this would return UDP (group 7) info  -- udpInErrors
//$udperrs = snmpget('localhost', 'public', '.1.3.6.1.2.1.7.3.0');
// or...
// $udperrs = snmpget('localhost', 'public', 'udp.udpInErrors.0');

?>


I think the above will get you in the ballpark to start psyching things 
out.  If you need any additional input, we may have to take it off-list, 
cause it can be a lil ugly.

John
p.s. I did a little "email editing" on the script, so be careful... my bad




More information about the talk mailing list