snmp-wan-router

If you’re using SNMP-traps on the switching equipment, you just need to have trap handler.
7CQU9K56EYRE
SNMP trap handler is a some program to receive trap-information from switches and do some action depending on what it received.

To set up snmptrapd it does not cause much difficulty – so now we have this moment not be discussed.

Actually in traps reception involved snmptrapd. For the processing of a given trap write in snmptrapd.conf:

traphandle 1.3.6.1.4.1.171.11.63.6.2.20.0.2 /scripts/trap.php

Now, after restarting the daemon snmptrapd, it will accept incoming traps (from switches) and in the presence of the trap with a specified MIB (1.3.6.1.4.1.171.11.63.6.2.20.0.2 – in our case), will call our handler, which would already be making the necessary actions.

PHP SNMP trap handler

SNMP traps receiving is actually quite simple. Here’s a sample SNMP traps’ handler on PHP:

  1. #!/usr/bin/php -q
  2. <?php
  3. $message = "";
  4. $fd = fopen("php://stdin", "r");
  5. while (!feof($fd)) $message .= fread($fd, 1024);
  6. ?>

What makes this script – gets into the variable $message text that is passed by snmptrapd daemon. The text comes divided marks the end of the line. The first line – it is always the host name (who send the trap), the second – IP-address of the host, the third – its uptime, the fourth – trap MIB. The other lines in the message – this is detailed information about arriving trap, if it is provided.

P.S. just for technorati.com: Technorati Profile





Опубликовать в twitter.com