The tutorial will give you idea, how you can send Nagios Report as pdf file via email. We will achieve this requirement, with the help of script and using wkhtmltopdf command line tool. We will set the Nagios Report script in crontab and send it via email to receiver person/team.
In our previous post we shared, how we can convert website page into pdf. Logically we will use same thing here.
But the main part of script is how we can get the Nagios report URL. It is quite easy to get any Nagios Report URL from Web browser. You have to simply Right Click on your desired Report Section of Nagios Dashbaord, then from right click mouse menu ,select new tab or window. Now check address bar of newly opened tab in web browser , you will see long Nagios Report URL.
Steps to setup the Nagios Report script
1. Install wkhtmltopdf :
We will suggest you to follow the our previous post to install wkhtmltopdf command in your CentOS/Debian/Ubuntu system.
2. Create nagios_report script :
Once you install wkhtmltopdf . Create a script to send Nagios report pdf file through email.
In this script, we will get Nagios Event Log report in the form of pdf file, which is one day old.
(a) Install mutt :
With the help of mutt we will send the email .Hence install mutt in your system first.
For CentOS / RHEL sudo yum install mutt For Ubuntu / Debian sudo apt-get install mutt
(b) Create a file nagios_report.sh
(c) In nagios_report.sh file, write the following content. You can also do copy paste from below given script content.
Change the variable value like _USER, _PASSWORD,_TO_EMAIL etc. as per your requirement or information.
Here, _URL is the Nagios Report URL.
#!/bin/bash # # Author : Sharad Kumar Chhetri # Date : 21-aug-2015 # Version : 1.0 # Description : The script will fetch the nagios eventlog report one day old. # ## _URL="http://localhost/nagios/cgi-bin/showlog.cgi?archive=1" _USER=nagios_username _PASSWORD=Your_Nagios_password _REPORT_PATH=/opt/NagiosReport _FILE_NAME=Nagios-EventLog-`date +%F --date="yesterday"`.pdf [email protected] _WKHTMLTOPDF=`which wkhtmltopdf` if [ -d $_REPORT_PATH ] then echo "NagiosReport directory already exist in /opt " else mkdir -p $_REPORT_PATH echo $(ls -ld $_REPORT_PATH) echo "$_REPORT_PATH directory created" fi ### Create pdf file of Nagios Event Log , Set the --page-height and --page-width as per your requirement. $_WKHTMLTOPDF --username $_USER --password $_PASSWORD --page-height 1200 --page-width 900 "$_URL" "$_REPORT_PATH/$_FILE_NAME" ### Send Email with attachment echo -e "Hello Team,nFind Nagios report dated of $(date +%F --date=yesterday), attachment is enclosed in this emailnBest RegardsnNagios Admin"|mutt -a "$_REPORT_PATH/$_FILE_NAME" -s "Report: Nagios Event Log $(date +%F --date=yesterday)" -- $_TO_EMAIL
(d) Give executable permission nagios_report.sh script :
chmod 700 /opt/nagios_report.sh
Run the script manually from terminal to check.
(e) Crontab setting :
As per your requirement now set the crontab for script. We are setting the script to be executed daily at 12:05 AM .
05 00 * * * /opt/nagios_report.sh
You can use this method for all types of report you generate on Nagios Dashboard. Logic is very simple, we just convert the website page into pdf file and send it through email.