how to nagios with gentoo
Written by Mrfroasty (Ufundi) // 22/07/2009 // Isio-gawanyo // Zima maoni
Seting up nagios, involves central PC that monitoring software nagios is installed and couple devices that we are monitoring.
In this scenario we 2 computers and 1 router.One computer called gendesktop is the central command center that nagios is installed to monitor itself, router and 1 remote server(fileserver).
Computer names:
- Central command center-gendesktop
- Router-router
- Gentoo Linux Server-fileserver
Preparations:
***PREPARE THE ROUTER
Make sure you have allowed snmp on “remote management” section of the router device.
Atleast on my device this was not on by default.
***PREPARE THE REMOTE BOX-FILESERVER:
On the fileserver,Check if necessary plugins like snmp, nrpe are installed on the this box.Feel free to remove some of them.
#emerge -pv nagios-plugins
net-analyzer/nagios-plugins-1.4.13-r4 USE=”ipv6 ldap mysql nagios-dns nagios-game nagios-ntp nagios-ping nagios-ssh radius samba snmp suid ups -postgres -ssl” 0 kB
Create commands on for the services that we want to monitor from this box:
Configuration file for npre lives /etc/nagios/nrpe.cfg, I ignored all other stuffs and change only the commands.
#Examples
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_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#disk
command[check_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_home]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /home
Start the deamon for this nrpe, and put it in the default run-level
#/etc/init.d/nrpe start && rc-update add nrpe default
I also added this on /etc/services {no idea if its needed
}
nrpe 5666/tcp
Verify nrpe on this client is all set:
#ps axuw | grep nrpe
#netstat -at | grep nrpe
####################COMMAND CENTER-GENDESKTOP######################
Objective, we want to monitor link status, ping and Uptime.There are more stuffs here can be monitored like bandwidth using mrtg, but we leave that to readers ![]()
Configuration on the gendesktop:
We need nagios with all its plugin, so enable its USE flags and install it.
#emerge -av nagios
P:S
Check if necessary plugins like snmp, nrpe are installed on the plugins
#emerge -pv nagios-plugins
net-analyzer/nagios-plugins-1.4.13-r4 USE=”ipv6 ldap mysql nagios-dns nagios-game nagios-ntp nagios-ping nagios-ssh radius samba snmp suid ups -postgres -ssl” 0 kB
WEB INTERFACE:
The web interface is cgi style, and it lives in on /usr/lib/nagios/cgi-bin.
Not so sure if .htaccess was there I created, but verify it, if not there create one.
#nano -w /usr/lib/nagios/cgi-bin/.htaccess
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /etc/nagios/auth.users
Require valid-user
Restrict access to your nagios /etc/apache2/modules.d/99_nagios3.conf:
#nano -w /etc/apache2/modules.d/99_nagios3.conf
ScriptAlias /nagios/cgi-bin/ /usr/lib/nagios/cgi-bin/
AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
Alias /nagios /usr/share/nagios/htdocs
AllowOverride AuthConfig
Order allow,deny
Allow from 127.0.0.1 192.168.1.1/24
Create user to access your web-interface:
# htpasswd2 -c /etc/nagios/auth.users nagiosadmin
Test if web-interface is working, shoot this on your browser http://localhost/nagios
Now lets test communication to the router, if communication is working we continue to create object file for this router.
Test SNMP WITH THE ROUTER:
#snmpwalk -v 1 -c public router
You should get lots of output data here, if it doesnt work.If it doesnt work consult troubleshooting area below.
If you do have communication there, lets create the object file for this router:
Create the dir:
#mkdir /etc/nagios/objects/routers
and create this file in there router.cfg.
###############################################################################
###############################################################################
#
# HOST DEFINITIONS-ROUTER
#
###############################################################################
###############################################################################
# Define the switch that we’ll be monitoringdefine host{
use generic-switch ; Inherit default values from a template
host_name router ; The name we’re giving to this switch
alias Linksys SRW224P Switch ; A longer name associated with the switch
address 192.168.1.254 ; IP address of the switch
hostgroups gendesktop,mzalendo.net,switches ; Host groups this switch is associated with
}###############################################################################
###############################################################################
#
# HOST GROUP DEFINITIONS-ROUTER
#
###############################################################################
################################################################################ Create a new hostgroup for switches
define hostgroup{
hostgroup_name switches ; The name of the hostgroup
alias Network Switches ; Long name of the group
}###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS-ROUTER
#
###############################################################################
###############################################################################
# Create a service to PING to switch
define service{
use generic-service ; Inherit values from a template
host_name router ; The name of the host the service is associated with
service_description PING ; The service description
check_command check_ping!200.0,20%!600.0,60% ; The command used to monitor the service
normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every minute until its final/hard state is determined
}# Monitor uptime via SNMP
define service{
use generic-service ; Inherit values from a template
host_name router
service_description Uptime
check_command check_snmp!-C public -o sysUpTime.0
}# Monitor Port 1 status via SNMP
define service{
use generic-service ; Inherit values from a template
host_name router
service_description Port 1 Link Status
check_command check_snmp!-C public -o ifOperStatus.1 -r 1 -m RFC1213-MIB
}# Monitor bandwidth via MRTG logs
#define service{
# use generic-service ; Inherit values from a template
# host_name router
# service_description Port 1 Bandwidth Usage
# check_command check_local_mrtgtraf!/var/lib/mrtg/192.168.1.254.log!AVG!1000000,1000000!5000000,5000000!10
# }
Verify that no problem no errors in your config files:
#nagios -v /etc/nagios/nagios.cfg
If no problem restart nagios deamon.
#/etc/init.d/nagios restart
REMOTE BOX FILESERVER OBJECT FILE:
creat the directy /etc/nagios/objects/servers/ and put this file in it fileserver.cfg
###############################################################################
###############################################################################
#
# HOST DEFINITION FOR FILESERVER
#
###############################################################################
################################################################################ Define a host for the local machine
define host{
use linux-server ; 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 fileserver
alias fileserver
address 192.168.1.xx
}###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
################################################################################ Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name fileserver ; The name of the hostgroup
alias MZALENDO LINUX SERVER ; Long name of the group
members fileserver ; Comma separated list of hosts that belong to this group
}
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
################################################################################LOAD
define service{
use generic-service ; Name of service template to use
host_name fileserver
service_description LOAD
check_command check_nrpe!check_load!5.0,4.0,3.0!10.0,6.0,4.0
}#USERS
define service{
use generic-service ; Name of service template to use
host_name fileserver
service_description USERS
check_command check_nrpe!check_users
}#ROOT
define service{
use generic-service ; Name of service template to use
host_name fileserver
service_description ROOT
check_command check_nrpe!check_root!20%!10%!
}#HOME
define service{
use generic-service ; Name of service template to use
host_name fileserver
service_description HOME
check_command check_nrpe!check_home!20%!10%!
}#Total procs
define service{
use generic-service ; Name of service template to use
host_name fileserver
service_description Total Procs
check_command check_nrpe!check_total_procs!250!400!RSZDT
}#zombie procs
define service{
use generic-service ; Name of service template to use
host_name fileserver
service_description Zombie Procs
check_command check_nrpe!check_zombie_procs
}gendesktop muhsin #Verify that no problem no errors in your config files:
#nagios -v /etc/nagios/nagios.cfg
If no problem restart nagios deamon.
#/etc/init.d/nagios restart
TROUBLESHOOTING
RESOURCES:
http://www.gentoo.org/doc/en/nagios-guide.xml
http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf
http://www.nagios.org/



