SNMP with Nagios

Associate
Joined
3 May 2009
Posts
805
Hi All,

Bit of a linux newbie here but im looking into Nagios for monitoring our servers/printers/switches etc. We currently use an incredibly old version of whatsup Gold but were looking for something else.

Ive got nagios up and running and using nconf to generate host files etc.

I'm now trying to setup SNMP monitoring for our watchguard firewall, basic stuff such as CPU.

However I have no idea how to add custom SNMP queries. Can't seem to find much info from High tech support (google).

Anybody use nagios and could advise on custom SNMP queries? Want to expand into printer toner levels, switches etc. Ive got it querying servers disk space using WMI which appears to be working well.
 
Check out Opsview Core, can do SNMP polling and an SNMP walk via the GUI with that, then create service checks etc from the SNMP output (all from the GUI). All based on Nagios too.
 
The first thing you will need to do is enable SNMP on the devices you wish to monitor, set a community string (I reccomend disabling/removing the READ/WRITE string, and creating a READ ONLY string that is NOT set to 'public')

Out of the box Nagios and SNMP can be a little tricky. To get the most of it, you need to know SNMP quite well and be familar with tools like snmpwalk.

On your linux box, install the net-snmp package if you have not already. You can then query all the stuff you wish to monitor by doing a 'walk' of a host.

An example command would be : snmpwalk -v2c -c public <ip>

Where - v2c is SNMP version 2c and -c is your community string

This can be rather daunting if you are not familar with it.

One thing you may wish to consider is check_mk - it's a plugin for nagios (though it is very extensive!) which allows you to add SNMP checks via a web interface - it will then query devices for 'interesting' values.

The printer check is a good example. IT will tell you toner use, drum, how many sheets it's printed, notfiy of jams etc - and you won't need to do any additional config.

More info on check_mk - http://mathias-kettner.de/check_mk.html

If you want to learn more from the pure nagios perspective, then start with the check_snmp plugin
 
Check out Opsview Core, can do SNMP polling and an SNMP walk via the GUI with that, then create service checks etc from the SNMP output (all from the GUI). All based on Nagios too.

Thanks for that, installed and giving it a go, so far so good. Bit slow but i guess that because im running it on a VM on my laptop atm. its IT manager friendly for my boss anyway....
 
I tend to use wrapper scripts for snmp monitoring with nagios.

If i have anew device, I'll set up a public read only access as stated above, then do a 'walk' over the device and output to a file 'smnpwalk -v2c -c public 192.168.0.1 > router.snmp.log'

I'll then use the log file created to pin down which oid's i need to use to get the data I'm after.

I'll then write a script and place it in /usr/lcoal/nagios/libexec (mark as exe) which I'll call from nagios when I want to check that device. The script will run the snmp query and configure the output to a human readable format, then exit using the correct exit codes so nagios sees the green, yellow, red states.

simple example;

Check to see if netgear Ready NAS 2100 disks are online

My wrapper script
#!/bin/bash

# bedug out to .debug file
exec 2> /tmp/$(basename $0).debug
set -x

# Run check_snmp with param
check=$(/usr/local/nagios/libexec/check_snmp -H $1 -o $2 -C nas-drive -P 2c)

# return result if CRITICAL
if [[ $check == *dead* ]]
then
echo "Disk OFFLINE - CRITICAL";
exit 2
fi

# return result if OK
if [[ $check == *ok* ]]
then
echo "Disk Online - OK";
exit 0
fi

# end script

commands.cfg entry..
define command{
command_name check_readynas_disk1
command_line $USER1$/check_nas_disk $HOSTADDRESS$ READYNAS-MIB::diskState.1
}

host & Service entry...
define host{
use linux-server
host_name MY-NAS-02
alias Systems NAS 2
address xxx.xxx.xxx.xxx
host_groups readynas-systems
max_check_attempts 10
contact_groups systems
}

define service{
use generic-service
hostgroup_name readynas-systems
service_description Disk 1 Status
check_command check_readynas_disk1
}

Hope that helps.

Nagios is HUGE and can do pretty much anything you can think of. Google has more information but free fell to ask if you get stuck.
 
As above, or check the Nagios Exchange - tons of good help and plugins there also.

I actually work for a monitoring company based on Nagios, so any help etc.
 
As above, or check the Nagios Exchange - tons of good help and plugins there also.

I actually work for a monitoring company based on Nagios, so any help etc.

Opsview by any chance?? They're in reading aren't they? :p

Blastman.... I also write scripts like you do. There are definite pros and cons. Sometimes I will just add commands to cfg files in Nagios to call check_snmp directly, where other times I'll create scripts and then just pass parameters In the command definition.

I find that the compiled check_snmp plugin performs much better than my interpreted perl scripts...but get mildly irritated with the rather bland "snmp ok" output.

But this "more ways to skin a cat" approach is one of the great things about nagios and I've lost many hours tinkering with it!!
 
Opsview by any chance?? They're in reading aren't they? :p

Blastman.... I also write scripts like you do. There are definite pros and cons. Sometimes I will just add commands to cfg files in Nagios to call check_snmp directly, where other times I'll create scripts and then just pass parameters In the command definition.

I find that the compiled check_snmp plugin performs much better than my interpreted perl scripts...but get mildly irritated with the rather bland "snmp ok" output.

But this "more ways to skin a cat" approach is one of the great things about nagios and I've lost many hours tinkering with it!!


I can relate to that. I too have 'wasted' many hours messing with nagios.

top tip, setup a cron job to run each night to tar & gzip all your config files to a different location.

Can't tell you how many times I've screwed it up and had to rebuilding or recover from backup files.
 
been using opsview the past few days, really getting to grips with it. Lots of the service checks are built in, i've written a few checks to check if files exists etc, really enjoying using it.

Trying to monitor disk temps on a ready nas duo (the smaller home boxes) but not having much luck with the custom READYNAS-MIB getting errors like this:

conf@opsview-appliance:/usr/local/nagios/libexec$ ./check_snmp -H nas-backup1 -o READYNAS-MIB::volumeStatus.1 -C public -P 2c
SNMP OK - = No Such Object available on this agent at this OID |

im using the vmware appliance. Ive got webmin installed on the box so will look at some cron jobs, any ideas on the most important locations for config files? so many places not sure where to backup.

i put the READYNAS-MIB.TXT into /usr/share/snmp/mibs/ with the others.
 
Last edited:
been using opsview the past few days, really getting to grips with it. Lots of the service checks are built in, i've written a few checks to check if files exists etc, really enjoying using it.

Trying to monitor disk temps on a ready nas duo (the smaller home boxes) but not having much luck with the custom READYNAS-MIB getting errors like this:

conf@opsview-appliance:/usr/local/nagios/libexec$ ./check_snmp -H nas-backup1 -o READYNAS-MIB::volumeStatus.1 -C public -P 2c
SNMP OK - = No Such Object available on this agent at this OID |

im using the vmware appliance. Ive got webmin installed on the box so will look at some cron jobs, any ideas on the most important locations for config files? so many places not sure where to backup.

i put the READYNAS-MIB.TXT into /usr/share/snmp/mibs/ with the others.

For the temp OID - try doing an snmpwalk using the numeric ID of the service you wish to check (a long string that will start with .1.3)

Typically you will find your nagios config files in /usr/local/nagios/etc. Here you will see nagios.cfg - there will also be an objects folder.

However some nagios based systems have slightly different directory structures so it's worth having a poke around and checking the opsview documentation

I would still reccomend taking a look at check_mk too - it is very good and super easy to add and monitor hosts. You don't need to manually add services as it has an inventory function and comes back with services you will likely want to monitor. For instance point it at an HP server with the SNMP Agents installed and it will tell you disk, ram, fan health, temperature, CPU load, memory load, network traffic etc - and all you have to do is specify the IP address you wish to inventory, and then tick the checks you wish to add out of what it finds.

personally I like tinkering with different tools and it's a good way to get a feel of functionality between different products
 
Back
Top Bottom