Managers like statistics. And they like it on a regular basis: Daily, Monthly, Trimestrial, Yearly... and so on. The Availability Reports created by Nagios are a very good indication for the availability of services so why not use these stats. There's only one small problem: Nagios doesn't support an export as PDF (yet). But with some tweaks this can be done in a couple of minutes. Here's a small howto:
- Linux server
- Nagios running (of course)
- You need to download and install html2ps
1) Download Availability Report of service 'Website' using your Nagios user (nagiosadmin for example):
wget --user nagiosadmin --password nagiospass -O /tmp/report -q "http://mynagios.server.local/nagios/cgi-bin/avail.cgi?show_log_entries=&host=HOST&service=Website&timeperiod=yesterday"
Note the bold marked params. HOST is of course the server you're monitoring on which the service 'Website' is running. Here we set the timeperiod to yesterday for a daily basis.
1b - optional)
By default, the reports will be in black/white (text only). If you want to make it a bit more colorful you may replace the css classes from the html code into bgcolors. Here's an example to change the 'ServiceOK' class to a green background colour:
sed -e 's/CLASS='\''serviceOK'\''/BGCOLOR='\''#00FF00'\''/g' /tmp/report > /tmp/report.tmp
mv /tmp/report.tmp /tmp/report
2) Convert the downloaded html file to ps (post script) using html2ps:
/usr/bin/html2ps -U /tmp/report > /tmp/report.ps
The parameter -U allows to create a post script file with colours. This is necessary if you replaced the css classes by bgcolors.
3) Convert the ps file into pdf
ps2pdf /tmp/report.ps /tmp/report.pdf
Of course you can auto-generate the reports now with these commands. I am generating several reports of services and servicegroups on a daily basis.
Thomas from wrote on Nov 7th, 2012:
wkhtmltopdf --username nagiosadmin --password blabla "http://mynagiosserver/nagios3/cgi-bin/avail.cgi?show_log_entries=&host=HOST&service=SERVICE&timeperiod=thismonth" /tmp/report.pdf
Thanks for your MySQL Slave Status Plugin. Works fine.
Claudio from Switzerland wrote on Feb 21st, 2012:
Yes, as mentioned in the article, the CSS styles are not copied, therefore they won't be shown in the PDF. You have two options, which come into my mind:
1) Do the replacement of CSS class tags by BGCOLOR, as described in the article at 1b optional. This will work, however you might have to do a lot of scripting until you have a nice design
2) Download the Nagios report as CSV file by adding &csvoutput to the URL:
wget --user nagiosadmin --password nagiospass -O /tmp/report -q "http://mynagios.server.local/nagios/cgi-bin/avail.cgi?show_log_entries=&host=HOST&service=Website&timeperiod=yesterday&timeperiod=24x7&csvoutput"
You will see that the values are easier to parse with this target file. You can now do whatever you want. You can take the values and create a nice HTML-output and save it into a html file or you can write the values into a database and create a report from there... You have a lot of options.
For a hosting project, I used the CSV file output to parse the values of certain services and hosts and write them into a database. These data are then shown on a website as live availability statistics.
jb from spain wrote on Feb 21st, 2012:
I\'m trying to generate pdfs form nagios,but the output haven\'t got any style applied. So output pdf it\'s very different from the html source.
Are there any params to make pdf more pretty than html?
Claudio from Switzerland wrote on Aug 21st, 2011:
Hmm I don't know if and how how groundworks interferes with Nagios.
The login page is http auth (typically a pop up in the browser asking for credentials) or a html login page? If second one is the case, the wget command will probably not work as a html login page would require submitting the login form (POST).
Francis from Philippines wrote on Aug 21st, 2011:
Got the password for the nagiosadmin user from the htpasswd file but still no go. I restarted the apache server and now it has no output. One thing, before its oly exporting what is basically a login page.
Francis from Philippines wrote on Aug 21st, 2011:
Yes, authentication is enabled. I checked the cgi.cfg and authentication=1 and nagios user is nagiosadmin. One thing though, this is a groundworks monitor open source installation. I\'m tempted to reset the password for the nagiosadmin user but I\'m worried it might break the groundworks installation.
Claudio from Switzerland wrote on Aug 19th, 2011:
Did you set up authentication for the Nagios website? If yes, you will need to use the user you have set the authentication for in the wget command. Also make sure that this user is defined in cgi.cfg.
Francis from Philippines wrote on Aug 19th, 2011:
Hi, I'm trying to generate the same thing that is outlined here. However, the output page is just showing the login page and no report for the host specified. I'm suspecting it has to do with the user login. I have no user called nagiosadmin, only nagios.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Container Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Icingaweb2 InfluxDB Internet Java KVM Kibana Kodi Kubernetes LTS LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher SSL Seafile Security Shell SmartOS Solaris Surveillance SystemD TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder