008. Nagvis Installation

Tested On

OS: CentOS 6.2 x86_64
Nagios Version: 3.5
Nagvis Version: 1.7.7
Hardware: Virtual Machine (VMware Server 2.0.0.2712)

About

Nagvis is an visualization addon for Nagios that can create beautiful maps for Nagios objects.

Prerequisite

  • Install Nagios server

Nagios Installation

  • we need to install the folllowing prerequisites packages: rrdtool perl-GD
yum install php-gd php-mbstring graphviz gcc-c++ rsync -y

Install and configure mk-livestatus

  • Download and install mk-livestatus
cd /usr/local/src/nagios/
wget http://mathias-kettner.de/download/mk-livestatus-1.2.2p2.tar.gz -O mk-livestatus.tar.gz
tar zxvf mk-livestatus.tar.gz
cd mk-livestatus-*
./configure && make && make install
  • Add the following lines to Nagios configuration file to configure nagios to load livestatus module
vi /usr/local/nagios/etc/nagios.cfg
...
broker_module=/usr/local/lib/mk-livestatus/livestatus.o /usr/local/nagios/var/rw/live
event_broker_options=-1
...
  • Reload Nagios
/etc/init.d/nagios reload

Install Nagvis

  • Download Nagvis
cd /usr/local/src/nagios/
wget "http://downloads.sourceforge.net/project/nagvis/NagVis%201.7/nagvis-1.7.9.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnagvis%2Ffiles%2FNagVis%25201.7%2F&ts=1378635410&use_mirror=garr" -O nagvis.tar.gz
tar zxf nagvis.tar.gz
cd nagvis-*
  • Start Nagvis installation
chmod +x install.sh
./install.sh -n /usr/local/nagios -p /usr/local/nagvis -l "unix:/usr/local/nagios/var/rw/live" -b mklivestatus -u apache -g apache -w /etc/httpd/conf.d -a y
  • Reload apache
service httpd reload

Nagvis installation completed.

Browse to http://nagios_server_ip_address/nagvis to configure new maps
Please visit http://www.nagvis.org/ for information about Nagvis configuration and usage.

006. NCONF Upgrade

OS: Ubuntu 9.10 x86_64
Nagios Version: 3.2.3 -> 3.3.1
Hardware: VMware Virtual Platform

About

As newer releases of NCONF are released they contain a lot of bug fixes and new features, so you realy should consider to  upgrade your NCONF and stay up to date.

Prerequisite

  • Nagios Backup – Create a backup for Nagios and NCONF
  • Check that you can roll back from backup if anything goes wrong

Upgrading NCONF Core

  • Download NCONF and extract
mkdir -p /usr/local/src/nagios
cd /usr/local/src/nagios
wget http://sourceforge.net/projects/nconf/files/nconf/1.3.0-0/nconf-1.3.0-0.tgz -O nconf.tgz
tar zxvf nconf.tgz
  • Copy Nconf extracted folder to /usr/local/nagios/share
cp -r nconf/* /usr/local/nagios/share/nconf/
  • Give permission to the webserver user on nconf folder
chown -R www-data:www-data /usr/local/nagios/share/nconf
  • Give execute permission to nconf/bin/* files
chmod  775 /usr/local/nagios/share/nconf/bin/*
  • Start interactive installation process by browsing to http://nconf_server_ip/nagios/nconf/UPDATE.php
    • Welcome to NConf update 1.3.0 – This page will check if your computer have all Nconf requirements installed -> Click Next if all OK
    • MySQL database configuration – In this page you will need to enter Nconf DB host, DB name, DB user and DB password you set earlier -> Click Next when you finish -> Click Next again if all OK
    • Click Convert to convert all your timeperiods, nagios-collector and nagios-monitor attributes that was removed in this release
    • After the convert script completed successfully click Next -> and if all OK again click Next
    • Please carefully examine the following release notes for additional update instructions -> Click Next
    • Update complete – In this step you need to go back to the Nconf server shell and remove the following files and directories: INSTALL, INSTALL.php, UPDATE, UPDATE.php -> Click finish
cd /usr/local/nagios/share/nconf
rm –rf INSTALL INSTALL.php UPDATE UPDATE.php call_ajax.php
  • Create symbolic link for Nagios bin file
ln -s /usr/local/nagios/bin/nagios /usr/local/nagios/share/nconf/bin/nagios
  • Add permission for nagios configuration files
chmod -R 775 /usr/local/nagios/etc
  • Create deployment configuration for Nconf generated files
vi /usr/local/nagios/share/nconf/config/deployment.ini
...
;; LOCAL deployment ;;
[deploy config]
type = local
source_file = "/usr/local/nagios/share/nconf/output/NagiosConfig.tgz"
target_file = "/usr/local/nagios/etc/"
action = extract
reload_command = sudo -u nagios /etc/init.d/nagios reload
...
  • Add nagios reload command to apache user and remove the default reuiqre tty setting in sudo configuration file
visudo
...
www-data ALL = (nagios) NOPASSWD: /etc/init.d/nagios reload
  • Add the following variables in NCONF configuration file
vi /usr/local/nagios/share/nconf/config/nconf.php
....
define('CHECK_UPDATE', 1);
define("DEBUG_GENERATE", 3); # [1=ERROR|2=WARN|3=INFO|4=DEBUG|5=TRACE]
define('ALLOW_DEPLOYMENT', 1);
define('CHECK_STATIC_SYNTAX', 1);
...

NCONF upgrade completed. Browse to http://nagios_server_ip_address/nagios/nconf and check out the new version.

Please visit http://www.nconf.org for more information.

004. Nagios Backup

OS: Ubuntu 9.10 x86_64
Nagios Version: 3.3.1
Hardware: VMware Virtual Platform

About

As newer releases of Nagios are released they contain a lot of bug fixes and new features, so you realy should consider to  upgrade your Nagios and stay up to date.

Prerequisite

Backup Nagios Core

  • On Nagios Server create the following backup script:
mkdir -p /usr/local/nachum234
vi /usr/local/local/nachum234/files_backup
#!/bin/bash
#
##################################################
#
# Global Variables
#
##################################################
SCRIPT_NAME=`basename $0`
BACKUP_TOOL=/bin/tar
DIRS="/usr/local/nagios"
BACKUP_PATH=/backup/nagios
[email protected]
LOG_DIR=/var/log/${SCRIPT_NAME}
LOG_FILE=${LOG_DIR}/${SCRIPT_NAME}.log
DAY_OF_MONTH=`date +%d`
##################################################
#
# Functions
#
##################################################
function validation
{
        # check that log dir exist
        if [ ! -d ${LOG_DIR} ]
        then
                mkdir -p ${LOG_DIR}
                err_handle $? "mkdir -p ${LOG_DIR}"
        fi
        # check that backup dir exist
        if [ ! -d ${BACKUP_PATH} ]
        then
                write_log "Error: backup dir ${BACKUP_PATH} does not exist!"
                exit 1
        fi
        # check that day of the month directory exist under backup directory
        if [ ! -d ${BACKUP_PATH}/${DAY_OF_MONTH} ]
        then
                mkdir -p ${BACKUP_PATH}/${DAY_OF_MONTH}
                err_handle $? "mkdir -p ${BACKUP_PATH}/${DAY_OF_MONTH}"
        fi
}
##################################################
function write_log
{
        echo "`date +%F_%T` $*" >> ${LOG_FILE}
}
##################################################
function err_handle
{
        ERR=$1
        COMMAND=$2
        if [ ${ERR} = 0 ]
        then
                write_log "command ${COMMAND} completed successfully"
        else
                write_log "Error: command ${COMMAND} failed with error code=${ERR}"
                cat ${LOG_FILE} | mail -s "${SCRIPT_NAME} script on `hostname` failed!" ${EMAIL}
                exit 2
        fi
}
##################################################
function backup_dir
{
        DIR_NAME=$1
        BACKUP_DIR=$2

        write_log "start backup ${DIR_NAME} repository"
        ${BACKUP_TOOL} -zcf ${BACKUP_DIR} ${DIR_NAME} > /dev/null 2>&1
        err_handle $? "${BACKUP_TOOL} -zcf ${BACKUP_DIR} ${DIR_NAME}"
        write_log "finish backup ${DIR_NAME} repository"
}
##################################################
#
# Main
#
##################################################
validation
write_log "------------- Start backup script -----------------------"
for DIR in ${DIRS}
do
        backup_dir "${DIR}" "${BACKUP_PATH}/${DAY_OF_MONTH}/`basename ${DIR}`.tar.gz"
done
write_log "-------------- Finish backup script ----------------------"
  • Set Global Variables section in the script (Email address, Backup path, etc…)
  • Create Backup directory
mkdir -p /backup/nagios
  • Run backup and check that it created the tar file and check the script log file
cd /usr/local/nachum234/
./files_backup
ls /backup/nagios/* 
less /var/log/files_backup/files_backup.log
  • Schedule Backup to run every day with Cron
ln -s /usr/local/nachum234/files_backup /etc/cron.daily/
  • Create logrotate entry for the script log file
vi  /etc/logrotate.d/files_backup
/var/log/files_backup/files_backup.log {
    weekly
    rotate 10
    notifempty
    missingok
}

Now your Nagios backup is set up. The script will run every day and will create a backup in day of the month directory in BACK_PATH, it will purge an old backup if it already exist in the day of the month directory. The script is saving the backup for one month only.

Backup NCONF

If you are using Nagios with NCONF (configuration front-end for Nagios), you should Backup NCONF also.

Prerequisite

  • Nagios Backup
  • NCONF Installation – Web application for creating Nagios configuration files

Backup NCONF

NCONF data is in a MySQL database so you need to backup  your MySQL database.

  • Create the following script
vi /usr/local/nachum234/mysql_backup
#!/bin/bash
#
# Global Variables
#
##################################################
SCRIPT_NAME=`basename $0`
LOG_DIR=/var/log/${SCRIPT_NAME}
LOG_FILE=${LOG_DIR}/${SCRIPT_NAME}.log
MYSQLDUMP=/usr/bin/mysqldump
BACKUP_DIR=/backup/nagios
[email protected]
DAY_OF_MONTH=`date +%d`
BACKUP_FILE_NAME=nconf.sql
##################################################
#
# Functions area
#
##################################################
function check_validation
{
        if [ ! -d ${LOG_DIR} ]
        then
                mkdir -p ${LOG_DIR}
                write_log "create log directory ${LOG_DIR}"
        fi
        if [ ! -d ${BACKUP_DIR} ]
        then
                mkdir -p ${BACKUP_DIR}
                write_log "create backup directory ${BACKUP_DIR}"
        fi
}
##################################################
function write_log
{
        DATE=`date +%F_%T`
        echo "${DATE} $*" >> ${LOG_FILE}
}
##################################################
function err_handle
{
        ERR_CODE=$1
        COMMAND=$2
        if [ ${ERR_CODE} = 0 ]
        then
                write_log "command ${COMMAND} completed successfully"
        else
                write_log "command ${COMMAND} Failed! Error Code = ${ERR_CODE}. exiting"
                cat ${LOG_FILE} | mail -s "svn_backup script failed!" ${EMAIL}
                exit 2
        fi
}
##################################################
function mysql_backup
{
        # check if subdirectory with the name of day_of_the_month exist under backup dir
        if [ ! -d ${BACKUP_DIR}/${DAY_OF_MONTH} ]
        then
                mkdir -p ${BACKUP_DIR}/${DAY_OF_MONTH}
        fi
        write_log "start database dump"
        ${MYSQLDUMP} -u root -pDV123456 -A -l > ${BACKUP_DIR}/${DAY_OF_MONTH}/${BACKUP_FILE_NAME}
        err_handle $? "${MYSQLDUMP} -A -l > ${BACKUP_DIR}/${DAY_OF_MONTH}/${BACKUP_FILE_NAME}"
        gzip -f ${BACKUP_DIR}/${DAY_OF_MONTH}/${BACKUP_FILE_NAME}
        err_handle $? "gzip ${BACKUP_DIR}/${DAY_OF_MONTH}/${BACKUP_FILE_NAME}"
}
##################################################
#
# Main
#
##################################################
check_validation
mysql_backup
  • Set Global Variables section in the script (Email address, Backup path, etc…)
  • Run backup and check that it created the sql file and check the script log file
cd /usr/local/nachum234/
./mysql_backup
ls /backup/nagios/* 
less /var/log/files_backup/mysql_backup.log
  • Schedule Backup to run every day with Cron
ln -s /usr/local/nachum234/files_backup /etc/cron.daily/
  • Create logrotate entry for the script log file
vi  /etc/logrotate.d/mysql_backup
/var/log/files_backup/mysql_backup.log {
    weekly
    rotate 10
    notifempty
    missingok
}

Now your NCONF backup is set up. The script will run every day and will create a backup in day of the month directory in BACK_PATH, it will purge an old backup if it already exist in the day of the month directory. The script is saving the backup for one month only.


005. Nagios Upgrade

OS: Ubuntu 9.10 x86_64
Nagios Version: 3.2.3 -> 3.3.1
Hardware: VMware Virtual Platform

About

As newer releases of Nagios are released they contain a lot of bug fixes and new features, so you realy should consider to  upgrade your Nagios and stay up to date.

Prerequisite

  • Your Nagios server was installed in /usr/local/nagios
  • Nagios Backup – Create a backup for Nagios and check that it you can roll backup from it if anything goes wrong

Upgrading Nagios Core

  • Download Nagios and extract
mkdir -p /usr/local/src/nagios
cd /usr/local/src/nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz
tar zxf nagios-3.3.1.tar.gz
cd nagios
  • Run configure
./configure
  • Run make all
make all
  • Install Nagios main and config files, and themes
make install
  • Restart Nagios
service nagios restart

Nagios upgrade completed. Browse to http://nagios_server_ip_address/nagios and check out the new version.

You can extend Nagios use by installing addons using these guide:

Please visit http://www.nagios.org/documentation for information about Nagios configuration and usage.

099. Nagios Error Messages

  1. Error Messge: make install generate the following message:

...
/usr/bin/install: omitting directory `includes/rss/extlib'
/usr/bin/install: omitting directory `includes/rss/htdocs'
/usr/bin/install: omitting directory `includes/rss/scripts'
make[1]: *** [install] Error 1
make[1]: Leaving directory `/usr/local/src/nagios/nagios/html'
make: *** [install] Error 2
  • Fix: change directory to your Nagios src directory and change the html Makefile
cd /usr/local/src/nagios/nagios/
sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile
sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/Makefile

002. Nconf Installation

OS: CentOS 5.6 i386, CentOS 5.7 i386, CentOS 5.7 x86_64
Nagios: version 3.3.1
Nconf: 1.3

About

Nconf is a configuration application for Nagios. It helps you generate Nagios configuration files and then use it on your Nagios system.

Nconf Requirements

  • Install Nconf prerequisites packages
yum install mysql-server perl-DBI perl-DBD-MySQL php-mysql sudo -y
  • Configure mysql-server to run at startup and start it
chkconfig mysqld on
service mysqld start
  • Restart apache
service httpd restart

Nconf installation

  • Download Nconf and extract Nconf
cd /usr/local/src/nagios
wget http://sourceforge.net/projects/nconf/files/nconf/1.3.0-0/nconf-1.3.0-0.tgz -O nconf.tgz
tar zxvf nconf.tgz
  • Move Nconf extracted folder to /usr/local/nagios/share
mv nconf /usr/local/nagios/share/nconf
  • Give permission to the webserver user on nconf folder
chown -R apache:apache /usr/local/nagios/share/nconf
  • Give execute permission to nconf/bin/* files
chmod  775 /usr/local/nagios/share/nconf/bin/*
  • Create database for Nconf
mysqladmin create nconf
  • Create a user to access the database, grant the appropriate privileges
    • Enter mysql console
mysql
  • In mysql console grant permission to your nconf user
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON nconf.* TO 'nconf'@'localhost' IDENTIFIED BY 'nconf';
 \q;
  • Start interactive installation process by browsing to http://nconf_server_ip/nagios/nconf/INSTALL.php
    • Welcome to NConf setup – This page will check if your computer have all Nconf requirements installed -> Click Next if all OK
    • MySQL database configuration – In this page you will need to enter Nconf DB host, DB name, DB user and DB password you set earlier -> Click Next when you finish ->  Click Next again if all OK
    • General configuration – In this page Nconf need to set the right path of Nconf install dir and Nagios binary -> Click Next
    • Authentication configuration – Allows you to active basic authentication. Since I put nconf in Nagios share folder I am already using Nagios authentication so I disable Nconf authentication -> Click Next
    • Check if config files are present – Give a summary report of the installation. In this step you need to go back to the Nconf server shell and remove the following files and directories: INSTALL, INSTALL.php, UPDATE, UPDATE.php -> Click finish
cd /usr/local/nagios/share/nconf
rm -rf INSTALL INSTALL.php UPDATE UPDATE.php
  • Create symbolic link for Nagios bin file
ln -s /usr/local/nagios/bin/nagios /usr/local/nagios/share/nconf/bin/nagios

Configure Nagios to work with Nconf

Nconf installation completed now we will configure Nagios to work with Nconf generated files and create a configuration that will apply Nconf changes.

  • Open Nagios configuration file, comment out all Nagios default configuration files and add Nconf configuration directories
vi /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
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
# Definitions for monitoring a Windows machine
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg
# Definitions for monitoring a router/switch
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg
# Definitions for monitoring a network printer
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg
# You can also tell Nagios to process all config files (with a .cfg
# extension) in a particular directory by using the cfg_dir
# directive as shown below:
cfg_dir=/usr/local/nagios/etc/global
cfg_dir=/usr/local/nagios/etc/Default_collector
  • Create deployment configuration for Nconf generated files
vi /usr/local/nagios/share/nconf/config/deployment.ini
...
;; LOCAL deployment ;;
[deploy config]
type = local
source_file = "/usr/local/nagios/share/nconf/output/NagiosConfig.tgz"
target_file = "/usr/local/nagios/etc/"
action = extract
reload_command = sudo -u nagios /etc/init.d/nagios reload
...
  • Add nagios reload command to apache user and remove the default reuiqre tty setting in sudo configuration file
visudo
...
#Defaults requiretty
...
apache ALL = (nagios) NOPASSWD: /etc/init.d/nagios reload
  • Copy Nagios images to the right directory
cp -a /usr/local/nagios/share/images/logos /tmp/base
mv /tmp/base /usr/local/nagios/share/images/logos/base
  • Browse to http://nconf_server_ip/nagios/nconf and generate and deploy nagios configuration files
Click Generate Nagios config
Click Deploy

You can install another Nagios addon for making graphs using this guide:

For more information about using Nconf please visit http://www.nconf.org

003. NagiosGraph Installation

OS: CentOS 5.6 i386, CentOS 5.7 i386, CentOS 5.7 x86_64
Nagios Version: 3.3.1
NagiosGraph Version: 1.4.4
Hardware: Virtual Machine (VMware Server 2.0.0.2712)

About

NagiosGraph is an addon for Nagios that take the performace data from Nagios services and create graphs that you can use to see your network health.

Prerequisite

  • Install Nagios server

Nagios Installation

  • we need to install the folllowing prerequisites packages: rrdtool perl-GD
yum install rrdtool perl-GD perl-CGI rrdtool-perl perl-Time-HiRes -y

Install NagiosGraph

  • Download NagiosGraph
cd /usr/local/src/nagios/
wget http://sourceforge.net/projects/nagiosgraph/files/nagiosgraph/1.4.4/nagiosgraph-1.4.4.tar.gz -O nagiosgraph.tar.gz
  • Extract NagiosGraph
tar zxf nagiosgraph.tar.gz
cd nagiosgraph-1.4.4
  • Make directory for NagiosGraph in Nagios directory
mkdir /usr/local/nagios/nagiosgraph
  • Copy etc NagiosGraph directory
cp -r etc /usr/local/nagios/nagiosgraph/
  • Change NagiosGraph path in cgi and perl scripts
sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/nagiosgraph/etc#g" cgi/*cgi 
sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/nagiosgraph/etc#g" lib/insert.pl
  • Copy cgi and perl scripts
cp lib/insert.pl /usr/local/nagios/libexec
cp cgi/*.cgi /usr/local/nagios/sbin
  • Copy CSS and JavaScript files
cp share/nagiosgraph.css /usr/local/nagios/share
cp share/nagiosgraph.js /usr/local/nagios/share
  • Edit nagiosgraph.conf and set the following:
vi /usr/local/nagios/nagiosgraph/etc/nagiosgraph.conf
...
# Location of output from nagiosgraph data processing
logfile = /usr/local/nagios/nagiosgraph/var/nagiosgraph.log

# Location of output from nagiosgraph CGI scripts
cgilogfile = /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log

# Location of nagios performance data log file.
perflog = /usr/local/nagios/var/perfdata.log

# Directory in which to store RRD files
rrddir = /usr/local/nagios/nagiosgraph/var/rrd

# File containing regular expressions to identify service and perf data
mapfile = /usr/local/nagios/nagiosgraph/etc/map

# Nagiosgraph CGI URL.
nagiosgraphcgiurl = /nagios/cgi-bin

# Nagios CGI URL. If the Nagiosgraph CGI scripts are in a directory other
# than the Nagios CGI directory, then specify the Nagios CGI URL here.
#nagioscgiurl = /nagios/cgi-bin

# JavaScript: URL to the nagiosgraph javascript file.
javascript = /nagios/nagiosgraph.js

# Stylesheet: URL to the nagiosgraph stylesheet.
stylesheet = /nagios/nagiosgraph.css

# File containing labels for services and data (optional)
#labelfile = /etc/nagiosgraph/labels.conf

# Location of showhost control file (optional)
#hostdb = /etc/nagiosgraph/hostdb.conf

# Location of showservice control file (optional)
#servdb = /etc/nagiosgraph/servdb.conf

# Location of showgroup control file (required for showgroup.cgi)
groupdb = /usr/local/nagios/nagiosgraph/etc/groupdb.conf

# File containing data sets that should be selected in queries (optional)
#datasetdb = /etc/nagiosgraph/datasetdb.conf
...
  • Create directories for NagiosGraph
mkdir /usr/local/nagios/nagiosgraph/var
mkdir /usr/local/nagios/nagiosgraph/var/rrd
  • In NagiosGraph SSI file, set the URL for nagiosgraph.js
vi share/nagiosgraph.ssi
...
<script type="text/javascript" src="/nagios/nagiosgraph.js"></script>
  • Copy NagiosGraph ssi file
cp share/nagiosgraph.ssi /usr/local/nagios/share/ssi/common-header.ssi
chown nagios:nagios /usr/local/nagios/share/ssi/common-header.ssi
  • Set NagiosGraph files permissions
chown -R nagios:nagios /usr/local/nagios/nagiosgraph
chmod 755 /usr/local/nagios/nagiosgraph/var/rrd
touch /usr/local/nagios/nagiosgraph/var/nagiosgraph.log
chmod 664 /usr/local/nagios/nagiosgraph/var/nagiosgraph.log
touch /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log
chown apache /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log
chmod 664 /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log

Nagios Configuration

  • In Nagios configuration file edit the following (you can mark out all these items and add this block to the end of the file):
vi /usr/local/nagios/etc/nagios.cfg
...
process_performance_data=1
service_perfdata_file=/usr/local/nagios/var/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata 
  • Copy NagiosGraph icon
cp -f share/graph.gif /usr/local/nagios/share/images/action.gif
  • Edit Nagios sidebar by adding bullets under “Trends”:
vi /usr/local/nagios/share/side.php
...
<li><a href="<?php echo $cfg["cgi_base_url"];?>/trends.cgi" target="<?php echo $link_target;?>">Trends</a>
<ul>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/show.cgi" target="<?php echo $link_target;?>">Graphs</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showhost.cgi" target="<?php echo $link_target;?>">Graphs by Host</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showservice.cgi" target="<?php echo $link_target;?>">Graphs by Service</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showgroup.cgi" target="<?php echo $link_target;?>">Graphs by Group</a></li>
</ul>
</li>

Nagios without Nconf (use this section if you are not using Nconf)

  • In Nagios command file add the following command:
vi /usr/local/nagios/etc/objects/commands.cfg
...
define command {
    command_name  process-service-perfdata
    command_line  /usr/local/nagios/libexec/insert.pl
}
  • In Nagios configuration add a template for graphed services
vi /usr/local/nagios/etc/objects/templates.cfg
...
define service {
       name graphed-service
       action_url /nagios/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagios/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j
}
  • Add the created graph template to all services that you can (has performance data) and want to create graphs
vi /usr/local/nagios/etc/objects/localhost.cfg
...
define service {
       use local-service,graphed-service
       ...
}
  • Restart Nagios
/etc/init.d/nagios restart

Nagios with Nconf (use this section if you use Nconf to configure your Nagios system)

  • In Nconf edit the Misccommand for processing performance data
Misccomands-> show
process-service-perfdata-> edit
"misc command line" =  /usr/local/nagios/libexec/insert.pl
-> submit
  • InNconf edit the “action_url” attribute to NagiosGraph URL
Attributes-> show
Select class-> service
action_url-> edit
"list of possible values" = \
/nagios/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagios/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j
-> submit
Attributes-> show
Select Class-> service-template
action_url-> edit
"list of possible values" = \
/nagios/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagios/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j
-> submit
  • Set action_url path on all service templates that you want to have graph for
Services templates-> show
-> + Advanced
select requested services
Advanced-> "multi modify"
"select the attribute which you want to modify" = "action URL"
"New value to write" = /nagios/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagios/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j 
-> submit
-> "Generate Nagios Config" -> Deploy

NagiosGraph installation completed.

Browse to http://nagios_server_ip_address/nagios/cgi-bin/show.cgi to see graphs from your nagios sysem.
Please visit http://nagiosgraph.sourceforge.net/ for information about NagiosGraph configuration and usage.

001. Nagios Installation

OS: CentOS 6.2 i386
Nagios Version: 3.5.1
Hardware: Virtual Machine (VMware Server 2.0.0.2712)

About

Nagios is a great network monitor system that help you monitor all network devices in your computers networks.

Prerequisite

  • First we need to install the folllowing prerequisites packages: httpd php  gcc glibc glibc-common gd gd-devel kernel-headers libtool-ltdl-devel
yum install httpd php  gcc glibc glibc-common gd gd-devel kernel-headers libtool-ltdl-devel wget make perl -y
  • Add user for Nagios and add apache user to his group – Nagios will run with that user
/usr/sbin/useradd -m nagios
/usr/sbin/usermod -a -G nagios apache

Installing Nagios Core

  • Download Nagios and extract
mkdir -p /usr/local/src/nagios
cd /usr/local/src/nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.1.tar.gz -O nagios.tar.gz
tar zxf nagios.tar.gz
cd nagios
  • Run configure make and install nagios files
./configure
make all
  • Install Nagios main and config files, and themes
make install
make install-init
make install-commandmode
make install-config
make install-webconf

Now we need to install Nagios Plugins in order to start monitoring a network objects

Install Nagios Plugins

  • Download Nagios Plugins
cd /usr/local/src/nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz -O nagios-plugins.tar.gz
tar zxf nagios-plugins.tar.gz
cd nagios-plugins-*
  •  Install dependencies
yum install openssl-devel gnutls-devel perl-devel libtap openssl net-snmp net-snmp-devel net-snmp-perl openldap openldap-devel mysql mysql-devel postgresql postgresql-devel smartmontools -y
  • Install rpmforge repository for more dependencies installation
rpm -Uhv http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
  • Install more dependencies
yum install fping qstat radiusclient-ng radiusclient-ng-devel libxml2-devel libgtop2-devel net-snmp-utils perl-Net-SNMP perl-Net-DNS -y
  • Run configure make and make install
./configure
make
make install
  • Download snmp plugins
cd /usr/local/src/nagios/
wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz
tar zxf nagios-snmp-plugins.1.1.1.tgz
cd nagios_plugins
./install.sh

cd /usr/local/nagios/libexec
wget "http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=1855&cf_id=24" -O check_iftraffic3.pl
chmod +x check_iftraffic3.pl

Start Nagios

  • Configure apache and nagios to run at startup
chkconfig httpd on
chkconfig nagios on
  • Start apache and nagios
service httpd start
service nagios start
  • Create password for nagiosadmin user
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Nagios installation completed. Browse to http://nagios_server_ip_address/nagios and use nagiosadmin password to see default Nagios configuration.

You can extend Nagios use by installing addons using these guide:

Please visit http://www.nagios.org/documentation for information about Nagios configuration and usage.