Nagios Source Install (RHEL)

Installing nagios from source on RHEL.

Requirements:

yum install gcc php httpd zlib gd openssl-devel

Install Server

[root@james nagios]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz

Configure Server

[root@james nagios-3.2.1]# ./configure –prefix /usr/local/nagios –with-cgiurl=/nagios/cgi-bin –with-nagios-user=nagios
–with-nagios-group=nagios –with-command-group=nagcmd

***TO ENABLE CGI MAP PICTORIAL DO THE FOLLOWING****

-make cgis
-make install-cgis

****************************************************************

[root@james nagios-3.2.1]# make all

[root@james nagios-3.2.1]# make install

[root@james nagios-3.2.1]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

*** Init script installed ***

Files with be install in the –prefix path (/usr/loca/nagios)

[root@james nagios]# ls
bin libexec sbin share var

*set cgi.cfg to not use authentication or will not be able to access http files.

[root@james nagios]# grep “use_authentication” etc/cgi.cfg
use_authentication=0

Create sample config files

[root@james nagios-3.2.1]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files. You’ll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

Create +RW dir

mkdir /usr/local/nagios/var/rw
[root@james var]# chown nagios:nagios rw

Install Nagios (NRPE) Client

Step 1:

requirements:

RHEL:
yum install net-snmp-utils net-snmp-perl net-snmp gcc openssl-devel gcc-c++

*IPtables should be turned off or apply port exception!

*may need to disable exclude=kernel* line in /etc/yum.conf to install kernel-headers for gcc-c++

ubuntu:
apt-get install libssl-dev

client:

[root@james nagios]# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz

Uncompress
tar -xvf nagios-plugins-1.4.15.tar.gz

Build Package
[root@james nagios-plugins-1.4.15]# ./configure –prefix=/usr/local/nrpe –with-openssl=/usr/bin/openssl

*note make sure that output includes ssl support!

–with-apt-get-command:
–with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
–with-ping-command: /bin/ping -n -U -w %d -c %d %s
–with-ipv6: yes
–with-mysql: no
–with-openssl: yes
–with-gnutls: no
–enable-extra-opts: no
–with-perl: /usr/bin/perl
–enable-perl-modules: no
–with-cgiurl: /nagios/cgi-bin
–with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
–enable-libtap: no

[root@james nagios-plugins-1.4.15] make

[root@james nagios-plugins-1.4.15]#make install

[root@james nagios-plugins-1.4.15]#make install-root

Verify all plugins are available….

[root@james libexec]# ls /usr/local/nrpe/libexec/
check_apt check_disk check_http check_load check_nt check_ping check_ssh check_wave utils.sh
check_breeze check_disk_smb check_icmp check_log check_ntp check_pop check_swap include
check_by_ssh check_dns check_ide_smart check_mailq check_ntp_peer check_procs check_tcp libexec
check_clamd check_dummy check_ifoperstatus check_mrtg check_ntp_time check_real check_time negate
check_cluster check_file_age check_ifstatus check_mrtgtraf check_nwstat check_rpc check_udp share
check_dhcp check_flexlm check_imap check_nagios check_oracle check_sensors check_ups urlize
check_dig check_ftp check_ircd check_nntp check_overcr check_smtp check_users utils.pm

Step 2:

Build NRPE binary and check_nrpe

download:

# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
# tar -xzf nrpe-2.12.tar.gz
# cd nrpe-2.12
#./configure

*** Configuration summary for nrpe 2.12 03-10-2008 ***:

General Options:
————————-
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios

Review the options above for accuracy. If they look okay,
type ‘make all’ to compile the NRPE daemon and client.

[root@magruber]# make
[root@magruber]# make all

Move check_nrpe plugin to plugins dir on nagios master server (not client

[root@magruber]# cp ./src/check_nrpe /usr/local/nrpe/libexec/
[root@magruber]# ls /usr/local/nrpe/libexec | grep check_nrpe
check_nrpe

Copy NRPE dameon

cp ./src/nrpe /usr/local/nrpe/

Nrpe.cfg file

scp monk:/root/scripts/nrpe.cfg /usr/local/nrpe/

Copy CHECK_* custom scripts

[root@shaggy nrpe-2.12]# scp monk:/root/scripts/check_* /usr/local/nrpe/libexec/
root@monk’s password:
check_ipmi 100% 489 0.5KB/s 00:00
check_lab_backups 100% 574 0.6KB/s 00:00
check_mdadm 100% 252 0.3KB/s 00:00
check_omreport 100% 1410 1.4KB/s 00:00
check_oracle 100% 8326 8.1KB/s 00:00
check_uptime 100% 108 0.1KB/s 00:00

*check_memory script won’t run unless /etc/sudoers contains the following line!

nagios ALL=(ALL) NOPASSWD: /usr/local/nrpe/libexec/

Add nrpe to startup

scp stone:/etc/init.d/nrpe /etc/init.d/
[root@shaggy nrpe-2.12]# chkconfig –add nrpe
[root@shaggy nrpe-2.12]# chkconfig –level 345 nrpe on
[root@shaggy nrpe-2.12]# chkconfig –list nrpe
nrpe 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Nrpe Init Script

####

Edit nrpe.cfg

#change from localhost to master nagios server.
allowed_hosts=10.200.50.100

Make sure paths match for plugins. In this example you will need to change /usr/local/nagios/ to /usr/local/nrpe.

Start nrpe and verify is started.

[root@scrappy nrpe]# ./nrpe -d /usr/local/nrpe/nrpe.cfg
[root@scrappy nrpe]# ps -ef | grep nrpe
4294967295 3899 1 0 12:46 ? 00:00:00 ./nrpe -d /usr/local/nrpe/nrpe.cfg
root 3901 3866 0 12:46 pts/2 00:00:00 grep nrpe

Verify can access from nagios server.

[root@james libexec]# /usr/local/nagios/libexec/check_nrpe -H scrappy
NRPE v2.12

define hostgroup{
hostgroup_name ssh-servers ; The name of the hostgroup
alias ssh-servers ; Long name of the group
members magnum,monk,kojak,quincy,stone,baretta,macgruber,marion,donuts,coffee,scrappy ;
}

Restart nagios

root@james objects]# /etc/init.d/nagios restart
Running configuration check…done.
Stopping nagios: .done.
Starting nagios: done.

NRPE Scripts that required SUDO Privileges.

On the remote servers:

1. Move the script to /usr/local/nrpe/libexec/ – the script should have the sudo command before ethtool
2. Vi /usr/local/nrpe/nrpe.cfg and include the line: “command[check_link_speed]=sudo /usr/local/nrpe/libexec/check_link_speed”
3. Visudo and
a. Comment out this line: “Defaults requiretty”
b. Add this line: “nagios ALL=(ALL) NOPASSWD:/usr/local/nrpe/libexec/check_link_speed”
4. Restart nrpe and it should work.

Nagios Dell custom plugin scripts

IPMI Tool

scp stone:/usr/local/nrpe/libexec/check_ipmi /usr/local/nrpe/libexec #requires ipmitools

yum install ipmitool

-add to crontab
[root@quincy ~]# crontab -u root -l
*/10 * * * * /usr/bin/ipmitool sdr > /tmp/ipmi-out.txt

Then run check_ipmi script to check

[root@donuts ~]# /usr/local/nrpe/libexec/check_ipmi -t
Temp -66degreesC ok Temp -69degreesC ok Temp -68degreesC ok Temp -65degreesC ok Temp 40degreesC ok Temp 40degreesC ok Temp 22degreesC ok

[root@donuts ~]# /usr/local/nrpe/libexec/check_ipmi -f
FAN1RPM 2550RPM ok FAN2RPM 2475RPM ok FAN3RPM 2625RPM ok FAN4RPM 2625RPM ok

Open Manage

Note: May need libxslt for omreport to install correctly>>>>

yum install libxslt

scp stone:/usr/local/nrpe/libexec/check_omreport /usr/local/nrpe/libexec #requires dell open manage

scp stone:/usr/local/nrpe/libexec/check_omreport /usr/local/nrpe/libexec #requires dell open manage

[root@donuts ~]# scp quincy:/root/OMI-SrvAdmin-Dell-Web-LX-620-677.rhel5.tar /root
root@quincy’s password:
OMI-SrvAdmin-Dell-Web-LX-620-677.rhel5.tar 64% 79MB 39.5MB/s 00:01 ETA

-uncrompress

[root@kojak linux]# tar -xvf OMI-SrvAdmin-Dell-Web-LX-620-677.rhel5.tar

-install prereqs

[root@donuts ~]# ls ./linux/RPMS/supportRPMS/opensource-components/RHEL5/
libcmpiCppImpl0-2.0.0-1.1.el5.i386.rpm
libcmpiCppImpl0-2.0.0Dell-1.1.el5.i386.rpm
libwsman1-2.1.5Dell-2.1.el5.i386.rpm
openwsman-client-2.1.5Dell-2.1.el5.i386.rpm
openwsman-server-2.1.5Dell-2.1.el5.i386.rpm
sblim-sfcb-1.3.2Dell-9.1.el5.i386.rpm
sblim-sfcc-2.1.0Dell-6.1.el5.i386.rpm

-run installer:
[root@donuts ~]# ./linux/supportscripts/srvadmin-install.sh

Add following to /root/.bashrc. logout, log back in

alias omreport=’/opt/dell/srvadmin/bin/omreport’

# The following examples use hardcoded command arguments…

command[check_users]=/usr/local/nrpe/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nrpe/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nrpe/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nrpe/libexec/check_procs -w 150 -c 200

Copy plugin files from master to client.

[root@monk nrpe]# scp james:/usr/local/nagios/libexec/* libexec/
The authenticity of host ‘james (10.200.50.100)’ can’t be established.
RSA key fingerprint is ce:69:86:a6:1f:f1:4e:52:1f:18:f0:c9:6e:da:ea:8e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘james,10.200.50.100’ (RSA) to the list of known hosts.
check_apt 100% 332KB 332.1KB/s 00:00
check_breeze 100% 2254 2.2KB/s 00:00
check_by_ssh 100% 108KB 108.4KB/s 00:00
check_clamd 100% 93KB 92.9KB/s 00:00
check_cluster 100% 62KB 62.5KB/s 00:00
check_dhcp 100% 99KB 99.3KB/s 00:00
check_dig 100% 101KB 101.0KB/s 00:00
check_disk
…..

Add nagios users and group

[root@monk nrpe]# useradd nagios
[root@monk nrpe]# chown -R nagios:nagios /usr/local/nrpe/

Make sure that Nagios has all privs to scripts dir. Use visudo command.

[root@donuts ~]# grep “nagios” /etc/sudoers
nagios ALL=(ALL) NOPASSWD: /usr/local/nrpe/libexec/

Start Daemon

[root@monk nrpe]# ps -ef | grep nrpe
nagios 18401 1 0 15:13 ? 00:00:00 ./nrpe -d /usr/local/nrpe/nrpe.cfg
root 18403 18110 0 15:14 pts/1 00:00:00 grep nrpe

Verify nrpe on client is running on port 5666.

[root@monk nrpe]# netstat -ntla | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN

Test connection from nagios master

[root@james objects]# /usr/local/nagios/libexec/check_nrpe -H 10.200.1.11 -p5666
NRPE v2.12

*If you get a “Connection refused by host” then the deamon is not propertly running on the client.

Now run nrpe module to test.

[root@james objects]# /usr/local/nagios/libexec/check_nrpe -H 10.200.1.11 -p5666 -c check_disk
DISK OK – free space: / 128225 MB (51% inode=99%);| /=122419MB;211428;237857;0;264286

Note: When you run the test you must specify the name in the command[] brackets per the below!
command[check_disk]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10% -p /

Booya!!

enable cgi downtime scheduling in nagios

1. enable nagios.cmd access.
[root@james conf]# chmod -R 777 /usr/local/nagios/var/rw/[root@james conf]# ls -la /usr/local/nagios/var/rw/total 8drwxrwxrwx 2 nagios nagios 4096 Dec 29 12:51 .drwxrwxr-x 7 nagios nagios 4096 Dec 29 12:54 ..prwxrwxrwx 1 nagios nagios 0 Dec 29 12:54 nagios.cmdprwxrwxrwx 1 nagios nagios 0 Dec 27 16:02 nagios.cmd-old
2. add auth user to access cgi’s in cgi.cfg

use_authenticaiontion=1
add authenticated user (name of user logged in via .htaccess file) or * for all for following.

authorized_for_system_information=*authorized_for_configuration_information=*authorized_for_system_commands=*authorized_for_all_services=*authorized_for_all_hosts=*authorized_for_all_service_commands=*authorized_for_all_host_commands=*

3. nagios.cfg enable check_external_commands=1
4. restart nagios.

Setup htaccess protect.

Modify httpd.conf

[root@james html]# grep “AllowOverride All” -A 5 -B 5 /etc/httpd/conf/httpd.conf
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#

Restart apache

Add .htaccess file to /var/www/html/nagios

[root@james html]# cat > /var/www/html/nagios/.htaccess
AuthName “Nagios”
AuthType Basic
AuthUserFile /var/www/html/nagios/.htpasswd
require valid-user

Create user pass auth file

[root@james html]# htpasswd -c /usr/local/nagios/share/.htpasswd nagios
New password:
Re-type new password:
Adding password for user nagios

uyser/pass: nagios/k@tz31@B

*If have problems authenticating then check /var/log/httpd/error_log

HTTPD config

Add below lines to httpd.conf. Restart apache.

#needed to cgi access

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin/

<directory “/usr/local/nagios/sbin/”>
Options ExecCGI
AllowOverride AuthConfig
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/local/nagios/share/.htpasswd
Require valid-user

Alias /nagios/ /usr/local/nagios/share/
<directory “/usr/local/nagios/share”>
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all

Modify cgi.cfg

[root@james nagios]# grep “use_authentication” /usr/local/nagios/etc/cgi.cfg
use_authentication=0

Update contact info

[root@james objects]# grep “email” /usr/local/nagios/etc/objects/contacts.cfg
email jjest@u.washington.edu ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

Create hosts.cfg and hostgroup.cfg files

Add lines to /usr/local/nagios/etc/objects/nagios.cfg

[root@james objects]# grep “cfg_file” -A 1 -B 1 /usr/local/nagios/etc/nagios.cfg
# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

#added by jj
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg

Disable localhost.cfg file for simplicity.

[root@james objects]# grep “localhost.cfg” -B 2 ../nagios.cfg

# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

hosts.cfg

[root@james objects]# head /usr/local/nagios/etc/objects/hosts.cfg
define host{
use linux-server
host_name magnum
alias magnum
address 10.200.1.40
}

define host{
use linux-server
host_name monk

hosgroups.cfg

[root@james objects]# head /usr/local/nagios/etc/objects/hostgroups.cfg
define hostgroup{
hostgroup_name ssh-servers ; The name of the hostgroup
alias ssh-servers ; Long name of the group
members magnum,monk,kojak,quincy,scooby,stone,marlowe,rockford ;
}

Run pref light check for errors.

[root@james nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

[root@james objects]# /etc/init.d/nagios restart
Running configuration check…done.
Stopping nagios: done.
Starting nagios: done.

==================================

Troubleshooting

UUID Email Error:

—–Original Message—–
From: 4294967295@lenora.micro.washington.edu [mailto:4294967295@lenora.micro.washington.edu]
Sent: Tuesday, August 23, 2011 10:54 AM
To: root@lenora.micro.washington.edu
Subject: *** SECURITY information for lenora.micro.washington.edu ***

lenora.micro.washington.edu : Aug 23 10:53:56 : 4294967295 : unknown uid: 4294967295 ; TTY=unknown ; PWD=unknown ; COMMAND=/usr/local/nrpe/libexec/check_link_speed

Answer: User and group ‘nagios’ need to be added to system.

If running RHEL 4 u may get this error when trying to start nrpe client

[root@baretta nrpe]# ./nrpe -d /usr/local/nrpe/nrpe.cfg
./nrpe: error while loading shared libraries: requires glibc 2.5 or later dynamic linker

Resolution:

Configuring Plugins

check_snmp: http://wiki.nagios.org/index.php/Howtos:snmp

check_sensors: need to install lmsensors.

===============================================

NRPE Client Install for Windows

-Download appropriate cpu archiecture:
http://sourceforge.net/projects/nscplus/

example setup screen. no other config needed.

-verify service is running.

-modify NSC.ini file on client

C:Program FilesNSClient++NSC.ini

[Settings]
allowed_hosts=10.200.50.100,10.200.1.124

[NSCClient]

port=12489

[NRPE]
port=5666

-Check client connection

[root@james libexec]# /usr/local/nagios/libexec/check_nrpe -H green
I (0.3.7.493 2009-10-12) seem to be doing fine…

Sample COmmands:

[root@james libexec]# /usr/local/nagios/libexec/check_nt -H green -v UPTIME -p12489
System Uptime – 25 day(s) 1 hour(s) 10 minute(s)

[root@james libexec]# /usr/local/nagios/libexec/check_nt -H green -p 12489 -v USEDDISKSPACE -l c
c: – total: 33.89 Gb – used: 12.31 Gb (36%) – free 21.58 Gb (64%) | ‘c: Used Space’=12.31Gb;0.00;0.00;0.00;33.89

[root@james libexec]# /usr/local/nagios/libexec/check_nt -H green -p 12489 -v MEMUSE
Memory usage: total:5731.60 Mb – used: 433.79 Mb (8%) – free: 5297.80 Mb (92%) | ‘Memory usage’=433.79Mb;0.00;0.00;0.00;5731.60

[root@james libexec]# /usr/local/nagios/libexec/check_nt -H green -p 12489 -v CPULOAD -l 60,90,95
CPU Load 0% (60 min average) | ’60 min avg Load’=0%;90;95;0;100

-uncoment following in nagios.cfg on nagios server.

# Definitions for monitoring a Windows machinecfg_file=/usr/local/nagios/etc/objects/windows.cfg

Open Manage install for EQ nagios checks:

PNP4Nagios Graphing

Install RRD Tool First!

http://www.cyberciti.biz/faq/howto-install-rrdtool-on-rhel-linux/

yum install cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel

uncompress

[root@james rrdtool-1.3.1]# tar -xzvf rrdtool-1.3.1.tar.gz

configure

[root@james opt]# export PKG_CONFIG_PATH=/usr/lib/pkgconfig/
[root@james opt]# cd rrdtool-1.3.1
[root@james rrdtool-1.3.1]# ./configure

Result…

Config is DONE!

With MMAP IO: yes
Static programs: no
Perl Modules: perl_piped perl_shared
Perl Binary: /usr/bin/perl
Perl Version: 5.8.8
Perl Options: PREFIX=/usr/local/rrdtool-1.3.1 LIB=/usr/local/rrdtool-1.3.1/lib/perl/5.8.8
Ruby Modules:
Ruby Binary: no
Ruby Options: sitedir=$(DESTDIR)NONE/lib/ruby
Build Tcl Bindings: no
Build Python Bindings: no
Build rrdcgi: yes
Build librrd MT: yes
Link with libintl: yes

Libraries: -lxml2 -lcairo -lcairo -lcairo -lm -lcairo -lpng12 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

Type ‘make’ to compile the software and use ‘make install’ to
install everything to: /usr/local/rrdtool-1.3.1.

… that wishlist is NO JOKE. If you find RRDtool useful
make me happy. Go to http://tobi.oetiker.ch/wish and
place an order.

— Tobi Oetiker

Complete build…

make
make install

Install PNP4Nagios

[root@james pnp4nagios-0.6.6]# ./configure –datarootdir=/usr/local/nagios/share/pnp –with-rrdtool=/opt/rrdtool-1.3.1/src/rrdtool –sysconfdir=/usr/local/nagios/etc/pnp –with-perfdata-dir=/usr/local/nagios/share/perfdata
–with-perfdata-logfile=/usr/local/nagios/var/perfdata.log –with-perfdata-spool-dir=/usr/local/nagios/var/spool/perfdata

*** Configuration summary for pnp4nagios-0.6.6 08-07-2010 ***

General Options:
————————- ——————-
Nagios user/group: nagios nagios
Install directory: /usr/local/pnp4nagios
HTML Dir: /usr/local/nagios/share/pnp
Config Dir: /usr/local/nagios/etc/pnp
Location of rrdtool binary: /opt/rrdtool-1.3.1/src/rrdtool Version 1.3.1
RRDs Perl Modules: *** NOT FOUND ***
RRD Files stored in: /usr/local/nagios/share/perfdata
process_perfdata.pl Logfile: /usr/local/nagios/var/perfdata.log
Perfdata files (NPCD) stored in: /usr/local/nagios/var/spool/perfdata

Web Interface Options: ————————- ——————-
HTML URL: http://localhost/pnp4nagios
Apache Config File: /etc/httpd/conf.d/pnp4nagios.conf

Finish compile.

make
make install

*** Main program, Scripts and HTML files installed ***

Please run ‘make install-webconf’ to install the
web configuration file

Please run ‘make install-config’ to install sample
configuration files

Please run ‘make install-init’ if you want to use
BULK Mode with NPCD

Configuration

[root@james conf.d]# htpasswd -c nagiosadmin /usr/local/nagios/etc/htpasswd.users
New password:
Re-type new password:
Adding password for user /usr/local/nagios/etc/htpasswd.users

Review the options above for accuracy. If they look okay,
type ‘make all’ to compile.

WARNING: The RRDs Perl Modules are not found on your system
Using RRDs will speedup things in larger installations.

Nagios failover setup

Once you have nagios configured you can setup a failover setup where if the nagios master is offline then a standby slave will enable notifications and checking. Here are the setup notes and as custome script i wrote in pythong to achieve this.

the following command checks if nagios is running locally

[root@scrappy nagios]# /usr/local/nagios/libexec/check_nagios -F /usr/local/nagios/var/status.dat -e 1 -C ‘/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg’

NAGIOS OK: 1 process, status log updated 5 seconds ago

now, set in nrpe config as following on remote slave/master to verify is running. must restart nrpe on machine installed on to reread nrpe.cfg

command[check_nagios_failover]=/usr/local/nagios/libexec/check_nagios -F /usr/local/nagios/var/status.dat -e 1 -C ‘/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg’

test nrpe remote command.

[root@scrappy nagios]# /usr/local/nagios/libexec/check_nrpe -H james -c check_nagios_failover

NAGIOS OK: 15 processes, status log updated 0 seconds ago

modify nagios.cfg on nagios slave. restart nagios.

execute_service_checks=0

enable_notifications=0

check_external_commands=1

now set crontab on slave to check for master failure.

[root@scrappy etc]# crontab -l

* * * * * nagios /usr/local/nagios/set_slave_status.py > /dev/null

Create script and modify master ip.

#!/usr/bin/python
import os
import commands
import sys

master='james'
slave='scrappy'

tmp_file='/tmp/nagios-failover-state.txt'
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
now=commands.getoutput('date +%s')

<a href="mailto:email='email@domain.com'">email='</a><a href="mailto:email@domain.com">email@domain.com</a>'
out=commands.getoutput('/usr/local/nagios/libexec/check_nrpe -H '+master+' -c check_nagios_failover')

#if not 0, then master is down.
master_return_val=out.find('OK')
#store state information
def failover_save_state(x):
fh=open(tmp_file,'w')
fh.write(x)
fh.close()

def sync_nagios_files():
     os.system('rsync -av '+master+':/usr/local/nagios/etc/objects/* /usr/local/nagios/etc/objects/')
     os.system('/etc/init.d/nagios reload')
     print "Master conf files synced with Slave."

     #read current state information
     fh=open(tmp_file,'r')
     current_state=fh.readlines()
     fh.close()

     current_state=current_state[0]
     #enable or disable checks for hosts
     #print current_state

if master_return_val &lt;= 0 and current_state is not 'enabled':
     if current_state=='enabled':
          print "Nagios slave ("+slave+") is active. Nagios master ("+master+") is down. No state change"

     else:
          os.system('/usr/bin/printf "[%lu] ENABLE_NOTIFICATIONSn" '+now+' &gt; '+commandfile)
          os.system('/usr/bin/printf "[%lu] START_EXECUTING_HOST_CHECKSn" '+now+' &gt; '+commandfile)
          os.system('/usr/bin/printf "[%lu] START_EXECUTING_SVC_CHECKSn" '+now+' &gt; '+commandfile)
          os.system('echo elvis has left the building | mail -s "[Nagios] Master Down! Slave Enabled." '+email)
          print "Nagios Failover enabled"
          failover_save_state('enabled')
          sync_nagios_files()

     elif current_state is not 'disabled':
          if current_state=='disabled':
               print "Nagios master ("+master+") is enabled. No state change."
          else:
               os.system('/usr/bin/printf "[%lu] DISABLE_NOTIFICATIONSn" '+now+' &gt; '+commandfile)
               os.system('/usr/bin/printf "[%lu] STOP_EXECUTING_HOST_CHECKSn" '+now+' &gt; '+commandfile)
               os.system('/usr/bin/printf "[%lu] STOP_EXECUTING_SVC_CHECKSn" '+now+' &gt; '+commandfile)
               os.system('echo We are all out of donuts. | mail -s "[Nagios] Master Restored. Slave Disabled." '+email)
               print "Nagios master restored"
               failover_save_state('disabled')

sync_nagios_files()

make executable

[root@scrappy nagios]# chown nagios.nagios /usr/local/nagios/etc/set_slave_status.py
[root@scrappy etc]# chmod o=rwx set_slave_status.py