Nagios 4.3.4: Adding graphs to Nagios Core.

Nagios Graphs

In this article we will be adding graphs to the Nagios server that will allow monitoring the services and hosts performance in the past, these graphs can be monitored for Day, Week, Month and Yearly

Assuming that you have already configured the Nagios 4.3.4 Core Server if not follow this link to configure

Create a folder for the source:

# mkdir -p /usr/local/src/nagiosgraph/
# cd /usr/local/src/nagiosgraph/

Download the latest version:

# wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz
# tar -xf nagiosgraph-1.5.2.tar.gz
# cd nagiosgraph-1.5.2

Installing the dependencies for Nagios Graphs in the Nagios server

# yum install perl-rrd* perl-GD* perl-CPAN

Configure Nagios::Config: FAIL

# perl -MCPAN -e shell
Press enter for all the prompts till we get cpan[1]> prompt
cpan[1]> install Nagios::Config
Press enter for all the prompts till we get cpan[1]> prompt
type \quit to get into shell prompt

Check that we have all the dependencies installed:

# ./install.pl --check-prereq
Output:
checking required PERL modules
  Carp...1.29
  CGI...3.64
  Data::Dumper...2.145
  Digest::MD5...2.52
  File::Basename...2.84
  File::Find...1.23
  MIME::Base64...3.13
  POSIX...1.32
  RRDs...1.4007
  Time::HiRes...1.9725
checking optional PERL modules  GD...2.46
checking nagios installation
  found nagios exectuable at /usr/local/nagios/bin/nagios
checking web server installation
  found apache executable at /usr/sbin/apache2
  found apache init script at /etc/init.d/apache2

Start the installation:

# ./install.pl --layout standalone --prefix /usr/local/nagiosgraph
Give the default answer to all the questions except the below one:
Modify the Nagios configuration? [n] y
Path of Nagios commands file? /usr/local/nagios/etc/objects/commands.cfg
Modify the Apache configuration? [n] y

Create the Apache configuration file at this location “/usr/local/nagiosgraph/etc/”,  so that we can get the Nagios graphs from the URL, below are the commands to create the file and edit with the below contents.

# touch /usr/local/nagiosgraph/etc/nagiosgraph-apache.conf
# vi /usr/local/nagiosgraph/etc/nagiosgraph-apache.conf

Add the following to the file:

# enable nagiosgraph CGI scripts
ScriptAlias /nagiosgraph/cgi-bin "/usr/local/nagiosgraph/cgi"
<Directory "/usr/local/nagiosgraph/cgi">
     Options ExecCGI
     AllowOverride None
     Require all granted
</Directory>
# enable nagiosgraph CSS and JavaScript
Alias /nagiosgraph "/usr/local/nagiosgraph/share"
<Directory "/usr/local/nagiosgraph/share">
    Options None
    AllowOverride None
    Require all granted
</Directory>

Restart Nagios and Apache:

# service nagios restart
# service apache2 restart

You can now view the graphs at https://you-ip-address/nagiosgraph/cgi-bin/show.cgi.

We can integrate these graphs into Nagios with a little hack. Nagios supports notes_url and action_url. These can be put per host/service in the Nagios config and allow for a link to an internal knowledge base article or a procedure page or whatever for that host.

We can also place a javascript URL to the graphs there. Place this inside any service check: in windows.cfg, localhost.cfg, services.cfg files which are located in /usr/local/nagios/etc folder

action_url      /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME
 
amp;service=$SERVICEDESC
 
amp;geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME
 
amp;service=$SERVICEDESC$

For example, the Load of the system:

# vi /usr/local/nagios/etc/objects/localhost.cfg
define service {
        use                              local-service
        host_name                  localhost
        service_description    Load
        check_command           check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        action_url              /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME
 
amp;service=$SERVICEDESC
 
amp;geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME
 
amp;service=$SERVICEDESC$ }

For the ping check you can show both RTA and packet loss:

define service {
        use                     local-service
        host_name               localhost
        service_description     PING
        check_command           check_ping!100.0,20%!500.0,60%
        action_url              /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME
 
amp;service=$SERVICEDESC
 
amp;db=pl,data&db=pl,warn&db=pl,crit&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME
 
amp;service=$SERVICEDESC
 
amp;db=pl,data&db=pl,warn&db=pl,crit }

We need to include the Nagios Graph Javascript in Nagios to make sure the mouseover works. Edit or create the following file:

# vi /usr/local/nagios/share/ssi/common-header.ssi

Place the following in there:

/nagiosgraph/nagiosgraph.js

Now save and reload Nagios:

# service nagios restart

 

Keywords: Nagios, Monitoring, Linux host, Adding Linux host, Nagios Graph, MRTG Graphs, Nagios MRTG Graphs

Leave a Reply

Your email address will not be published.

Have a Question?