Nagios is a well known monitoring system that have more functionlities and very simple and light wieght application. I have installed and tested in Centos. Here is how we can install nagios. First We need to configure nagios server. For that make sure that epel and rpmforge repos are enabled in the server.
After that install nagios core, nagios plugins and nagios nrpe.
I have installed and tested in Centos. Here is how we can install nagios
First We need to configure nagios server.
For that make sure that epel and rpmforge repos are enabled in the server.
After that install nagios core, nagios plugins and nagios nrpe
{codecitation}
yum install nagios nagios-plugins nagios-plugins-nrpe nagios-devel nagios-nrpe
{/codecitation}
The other rpm that is needed for the proper working is xinetd. So install that one too.
{codecitation}
yum install xinetd
{/codecitation}
All the configuration files are stored in "/etc/nagios". The main configuration file is nagios.cfg where all other configuration files are included.
In "/etc/nagios/objects" all other configuration files are present.
Now all required rpms for the nagios servers are installed in the server.
Now to access the server using a web interface add the following the httpd configuration file.
{codecitation}
ScriptAlias /nagios/cgi-bin "/usr/lib/nagios/cgi"
<Directory "/usr/lib/nagios/cgi">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/htpasswd.users
Require valid-user
</Directory>
ScriptAlias /nagios "/usr/share/nagios"
<Directory "/usr/share/nagios">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/htpasswd.users
Require valid-user
</Directory>
{/codecitation}
Then you need to create the users in the "/etc/nagios/htpasswd.users". We can create two users one is nagiosadmin and other is guest.
{codecitation}
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
htpasswd /etc/nagios/htpasswd.users guest
{/codecitation}
Now restart apache and you can now access nagios as follows.
{codecitation}
http://<ip>/nagios
{/codecitation}
Make sure that you have nagios and other service running in the server as follows.
{codecitation}
/etc/init.d/nagios restart
/etc/init.d/nrpe restart
/etc/init.d/xinetd restart
{/codecitation}
Check the functionality as follows.
{codecitation}
/usr/lib/nagios/plugins/check_nrpe -H localhost
{/codecitation}
Now we can move to nagios client machine where we install nagios plguins and nrpe only.
{codecitation}
yum install nagios-plugins nagios-plugins-nrpe nagios-nrpe
{/codecitation}
Make sure you have allowed access to nrpe from the nagios server in the file given below.
{codecitation}
more /etc/xinetd.d/nrpe
# default: off
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
type = UNLISTED
port = 5666
socket_type = stream
wait = no
user = nagios
group = nagios
server = /usr/sbin/nrpe
server_args = -c /etc/nagios/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = <ip of remote nagios server>
}
{/codecitation}
Also allow the host in the file given below.
{codecitation}
grep allowed /etc/nagios/nrpe.cfg
# that are allowed to talk to the NRPE daemon.
#allowed_hosts=127.0.0.1
allowed_hosts=<ip of remote nagios server>
{/codecitation}
Now restart the nrpe
{codecitation}
/etc/init.d/nrpe restart
{/codecitation}
Make sure that openssl is installed in both server and check the communication between the nagios server and client as follows from the nagios server machine
{codecitation}
/usr/lib/nagios/plugins/check_nrpe -H <ip of nagios client>
{/codecitation}
If it is correct, you will get something like this.
{codecitation}
/usr/lib/nagios/plugins/check_nrpe -H <ip of nagios client>
NRPE v2.12
{/codecitation}
Now we need to configure the nagios server so that it will accept the data from nagios client correctly.
In /etc/nagios/objects/commands.cfg
Add the following
{codecitation}
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
{/codecitation}
Also create a file called /etc/nagios/objects/<hostname of remote client nagios server>.cfg
{codecitation}
define host{
name linux-box-remote ; Name of this template
use generic-host ; Inherit default values
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS - ITS A TEMPLATE
}
define host{
use linux-box-remote ; Inherit default values from a template
host_name server1 ; The name we're giving to this server
alias Remote Server ; A longer name for the server
address <ip of the nagios client> ; IP address of the server
}
define service{
use generic-service
host_name server1
service_description CPU Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name server1
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name server1
service_description Space
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name server1
service_description Total Processes
notifications_enabled 0
check_command check_nrpe!check_total_procs!250!400!RSZDT
}
define service{
use generic-service
host_name server1
service_description Zombie Processes
check_command check_nrpe!check_zombie_procs
}
{/codecitation}
Now check the configuration and confirm that there is no errors in nagios configuration as follows.
{codecitation}
nagios -v /etc/nagios/nagios.cfg
{/codecitation}
If there are no errors, reload the nagios configuration file so that nagios will take the new configuration.
{codecitation}
/etc/init.d/nagios reload
{/codecitation}
Now go the nagios client server where you can give more functions for the remote server by editing the file given below.
{codecitation}
/etc/nagios/nrpe.cfg
You can add new commands as follows.
# The following examples use hardcoded command arguments...
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda5
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
# The following examples allow user-supplied arguments and can
# only be used if the NRPE daemon was compiled with support for
# command arguments *AND* the dont_blame_nrpe directive in this
# config file is set to '1'. This poses a potential security risk, so
# make sure you read the SECURITY file before doing this.
#command[check_users]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
#command[check_load]=/usr/lib/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
#command[check_disk]=/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
#command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
{/codecitation}
The commands that are available now are given below.
{codecitation}
/usr/lib/nagios/plugins/
check_apt check_file_age check_imap check_mysql check_nwstat check_sensors check_udp utils.py
check_breeze check_flexlm check_ircd check_mysql_query check_oracle check_simap check_ups utils.pyc
check_by_ssh check_fping check_jabber check_nagios check_overcr check_smtp check_users utils.sh
check_clamd check_ftp check_ldap check_nntp check_pgsql check_snmp check_wave
check_cluster check_game check_ldaps check_nntps check_ping check_spop contrib/
check_dig check_hpjd check_load check_nrpe check_pop check_ssh eventhandlers/
check_disk check_http check_log check_nt check_procs check_ssmtp negate
check_disk_smb check_ide_smart check_mailq check_ntp check_radius check_swap plugins.pm
check_dns check_ifoperstatus check_mrtg check_ntp_peer check_real check_tcp urlize
check_dummy check_ifstatus check_mrtgtraf check_ntp_time check_rpc check_time utils.pm
{/codecitation}
Let me know if you have any queries.
If you are adding more servers, copy the template and replace hostname of old server as follows.
{codecitation}
sed -i 's/oldremoteserver/newremoteserver/g' newremoteserver.tv.cfg
{/codecitation}