0

I need to extract a single bit from an SNMP trap, which reports the state of eight digital sensors. The OIDs of the sensors are:

".1.3.6.1.4.1.42505.1.2.1.1.7.x"

where x can be 0 to 7.

The hex dump of the UDP packets that contain the traps is as follows:

30 3E 02 01 00 04 03 69 70 73 A4 34 06 09 2B 06 01 04 01 82 CC 09 01 40 04 0A 0A 0B 66 02 01 06 02 01 01 43 04 00 01 27 63 30 15 30 13 06 0E 2B 06 01 04 01 82 CC 09 01 02 01 01 07 01 02 01 00 

Might somebody point me in the direction of how to parse these packets? I do not need a fully fledged trap parsing package, as that would be overkill. All I need is to parse the packets with PHP in order to extract the single relevant bit.

1 Answer 1

1

It seems you are asking for RFC 1157

But installing php-snmp would probably be easier.

5
  • thank you for your immediate answer. I have successfully used snmpget to pull the values from the device. Where I am however lost, is how to use the "pushed" traps and parse them into meaningful data. Which of the methods provided by php-snmp are appropriate for that?
    – aag
    Aug 14, 2018 at 19:45
  • 1
    If you use snmpget, you already get the values parsed. The snmpget function should give you a string value from the smnp data.
    – RalfFriedl
    Aug 14, 2018 at 20:10
  • I apologize for being so illiterate of coding (I am a medical doctor in real life, php is just a hobby). My understanding is that the php snmp function takes three obligatory and two facultative arguments (string $hostname , string $community , string $object_id [, int $timeout = 1000000 [, int $retries = 5]]). However my trap delivers a listener $snmp_trap variable, which I need to process. How can I pass a $snmp_trap variable to snmpget for processing? Note that I am not polling a snmp server, the variable is already available.
    – aag
    Aug 15, 2018 at 8:59
  • The php function, similar to the snmpget command, sends a request and display the answer contained in the reply. Both don't accept a raw packet as input. If you just need to watch one bit, just dump three packets containing both states and look for differences. There will be differences between the packets containing the same states. These don't matter to you. There will be an additional difference between packets with different state. The RFC should help with the interpretation.
    – RalfFriedl
    Aug 15, 2018 at 9:07
  • Thanks. It's kind of a hack, and maybe not the most elegant solution - but preliminary results suggest that it is going to work!
    – aag
    Aug 16, 2018 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .