nagios csv question

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
marpan
Posts: 4
Joined: Fri Sep 12, 2014 1:05 pm

nagios csv question

Post 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
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: nagios csv question

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
marpan
Posts: 4
Joined: Fri Sep 12, 2014 1:05 pm

Re: nagios csv question

Post by marpan »

Thank you for your quick reply. I am somewhat new to Nagios and I will check study your examples.

Thank you,
Mark
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: nagios csv question

Post by abrist »

No problem. Let me know if you have any other questions.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
marpan
Posts: 4
Joined: Fri Sep 12, 2014 1:05 pm

Re: nagios csv question

Post 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
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: nagios csv question

Post by abrist »

No problem. I like obscure things :P

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
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
marpan
Posts: 4
Joined: Fri Sep 12, 2014 1:05 pm

Re: nagios csv question

Post 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
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: nagios csv question

Post by abrist »

For specific timeframes, like "yesterday 11am to 6pm today".
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: nagios csv question

Post 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.
Former Nagios employee
DiegoAnjos
Posts: 49
Joined: Thu Feb 14, 2013 9:32 am

Re: nagios csv question

Post by DiegoAnjos »

Hi @abrist

Is it possible to get the "time" results in format DD:HH:MM:SS ?

Regards,
Diego
Locked