Thursday, May 3, 2012

Nagios production Deployment in Real Life in Short



Nagios is a system and network monitoring application.

Some of the many features of Nagios® include:



  • Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)
  • Monitoring of host resources (processor load, disk usage, etc.)
  • Simple plugin design that allows users to easily develop their own service checks
  • Parallelized service checks
  • Ability to define network host hierarchy using "parent" hosts, allowing detection of and distinction between hosts that are down and those that are unreachable
  • Contact notifications when service or host problems occur and get resolved (via email, pager, or user-defined method)
  • Ability to define event handlers to be run during service or host events for proactive problem resolution
  • Automatic log file rotation
  • Support for implementing redundant monitoring hosts
  • Optional web interface for viewing current network status, notification and problem history, log file, etc.
Related Programs
  • Munin - Munin is a networked resource monitoring tool that can help analyze resource trends and "what just happened to kill our performance?" problems. It is designed to be very plug and play. A default installation provides a lot of graphs with almost no work. Plugins for Xserve G4, G5 & Intel.
  • Centreon - Network, Systems and Application monitoring based upon the Open Source monitoring engine Nagios



Nagios Server Installation

Instructions for basic configuration of a Nagiosserver for monitoring servers, routers, applications and more.
Prerequisites
 

Install the Apache web server.
Install the neccessary graphic libraries:

yum -y install libpng-devel libjpeg-devel gd-devel

Requires libtool?
yum -y install libtool
Nagios Base Installation
Create a nagios user and group for the program to run under:

adduser nagios

Create the installation directory:
mkdir /usr/local/nagios
chown nagios.nagios /usr/local/nagios

Add the command file group and add the Apache user to it (in our case, that user is "nobody"):
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nobody
/usr/sbin/usermod -G nagcmd nagios

Downloadthe latest Nagios source code (3.2.1 at time of writing):

Run the configure script:
./configure --with-command-group=nagcmd

Compile and install the binaries:
make all
make install
make install-commandmode

If you want to use the included init scripts, install them into
/etc/rc.d/init.d:
make install-init
Initial Configuration
Install the sample configuration files:

make install-config

The sample files, installed in
/usr/local/nagios/etc will work for getting Nagios started with just one change. Edit /usr/local/nagios/etc/objects/contacts.cfgand change the email address of the nagiosadmincontact.


Web Interface

Apache VirtualHost Configuration

mkdir -p /var/websites/nagios/htdocs
mkdir -p /var/websites/nagios/logs

Add the following to /usr/local/apache2/conf/extra/http-vhost.conf:

# nagios Virtual Host Webinterface
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/websites/nagios/htdocs
ServerName nagios.yourdomain.com
ErrorLog /var/websites/nagios/logs/nagios-error.log
CustomLog /var/websites/nagios/logs/nagios-access.log combined
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
</VirtualHost>


OR

Lighttpd Configuration

If you are using Lighttpd instead of Apache, you'll need to make some modifications to your lighttpd.conf file.

Firstly, you'll need to ensure you have the required modules loaded. At a minimum, you will need:

server.modules = (
"mod_cgi",
"mod_auth",
"mod_alias",
)
<code>
alias.url = (
"/nagios/cgi-bin" => "/usr/local/nagios/sbin",
"/nagios" => "/usr/local/nagios/share"
)
$HTTP["url"] =~ "^/nagios/cgi-bin" {
cgi.assign = ( "" => "" )
}
Add the Authentication configuration:
$HTTP["url"] =~ "^/nagios/cgi-bin" {
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = "/usr/local/nagios/etc/htpasswd.users"
auth.require = ( "" => (
"method" => "basic",
"realm" => "Nagios Access",
"require" => "user=nagiosadmin"
)
)
}
$HTTP["url"] =~ "^/nagios" {
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = "/usr/local/nagios/etc/htpasswd.users"
auth.require = ( "" => (
"method" => "basic",
"realm" => "Nagios Access",
"require" => "user=nagiosadmin"
)
)
}






The Lighttpd wiki also has a Nagios installation tutorial.
Password Security

Create the password file and an admin user:
/usr/local/apache2/bin/htpasswd \
-c /usr/local/nagios/etc/htpasswd.users <username>

If you don't have the htpasswd program, you can always use one of the web-based programs to create entries for the /usr/local/nagios/etc/htpasswd.users file.

Want to be able to execute commands from the web interface? You'll need to edit /usr/local/nagios/etc/nagios.cfg to enable external 

commands:
check_external_commands=1



Check Plugins


The check plugins for Nagios are packaged separately from the main program so we'll need to download the latest version (version 1.4.14 at time of writing), compile and install those.

cd /extra/src

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz
tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14

If you are wanting to monitor network devices using SNMP, you'll need to make sure the net-snmp and net-snmp-utils packages are installed:

yum install net-snmp net-snmp-utils

Configure, compile and install the plugins, using a Redhat fix since we used CentOS:
./configure \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-redhat-pthread-workaround
make
make install


3rd-party Plugins

There are a variety of useful check plugins available asides from the stand Nagios plugin package. Most plug-ins can be found at NagiosExchange, a repository of plugins and addons.

Some of the specific plugins that are useful:
 
check_cups_queue - check the size/status of a queue on a CUPS print server
 
check_lpstat - check printers and print-queue length using lpstat
check_rbl - check if the host is on any of the public email blacklists.
check_ssl_certificate - check the expiration of an SSL certificate
check_clamav - check that ClamAV signatures are up-to-date

Apache web server plugins:
 
check_apachestatus.pl - A Nagios plugin that parses the status page of an apache server, the plugin returns the response time, the amount of idle, busy and open slots. 

The perfdata returns the status of all slots. Optionally you can specify how much slots should be available. See also Monitoring Apache Session load with Nagios through mod_status
 
check_apachestatus_auto.pl - parses the status page of an apache server, the plugin returns the response time, the amount of idle, busy, open and total slots. 

The perfdata returns the status of all slots including Requests/sec, Bytes/Request and Bytes/sec. Optionally you can specify how much slots should be available. 

Use http(s) and basic user authentication with non standard server-status urls.
 
check_apache2.sh - check the Apache's server status via the famous mod_status. 

Make sure, that you have permissions to access 

http://yourserver:port/server-status and that the Nagios User has the right to call 'ps ax' and 'ps -Ao pcpu,args', otherwise the script refuses to work.
 
SNMP Interface check - Checks by snmp host interface state and usage.
Requires that the Net::SNMP module for Perl is installed.
 
cd /usr/local/nagios/libexec
wget http://nagios.manubulon.com/check_snmp_int.pl
chmod ugo+x check_snmp_int.pl


eg

check_clam_version

This plugin queries ClamAV and checks if the version is up-to-date or not based on the value. Information on the plugin can be found here.

cd /usr/local/nagios/libexec

wget http://fupps.com/code/sundry/clamnag.pl
chmod ug+x clamnag.pl
chown nagios:nagios clamnag.pl

To add the check plugin to your NRPE config, edit /usr/local/nagios/etc/nrpe.cfg

command[check_clam_version]=/usr/local/nagios/libexec/clamnag.pl
Add an NRPE service check on your Nagios server.


check_daemontools_service

OpenFusion has a set of Nagios plugins which include a 
check_daemontools_plugin. A copy of the specific plugin is also available here.

Installation

Download the plugin:
cd /usr/local/nagios/libexec



wget http://www.productionmonkeys.net/sites/productionmonkeys.net/files/nagios/check_daemontools_service

chmod ugo+x check_daemontools_service
chown nagios:nagios check_daemontools_service

The latest version fo the plugin requires the Nagios::Plugin::Getopt and 

Nagios::Plugin::Functions modules for Perl be installed:
perl -MCPAN -e shell

install Nagios::Plugin::Getopt
install Nagios::Plugin::Functions

exit

The check command takes the syntax of

check_daemontools_service -s <service> [-c <crit_secs>] [-w <warn_secs>][-v]

. The warning and critical times can be adjusted to your preference. 

Given that if a daemontools service will have a run time of less than 2 seconds if it hasn't started, the critical time can be set quite low. 

Edit /usr/local/nagios/etc/nrpe.cfg and add entries for the services you want to check, such as:

command[check_daemon_smtp]=/usr/local/nagios/libexec/check_daemontools_service -s /service/smtp -w 15 -c 5

Restart NRPE

Non-root access to svstat
<code>svstat

must be run as the root user in order to check service status. Edit /etc/sudoers and add an entries for the Nagios user:

nagios ALL=(ALL) NOPASSWD:/usr/local/bin/svstat

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

/check_daemontools_service



Nagios Server Configuration

Since you should have figured out how to install a Nagios server in the first place, I'm not going to provide you with instructions on how to configure a host or service entry for your mail server other than the syntax for the service check_command would be 

check_nrpe!check_daemon_smtp


Troubleshooting

My latest install of this had difficulty locating the svstat executable. I ended up creating a symbolic link to it in /usr/bin:

ln -s /usr/local/bin/svstat /usr/bin/svstat


check_qmailq

The original plugin is from http://www.openfusion.com.au/labs/nagios/

Download the check plugin:

cd /usr/local/nagios/libexec

wget http://www.dwadson.com/files/nagios/check_qmailq

chmod ugo+x check_qmailq

The check command takes the syntax of check_qmailq -w count -c count [-W pre_count] [-C pre_count] [-q /path/to/qmail-qstat]. The warning and critical message counts can be adjusted to your preference. 

Edit /usr/local/nagios/etc/nrpe.cfg and add entries for the services you want to check, such as:

command[check_qmailq]=/usr/local/nagios/libexec/check_qmailq -w 25 -c 50

Restart NRPE

Nagios user permissions to access Qmail queue

In order to access the Qmail queue, the Nagios user needs to be added to the qmail group. Since that user only has read access to the queue, this isn't a security risk (or at least much of one...). Edit /etc/group:
qmail:x:162:nagios

Nagios Server Configuration

Since you should have figured out how to install a Nagios server in the first place, I'm not going to provide you with instructions on how to configure a host or service entry for your mail server other than the 

syntax for the service check_command would be check_nrpe!check_qmailq



Check_mk

Check_mk adopts a new a approach for collecting data from operating systems and network components. It obsoletes NRPE, check_by_ssh, 

NSClient and check_snmp. It has many benefits, the most important of which are: significant reduction of CPU usage on the Nagios host and automatic inventory of items to be checked on hosts.

Client installation

cd /extra/src
wget http://mathias-kettner.de/download/check_mk-agent-1.1.3-1.noarch.rpm


NRPE

The NRPE addon is designed to allow you to execute Nagios plugins on remote Linux/Unix machines. The main
reason for doing this is to allow Nagios to monitor "local" resources (like CPU load, memory usage, etc.) on
remote machines. Since these public resources are not usually exposed to external machines, an agent like
NRPE must be installed on the remote Linux/Unix machines.



NRPE Installation

On the remote server, download the latest source tarball of the NRPE add-on (2.12 at time of writing):

mkdir -p /extra/src

cd /extra/src

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz

tar zxvf nrpe-2.12.tar.gz

cd nrpe-2.12

NRPE will need a user to run as. In this example for Redhat, we'll add a 

"nagios" user that isn't allowed to actually log in.
useradd -s /bin/false nagios

In order to run NRPE under daemontools, we need to patch it to run in the foreground. The following patch is a modification of one posted on the nagios-devel mailing list, modified for the current version of NRPE:

wget http://productionmonkeys.net/sites/productionmonkeys.net/files/nrpe_foreground.patch
patch -p0 < nrpe_foreground.patch







Configure, compile, and install NRPE:

./configure

make all

make install

Adjust the permission on the Nagios directories:

chown nagios:nagios /usr/local/nagios

chown -R nagios:nagios /usr/local/nagios/libexec

Copy the sample config file:

mkdir /usr/local/nagios/etc
 
chown nagios:nagios /usr/local/nagios/etc

cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg

Check Plugins
NRPE does not come with any check plugins - you'll need to install them with the same procedure as for a full Nagios server install.


Configuration

The configuration file, /usr/local/nagios/etc/nrpe.cfg will need to be modified in order to work.

FIrstly, the allowed_hosts must be modified to include the IP address of your Nagios server.
allowed_hosts=127.0.0.1,<nagios server ip address>

Then, you'll need to configure which checks you want to be made on the server. The sample config has checks for users, disk space, CPU load, etc. already enabled. You can modify those to suit your needs, or add your own plugins.

Automatic Startup

We're going to use daemontools. If you haven't already, install daemontools.

Create a directory for the NRPE service:

mkdir -m 1755 /var/service/nrpe

cd /var/service/nrpe

Create the run script and make it executable:

echo '#!/bin/sh' > run
echo 'exec 2>&1' >> run
echo 'exec /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d -f' >> run

chmod 755 run

Our log script comes from John Simpson's:
mkdir -m 755 log

cd log

wget http://qmail.jms1.net/scripts/service-any-log-run

mv service-any-log-run run

chmod 755 run

Finally, add the service to daemontools by creating the symbolic link in 

/service

ln -s /var/service/nrpe /service/nrpe
Confirm that the service is running:
svstat /service/nrpe /service/nrpe/log





Nagios Server Configuration

Your Nagios server needs the NRPE plug-in installed in order to query the remote server. Download the source tarball as per above, then:
./configure
make all
make install-plugin
The command definitions on your Nagios server needs to include NRPE.:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}




Automatic Startup


Control the running of your Nagios server using init scripts or daemontools.

Init Script

If you installed the included startup scripts, add them to the system services and have it automatically start at system boot:

chkconfig --add nagios

chkconfig nagios on

Verify your initial Nagios configuration:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
And if there are no errors, you can control Nagios with:
/etc/rc.d/init.d/nagios {start|stop|restart|reload|force-reload|status}
or
service nagios {start|stop|restart|reload|force-reload|status}

Daemontools

These instructions show how to use daemontools. If you just want to use an init script, read the Nagios documentation - init scripts are provided.

If you haven't already, install daemontools.

Then, create a directory for the Nagios service:

mkdir -m 1755 /var/service/nagios

cd /var/service/nagios

Create a run script and make it executable:
#!/bin/sh
nagiosDir=/usr/local/nagios
exec 2>&1
exec $nagiosDir/bin/nagios $nagiosDir/etc/nagios.cfg 2>&1
Then make the script executable:
chmod 755 run

Our log script comes from John Simpson's:

mkdir -m 755 log

cd log

wget http://qmail.jms1.net/scripts/service-any-log-run

mv service-any-log-run run

chmod 755 run

Finally, add the service to daemontools by creating the symbolic link in /service

ln -s /var/service/nagios /service/nagios
Confirm that the service is running:
svstat /service/nagios /service/nagios/log



Advanced Configuration



Nagios configuration and Subversion

Using a version control system such as Subversion can make editing your configuration files more manageable. You'll be able to keep track of what revisions, roll back to old versions, edit the files using your favourite text editor, etc.

To start, your Nagios server will need to have the SVN client installed on it.

Assuming you've installed a Subversion (and Trac) server according to our directions, on the svn server create a base set of folders to hold your initial import:

cd /tmp
mkdir nagios-config

cd nagios-config
mkdir branches trunk tags

Copy the entire /usr/local/nagios/etc directory, including all files and subdirectories, from your Nagios server into /tmp/nagios-config/trunk/ on your svn server.

Once you've gotten the files copied, on the svn server, create a project from /tmp/nagios-config as per these instructions.

On your Nagios server, move your original config files:
cd /usr/local/nagios
mv etc etc.orig

Then checkout the copy from your svn server:
svn checkout http://<your_svn_server>/svn/nagios-config/trunk .

You can now work with your Nagios config using your favourite SVN tools.

Contacts and Contactgroups
Hosts and Hostgroups
Lilac
Service and Servicegroups
Timeperiods


Contacts and Contactgroups

Contact definitions will be saved in /usr/local/nagios/etc/contacts.cfg. If you have a lot of contacts and groups, you might want to split the contact group definitions into a separate file: /usr/local/nagios/etc/contactgroups.cfg.
define contactgroup{
contactgroup_name admins
alias Administrators
members dwadson
}
define contact{
contact_name dwadson
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email,notify-by-epager
host_notification_commands host-notify-by-email,host-notify-by-epager
email <email address>
pager <pager address>
}




Hosts and Hostgroups

Host definitions will be saved in /usr/local/nagios/etc/hosts.cfg.
define host{
host_name Bogus-server
alias Bogus Server #1
address 192.168.1.12
check_command check-host-alive
max_check_attempts 5
check_period 24x7
process_perf_data 0
contact_groups admins
notification_interval 30
notification_period 24x7
notification_options d,u,r
}
Depending on many services you plan on monitoring, it might be easier to store host group definitions in a separate file: /usr/local/nagios/etc/hostgroups.cfg. Otherwise, you can simply include them in /usr/local/nagios/etc/host.cfg
define hostgroup{
hostgroup_name mail
alias Mail Servers
members mailserver1,mailserver2
}




Service and Servicegroups
Posted in
nagios
Service definitions will be saved in /usr/local/nagios/etc/services.cfg.
By using templates, you can simplify the entries for individual services by not having repeated entries for common settings.

# Generic service definition template - This is NOT a real service, just a template!
define service{
name generic-service
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 60
notification_period none
register 0
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 1
check_freshness 0
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
failure_prediction_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
register 0
}
Now, the actual service definition can be much shorter:
define service{
use generic-service
host_name <name>
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
Since the number of services being defined might grow large, it's probably easier to store service group definitions in a separate file, if you choose to use them: /usr/local/nagios/etc/servicegroups.cfg.
define servicegroup{
servicegroup_name smtp
alias SMTP Servers
members mailserver1,SMTP,mailserver2,SMTP
}




 Timeperiods

Time Period definitions will be saved in /usr/local/nagios
/etc/timeperiods.cfg.

define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}
define timeperiod{
timeperiod_name workhours
alias "Normal" Working Hours
monday 08:30-17:00
tuesday 08:30-17:00
wednesday 08:30-17:00
thursday 08:30-17:00
friday 08:30-17:00
}
define timeperiod{
timeperiod_name nonworkhours
alias Non-Work Hours
sunday 00:00-24:00
monday 00:00-08:30,17:00-24:00
tuesday 00:00-08:30,17:00-24:00
wednesday 00:00-08:30,17:00-24:00
thursday 00:00-08:30,17:00-24:00
friday 00:00-08:30,17:00-24:00
saturday 00:00-24:00
}
define timeperiod{
timeperiod_name none
alias No Time Is A Good Time
}











Lilac

Lilacis a configuration tool for Nagios, the industry standard in open source monitoring. Lilac makes configuration easy with simple to use screens and tools for auto-discovery and importing of existing configurations.

Prerequisites

PDO MySQL requires libtool:

yum install libtool-ltdl-devel

Then compile PHP with PDO MySQL and Process Control by adding these options to your ./configure:
--with-pdo-mysql=/usr/local/mysql \
--enable-pcntl

In order to use the Auto Discovery feature of Lilac, install Nmap
yum install nmap
In order to run nmap and the Nagios binary, Lilac needs access to do so. Since Nagios needs to be run by root, we need to set this up with sudo. 

Edit
/etc/sudoers</etc>:
<code>
#Defaults requiretty
nobody ALL=(ALL) NOPASSWD: /usr/bin/nmap
nobody ALL=(ALL) NOPASSWD: /usr/local/nagios/bin/nagios
Installation

Download the latest source
cd /extra/src
wget http://www.lilacplatform.com/trac/downloads/5 -O lilac-1.0.3.tar.gz
tar zxf lilac-1.0.3.tar.gz

Move it to the web root:
mv lilac-1.0.3 /var/websites/nagios/htdocs/lilac
Access it from your web browser



NDOutils

The NDOUTILS addon is designed to store all configuration and event data from Nagios in a database. Storing information from Nagios in a database will allow for quicker retrieval and processing of that data and will help serve as a foundation for the development of a new PHP-based web interface in Nagios 3.0.

Prerequisites

MySQL must be installed. Having had nothing but grief getting 
DB::mysql to install with a source installation of MySQL 5.0x, the easiest thing to do was just install MySQL server via yum:

yum install mysql-server mysql-devel

That also took care of installing DB::mysql for Perl.
ndoutils Installation

Download the latest version of the NDOUTILS:

cd /extra/src
wget http://umn.dl.sourceforge.net/sourceforge/nagios/ndoutils-1.4b7.tar.gz
tar zxvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
Configure and compile the code:
./configure
make

Database Initialization

Create a database and user in MySQL - the easiest way is to use 

phpMyAdmin to add a user named nagios and a database of the same name that the user has privileges on. Or, create the database manually:

mysql -u root -p
CREATE DATABASE nagios;
GRANT all privileges on nagios.* to nagios@"localhost" identified by 'passwrd';

Once that is done, run the DB installation script in the db/ subdirectory of the NDO distribution to create the necessary tables in the database:

cd /extra/src/ndoutils-1.4b7
cd db
./installdb

Install the NODMOD broker module
Copy the compiled broker module to your Nagios directory:
cp src/ndomod-2x.o /usr/local/nagios/bin/ndomod.o

Copy the sample NDOMOD config file to your Nagios installation after modifying it to suit your needs:
cp config/ndomod.cfg /usr/local/nagios/etc

Add a line to the main Nagios config file /usr/local/nagios/etc/nagios.cfg:

broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg

In order for the Nagios daemon to send information to the NDOMOD module, make sure you have a line in there that reads:
event_broker_options=-1

Installing the NDO2DB daemon

Copy the compiled NDO2DB daemon to your Nagios installation:
cp src/ndo2db-2x /usr/local/nagios/bin/ndo2db

Copy the sample NDO2DB config file to your Nagios installation after modifying it to suit your needs (i.e. the database settings):

cp config/ndo2db.cfg /usr/local/nagios/etc/
Start the daemon running (no init script yet)
/usr/lo


NagVis

NagVis can be used to visualize Nagios Data, e.g. to display IT processes like a mail system or a network infrastructure.

Key features are:
Display of single Hosts or Services
Display the state of a Host dependent on the state of its services (“recognize services”)
Visualize a complete Host- oder Servicegroup with one icon
Define Sub-Map icons wich represent a complete NagVis Map of Hosts/Services/Groups in one icon (drill down)
Visualization of complete IT Processes using self drawn graphics

Prerequisites

The ndoutils must be installed
PHP must be installed. Since our ndoutils were installed with an RPM verison of MySQL and Apache was installed from source, our PHP configure line was:

./configure --with-apxs2=/usr/local/apache2/bin/apxs

Installation

Download the source:

cd /extra/src
wget http://internap.dl.sourceforge.net/sourceforge/nagvis/nagvis-1.2.1.tar.gz
tar zxvf nagvis-1.2.1.tar.gz

Place the NagVis directory tree into your Nagios share Folder (usally /usr/local/nagios/share).
mv nagvis-1.2.1 /usr/local/nagios/share/nagvis




Copy the configuration file:

cd /usr/local/nagios/share/nagvis
cp etc/nagvis.ini.php-sample etc/nagvis.ini.php

Edit /usr/local/nagios/share/nagvis/etc/nagvis.ini.php and set the appropriate info for your MySQL server.

Set the permission on the nagvis directories:

chown nobody:nobody /usr/local/nagios/share/nagvis -R
chmod 664 /usr/local/nagios/share/nagvis/etc/nagvis.ini.php
chmod 775 /usr/local/nagios/share/nagvis/nagvis/images/maps
chmod 664 /usr/local/nagios/share/nagvis/nagvis/images/maps/*
chmod 775 /usr/local/nagios/share/nagvis/nagvis/etc/maps
chmod 664 /usr/local/nagios/share/nagvis/nagvis/etc/maps/*
Start the daemon:
/usr/local/nagios/bin/ndo2db-2x -c /usr/local/nagios/etc/ndo2db.cfg
Access the web config tool at http://<nagiosserver>/<path-to-nagvis>/config.php



PNP4Nagios
 
PNP is an addon to Nagios which analyzes performance data provided by plugins and stores them automatically into RRD-databases

Prerequisites

    RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. Use it to write your custom monitoring shell scripts or create whole applications using its Perl, Python, Ruby, TCL or PHP bindings.
    Our CentOS server needed a few devel libraries installed for RRDtool:
    yum -y install cairo-devel glib2-devel pango-devel

    Download the latest source for RRDtool
    cd /extra/src
    wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.3.tar.gz
    tar zxf rrdtool-1.4.3.tar.gz
    cd rrdtool-1.4.3

    Configure it with a few adjustments for our setup:
    ./configure --prefix=/usr/local/rrdtool

    If everything is ok, then build and install it
    make
    make install
    Zlib support for PHP - --with-zlib

Installation
Download the latest version of PNP4Nagios:
cd /extra/src
wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.3.tar.gz/download
tar zxf pnp4nagios-0.6.3.tar.gz
cd pnp4nagios-0.6.3

Configure it:
./configure \
--with-rrdtool=/usr/local/rrdtool/bin/rrdtool \
--with-httpd-conf=/usr/local/apache2/conf/extra \
--with-perl_lib_path=/usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi

Then build and install:
make all
make install

Copy the sample config files:
make install-config

Add pnp4nagios to your Apache configuration:

    Install the Apache config file into /usr/local/apache2/conf/extra/pnp4nagios.conf:
    make install-webconf

    Then edit /usr/local/apache2/conf/httpd.conf and add a line to load the PNP4Nagios conf file:
    Include conf/extra/pnp4nagios.conf
    orcan add the contents of src/httpd.conf to your Nagios VirtualHost directive:
    Alias /pnp4nagios "/usr/local/pnp4nagios/share"

    <Directory "/usr/local/pnp4nagios/share">
      AllowOverride None
      Order allow,deny
      Allow from all
      #
      # Use the same value as defined in nagios.conf
      #
      AuthName "Nagios Access"
      AuthType Basic
      AuthUserFile /usr/local/nagios/etc/htpasswd.users
      Require valid-user
      <IfModule mod_rewrite.c>
        # Turn on URL rewriting
        RewriteEngine On
        Options FollowSymLinks
        # Installation directory
        RewriteBase /pnp4nagios/
        # Protect application and system files from being viewed
        RewriteRule ^(application|modules|system) - [F,L]
        # Allow any files or directories that exist to be displayed directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Rewrite all other URLs to index.php/URL
        RewriteRule .* index.php/$0 [PT,L]
      </IfModule>
    </Directory>

Access the PNP4Nagios Environment Tests by going to http:///pnp4nagios. If it passes all the tests, remove the install.php file:
rm /usr/local/pnp4nagios/share/install.php

NPCD Daemon
We're going to use daemontools. If you haven't already, install daemontools.
Copy the sample NPCD config file:
cp /usr/local/pnp4nagios/etc/npcd.cfg-sample /usr/local/pnp4nagios/etc/npcd.cfg

Create a directory for the NRPE service:
mkdir -m 1755 /var/service/npcd
cd /var/service/npcd

Create the run script and make it executable:
echo '#!/bin/sh' > run
echo 'exec 2>&1' >> run
echo 'exec /usr/local/pnp4nagios/bin/npcd -f /usr/local/pnp4nagios/etc/npcd.cfg' >> run
chmod 755 run

Our log script comes from John Simpson's:
mkdir -m 755 log
cd log
wget http://qmail.jms1.net/scripts/service-any-log-run
mv service-any-log-run run
chmod 755 run

Finally, add the service to daemontools by creating the symbolic link in /service
ln -s /var/service/npcd /service/npcd

Confirm that the service is running:
svstat /service/npcd /service/npcd/log

Data Collection

Nagios needs to be configured to trigger the data collector by editing /usr/local/nagios/etc/nagios.cfg and editing/uncommenting some lines:
process_performance_data=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata

Edit /usr/local/nagios/etc/objects/commands.cfg and remove the existing process-service-perfdata and process-host-perfdata commands. Then add the new PNP4Nagios commands for service and host performance data logging:
 
define command {
       command_name    process-service-perfdata
       command_line    /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
}

define command {
       command_name    process-host-perfdata
       command_line    /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}

Nagios Web Front-End Integration
 
In order to easily view the graphs from your Nagios server, we can take advantage of Nagios' external URL features in extended info configs. There are two ways of doing it - regular links or Javascript pop-ups:

    Regular Links
 
    Edit /usr/local/nagios/etc/objects/templates.cfg and add:
 
    # PNP4Nagios host/service definitions
    define host {
       name       host-pnp
       action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_
       register   0
    }

    define service {
       name       srv-pnp
       action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
       register   0
    }

    Javascript pop-ups
 
    Copy status-header.ssi to your Nagios web files:
 
    cp /extra/src/pnp4nagios-0.6.3/contrib/ssi/status-header.ssi \
    /usr/local/nagios/share/ssi/

    Edit /usr/local/nagios/etc/objects/templates.cfg and add:
 
    define host {
       name       host-pnp
       action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_
       register   0
    }

    define service {
       name       srv-pnp
       action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
       register   0
    }

To use them, add them to your host/service definitions with something similiar to:

define host{
        use                     linux-server,host-pnp    ; Name of host templates to use
                                                         ; This host definition will inherit all variables that are defined
                                                         ; in (or inherited by) the linux-server host template definition.
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }

define service{
        use                     local-service,srv-pnp   ; Name of service template to use
        host_name               localhost
        service_description     PING
        check_command           check_ping!100.0,20%!500.0,60%
        }






Statusmap Icons

The base install of Nagios doesn't have any fancy icons for use on the statusmap so we'll add some to make a nicer display.

NagiosExchange has a nice collection of image packs. If you want, you can create your own, but we're going to use a pre-made set of generic icons for routers, servers, etc. Whatever the case, download your icons to /usr/local/nagios/share/images/logos. For the statusmap, you must have icons in the GD2 format.

To enable the icons, we'll create an extended host info file to contain the extra details our hosts will need at /usr/local/nagios/etc/hostextinfo.cfg.

At this point, we aren't going to bother with map coordinates, notes or any Extended Host Information options other than statusmap_image. So the basic definition will be:

define hostextinfo{
host_name <host alias>
icon_image <icon image filename>
vrml_image <icon image filename>
statusmap_image <statusmap image>.gd2
}

No comments:

Post a Comment