Nagios is hands-down the best monitoring tool to monitor host and network equipments. Using Nagios plugins you can monitor pretty much monitor anything.
I use Nagios intensively and it gives me peace of mind knowing that I will get an alert on my phone, when there is a problem. More than that, if warning levels are setup properly, Nagios will proactively alert you before a problem becomes critical.
Earlier I wrote about, how to setup Nagios to monitor Linux Host, Windows Host and VPN device.
In this article, I’ll explain how to configure Nagios to monitor network switch and it’s active ports.
1. Enable switch.cfg in nagios.cfg
Uncomment the switch.cfg line in /usr/local/nagios/etc/nagios.cfg as shown below.
[nagios-server]# grep switch.cfg /usr/local/nagios/etc/nagios.cfg cfg_file=/usr/local/nagios/etc/objects/switch.cfg
2. Add new hostgroup for switches in switch.cfg
Add the following switches hostgroup to the /usr/local/nagios/etc/objects/switch.cfg file.
define hostgroup{
hostgroup_name switches
alias Network Switches
}
3. Add a new host for the switch to be monitered
In this example, I’ve defined a host to monitor the core switch in the /usr/local/nagios/etc/objects/switch.cfg file. Change the address directive to your switch ip-address accordingly.
define host{
use generic-switch
host_name core-switch
alias Cisco Core Switch
address 192.168.1.50
hostgroups switches
}
4. Add common services for all switches
Displaying the uptime of the switch and verifying whether switch is alive are common services for all switches. So, define these services under the switches hostgroup_name as shown below.
# Service definition to ping the switch using check_ping
define service{
use generic-service
hostgroup_name switches
service_description PING
check_command check_ping!200.0,20%!600.0,60%
normal_check_interval 5
retry_check_interval 1
}
# Service definition to monitor switch uptime using check_snmp
define service{
use generic-service
hostgroup_name switches
service_description Uptime
check_command check_snmp!-C public -o sysUpTime.0
}
5. Add service to monitor port bandwidth usage
check_local_mrtgtraf uses the Multil Router Traffic Grapher – MRTG. So, you need to install MRTG for this to work properly. The *.log file mentioned below should point to the MRTG log file on your system.
define service{
use generic-service
host_name core-switch
service_description Port 1 Bandwidth Usage
check_command check_local_mrtgtraf!/var/lib/mrtg/192.168.1.11_1.log!AVG!1000000,2000000!5000000,5000000!10
}
6. Add service to monitor an active switch port
Use check_snmp to monitor the specific port as shown below. The following two services monitors port#1 and port#5. To add additional ports, change the value ifOperStatus.n accordingly. i.e n defines the port#.
# Monitor status of port number 1 on the Cisco core switch
define service{
use generic-service
host_name core-switch
service_description Port 1 Link Status
check_command check_snmp!-C public -o ifOperStatus.1 -r 1 -m RFC1213-MIB
}
# Monitor status of port number 5 on the Cisco core switch
define service{
use generic-service
host_name core-switch
service_description Port 5 Link Status
check_command check_snmp!-C public -o ifOperStatus.5 -r 1 -m RFC1213-MIB
}
7. Add services to monitor multiple switch ports together
Sometimes you may need to monitor the status of multiple ports combined together. i.e Nagios should send you an alert, even if one of the port is down. In this case, define the following service to monitor multiple ports.
# Monitor ports 1 - 6 on the Cisco core switch.
define service{
use generic-service
host_name core-switch
service_description Ports 1-6 Link Status
check_command check_snmp!-C public -o ifOperStatus.1 -r 1 -m RFC1213-MIB, -o ifOperStatus.2 -r 1 -m RFC1213-MIB, -o ifOperStatus.3 -r 1 -m RFC1213-MIB, -o ifOperStatus.4 -r 1 -m RFC1213-MIB, -o ifOperStatus.5 -r 1 -m RFC1213-MIB, -o ifOperStatus.6 -r 1 -m RFC1213-MIB
}
8. Validate configuration and restart nagios
Verify the nagios configuration to make sure there are no warnings and errors.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check
Restart the nagios server to start monitoring the VPN device.
# /etc/rc.d/init.d/nagios stop Stopping nagios: .done. # /etc/rc.d/init.d/nagios start Starting nagios: done.
Verify the status of the switch from the Nagios web UI: http://{nagios-server}/nagios as shown below:
9. Troubleshooting
Issue1: Nagios GUI displays “check_mrtgtraf: Unable to open MRTG log file” error message for the Port bandwidth usage
Solution1: make sure the *.log file defined in the check_local_mrtgtraf service is pointing to the correct location.
Issue2: Nagios UI displays “Return code of 127 is out of bounds – plugin may be missing” error message for Port Link Status.
Solution2: Make sure both net-snmp and net-snmp-util packages are installed. In my case, I was missing the net-snmp-utils package and installing it resolved this issue as shown below.
[nagios-server]# rpm -qa | grep net-snmp net-snmp-libs-5.1.2-11.el4_6.11.2 net-snmp-5.1.2-11.el4_6.11.2 [nagios-server]# rpm -ivh net-snmp-utils-5.1.2-11.EL4.10.i386.rpm Preparing... ########################################### [100%] 1:net-snmp-utils ########################################### [100%] [nagios-server]# rpm -qa | grep net-snmp net-snmp-libs-5.1.2-11.el4_6.11.2 net-snmp-5.1.2-11.el4_6.11.2 net-snmp-utils-5.1.2-11.EL4.10
Note: After you’ve installed net-snmp and net-snmp-utils, re-compile and re-install nagios plugins as explained in “6. Compile and install nagios plugins” in the Nagios 3.0 jumpstart guide.
Two Best Nagios Books
These are the two best nagios books that covers the latest Nagios 3. I strongly recommend that you read both of these books to gain a detailed understanding on Nagios. Since Nagios is free software, spending few dollars on the books can be the best investment you can make.
|
|
|
|
|
|
Awesome Nagios Articles
Following are few awesome Nagios articles that you might find helpful.
- How To Monitor Remote Windows Machine Using Nagios on Linux
- How To Monitor Remote Linux Host using Nagios 3
- Nagios 3 Jumpstart Guide For Linux – Overview, Installation and Configuration
Get free Unix tutorials, tips and tricks straight to your email in-box.
If you enjoyed this article, you might also like..

![[Nagios GUI for Network Switch] [Nagios GUI for Network Switch]](http://www.thegeekstuff.com/wp-content/uploads/2008/10/nagios-ui-for-switch.jpg)

My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 3 trackbacks }
{ 10 comments… read them below or add one }
You should maybe consider graphing tools like cacti or big brother for your network usage. Nagios is mainly targeted as a status monitoring application.
Nagios is a really good status monitoring system, but is better to install Cacti in order to graph our devices, the main advantage of Cacti, is the simple but powerful usage.
hello every one
I want to find the health of all the router and switches connected in my organization LAN using java. So, could you help me in the concern topic.
What if there are 2 switches in a stack? How do I monitor the ports on the 2nd switch on the stack?
@Prune, @Bryan,
Thanks for the information about Cacti – The complete RRDtool based graphing solution. I’ll check it out.
@Jeremy,
If you are using cisco switches, Check-out check_cisco.pl Nagios Pluginfound in the Nagios Exchange that seems to monitor the ports that are part of the multiple stacked switches.
Hello,
How about if i want to monitor network bandwidth usage within a building, where do i should place the nagios server? after the firewall?
Hi Guys,
I’m interested in monitoring a switch stack (echoing Jeremy’s question above). The cisco plugin that Ramesh linked to looks good, but I’m using Enterasys equipment.
Is anyone aware of any ways to monitor switch stacks via snmp?
Cheers,
Cameron
Hy guys!
Does anyone have an idea on making smth like subservices in Nagios. A.e. I need to monitor the throughput on each port of the switch and each port status. I wrote a small script using snmpwalk command, that gives a list of ports and their status(or anything that snmpwalk shows) as a result. And I dont’t even imagine how to make Nagios understand it in this way: host -> service(my script) -> port(as a result of the previous) -> smth I choose from snmpwalk
Thanx
Where is the mapping between snmp port numbers and switch port numbers defined? It’s simple enough for the first 24 ports, but my 2950 then has two more ports labelled 1 and 2 (ie duplicating the first 2 port numbers). If I use snmpwalk to see what ports are being monitored, I get 28 in all:
# snmpwalk -v1 -c public my_switch -m ALL .1 | grep ifOperStatus
RFC1213-MIB::ifOperStatus.1 = INTEGER: down(2)
RFC1213-MIB::ifOperStatus.2 = INTEGER: down(2)
RFC1213-MIB::ifOperStatus.3 = INTEGER: down(2)
…
RFC1213-MIB::ifOperStatus.26 = INTEGER: down(2)
RFC1213-MIB::ifOperStatus.27 = INTEGER: up(1)
RFC1213-MIB::ifOperStatus.28 = INTEGER: up(1)
I’ve not been able to find this information from the usual sources (ie Google, Cisco).
Hi,
Always i have: check_mrtgtraf: Impossible d’ouvrir le fichier de log de MRTG
In the configuration of switch I have:
check_command check_local_mrtgtraf!/var/lib/mrtg/192.168.1.253_1.log!AVG!1000000,1000000!5000000,5000000!10
but in var/lib/mrtg i don’t have a file 192.168.1.253_1.log
Can someone help me?
thank you in advance