Centos 6.x / RHEL 6.x – Apache / Nagios 4.x – Install nagiosgraph plugin

Published on Author gryzli

Nagiosgraph gets performance data from Nagios and by using RRDtool generates nice graphics for this data. The plugin’s home page is here:

http://nagiosgraph.sourceforge.net/

Prerequisites

Here I assume that you already have Nagios Core 4.x installed with the appropriate Apache configurations.

 

Installing yum packages

yum install perl-CGI rrdtool-perl perl-Time-HiRes perl-GD perl-CPAN perl-Module-Build

 

Install Nagios::Config by cpan

cpan> install Nagios::Config

 

1. Download and untar the source

The current version of nagiosgraph is 1.5.2  and can be downloaded from here:

http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnagiosgraph%2F&ts=1416475526&use_mirror=switch

 

cd /tmp

wget 'http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnagiosgraph%2F&ts=1416475526&use_mirror=switch' -O nagiosgraph-1.5.2.tar.gz

tar xvzf  nagiosgraph-1.5.2.tar.gz

cd  nagiosgraph-1.5.2

 

 

2. Run prerequisites check and install

 

2.1 Run prerequisites check

First we need to run the prerequisites check, which is an option supported by the install.pl script.

perl install.pl --check-prereq

If everything is OKAY, then the command above must return something like that:

checking required PERL modules
  Carp...1.11
  CGI...3.51
  Data::Dumper...2.124
  Digest::MD5...2.39
  File::Basename...2.77
  File::Find...1.14
  MIME::Base64...3.08
  POSIX...1.17
  RRDs...1.3008
  Time::HiRes...1.9721
checking optional PERL modules
  GD...2.44
  Nagios::Config...36
checking nagios installation
  found nagios exectuable at /usr/local/nagios/bin/nagios
  found nagios init script at /etc/init.d/nagios
checking web server installation
  found apache executable at /usr/sbin/httpd
  found apache init script at /etc/init.d/httpd

 

2.2 Install the plugin

If everything went okay with the prereq check, then you can go on withe installation. I personally prefer to install the plugin in a separate directory: /usr/local/nagiosgraph

The install command is as simple as:

perl install.pl

During the installation you will be asked some questions, and most of them you can leave with their default values.

In my case I choose  YES to  modify_apache_config and modify_nagios_config . Choosing yes in these steps will do the following:

Automatically add nagiosgraph.conf in /etc/httpd/conf.d/  (If you have default Apache installation) with the following conent

# enable nagiosgraph CGI scripts
ScriptAlias /nagiosgraph/cgi-bin "/usr/local/nagiosgraph/cgi"
<Directory "/usr/local/nagiosgraph/cgi">
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
#   AuthName "Nagios Access"
#   AuthType Basic
#   AuthUserFile NAGIOS_ETC_DIR/htpasswd.users
#   Require valid-user
</Directory>
# enable nagiosgraph CSS and JavaScript
Alias /nagiosgraph "/usr/local/nagiosgraph/share"
<Directory "/usr/local/nagiosgraph/share">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>

 

Automatically Modify nagios.conf (/usr/local/nagios/etc/nagios.conf in my case) and add some perfdata settings:

# begin nagiosgraph configuration
# process nagios performance data using nagiosgraph
process_performance_data=1
service_perfdata_file=/tmp/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-for-nagiosgraph
# end nagiosgraph configuration

Automatically modify /usr/local/nagios/etc/objects/commands.cfg

# begin nagiosgraph configuration
# command to process nagios performance data for nagiosgraph
define command {
  command_name process-service-perfdata-for-nagiosgraph
  command_line /usr/local/nagiosgraph/bin/insert.pl
}
# end nagiosgraph configuration

 

Finally after the install.pl completes, I have the following output:

  ng_prefix            /usr/local/nagiosgraph
  ng_etc_dir           /usr/local/nagiosgraph/etc
  ng_bin_dir           /usr/local/nagiosgraph/bin
  ng_cgi_dir           /usr/local/nagiosgraph/cgi
  ng_doc_dir           /usr/local/nagiosgraph/doc
  ng_examples_dir      /usr/local/nagiosgraph/examples
  ng_www_dir           /usr/local/nagiosgraph/share
  ng_util_dir          /usr/local/nagiosgraph/util
  ng_var_dir           /usr/local/nagiosgraph/var
  ng_rrd_dir           /usr/local/nagiosgraph/var/rrd
  ng_log_dir           /usr/local/nagiosgraph/var/log
  ng_log_file          /usr/local/nagiosgraph/var/log/nagiosgraph.log
  ng_cgilog_file       /usr/local/nagiosgraph/var/log/nagiosgraph-cgi.log
  ng_url               /nagiosgraph
  ng_cgi_url           /nagiosgraph/cgi-bin
  ng_css_url           /nagiosgraph/nagiosgraph.css
  ng_js_url            /nagiosgraph/nagiosgraph.js
  nagios_cgi_url       /nagios/cgi-bin
  nagios_perfdata_file /tmp/perfdata.log
  nagios_user          nagios
  www_user             apache
  modify_nagios_config y
  nagios_config_file   /usr/local/nagios/etc/nagios.cfg
  nagios_commands_file /usr/local/nagios/etc/objects/commands.cfg
  modify_apache_config y
  apache_config_dir    /etc/httpd/conf.d
  apache_config_file

 

 3. Fine-Tune and enable  Graph Icons in Nagios + Graphs in Nagios Mouseover

In order to enable Graph icons in nagios, and also enable Graphs Mouseover  I have done the following modificatoins:

1. Add service definition which contains the right action_url

Add the following service definition in your service config file:

define service {
  name graphed-service
  action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
  action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$

  register 0
}

 

2. Modify all services to include “graphed-service”

You must modify all of the services you want to use graphing on, by changing the following:

use generic-service
# ==>
use generic-service,graphed-service

 

3. Modify all hosts which want to include graphs

In your host {} configuration sections, you must add the following:

action_url        /nagiosgraph/cgi-bin/showhost.cgi?host=$HOSTNAME$

 

4. Finally  create the common-header.ssh in order to activate javascript mouseover graphs

cp -a /usr/local/nagiosgraph/examples/nagiosgraph.ssi /usr/local/nagios/share/ssicommon-header.ssi

 

5. At the end make sure to restart your Nagios and Apache servers

 

 

 

4 Responses to Centos 6.x / RHEL 6.x – Apache / Nagios 4.x – Install nagiosgraph plugin

  1. Fine-Tune and enable Graph Icons in Nagios + Graphs in Nagios Mouseover in this section Point number1 in which you said you have to add service definition to service config file I have two questions with you .

    I am new to nagios kindly let me know soon

    1, what is service config file ? is it /usr/local/nagios/etc/nagios.cfg ?? and where to add “define service {
    name graphed-service
    action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
    action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$’ onMouseOver=’showGraphPopup(this)’ onMouseOut=’hideGraphPopup()’ rel=’/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$

    register 0
    }” in this file .

    2. and in action_url action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
    should i have to put my hostname of machine or what ?

  2. Hi Salman,

    1. Yes you can use “/usr/local/nagios/etc/nagios.cfg” file for adding the configuration directives.
    2. No, you must not change the “$HOSTNAME$ , it is special keyword, which is used by Nagios , so it must be written as it is

    Regards

  3. Thanks for your reply . Actually I am a bit confused in your step 3. Fine-Tune and enable Graph Icons in Nagios + Graphs in Nagios Mouseover in step 1 which is

    1. Add service definition which contains the right action_url

    Add the following service definition in your service config file:

    Can you please tell me in which file I have to add this ???

  4. Hello,

    I am facing an issue with the step 2.1.
    When I run the perl install.pl –check-prereq, I got the output with “CGI… ***FAIL***”

    but when I tred to install the CGI package it returns:
    ” package perl-CGI.pm-2.56-6.i386 is already installed”

    Do you have any idea how I can fix this issue?