Professional Documents
Culture Documents
Contents
Description
Requiered Packages
Procedure
1) Scope
2) Create Account Information
3) Download Nagios and the Plugins
4) Compile and Install Nagios
5) Customize Configuration
6) Configure the Web Interface
7) Compile and Install the Nagios Plugins
8) Start Nagios
9) Login to the Web Interface
10)Other Modifications
11)add windows Machines to monitor
12)Add linux machines to monitor
13)Add switches/Routers to monitor
14)configure email alerts in nagios
. Conclusion
Scope:
This guide is intended to provide you with simple instructions on how to install Nagios from
source (code) on Ubuntu and have it monitoring your local machine inside of 20 minutes. No
advanced installation options are discussed here - just the basics that will work for 95% of
users who want to get started.
Configuration files for nagios:
If you follow these instructions, here's what you'll end up with:
Required Packages:
Make sure you've installed the following packages on your Ubuntu installation before
continuing.
Apache 2
PHP
GCC compiler and development libraries
GD development libraries
Procedure:
You can use apt-get to install these packages by running the following commands:
sudo apt-get install apache2
sudo apt-get install libapache2-mod-php5
sudo apt-get install build-essential
sudo apt-get install libgd2-xpm-dev
Don't start Nagios yet - there's still more that needs to be done...
4) Customize Configuration:
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file
vi /usr/local/nagios/etc/objects/contacts.cfg
5) Configure the Web Interface:
Install the Nagios web config file in the Apache conf.d directory.
make install-webconf
Create a nagiosadmin account for logging into the Nagios web interface. Remember the
password you assign to this account - you'll need it later.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache to make the new settings take effect.
/etc/init.d/apache2 reload
6) Compile and Install the Nagios Plugins:
Extract the Nagios plugins source code tarball.
cd ~/downloads
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
Compile and install the plugins.
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
7) Start Nagios:
Configure Nagios to automatically start when the system boots.
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
nagiosadmin
generic-contact
Nagios Admin
host_notifications_enabled
service_notifications_enabled 1
host_notification_period
service_notification_period
host_notification_options
24x7
24x7
d,u,r
service_notification_options w,u,c,r
email
noreply.rimc@sreesaila.com
can_submit_commands
}
10)Here to add windows Machines to monitor:
Sudo gedit /usr/local/nagios/etc/objects/windows.cfg
WINDOWS.CFG - SAMPLE CONFIG FILE
# HOST DEFINITIONs
# Define a host for the Windows machine we'll be monitoring
# Change the host_name, alias, and address to fit your situation
define host{
use
windows-server
host_name
winserver
alias
address
}
SERVICE DEFINITIONS
# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above
define service{
use
generic-service
host_name
winserver
check_nt!CLIENTVERSION
}
# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above
define service{
use
generic-service
host_name
winserver
service_description Uptime
check_command
check_nt!UPTIME
}
# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above
define service{
use
generic-service
host_name
winserver
check_nt!CPULOAD!-l 5,80,90
}
# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined above
define service{
use
generic-service
host_name
winserver
check_nt!MEMUSE!-w 80 -c 90
}
# Create a service for monitoring C:\ disk usage
# Change the host_name to match the name of the host you defined above
define service{
use
generic-service
host_name
winserver
check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
# Create a service for monitoring the W3SVC service
# Change the host_name to match the name of the host you defined above
define service{
use
generic-service
host_name
winserver
service_description W3SVC
check_command
}
# Create a service for monitoring the Explorer.exe process
# Change the host_name to match the name of the host you defined above
define service{
use
generic-service
host_name
winserver
service_description Explorer
check_command
}
11)To add linux machines to edit :
Sudo gedit localhost.cfg
define host{
use
linux-server
;linux server
;computername
localhost
127.0.0.1
# SERVICE DEFINITIONS
# Define a service to "ping" the local machine
define service{
use
local-service
host_name
service_description
check_command
localhost
PING
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
host_name
localhost
service_description
check_command
Root Partition
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
host_name
localhost
service_description
check_command
Current Users
check_local_users!20!50
}
# Define a service to check the number of currently running procs
local-service
host_name
service_description
check_command
localhost
Total Processes
check_local_procs!250!400!RSZDT
}
# Define a service to check the load on the local machine.
define service{
use
local-service
host_name
localhost
service_description
Current Load
check_command
check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
define service{
use
local-service
host_name
service_description
check_command
localhost
Swap Usage
check_local_swap!20!10
}
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use
local-service
host_name
localhost
service_description
SSH
check_command
check_ssh
notifications_enabled
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use
local-service
host_name
localhost
service_description
check_command
HTTP
check_http
notifications_enabled
}
12)To add switches /routers to edit:
Sudo gedit switches.cfg
Definehost{
Service
Host_name
Alias
Host_ip
}
generic service
adslrouter
adslrouter
192.168.100.10
# Generic service definition template - This is NOT a real service, just a template!
define service{
name
generic-service
active_checks_enabled
passive_checks_enabled
parallelize_check
1
1
obsess_over_service
check_freshness
notifications_enabled
event_handler_enabled
flap_detection_enabled
failure_prediction_enabled
process_perf_data
retain_status_information
retain_nonstatus_information 1
is_volatile
check_period
24x7
max_check_attempts
normal_check_interval
10
retry_check_interval
contact_groups
2
admins
notification_options
w,u,c,r
notification_interval
60
notification_period
24x7
register
}
# Local service definition template - This is NOT a real service, just a template!
define service{
name
local-service
use
generic-service
max_check_attempts
normal_check_interval
retry_check_interval
register
}
Now we edit the /usr/local/nagios/nagios.cfg
Sudo gedit nagios.cfg
In this file we remove # mark before the lines as below
/usr/local/nagios/etc/objects/windows.cfg
/usr/local/nagios/etc/objects/host.cfg
/usr/local/nagios/etc/objects/switches.cfg
/usr/local/nagios/etc/objects/printer.cfg
13)configure email alerts in nagios
Mail server configuration
Sudo apt-get install sendmail
Now go to /usr/local/nagios/etc/resource.cfg
admin_email=trainee2@sreesaila.com
admin_pager=pagenagios@localhost
and now goto /usr/local/nagios/etc/objects/commands.cfg file and edit
sudo gedit /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name
notify-host-by-email
command_line
/usr/bin/sendemail -s $USER7$ -xu $USER9$ -xp $USER10$ -t
$CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert:
$HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type:
$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress:
$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" -o
timeout=120
}
define command{
command_name
notify-service-by-email
command_line
/usr/bin/sendemail -s $USER7$ -xu $USER9$ -xp $USER10$ -t
$CONTACTEMAIL$ -f $USER5$ -l /var/log/sendemail -u "** $NOTIFICATIONTYPE$ Service
Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios
*****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost:
$HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time:
$LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" -o timeout=120
}
Conclusion:
Managing your system performance in a Nagios environment is not a black and white formula it's a balancing act with the
resources available on your server. Between the configuration changes described above, using
RAM disks, and offloading MySQL, a
single Nagios server can be configured to handle well over 10,000 active checks. The key ideas
to keep in mind are:
How many checks do I need to run?
Wow often to I need to run them?
Can my hardware handle the check load it has been given?