It will be useful for the managers to get a summarized status report of the system daily. This can be achieved through following script . The script should be listed in the crontab to execute in daily basis.
Steps (Commands should be written to the script file)
1. Generate the html version of the report automatically.
wget -v --user nagios_user --password 'password' --no-check-certificate -O ./`date +%Y%m%d`-report.html "https://your_nagios_server_URL/nagios/cgi-bin/avail.cgi?show_log_entries=&host=Host1&service=all&timeperiod=yesterday&timeperiod=24x7"
Here replace nagios_user with whoever the user having privileges to generate status report and 'password' with his password, Host1 to the host name that you want to generate report. It is better to run the command separately and check whether you are getting the html file correctly. If everything is fine you will get a a html report with the date
i.e. 20110627-report.html
If you have no idea how to get the https:// .... code part, just put a tail -f for the http access log of the server (nagious) and generate the report from the nagios GUI. The required code to generate the report will be on your screen.
Here my nagios is running on https://..So I need to put a tail -f for /var/log/httpd/ssl_access_log and generate the required report from the nagios GUI.
Get the code and replace it with the code above.
2. Copy this file to a temporary file named rep.html
cp `date +%Y%m%d`-report.html rep.html
The temporary file will be useful for HTML altering purposes with sed command.
3. Convert HTML file to PS2
/usr/bin/html2ps -U rep.html > rep.ps
4. Convert ps file to PDF version
ps2pdf rep.ps report`date +%Y%m%d`.pdf
This will create a pdf file with the name report-yyyymmdd.pdf
5. Mail the content to the appropriate user
nail -a reportyyyymmdd.pdf -s "Nagios Report" admin@your_domain
Now the script file should be called through a cronjob
If you wish to set the cron job to a user, login to the system as that user and type the command crontab -e which enables him to edit the cron jobs
Put an entry related to the cron job
15 00 * * * /home/user/scrip.sh
Here the scrip.sh is the file you have all commands related to nagios report generation + emailing parameters
Save and exit from the crontab edit mode.
Make sure the user has the privileges to execute the file 'script.sh'
Steps (Commands should be written to the script file)
1. Generate the html version of the report automatically.
wget -v --user nagios_user --password 'password' --no-check-certificate -O ./`date +%Y%m%d`-report.html "https://your_nagios_server_URL/nagios/cgi-bin/avail.cgi?show_log_entries=&host=Host1&service=all&timeperiod=yesterday&timeperiod=24x7"
Here replace nagios_user with whoever the user having privileges to generate status report and 'password' with his password, Host1 to the host name that you want to generate report. It is better to run the command separately and check whether you are getting the html file correctly. If everything is fine you will get a a html report with the date
i.e. 20110627-report.html
If you have no idea how to get the https:// .... code part, just put a tail -f for the http access log of the server (nagious) and generate the report from the nagios GUI. The required code to generate the report will be on your screen.
Here my nagios is running on https://..So I need to put a tail -f for /var/log/httpd/ssl_access_log and generate the required report from the nagios GUI.
Get the code and replace it with the code above.
2. Copy this file to a temporary file named rep.html
cp `date +%Y%m%d`-report.html rep.html
The temporary file will be useful for HTML altering purposes with sed command.
3. Convert HTML file to PS2
/usr/bin/html2ps -U rep.html > rep.ps
4. Convert ps file to PDF version
ps2pdf rep.ps report`date +%Y%m%d`.pdf
This will create a pdf file with the name report-yyyymmdd.pdf
5. Mail the content to the appropriate user
nail -a reportyyyymmdd.pdf -s "Nagios Report" admin@your_domain
Now the script file should be called through a cronjob
If you wish to set the cron job to a user, login to the system as that user and type the command crontab -e which enables him to edit the cron jobs
Put an entry related to the cron job
15 00 * * * /home/user/scrip.sh
Here the scrip.sh is the file you have all commands related to nagios report generation + emailing parameters
Save and exit from the crontab edit mode.
Make sure the user has the privileges to execute the file 'script.sh'
Where is the script for download. thanks for the effort. God bless you
ReplyDeleteHi, InfinityDon,
ReplyDeleteThe script.sh is the file that you put all the commands (step 1 to step 5). Here is a sample script.sh file.
# /bin/sh
cd /home/yourhomefolder/nagios_report
wget -v --user your_nagious_user --password 'yourpassword' --no-check-certificate -O ./`date +%Y%m%d`-report.html "https://localhost/nagios/cgi-bin/avail.cgi?show_log_entries=&service=all&timeperiod=yesterday&smon=6&sday=1&syear=2011&shour=0&smin=0&ssec=0&emon=6&eday=26&eyear=2011&ehour=24&emin=0&esec=0&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedservicestate=0&backtrack=4"
cp `date +%Y%m%d`-report.html rep.html
/usr/bin/html2ps -U rep.html > rep.ps
ps2pdf rep.ps report`date +%Y%m%d`.pdf
nail -s "Yesterday's Nagios Report - Your Systems" -a /home/yourhomefolder/nagios_report/report`date +%Y%m%d`.pdf -c user1@yourdomain.lk you@userdomain.lk
Hope this will help you
How to get report from nagios every 3 hours....
ReplyDeleteThanks
How to get daily , weekly and monthly detailed report on usage and performance from Nagios
ReplyDeleteSorry for the delayed response, the report is generated from scrip which activated through the cronjob. You can activated the script according to your requirement by changing the parameters in the crontab. For example every Saturday 2 pm is 0 2 * * 6
DeleteThe script should also change to get the details fro the required time period.
For more time settings visit http://www.pantz.org/software/cron/croninfo.html
Hi, thank you for the article!
ReplyDeleteIs there a way I can display the alias of a host in the report? Thank you!
IJ