Using Nagios to Monitor Networks

Posted by philcore on Mon 28 Nov 2005 at 12:23

Nagios is a powerful, modular network monitoring system that can be used to monitor many network services like smtp, http and dns on remote hosts. It also has support for snmp to allow you to check things like processor loads on routers and servers. I couldn't begin to cover all of the things that nagios can do in this article, so I'll just cover the basics to get you up and running.

apt-get install nagios-text
First we need to define people that will be notified, and define how they should be notified. In the example below, I define two users, joe and paul. Joe is the network guru and cares about routers and switches. Paul is the systems guy, and he cares about servers. Both will be notified via email and by pager. Note that if you are going to monitor your email server, you will want to use another notification method besides email. If your email server is down, you can't send anybody an email to notify them! :) In that case you will want to use a pager server to send a text message to a phone or pager, or set up a second nagios monitor that uses a different mail server to send email.

Edit /etc/nagios/contacts.cfg and add the following users:

define contact{
    contact_name                    joe
    alias                           Joe Blow
    service_notification_period     24x7
    host_notification_period        24x7
    service_notification_options    w,u,c,r
    host_notification_options       d,u,r
    service_notification_commands   notify-by-email,notify-by-pager
    host_notification_commands      host-notify-by-email,host-notify-by-epager
    email                           joe@yourdomain.com
    pager                           5555555@pager.yourdomain.com
    }

define contact{
    contact_name                    paul
    alias                           Paul Shiznit
    service_notification_period     24x7
    host_notification_period        24x7
    service_notification_options    w,u,c,r
    host_notification_options       d,u,r
    service_notification_commands   notify-by-email,notify-by-epager
    host_notification_commands      host-notify-by-email,host-notify-by-epager
    email                           paul@yourdomain.com
    pager                           5556666@pager.yourdomain.com
    }

Now add the users to groups.
In /etc/nagios/contactgroups.cfg add the following:
define contactgroup{
    contactgroup_name   router_admin
    alias               Network Administrators
    members             joe
}

define contactgroup{
    contactgroup_name   server_admin
    alias               Systems Administrators
    members             paul
}

You can add multiple members to a contact group by listing comma separated users.

Now to define some hosts to monitor. For my example, I define two machines, a mail server and a router.

Edit /etc/nagios/hosts.cfg and add:

define host{
    use                     generic-host
    host_name               gw1.yourdomain.com
    alias                   Gateway Router
    address                 10.0.0.1
    check_command           check-host-alive
    max_check_attempts      20
    notification_interval   240
    notification_period     24x7
    notification_options    d,u,r
    }

define host{
    use                     generic-host
    host_name               mail.yourdomain.com
    alias                   Mail Server
    address                 10.0.0.100
    check_command           check-host-alive
    max_check_attempts      20
    notification_interval   240
    notification_period     24x7
    notification_options    d,u,r
    }
Now we add the hosts to groups. I define groups called 'routers' and 'servers' and add the router and mail server respectively.

Edit /etc/nagios/hostgroups.cfg

define hostgroup{
    hostgroup_name  routers
    alias           Routers
    contact_groups  router_admin
    members         gw1.yourdomain.com
    }

define hostgroup{
    hostgroup_name  servers
    alias           Servers
    contact_groups  server_admin
    members         mail.yourdomain.com
    }
Again, for multiple members, just use a comma separated list of hosts.

Next define services to monitor on each of the hosts. Nagios has many built-in plugins for monitoring. On a debian sarge system, they are stored in /usr/lib/nagios/plugins. Here we want to monitor the smtp service on the mail server, and do ping checks on the router.

Edit /etc/nagios/services.cfg

define service{
    use                     generic-service 
    host_name               mail.yourdomain.com
    service_description     SMTP
    is_volatile             0
    check_period            24x7
    max_check_attempts      3
    normal_check_interval   5
    retry_check_interval    1
    contact_groups          server_admin
    notification_interval   240
    notification_period     24x7
    notification_options    w,u,c,r
    check_command           check_smtp
    }

define service{
    use                     generic-service 
    host_name               gw1.yourdomain.com
    service_description     PING
    is_volatile             0
    check_period            24x7
    max_check_attempts      3
    normal_check_interval   5
    retry_check_interval    1
    contact_groups          router_admin
    notification_interval   240
    notification_period     24x7
    notification_options    w,u,c,r
    check_command           check_ping!100.0,20%!500.0,60%
    }

And that's it. To test your configurations, you can run
nagios -v /etc/nagios/nagios.cfg
If all is well we can restart nagios and move on to the apache side to get a visual view of the monitor.
/etc/init.d/nagios restart
Assuming you have a working apache install, you can add the apache.conf file included in the nagios package to set up the nagios cgi administration interface. The web interface is not required to run nagios, but it is definitely worth setting it up. The simplest way to get it up and running is to copy the supplied conf file over to our apache installation. On my system, I'm running apache2. Systems running apache 1.3.xx will have slightly different setups.
cp /etc/nagios/apache.conf /etc/apache2/sites-enabled/nagios
Of course you may want to set it up as a virtual server, but I leave that as an exercise for the reader. Now you will want to set up an allowed user to view the cgi interface. By default, nagios issues full administrative access to the nagiosadmin user. Nagios uses apache htpasswd style authentication. So here we add a user and password to the default nagios htpasswd file. Here we add the user nagiosadmin with password mypassword to the nagios htpasswd file.
htpasswd2 -nb nagiosadmin mypassword >> /etc/nagios/htpasswd.users
You should now be able to restart apache and logon to

http://your.nagios.server/nagios

Nagios is a very powerful tool for monitoring networks. I've only touched on the basics here, but it should be enough to get you up and running. Hopefully, once you do, you'll start experimenting with all the cool features and plugins that are available. The documentation included in the cgi interface is very detailed and helpful.

 

 


Posted by hardik (61.95.xx.xx) on Mon 28 Nov 2005 at 12:53
It's very useful tools for very large scale networks
and servers, I like its's per user/group base monitoring,
Pager base notification. But which type of action taken by
Nagios if problem arise. If you want to monitor only small
scale server i will recomend Monit, And it is also esier to
setup. Finally it's very nice article for newbie like me.

Check URL http://www.debian-administration.org/articles/269
For Monit.

Cheers,
Hardik Dalwadi.

[ Parent | Reply to this comment ]

Posted by Anonymous (217.136.xx.xx) on Mon 28 Nov 2005 at 13:13
Nice article. I would appreciate a "part 2" about the SNMP configuration. I already had Nagios running, but never got started with the SNMP stuff...

[ Parent | Reply to this comment ]

Posted by uroboros (217.11.xx.xx) on Mon 28 Nov 2005 at 14:08
[ View Weblogs ]
I agree. The same with me too. :)

--
If you're smart enough to ask this question, you're smart enough to RTFM and find out yourself.

[ Parent | Reply to this comment ]

Posted by Anonymous (70.9.xx.xx) on Fri 16 Dec 2005 at 14:09
Agreed. I don't mean to offend, but honestly... there are countless how-tos that will get you to the point that this article finishes with. The last thing we need is yet another...

What is needed are articles covering advanced usage, little known tricks, how to get the most out of nagios, etc... SNMP, custom scripting, redundant monitors, etc...

Someone has done all of this... yet those that have seem to be tight lipped about how to get it done.

Very disappointing, considering the open nature of the app.



[ Parent | Reply to this comment ]

Posted by Anonymous (204.50.xx.xx) on Wed 25 Jan 2006 at 00:58
SNMP is apparently non-standard across different versions of UNIX (ie. HPUX, AIX, Solaris, Linux). Each Unix vendor impliments SNMP in a slightly different and non-compatible way, while staying within the spec of SNMP.

So I advise staying away from SNMP. I think a better approach would be to use the python-based "nrpe" scripts to obtain this same information. In Debian, these scripts are provided by the packages nagios-nrpe-*. These scripts work as advertised in Debian. I'm not so sure about them working for other Unices. If this is the case, at least one can fix these rather simple python scripts to make it work (and please be kind and send these fixes upstream to the nrpe maintainer). If SNMP were to not work for you on every platform you need, you're much more out of luck.

[ Parent | Reply to this comment ]

Posted by Anonymous (83.221.xx.xx) on Wed 22 Nov 2006 at 11:45
I'm trying to configure snmp in Nagios and it's just a little bit difficult.
In this article I didn't find anything that could help me about it.
Can you help me?

[ Parent | Reply to this comment ]

Posted by Anonymous (202.133.xx.xx) on Sat 16 May 2009 at 20:52
I configured nagios as per nagios pdf all service working fine but snmp is not working

[ Parent | Reply to this comment ]

Posted by eric (194.2.xx.xx) on Mon 28 Nov 2005 at 14:41
[ View Weblogs ]
Nagios is a great tool we used daily to monitor servers, internet lines, network switches, etc, but it's (a little bit) difficult to configure, and moreover to 'maintain' (to add servers, services...) because who have to deal with text files.

I recently discovered oreon which offers a frontend to Nagios. I don't tried it at the moment, but it seems a good tool.
Did anyone tried it ?

[ Parent | Reply to this comment ]

Posted by Anonymous (68.149.xx.xx) on Tue 29 Nov 2005 at 03:35
I haven't used Oreon, but I have used Fruity. When I last tried it several months ago it still had a few bugs, but it still saved me tons of time generating larger configurations.

[ Parent | Reply to this comment ]

Posted by Anonymous (157.159.xx.xx) on Mon 4 Jun 2007 at 13:09
Is it packaged for Debian ?

[ Parent | Reply to this comment ]

Posted by Anonymous (209.74.xx.xx) on Wed 30 Nov 2005 at 19:06
I haven't tried a frontend yet, but I've found that templates save me a ton of time.

I'm really looking forward to version 3 of nagios, which I have been told should be php/mysql driven and I expect web configurable.

[ Parent | Reply to this comment ]

Posted by sfrank (193.226.xx.xx) on Tue 29 Nov 2005 at 10:48
as being said, it covers the basics, but it does it greatly. hope to read the sequel. ;-)

[ Parent | Reply to this comment ]

Posted by Anonymous (213.216.xx.xx) on Thu 1 Dec 2005 at 10:21
I would also note the package 'mon' from kernel.org.

[ Parent | Reply to this comment ]

Posted by Anonymous (69.17.xx.xx) on Fri 16 Dec 2005 at 17:09
I am also using nagios at work. I really like the ability to write my own monitoring plugins. I wrote a simple xmlrpc/python plugin that allows me to monitor our services at our hosting facilty. Nagios helps me sleep better at night! -Tom

[ Parent | Reply to this comment ]

Posted by Anonymous (203.217.xx.xx) on Fri 16 Dec 2005 at 22:01
Hi All,

I'm always surprised that no-one ever reviews Zabbix from www.zabbix.org.

It's a GPLed open source project which offers advanced monitoring, alerting and visualisation features. It's configured via web pages and is trivial to set up.

Features:

  • Runs on AIX, FreeBSD, HP-UX, Linux, MacOS X, NetBSD, OpenBSD, Solaris, Tru64/OSF
  • SQL database for storing configuration, collected data and trends
  • Web interface offers minimal learning, ubiquitous access
  • Instant drill down from real-time status of IT Services to historical trend and statistics
  • Data visualisation and mapping
  • High performance native ZABBIX agents for performance and integrity monitoring for virtually all platforms (UNIX, Win32)
  • Monitoring of "agentless" environments
  • Assuring and monitoring SLA for IT Services
  • Monitoring of SNMP (v1,v2,v3) devices

To me it is, visually, slightly more appealing than nagios which can be important when trying to present to pointy headed bosses.

Cheers...

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Fri 16 Dec 2005 at 23:07
[ View Steve's Scratchpad | View Weblogs ]

Write a review. Submit it. It will be posted.

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (67.79.xx.xx) on Thu 20 Jul 2006 at 22:07
Would you be interested in posting your Python framework for your plugin to help kickstart a Python newbie?


[ Parent | Reply to this comment ]

Posted by teklimbu (202.79.xx.xx) on Sun 13 Aug 2006 at 10:01
Hi All,

Can somebody please provide me a script to check the status of my Squid Proxy server using port 3128 from Nagios.

I am also trying to get Zabbix to run in my Debian etch machine.
However, I am getting some errors while installing Zabbix. Below are the errors:

home# apt-get install zabbix-server

Reading package lists... Done
Building dependency tree... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.

Since you only requested a single operation it is extremely likely that
the package is simply not installable and a bug report against
that package should be filed.
The following information may help to resolve the situation:

The following packages have unmet dependencies.
zabbix-server: Depends: libmysqlclient12 but it is not installable
Depends: libsnmp5 (>= 5.1) but it is not installable
E: Broken packages


Thanks in advance,

Yours sincerely,

Tek Bahadur Limbu

[ Parent | Reply to this comment ]

Posted by Anonymous (203.200.xx.xx) on Fri 27 Jan 2006 at 07:46
this is the comman doc we can get it any junk site nothig specical about it, But a good try

[ Parent | Reply to this comment ]

Posted by philcore (70.161.xx.xx) on Fri 27 Jan 2006 at 11:40
[ View Weblogs ]
I hope that means you'll be submitting a "special" version here for us all to read. Hopefully with a spell checker. ;)

But thanks, I'm glad you approve.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.171.xx.xx) on Fri 17 Feb 2006 at 15:59
I have to agree with above posters decrying the lack of advanced tutorial info for Nagios administrators. I'm currently struggling through creating my own SNMP plugins using simple shell scripts and can find almost no info at all to assist me.

Should I ever get this stuff working I might knock together a quick howto of my own ;-)

[ Parent | Reply to this comment ]

Posted by Anonymous (64.131.xx.xx) on Wed 15 Mar 2006 at 05:20
Why bother with the hassle of nagios? Use something easy to setup like bixdata.com

[ Parent | Reply to this comment ]

Posted by Anonymous (198.203.xx.xx) on Wed 27 Jan 2010 at 12:44
Because bixdata is only free for 30 servers while you can use Nagios (with a little effort) for a HUGE network like I do.

[ Parent | Reply to this comment ]

Posted by Anonymous (83.213.xx.xx) on Sat 26 Aug 2006 at 13:48
I make a spanish translation of this article at http://www.pastelero.net/2006/08/26/usando-nagios-para-monitoriza r-redes/, if you have any problem with this, please tell me.

[ Parent | Reply to this comment ]

Posted by Anonymous (89.210.xx.xx) on Sun 15 Oct 2006 at 13:14
Perfect Article for this quick-and-dirty howto:)) Thank you for posting it!!!

[ Parent | Reply to this comment ]

Posted by Anonymous (212.54.xx.xx) on Sun 29 Oct 2006 at 11:51
Very good one. But it doesn't work with the latest apache2.2-common etch debian upgrade @ 26/10/2006. Apache2 fails to start :(

[ Parent | Reply to this comment ]

Posted by Anonymous (209.184.xx.xx) on Fri 23 Feb 2007 at 19:51
Does anybody know what is so special about the nagios-mysql package? I installed hoping it would use mysql to store the configuration, but it still seams to use text files.

[ Parent | Reply to this comment ]

Posted by Anonymous (82.23.xx.xx) on Fri 11 Jan 2008 at 07:57
Great article. Got me going within say 30 mins. Wasted a couple of hours as I installed nagios-mysql and didn't need it. Actually the config files ain't so bad. Twelve nodes being monitored and prolly going to have ten+ in the next 30 mins.

This was enough to get me started. Just have a look at the existing config files. Filed with loads of comments ^_^

[ Parent | Reply to this comment ]

Posted by xurizaemon (60.234.xx.xx) on Sun 8 Jun 2008 at 13:28
I'd back that. I wasted about 15 with nagios-mysql before realising that, as you say, nagios-text Just Works (TM). Configuration is identical, but using textfiles removes one potential failure point (db server) and simplifies the config a little (on my Debian etch, the dbconfig install step set up a working MySQL account, but Nagios just complained "Error: Could not read host and service status information!" until I ditched nagios-mysql and installed nagios-text in it's place). Delight!

[ Parent | Reply to this comment ]

Posted by Anonymous (203.82.xx.xx) on Wed 28 Jan 2009 at 07:39
How to configure nagios
Step by Step guide :-


export http_proxy=http://xx.xx.xx.xx:xxxx

/usr/sbin/useradd -m nagios
passwd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache
mkdir ~/downloads
cd ~/downloads
wget http://osdn.dl.sourceforge.net/sourc...s-3.0.2.tar.gz
wget http://osdn.dl.sourceforge.net/sourc...-1.4.11.tar.gz tar xzf nagios-3.0.2.tar.gz
cd nagios-3.0.2
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
cd /usr/local/nagios/etc
ls
cd /root/downloads/nagios-3.0.2
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users xxxwhateverxxx
apachectl -S
service httpd restart
cd ~/downloads
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chkconfig --add nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios start

If you have any problem pls mail us on jaydeep.galtewar@gmail.com. we ll figure it some thing.
Regards
JD


[ Parent | Reply to this comment ]

Posted by Anonymous (67.176.xx.xx) on Thu 18 Mar 2010 at 07:09
Anyone who needs a GUI interface should really check out NConf http://www.nconf.org/dokuwiki/doku.php. It takes a lot of the hassle out of repetitive setup and gives your non-technical users an easy way to configure Nagios.

[ Parent | Reply to this comment ]

Posted by Anonymous (142.166.xx.xx) on Fri 7 May 2010 at 19:55
If I add some router, switches and server to some that was allready there do I need to reset the server to see them on the website

[ Parent | Reply to this comment ]

Posted by Anonymous (117.239.xx.xx) on Fri 14 Dec 2012 at 12:23
very helpful thank you

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 498 votes ~ 5 comments )

 

 

Related Links