How to script nagios csv export

csvexportnagios

nagios 3 can export availability data as csv (clicking through the web gui). Now I would like to do that automated and on a regular basis, so I am looking for a way to set all the parameters (e.g. reporting period) and then get the csv. Since the parameters seem not encoded in the url, I do not see an obvious solution.

Can this be scripted? If yes, how? Or do I need to do screen scraping?

Best Answer

You could script this with your favorite language (perl, python, etc.) or use curl/wget. All of the CGIs can be run from the command line as well, but you'll have to set the REMOTE_USER env variable.

The params are absolutely encoded in the URL, but the stock Nagios web interface uses frames, so you don't see them. View the actual frame that the report is in, and you'll see the GET params.

You can also use a browser add-on like Live HTTP Headers (for Firefox) to show you exactly what is being requested. For example:

GET /cgi-bin/nagios3/avail.cgi?show_log_entries=&host=all&service=all&timeperiod=last7days&smon=11&sday=1&syear=2013&shour=0&smin=0&ssec=0&emon=11&eday=25&eyear=2013&ehour=24&emin=0&esec=0&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedservicestate=0&backtrack=4&csvoutput=