Nagios is the new name for NetSaint, a network/service monitoring tool. It was designed for Linux, but can be compiled and run perfectly well under any UNIX variant as far as I am aware. The monitoring daemon runs intermittent checks on hosts and services you specify.Nagios can send report through sms, email, instant message, etc..
Please follow the steps to install nagios.
Download nagios from source
wget http://prdownloads.sourceforge.net/nagios/nagios-2.9.tar.gz?download
Unpack the sourc file
tar -xzvf nagios-2.9.tar.gz
create user for nagios
useradd nagios
Create Installation Directory
mkdir /usr/local/nagios
Change the owner of the base installtion directory to be the Nagios user and group you added earlier as follows:
chown nagios.nagios /usr/local/nagios
Create a new command file group whose members include the user your web server is running as and the user Nagios is running
as.
groupadd nagcmd
Add the users that your web server and Nagios run as to the newly created group
usermod -G nagcmd nagios
usermod -G nagcmd nobody
Run the configuration script.
./configure –prefix=/usr/local/nagios –with-cgiurl=/nagios/cgi-bin –with-htmurl=/nagios/ –with-nagios-user=nagios –with-nagios-group=nagios –with-command-group=nagcmd
Compile Binaries-
make all
Install the Binaries And HTML Files-
make install
9. Install An Init Script-
make install-init
Download Nagios plugin to /usr/local/nagios from
untar; and cd into the new directory.
Compile Binaries- make
make install
Setup The Web Interface
ADD THE FOLLOWING ENTRIES TO HTTPD.CONF
Configure Aliases and Directory Options For The Web Interface
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
<Directory /usr/local/nagios/sbin/>
AllowOverride AuthConfig
Options ExecCGI
Allow from all
Order allow,deny
</Directory>Alias /nagios/ /usr/local/nagios/share/
<Directory /usr/local/nagios/share>
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
Include the file in the Apache configuration file.
Create a user for the web authentication -nagiosadmin
Provide a password that will be used when nagiosadmin authenticates to the web server.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enable Authentication/Authorization Functionality In The CGIs
Set use_authentication=0 in cgi.cfg file.
Set the default Permissions To CGI Information
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
Restart The Web Server
cd /user/local/nagios/etc
Create directories hosts and services
mkdir hosts.
mkdir services.
Specify the directories in the nagios.cfg file.
cfg_dir=/usr/local/nagios/etc/hosts
cfg_dir=/usr/local/nagios/etc/services
In each of these directories we need to create files for each servers we need to monitor.
Each of these files will contain the hostname and ip of the respective servers.
For this we need to make a copy of the HOSTS block in the localhost.cfg file for each servers.
Similarly we need to make a copy of the SERVICES block of the localhost.cfg for each servers
in the services directory.
We need to specify the emailID where we recieve the alerts in the localhost.cfg file.
Also we need to add all the hostname we are monitoring in the HOSTGROUP of the localhost.cfg file.
Once this is done, we need to start nagios.
We can see the logg details of nagios in the /usr/local/nagios/var/nagios. log file.
This completes the configuration of NAGIOS!!!
SAMPLE CONFIGURATION TO ADD A HOST
———————————-
# Generic host definition template – This is NOT a real host, just a template!
define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24×7 ; Send host notifications at any time
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL HOST, JUST A TEMPLATE!
}
# Linux host definition template – This is NOT a real host, just a template!
define host{
name swww3.couchsurfing.com ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template
check_period 24×7 ; By default, Linux hosts are checked round the clock
max_check_attempts 10 ; Check each Linux host 10 times (max)
check_command check-host-alive ; Default command to check Linux hosts
notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day
; Note that the notification_period variable is being overridden from ; the value that is inherited from the generic-host template!
notification_interval 120 ; Resend notification every 2 hours
notification_options d,u,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL HOST, JUST A TEMPLATE!
}
# Since this is a simple configuration file, we only monitor one host – the
# local host (this machine).
define host{
use swww3.couchsurfing.com ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name swww3.couchsurfing.com
alias swww3.couchsurfing.com
address 207.210.80.122
}
SAMPLE CONFIGURATION TO ADD SERVICES TO A HOST
———————————————-
# Generic service definition template – This is NOT a real service, just a template!
define service{
name generic-service ; The ‘name’ of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service ‘freshness’
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
# Local service definition template – This is NOT a real service, just a template!
define service{
name local-service ; The name of this service template
use generic-service ; Inherit default values from the generic-service definition
check_period 24×7 ; The service can be checked at any time of the day
max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state
normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the ‘admins’ group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24×7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
# Define a service to “ping” the local machine
define service{
use local-service ; Name of service template to use
host_name www4.couchsurfing.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use local-service ; Name of service template to use
host_name www4.couchsurfing.com
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.
define service{
use local-service ; Name of service template to use
host_name www4.couchsurfing.com
service_description Current Users
check_command check_local_users!20!50
}
# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use local-service ; Name of service template to use
host_name www4.couchsurfing.com
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
# Define a service to check the load on the local machine.
define service{
use local-service ; Name of service template to use
host_name www4.couchsurfing.com
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}

















