Maybe I didn't look hard enough because a lot of people run both Cacti and Nagios so something must be out there, but I wasn't able to track down something nice and simple.
Eventually I used the script written by crony in this topic and changed it quite a bit to suite my needs.
It can check Nagios servers remotely, both version 2 and 3, graphs hosts, services, latency and check stats (active/passive service/host checks per 5 minutes).
So I'd hereby like to share my scripts and templates with the community. I'm open for suggestions, questions and will try to help troubleshoot any issues you might have.
I'm also planning support for Nagios v1 and might add some more graphs such as scheduling statistics if there's a demand for it.
Code: Select all
Nagios Statistics - Cacti scripts and templates
============
Info
============
Simple system for Cacti to graph Nagios statistics.
It was grown from a script made by 'crony' on the cacti forums: http://forums.cacti.net/post-141347.html#141347
Since then heavily modified, turned into a CGI script and extended with Cacti wrapper for remote checking
With templates created from scratch:
- Nagios Statistics - Check Statistics - Shows 'per 5 minutes' statistics of amount of checks executed/received
- Nagios Statistics - Host Checks - Shows how many hosts are being checked and their status
- Nagios Statistics - Host Problems - Shows how many problems there are for hosts
- Nagios Statistics - Latency - Shows the average latency for host/service checks
- Nagios Statistics - Service Checks - Shows how many services are being checked and their status
- Nagios Statistics - Service Problems - Shows how many problems there are for services
Created by Kleborp, feel free to use whatever you want for your own purposes
============
Requirements
============
- Cacti 0.8.7d or higher (created with 0.8.7d and also tested with 0.8.7e)
- Nagios v2.xx or v3.x.x (tested with nagios 2.12, 3.1.2 and 3.2.0)
- Perl on both Cacti and Nagios server
- Wget on the Cacti server
============
Files
============
- mrtgstats.cgi - CGI Perl script to be placed on the to be checked Nagios server
- check_nagios.pl - Wrapper Cacti script that passes the output of the CGI script to Cacti
- *.xml - Template files to be imported in Cacti
- README - This file
============
Installation
============
CGI Nagios script:
- Copy 'mrtgstats.cgi' to your nagios server
- Copy it to nagios's cgi-bin directory as root ('/usr/lib/nagios/cgi-bin/' on RHEL/CentOS/Fedora)
- Change ownership and permissions (see ' ls -al' in the cig-bin directory for refence, it should be the same as the rest (root:root or nagios:nagios and +x probably))
- Test it by going to 'http://your-nagios/nagios/cgi-bin/mrtgstats.cgi?type=latency'
- If it shows no/weird output or an internal server error:
- Make sure the 'nagiostats' binary location is configured properly in mrtgstats.cgi
- Make sure it didn't accidentally copy as dos text file, which breaks cgi in some http servers like lighttpd (run 'dos2unix mrtgstats.cgi' to be sure)
- If it still doesn't work, panic, or post on the forums with some details including nagios version, apache/lighttpd access/error logs, etc
Cacti wrapper script:
- Copy 'check_nagios.pl' to your cacti/scripts/ directory
- Make sure it's executable by the user your cacti/spine runs as
Import templates:
- For each .xml file included, import it through the 'Import Templates' bit
Create pretty graphs:
- Add the Graph Templates to a host (preferably your nagios sever, though it technically doesn't matter as you have to enter the cgi-bin url anyway)
- When creating the graphs for a host it'll show 3 input fields per graph:
- 'Nagios cgi-bin url' this is the cgi-bin url of nagios, not the full url to mrtgstats.cgi, for example: http://your-nagios/nagios/cgi-bin/
- 'Web Auth username' Optional field, fill this in if your nagios requires web authentication
- 'Web Auth password' Optional field, same as above, note that creating an account that doesn't have admin access in nagios itself is preferable (like a view only user)
============
Bugs
============
Some known bugs:
- After reloading the nagios configuration it might show inaccurate data (less hosts/checks/downtime/etc than there actually are), I believe this is a 'bug' in nagiostats
- The 'Service Problems' and 'Host Problems' graphs can use the same data source as 'Service Checks' and 'Host Checks', however by default Cacti will create a data source for each graph created, to 'solve' this, only add the Service Checks and Host Checks graph templates to a hoste, after creating those, manually do 'Add' in 'Graph Management', select your host, and template, and after creating that select the right data source fields.
- Latency times are rounded to 2 decimals, even though nagiostats gives it in microseconds, I cheated by dividing it by 1000 and using 'Load Average' as GPRINT function so I wouldn't have to make my own with 3 decimals
============
Changelog
============
* Sat 15/08/2009 - Intial release