<< Prev  |  TOC  |  Front Page  |  Talkback  |  FAQ  |  Next >>
LINUX GAZETTE
...making Linux just a little more fun!
A quick and Dirty guide to extending snmp
By David Dorgan

A quick and Dirty guide to extending snmp

Monitoring and Graphing Applications with SNMP and MRTG.

There are two basic sections in this article, first will be checking
services or processes via net-snmp.

First off download net-snmp from net-snmp.org, a simple
./configure ; make ; make install should do the trick in most cases.
After this you should run sudo snmpconf, to create your snmpd.conf
file, which will contain your community names, location etc...
Then with the basic configuration you could start the snmpd with
sudo snmpd, or sudo snmpd -r which enables net-snmp to drop most
privileges just after startup.

In this default setting, with a default configuration,
you could do something like snmpwalk -v 1 -c public localhost , to see
some of the built-in settings. Now to get to the interesting section,
let’s say you want to monitor an application you just wrote...
let’s say you want to check if port 25 is up, via snmp....
You could write a simple python application[0], which returns 0
for a success, or 1 for a failure...

(In real life you would probably just do this from a remote host, but this
is just a simple example which can be expanded to your application).

Now to monitor this event, in your /etc/snmpd.conf add a line like...
exec 1.3.6.1.4.1.5000.100 check-smtp /software/snmp/check-smtp.py

A oversimplified explanation of the number would be,
1.3.6.1.4.1 means enterprise, 5000 would be your organisations MIB
number, and 100 would be the specific OID. For more information on getting
an organisation private enterprise number, you should see
http://www.iana.org/cgi-bin/enterprise.pl

Now if you type snmpwalk -v 1 -c public localhost 1.3.6.1.4.1.5000.100
you will see not just the reply, but all objects within the OID.
If you wanted to be specific (which you may need to do for snmp managers
or mrtg...you would have something like snmpwalk -v 1 -c public localhost 1.3.6.1.4.1.5000.100.101.1

Or graph something (anything) on a remote machine with snmp and mrtg?

Now let’s say, you wanted a simple mrtg graph, which only checked for the amount
of threads in a mysql database, which while useful, is once again a pretty
simple example, let’s say you didn’t mind spawning a shell and executing a command,
you might do something like mysqladmin status | awk {’print $4’} ...
which is fairly system unfriendly, but there isn’t much point presenting a robust
c application in this case. Now in /etc/snmpd.conf add

exec 1.3.6.1.4.1.5000.101 mysql-thread-load /software/snmp/mysql-thread-load.sh


inside the file have
#!/bin/sh
mysqladmin status | awk {’print $4’}

and make sure it’s executable by the calling process.

Here is a sample partial mrtg config[1].

The reason in Target that you have specified the number twice, breaking it up with an & sign,
is that mrtg generally expects two inputs, one for incoming and one for outgoing, this way
it just uses the same reply for both. Of course you could monitor something like mysql threads,
and load average, and they could be graphed in the same picture, which can be interesting
for correlation between application and system load.



[0]:
import socket
import time

HOST = ’localhost’
PORT = 25

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((HOST, PORT))
print ’0’
except socket.error:
print ’1’;


[1]:
Target[mysqlconnections]: 1.3.6.1.4.1.5000.101.101.1&1.3.6.1.4.1.5000.101.101.1:public@hostname
options[mysqlconnections]: nobanner,absolute,gauge,growright,nopercent
Title[mysqlconnections]:Mysql Threads
PageTop[mysqlconnections]: <h1>Mysql Threads</h1>
MaxBytes[mysqlconnections]: 1000
YLegend[mysqlconnections]: connections
ShortLegend[mysqlconnections]: connections
LegendI[mysqlconnections]: connections:
LegendO[mysqlconnections]:
Legend1[mysqlconnections]: connections
Legend2[mysqlconnections]:
Step[mysqlconnections]: 12


$Id: dirty-snmp.html,v 1.4 2003/08/30 15:00:35 davidd Exp $

 

[BIO] David has been a very productive writer and plans to contribute more of his work in the future.


Copyright © 2003, David Dorgan. Copying license http://www.linuxgazette.com/copying.html
Published in Issue 96 of Linux Gazette, November 2003

<< Prev  |  TOC  |  Front Page  |  Talkback  |  FAQ  |  Next >>