Page 1 of 3
nagios csv question
Posted: Fri Sep 12, 2014 1:26 pm
by marpan
Hello,
I have searched the forums and not sure if what I found applies to us. I am trying to find out if there are patches needed to be able to export the availabilty report to a .csv file. Currently the parameters we have tried with wget return a file output in html.
We need to be able to export the report to .csv rather than html output.
We have Nagios Core 3.5.1 and our sys admin says that we use pre-build binaries from Red Hat's official package.
Thank you for any help you can provide.
Thank you,
Mark
Re: nagios csv question
Posted: Fri Sep 12, 2014 3:41 pm
by abrist
There are ways to get a csv, but I think you may be on to something. There is a csvoutput GET parameter. Running the following command should output a csv file for yesterday's availability of all hosts (host=all) (also, take note of the final query parameter "csvoutput="):
Code: Select all
REQUEST_METHOD="GET" REMOTE_USER="nagiosadmin" QUERY_STRING="show_log_entries=&host=all&timeperiod=today&smon=9&sday=1&syear=2014&shour=0&smin=0&ssec=0&emon=9&eday=12&eyear=2014&ehour=24&emin=0&esec=0&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedhoststate=0&initialassumedservicestate=0&backtrack=4&csvoutput=" /usr/local/nagios/sbin/avail.cgi
But running an availability report against one individual host (host=localhost):
Code: Select all
REQUEST_METHOD="GET" REMOTE_USER="nagiosadmin" QUERY_STRING="show_log_entries=&host=all&timeperiod=today&smon=9&sday=1&syear=2014&shour=0&smin=0&ssec=0&emon=9&eday=12&eyear=2014&ehour=24&emin=0&esec=0&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedhoststate=0&initialassumedservicestate=0&backtrack=4&csvoutput=" /usr/local/nagios/sbin/avail.cgi
Outputs HTML. After running a few availability reports from the web ui, it looks like the csvoutput parameter is only available when specifying either "host=all" or "service=all". None of the other options display the checkbox nor work with the csvoutput parameter when specified from the cli/browser. I am not familiar enough with avail.cgi to comment on the "why?". Sounds like a good feature request. Also, I bet it is a snap to do clientside with the new json cgis (archivejson.cgi). Feel free to explore the new json cgis in core 4 through the query generator: /nagios/jsonquery.html
That being said, you absolutely can GET availability reports in csv from core 3, albeit just for "all hosts" and "all services" using variations of the parameters in first GET request above.
Re: nagios csv question
Posted: Fri Sep 12, 2014 4:14 pm
by marpan
Thank you for your quick reply. I am somewhat new to Nagios and I will check study your examples.
Thank you,
Mark
Re: nagios csv question
Posted: Mon Sep 15, 2014 12:51 pm
by abrist
No problem. Let me know if you have any other questions.
Re: nagios csv question
Posted: Wed Jan 14, 2015 4:11 pm
by marpan
Hello again and Thank you for your help with this. I was able to get my script to export the availability report to csv using wget.
Right now I export the availability report for last 24 hours.
After searching I have not found an example, of how to use the time parameters with the wget.
I see there are the following parameters
smon, sday, syear, shour, smin, ssec
emon, eday, eyear, ehour, emin, esec
What I am hoping is that I can set the wget with these parameters to pull availability report as of the last xx minutes from the current time the script runs. That is, If it runs today at 18:00 hours, can I use these parameters to pull availability data as of today between 17:30 hours and 18:00 hours?
Is this possible using wget and is there anything that describes the format? So far it seems to ignore what I put into these parameters.
Thank you,
Mark
Re: nagios csv question
Posted: Wed Jan 14, 2015 4:33 pm
by abrist
No problem. I like obscure things
It looks like you can forgo using any of the time parameters, by just using the timeperiod parameter:
timeperiod
Timeperiod which should be used for the availability report. Options:
today; yesterday; thisweek; lastweek; thismonth; lastmonth; thisquarter; lastquarter; thisyear; lastyear; last24hours; last7days; last31days; custom
Re: nagios csv question
Posted: Wed Jan 14, 2015 8:41 pm
by marpan
Thank you for your reply. I will experiment more with the timeperiod.
Do you know when would one would want to use the shour/ehour, smin/emin parameters in wget?
Thank you,
Mark
Re: nagios csv question
Posted: Thu Jan 15, 2015 4:10 pm
by abrist
For specific timeframes, like "yesterday 11am to 6pm today".
Re: nagios csv question
Posted: Thu Jan 15, 2015 4:10 pm
by tmcdonald
The s<unit> and e<unit> parameters stand for "start" and "end" respectively. They can be used for very fine-tuned searches, for example if you need to (for whatever reason) look at exactly a 37-second window.
Re: nagios csv question
Posted: Wed Nov 11, 2015 2:21 pm
by DiegoAnjos
Hi
@abrist
Is it possible to get the "time" results in format DD:HH:MM:SS ?
Regards,
Diego