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-textFirst 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.cfgIf 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 restartAssuming 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/nagiosOf 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.usersYou 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.
[ Parent | Reply to this comment ]
--
If you're smart enough to ask this question, you're smart enough to RTFM and find out yourself.
[ Parent | Reply to this comment ]
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 ]
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 ]
In this article I didn't find anything that could help me about it.
Can you help me?
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Write a review. Submit it. It will be posted.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
But thanks, I'm glad you approve.
[ Parent | Reply to this comment ]
Should I ever get this stuff working I might knock together a quick howto of my own ;-)
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
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 ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message ]
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 ]