Generate CSV report from command line

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Generate CSV report from command line

Post by rajasegar »

Nagios XI 2014R1.2

Code: Select all

curl "http://10.17.19.235/nagiosxi/backend/?cmd=getstatehistory&&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=both&mode=csv&username=nagiosadmin&ticket=ei5111111"
Please advice if the above can be exported as csv instead of xml.

Thanks.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Generate CSV report from command line

Post by abrist »

Unfortunately no. The XI backend responds only with XML. The Core JSON backend responds in JSON format (through the json cgis). There are a few reports that can be exported as csv, though you are probably better off just converting the xml to csv using one of the many online or cli tools. I think excel can convert them as well.
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.
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: Generate CSV report from command line

Post by rajasegar »

Can you please advice how to query using time period?

Code: Select all

curl "http://10.17.19.235/nagiosxi/backend/?cmd=getstatehistory&search=&reportperiod=custom&startdate=2015-03-12+7%3A00&enddate=2015-03-12+15%3A30&hostgroup=&servicegroup=&statetype=both&reporttime&username=nagiosadmin&ticket=ei111111"
The URL above just returns last 24 hours based on current datetime.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: Generate CSV report from command line

Post by rajasegar »

Already found solution

Timestamp must use unix format

date -d '2015-03-10 07:30:00' +"%s"

curl "http://10.17.19.235/nagiosxi/backend/?c ... t=ei111111" >t.xml

Please close this thread.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Generate CSV report from command line

Post by ssax »

Thank you for posting the solution, closing now.
Locked