V-TEK Weblog about webdevelopment and linux

24Oct/080

Extending SNMP using shell scripts

Note: If you are unfamiliair with SNMP please read the "SNMP explained" post first!

Like I promised in my previous post "SNMP explained" , the next post about SNMP is about extending SNMP.
To extend SNMP, you'll have to extend the SNMP daemon on the agent called "snmpd", this can be done by editing the config file ofthe SNMP daemon snmpd.conf which ( on most distros ) can be found in /etc/snmp or /etc/snmpd .

In this file you can setup the shell command that needs to be executed, and which output should be used for the SNMP agent.

So let's start by making a silly shell script at /tmp/foo.sh

#!/bin/sh
#
# foo.sh

echo "123"
So, our script is called foo.sh and is located in the tmp folder.

Now we'll edit the snmpd.conf to let it be executed. Look up the part about extending with the "exec" rules and insert the following line into it:

extfix foo /bin/sh /tmp/foo.sh

After you restart your snmp daemon you can use snmpwalk to get the results using snmpwalk

$ snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.8.1
UCD-SNMP-MIB::extIndex.1 = INTEGER: 1
UCD-SNMP-MIB::extNames.1 = STRING: foo
UCD-SNMP-MIB::extCommand.1 = STRING: /bin/sh /tmp/foo.sh -arg1
UCD-SNMP-MIB::extResult.1 = INTEGER: 0
UCD-SNMP-MIB::extOutput.1 = STRING: 123
UCD-SNMP-MIB::extErrFix.1 = INTEGER: 0
UCD-SNMP-MIB::extErrFixCmd.1 = STRING:

That's it .. there are new variables into the SNMP agent, all you have to do is to update your manager to get this specific data from the agent.

Tagged as: , No Comments
21Oct/080

SNMP explained

Due to a project I'm working on for XXL Webhosting, I decided to write a little explanation of SNMP ( Simple Network Management Protocol ).

In this post you can read the basics of SNMP and the usage of it. After this post I will write a post about implementing your own variables into SNMP so that you can extend the default variables of SNMP.

   

Recent Comments

Tags

Apache cakephp cpanel dav dd-wrt DNS Ext3 Framework GIT GNU grub javascript Kernel lilo Linux LPI LVM MVC MySQL Netbeans Netfilter PHP piping ps3 redirection regex Ruby on Rails Samba Sendmail Shell Skype SNMP Squid Symfony ubuntu upnp vim windows X Xorg X Window System