0

I am trying to extract the nagios availability report data from nagios (Nagios® Core™ 4.0.8) for a week(7days) and get the output in csv format.

Here is the URL in am querying to backend /passing as arguments to avail.cgi :

https://username:password@nagioshostname/nagios/cgi-bin/avail.cgi?show_log_entries=&servicegroup=services1&timeperiod=last7days&smon=8&sday=1&syear=2017&shour=0&smin=0&ssec=0&emon=8&eday=3&eyear=2017&ehour=24&emin=0&esec=0&rpttimeperiod=24x7&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedhoststate=3&initialassumedservicestate=0&backtrack=4&csvoutput=1

above URL without returns me data with avail.cgi which ends up having html & response.

<BR><BR>
<DIV ALIGN=CENTER CLASS='dataTitle'>Servicegroup 'services1' Host State Breakdowns:</DIV>
<DIV ALIGN=CENTER>
<TABLE BORDER=0 CLASS='data'>
<TR><TH CLASS='data'>Host</TH><TH CLASS='data'>% Time Up</TH><TH CLASS='data'>% Time Down</TH><TH CLASS='data'>% Time Unreachable</TH><TH CLASS='data'>% Time Undetermined</TH></TR>
<tr CLASS='dataOdd'><td CLASS='dataOdd'><a href='avail.cgi?host=server1.amaze.com%3A1717&show_log_entries&t1=1506233939&t2=1506838739&backtrack=4&assumestateretention=yes&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=3&initialassumedservicestate=0&show_log_entries&showscheduleddowntime=yes&rpttimeperiod=24x7'>server1.amaze.com1717</a></td><td CLASS='hostUP'>100.000% (100.000%)</td><td CLASS='hostDOWN'>0.000% (0.000%)</td><td CLASS='hostUNREACHABLE'>0.000% (0.000%)</td><td class='dataOdd'>0.000%</td></tr>
<tr CLASS='dataEven'><td CLASS='dataEven'><a href='avail.cgi?host=server2.amaze.com%3A1717&show_log_entries&t1=1506233939&t2=1506838739&backtrack=4&assumestateretention=yes&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=3&initialassumedservicestate=0&show_log_entries&showscheduleddowntime=yes&rpttimeperiod=24x7'>server2.amaze.com</a></td><td CLASS='hostUP'>100.000% (100.000%)</td><td CLASS='hostDOWN'>0.000% (0.000%)</td><td CLASS='hostUNREACHABLE'>0.000% (0.000%)</td><td class='dataEven'>0.000%</td></tr>
<tr CLASS='dataOdd'><td CLASS='dataOdd'><a href='avail.cgi?host=server3.amaze.com%3A1717&show_log_entries&t1=1506233939&t2=1506838739&backtrack=4&assumestateretention=yes&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=3&initialassumedservicestate=0&show_log_entries&showscheduleddowntime=yes&rpttimeperiod=24x7'>server3.amaze.com</a></td><td CLASS='hostUP'>100.000% (100.000%)</td><td CLASS='hostDOWN'>0.000% (0.000%)</td><td CLASS='hostUNREACHABLE'>0.000% (0.000%)</td><td class='dataOdd'>0.000%</td></tr>
<tr CLASS='dataEven'><td CLASS='dataEven'><a href='avail.cgi?host=server4.amaze.com%3A1717&show_log_entries&t1=1506233939&t2=1506838739&backtrack=4&assumestateretention=yes&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=3&initialassumedservicestate=0&show_log_entries&showscheduleddowntime=yes&rpttimeperiod=24x7'>server4.amaze.com</a></td><td CLASS='hostUP'>100.000% (100.000%)</td><td CLASS='hostDOWN'>0.000% (0.000%)</td><td CLASS='hostUNREACHABLE'>0.000% (0.000%)</td><td class='dataEven'>0.000%</td></tr>

Is there any way to get the data in csv format or json other than this html output ? I am aware that if i query the same in browser it will show the results in proper HTML page but my further use case is different and I want to evaluate the data from here so I need the report in such a format which I can later manipulate with a language (ex :- python) according to the need.

Alex
  • 189
  • 4
  • 23

1 Answers1

0

https://username:password@nagioshostname/nagios/jsonquery.html

Select "Archive JSON CGI" then set "Query" to "Availability".

Lots of options in there to get specific.

Enjoy :)

Will Ryan
  • 661
  • 1
  • 7
  • 17
  • It doesn't gives me option to get directly in CSV format , Also i am not able to set the time period value . will that be an epoch format? – Alex Oct 27 '17 at 23:45
  • Hi, yes, the date/time is in epoch format and this returns in JSON format. I don't think there's a way to get CSV data out. You'll have to reformat the JSON in to CSV yourself i believe – Will Ryan Oct 31 '17 at 11:28
  • Thanks I did the same :-) – Alex Nov 01 '17 at 04:03