Page 1 of 1

Export Allowed Hosts with Specific Information to CSV

Posted: Thu Oct 27, 2016 8:16 am
by Deantwo
I got a user with readonly access to a specific hostgroup on my server.
He would like to be able to export a CSV file of all the hosts he has access to.

Looking around I found a few possible solutions, but they aren't very customizable. For example allowing me or him to specify which columns should be exported.
Examples of what I found: (source)

Code: Select all

http://<ip>/nagios/cgi-bin/objectjson.cgi?query=hostlist

Code: Select all

http://<ip>/nagiosxi/backend/?cmd=gethosts&brevity=3
So is there a way for me to maybe create my own version of one of those?

Also found linux code, so I could maybe make a bash script to do this, but there are a few issues with this.

Code: Select all

echo "use nagiosql; select display_name,notes,address from tbl_host into outfile '/tmp/hosts.csv' fields terminated by ',' enclosed by '\"' lines terminated by '\n'" | mysql -u root -pnagiosxi
First of all, it gets ALL hosts, rather than only the ones the user has access to. I am not familier with how the nagiosql is structured, so I don't know how to limit it to a hostgroup.
Not to mention the fact that I need display it on the Nagios XI site, which I have no idea how to do. Maybe it is possible to create a tool or something that can do this?

The output I am hoping to produce is simply something like this:

Code: Select all

<display_name>,<notes>,<address>
<display_name>,<notes>,<address>
<display_name>,<notes>,<address>
Is anyone able to point me in the right direction?

Re: Export Allowed Hosts with Specific Information to CSV

Posted: Thu Oct 27, 2016 10:21 am
by tmcdonald
What XI version are you on? In 5+ there is a new API with some filtering options. The documentation is in the XI interface in the Help menu, under the "Backend API Docs" section on the left. Take a look at that and see if you are able to get what you need. Currently it only support JSON and XML, but it's not terribly hard to convert that to CSV.