Nagiosgraph is a Nagios Addon that parses output and performance data from Nagios plugins and stores the data in RRD files. Nagiosgraph creates graphs and generates HTML pages with graphic reports from the data.
This tutorial is tested on CentOS/RHEL 6.3, and have following Nagios core and plugin package:
Nagios Core: nagios-4.0.0
Nagios Plugin: nagios-plugins-1.4.16
To install Nagios please see my Nagios Installation Docs.
Installation Prerequisite
- Nagios server in working condition.
- We require following packages as well:
yum -y install perl-GD php-gd rrdtool-perl rrdtool-php rrdtool perl-CGI perl-Time-HiRes
Installation
*) Create a directory where you would download nagios software:
mkdir /usr/local/src
cd /usr/local/src
*) Download nagiosgraph package/Untar it and navigate it to that directory
wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.4.4/nagiosgraph-1.4.4.tar.gz
tar -xzvf nagiosgraph-1.4.4.tar.gz
cd nagiosgraph-1.4.4
*) Check for any other Nagiosgraph dependency using "install.pl" script with "check-prereq" options:
./install.pl --check-prereq
checking required PERL modules
Carp...1.11
CGI...3.51
Data::Dumper...2.124
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
checking nagios installation
found nagios at /usr/local/nagios/bin/nagios
checking web server installation
found apache at /usr/sbin/httpd
Note:
*) In case any dependency is missing we need to install it using cpan or yum command.
*) You need to be root to run this script.
There are two ways to install nagiosgraph either automatically or manually.
1) Automated way which install file and set permission automatically
./install.pl --layout overlay --prefix /usr/local/nagios
checking required PERL modules
Carp...1.11
CGI...3.51
Data::Dumper...2.124
File::Basename...2.77
File::Find...1.14
MIME::Base64...3.08
POSIX...1.17
RRDs...1.3008
Time::HiRes... ***FAIL***
checking optional PERL modules
GD...2.44
checking nagios installation
found nagios at /usr/local/nagios/bin/nagios
checking web server installation
found apache at /usr/sbin/httpd
Destination directory (prefix)? [/usr/local/nagios]
Location of configuration files (etc-dir)? [/usr/local/nagios/etc/nagiosgraph]
Location of executables? [/usr/local/nagios/libexec]
Location of CGI scripts? [/usr/local/nagios/sbin]
Location of documentation (doc-dir)? [/usr/local/nagios/docs/nagiosgraph]
Location of examples? [/usr/local/nagios/docs/nagiosgraph/examples]
Location of CSS and JavaScript files? [/usr/local/nagios/share]
Location of utilities? [/usr/local/nagios/docs/nagiosgraph/util]
Location of state files (var-dir)? [/var/nagios]
Location of RRD files? [/var/nagios/rrd]
Location of log files (log-dir)? [/var/nagios]
Path of log file? [/var/nagios/nagiosgraph.log]
Path of CGI log file? [/var/nagios/nagiosgraph-cgi.log]
URL of CGI scripts? [/nagios/cgi-bin]
URL of CSS file? [/nagios/nagiosgraph.css]
URL of JavaScript file? [/nagios/nagiosgraph.js]
Path of Nagios performance data file? [/tmp/perfdata.log]
URL of Nagios CGI scripts? [/nagios/cgi-bin]
username or userid of Nagios user? [nagios]
username or userid of web server user? [apache]
Modify the Nagios configuration? [n]
Modify the Apache configuration? [n]
configuration:
ng_layout overlay
ng_prefix /usr/local/nagios
ng_etc_dir /usr/local/nagios/etc/nagiosgraph
ng_bin_dir /usr/local/nagios/libexec
ng_cgi_dir /usr/local/nagios/sbin
ng_doc_dir /usr/local/nagios/docs/nagiosgraph
ng_examples_dir /usr/local/nagios/docs/nagiosgraph/examples
ng_www_dir /usr/local/nagios/share
ng_util_dir /usr/local/nagios/docs/nagiosgraph/util
ng_var_dir /var/nagios
ng_rrd_dir /var/nagios/rrd
ng_log_dir /var/nagios
ng_log_file /var/nagios/nagiosgraph.log
ng_cgilog_file /var/nagios/nagiosgraph-cgi.log
ng_url /nagios
ng_cgi_url /nagios/cgi-bin
ng_css_url /nagios/nagiosgraph.css
ng_js_url /nagios/nagiosgraph.js
nagios_cgi_url /nagios/cgi-bin
nagios_perfdata_file /tmp/perfdata.log
nagios_user nagios
www_user apache
modify_nagios_config n
nagios_config_file /usr/local/nagios/etc/nagios.cfg
nagios_commands_file /usr/local/nagios/var/rw/nagios.cmd
modify_apache_config n
apache_config_dir /etc/httpd/conf.d
apache_config_file
Continue with this configuration? [y]
OR
2) Manual steps to install Nagiosgraph.
2.1) Create NagiosGraph directory and copy its configuration file in it:
mkdir /usr/local/nagios/etc/nagiosgraph
cp -vr etc /usr/local/nagios/etc/nagiosgraph/
2.2) Change NagiosGraph path in cgi and perl scripts:
sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/etc/nagiosgraph/#g" cgi/*cgi
sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/etc/nagiosgraph/#g" lib/insert.pl
2.3) Copy cgi scripts to nagios appropriate directory that will be served by the web-server:
cp cgi/*.cgi /usr/local/nagios/sbin
2.4) Copy insert.pl to nagios appropriate directory from which it can be executed:
cp lib/insert.pl /usr/local/nagios/libexec
2.5) Copy CSS and JavaScript files to a nagios directory that would be served by the web server:
cp share/nagiosgraph.css /usr/local/nagios/share
cp share/nagiosgraph.js /usr/local/nagios/share
2.6) In NagiosGraph SSI file, set the URL for nagiosgraph.js,copy it to its appropriate location:
vi share/nagiosgraph.ssi
src="/nagiosgraph/nagiosgraph.js" to src="/nagios/nagiosgraph.js"
cp share/nagiosgraph.ssi /usr/local/nagios/share/ssi/common-header.ssi
2.7) Replace the Nagios action icon with the nagiosgraph graph icon:
cp share/graph.gif /usr/local/nagios/share/images/action.gif
Configuration
Edit Nagiosgraph configuration file and set at least the following parameters:
vi /usr/local/nagios/etc/nagiosgraph/nagiosgraph.conf
perflog = /usr/local/nagios/var/perfdata.log
rrddir = /usr/local/nagios/var/rrd
mapfile = /usr/local/nagios/etc/nagiosgraph/map
nagiosgraphcgiurl = /nagios/cgi-bin
javascript = /nagios/nagiosgraph.js
stylesheet = /nagios/nagiosgraph.css
logfile = /usr/local/nagios/var/nagiosgraph.log
cgilogfile = /usr/local/nagios/var/nagiosgraph-cgi.log
Creating necessary directory and fixing the permissions
Changing the ownership of conf and other necessary file that we have copyied earlier
chown nagios:nagios /usr/local/nagios/etc/nagiosgraph
chown nagios:nagios /usr/local/nagios/sbin
chown nagios:nagios /usr/local/nagios/libexec/insert.pl
chown nagios:nagios /usr/local/nagios/share/nagiosgraph.css /usr/local/nagios/share/nagiosgraph.js
chown nagios:nagios /usr/local/nagios/share/ssi/common-header.ssi
Created RRD directory and set permission of "rrddir" to be writable by *nagios* user and read by *apache* (webserver user).
mkdir /usr/local/nagios/var/rrd
chmod nagios:apache /usr/local/nagios/var/rrd
chmod 755 /usr/local/nagios/var/rrd
Set writeable permissions to user *nagios* for “logfile” config directive:
touch /usr/local/nagios/var/nagiosgraph.log
chown nagios /usr/local/nagios/var/nagiosgraph.log
chmod 644 /usr/local/nagios/var/nagiosgraph.log
Set writeable permissions to user *apache* for “cgilogfile” config directive:
touch /usr/local/nagios/var/nagiosgraph-cgi.log
chown apache /usr/local/nagios/var/nagiosgraph-cgi.log
chmod 644 /usr/local/nagios/var/nagiosgraph-cgi.log
Make sure that the *nagios* user can create and delete perfdata files:
Nagios Configuration
Add the following line at the end of Nagios configuration file:
vi /usr/local/nagios/etc/nagios.cfg
# 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
In the Nagios commands file (commands.cfg) define the process-service-perfdata command at the end:
vi /usr/local/nagios/etc/objects/commands.cfg
# command to process nagios performance data for nagiosgraph
define command {
command_name process-service-perfdata-for-nagiosgraph
command_line /usr/local/nagios/libexec/insert.pl
}
Modify the Nagios sidebar (e.g. /usr/local/nagios/share/side.php) by inserting bullets under the 'Trends' heading:
<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>
Validation and testing.
Verify Nagios configuration and restart it once every thing is ok
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios restart
Verify that nagiosgraph configuration is working by running showconfig.cgi:
http://localhost/nagios/cgi-bin/showconfig.cgi
OR
http://Server-IP-Address/nagios/cgi-bin/showconfig.cgi
If everything is working up to this point, try graphing some data by running show.cgi:
http://localhost/nagios/cgi-bin/show.cgi
OR
http://Server-IP-Address/nagios/cgi-bin/show.cgi
Note: If you get a 500 internal error and the issue is with Apache. If you get a “no rrd data found” error, then the configuration of nagiosgraph is incorrect.
To test if you configuration is working you can try to run the script directly:
cd /usr/local/nagios/libexec
./insert.pl
To verify that there is some data in the RRD directory:
ls /var/nagios/rrd/
web001 web002 app001 app002 db001 db002
Adding Service to NagiosGraph
Now we need to define an action URL for the services that we want to graph, so that you can click to go directly to the graphs for that service from the Nagios Core web interface.
define service {
name graphed-service
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$&period=week&rrdopts=-w+450+-j
}
Then, you can have the services you want graphed inherit from it, as well as from any other templates they use, by adding "graphed-service" to the value for the use directive:
define service {
use generic-service,graphed-service
host_name web001
service_description PING
check_command check_ping!100,10%!200,20%
}
You should do this for all the services for which you want graphing.
Validate the configuration file and reload the Nagios Core server once again:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios reload
With this done, visiting the Service section of the web interface should include action icons after each graphed service.