NagiosGraph is an addon for Nagios that take the performance data from Nagios services and create graphs that you can use to see your network health.
Install NagiosGraph
First we will install the package prerequisites:
sudo apt install libcgi-pm-perl librrds-perl libgd-gd2-perl libnagios-object-perl
Next we will download NagiosGraph (download the lastest version)
cd /usr/local/nagios/
sudo wget https://sourceforge.net/projects/nagiosgraph/files/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz -O nagiosgraph.tar.gz
Next we will extract Nagios Graph
sudo tar zxf nagiosgraph.tar.gz
sudo cd nagiosgraph-1.5.2
Make directory for NagiosGraph in Nagios directory, and copy etc subfolder
sudo mkdir /usr/local/nagios/nagiosgraph
sudo cp -r etc /usr/local/nagios/nagiosgraph/
Change NagiosGraph path in cgi and perl scripts
sudo sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/nagiosgraph/etc#g" cgi/*cgi
sudo sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/nagiosgraph/etc#g" lib/insert.pl
Copy cgi and perl scripts
sudo cp lib/insert.pl /usr/local/nagios/libexec
sudo cp cgi/*.cgi /usr/local/nagios/sbi
Copy CSS and JavaScript files
sudo cp share/nagiosgraph.css /usr/local/nagios/share
sudo cp share/nagiosgraph.js /usr/local/nagios/share
Edit nagiosgraph.conf and set the following:
sudo nano /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
sudo mkdir /usr/local/nagios/nagiosgraph/var
sudo mkdir /usr/local/nagios/nagiosgraph/var/rrd
In NagiosGraph SSI file, set the URL for nagiosgraph.js
sudo nano share/nagiosgraph.ssi
<script type="text/javascript" src="/nagios/nagiosgraph.js"></script>
Copy NagiosGraph ssi file
sudo cp share/nagiosgraph.ssi /usr/local/nagios/share/ssi/common-header.ssi
sudo chown nagios:nagios /usr/local/nagios/share/ssi/common-header.ssi
Set NagiosGraph files permissions
sudo chown -R nagios:nagios /usr/local/nagios/nagiosgraph
sudo chmod 755 /usr/local/nagios/nagiosgraph/var/rrd
sudo touch /usr/local/nagios/nagiosgraph/var/nagiosgraph.log
sudo chmod 664 /usr/local/nagios/nagiosgraph/var/nagiosgraph.log
sudo touch /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log
sudo chown www-data/usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log
sudo 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):
sudo nano /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
sudo cp -f share/graph.gif /usr/local/nagios/share/images/action.gif
Edit Nagios sidebar by adding bullets under “Trends”:
sudo nano /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>
In Nagios command file add the following command:
/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
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
register 0
}
Next configure the services that needs to be graphed on nagios graph. Note, we only need to append the service template that we defined in our template configuration from above:
define service {
use generic-service,graphed-service
host_name WEB01
service_description SSH
check_command check_ssh
notifications_enabled 1
}
define service {
use generic-service,graphed-service
host_name WEB01
service_description HTTP
check_command check_http
notifications_enabled 1
}
Restart Nagios
sudo systemctl restart nagios.service
You can now delete the installer:
sudo rm /usr/local/nagios/nagiosgraph.tar.gz
sudo rm -r /usr/local/nagios/nagiosgraph-1.5.2
Browse to https://nagios_server_ip_address/nagios/cgi-bin/show.cgi to see graphs from your nagios system, or Browse to https://nagios_server_ip_address/nagios and launch the graph from the services you have enabled.
Please visit https://nagiosgraph.sourceforge.net/ for information about NagiosGraph configuration and usage.
Ref: https://allcloud.io/blog/install-nagiosgraph/
Ref: https://ruan.dev/blog/2019/03/18/how-to-setup-the-nagiosgraph-plugin-on-nagios-monitoring-server