Make a PHP site send SNMP information to a network management app
Asked Answered
F

3

8

I'm trying to make a PHP website send information through SNMP. I've been reading allot about SNMP, but I'm still a bit clueless about where to start.

I believe I need to create an MIB with all the OIDs my website will use to send the info. Is this correct? How and where can I define those variables (OIDs)? Can someone point me in the right direction?

I'm using FreeBSD on the server.

Thanks in advance.

Foresail answered 8/9, 2009 at 15:40 Comment(2)
Are you trying to have your PHP process listen for SNMP object-get requests, or are you trying to have it send out SNMP traps?Festinate
Actually I'm trying to set values and send traps. For instance I would like to take the execution time of the requested page and set it in a SNMP OID, and send the trap. Then the network manager app would get the trap and be aware that a page request was made and it took n seconds to load.Foresail
N
4

What you are trying to do is send an "SNMP trap". You don't need to define a MIB necessarily. A MIB just translates a "semi human friendly" name into an OID, such as SNMPv2-MIB::sysContact.0 into .1.3.6.1.2.1.1.4.0 . For a private application, you could theoretically use any OID you want, just as you could theoretically use any IP address you want for a private network that's not connected to others. I am not sure if there is a preferred "private" OID branch. There is some good info to get you started at http://www.paessler.com/support/kb/questions/49/ . It looks like PHP does not directly support sending SNMP traps though, but you could invoke the "snmptrap" command.

Norven answered 9/9, 2009 at 5:16 Comment(1)
Your answer gave me valuable info to get on the right path. Thanks.Foresail
H
1

There are a couple of issues:

  • To get your own top level identifier I think you actually have to request it somewhere (and probably pay money?) however there is an experimental range that you can use to test. (this is not a php issue, it is an snmp issue/feature)

  • As far as I know the protocol assumes a process to listen on a port that is totally different from the http port, and also not using TCP but UDP. Just creating a php page the usual way is not going to work.

A possible solution might be to use a snmp module in apache (or whatever webserver you are using) that allows you to program the response logic in php. My feeling is that most of the snmp php stuff that you encounter on the web is not about the agent part but about the manager part.

Holden answered 8/9, 2009 at 20:17 Comment(1)
Yes, I'm already using the snmp module on Apache. I just need to be able to write an OID value everytime a page is requested. But for this I believe I have to create "the structure" in MIB.Foresail
B
0

What i know is that SNMP is a protocol where an host send request for value of a particular OID to a device and then receive a response.

I'm not sure you can have a php website that answer to this packets.

The only information I have found is that PHP have an SNMP client class PHP SNMP

And wikipedia gives you detailed info about SNMP link text

But I'm still sure that a website can't act as an SNMP server.

Bennett answered 8/9, 2009 at 19:32 Comment(2)
PHP has socket functions, so it can be used to listen for SNMP requests by creating a UDP socket with socket_create.Festinate
I know that PHP has socket functions ... but a "website" as asked in the question cannot create a wait loop to receive UDP packet.. If the question was about a php program that runs in a box .. ok!Bennett

© 2022 - 2024 — McMap. All rights reserved.