LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Extend SNMP Agent to launch command with variable parameters (http://www.linuxquestions.org/questions/linux-server-73/extend-snmp-agent-to-launch-command-with-variable-parameters-4175436156/)

jdani 11-07-2012 04:41 PM

Extend SNMP Agent to launch command with variable parameters
 
Hi,

I'm trying to launch a command with variables arguments through SNMP, I think extending the SNMP Agent is best option, but I'm not quite sure...

The situation is this: I have to look for the AP a host (using as search criteria its mac) is connected, and every AP are in the same network. I think I could send an SNMP request to broadcast and wait for the AP with the host associated response... but I need to send the host mac in the SNMP request and use it in the command as argument. Is this possible??

Habitual 11-08-2012 07:07 AM

http://net-snmp.sourceforge.net/tuto...kit/index.html

jdani 11-16-2012 04:33 AM

Solved! I used SNMP Traps like this:
In the (Debian) server:

/etc/default/snmpd
Code:

# This file controls the activity of snmpd and snmptrapd

# Don't load any MIBs by default.
# You might comment this lines once you have the MIBs downloaded.
export MIBS=/usr/share/mibs

# snmpd control (yes means start daemon).
SNMPDRUN=no

# snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-x -Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'

# snmptrapd control (yes means start daemon).  As of net-snmp version
# 5.0, master agentx support must be enabled in snmpd before snmptrapd
# can be run.  See snmpd.conf(5) for how to do this.
TRAPDRUN=yes

# snmptrapd options (use syslog).
TRAPDOPTS='-On -Lsd -p /var/run/snmptrapd.pid'

# create symlink on Debian legacy location to official RFC path
SNMPDCOMPAT=yes


/etc/snmp/snmptrapd.conf
Code:

authCommunity execute public

traphandle .1.3.6.1.4.1.2021.991.17 /root/FindMac.sh


/root/FindMac.sh
Code:

#!/bin/bash

read host
read info
read OID
read otherInfo
read mac

echo $mac > /root/log.txt

The MAC will be stored at "/root/log.txt", now you only have to write the script to do what ever you need...


In the client:
Code:

snmptrap -v 2c -c public [SERVER_IP_OR_HOSTNAME] '' NOTIFICATION-TEST-MIB::demo-notif SNMPv2-MIB::sysLocation.0 s "aa:bb:cc:dd:ee:ff"
After launching this, the file "/root/log.txt" in the server will contain "aa:bb:cc:dd:ee:ff".

Notes:
1. The OID and MIB I used in this example aren't the correct ones, but it's working for my testing purposes.
2. The security in this example is TOO POOR.
I have to change this to port it to production environment.


All times are GMT -5. The time now is 07:41 AM.