Page 1 of 1

Nagios XI MySQL export query help

Posted: Tue Jan 31, 2017 12:11 pm
by highness
Had a business unit request a CSV export of all of our hosts, their respective services as well as the command arguments in MySQL. The query works well and looks like this:

Code: Select all

select a.alias, b.display_name, b.check_command_args from nagios.nagios_hosts a, nagios.nagios_services b where ((a.host_object_id = b.host_object_id)) order by a.alias INTO OUTFILE "/tmp/hosts_n_services.csv" fields terminated by ',' enclosed by '"' lines terminated by '\n';
I just got another request to add the host group that each host is assigned to this query - after poking around for a bit, I'm not seeing an easy way to include that. Is there any MySQL gurus who could give me an assist on this query?

Re: Nagios XI MySQL export query help

Posted: Tue Jan 31, 2017 3:35 pm
by tmcdonald
This is a bit out of scope for standard support, but look into the tbl_lnkHostToHostgroup table in the nagiosql database. That is what maintains the relations in the CCM between a host and the hostgroups it is in. There is also tbl_lnkHostgroupToHost in case the host was added from the hostgroup edit page. There are also templates to consider, which is why this is such a weird query to write.

Re: Nagios XI MySQL export query help

Posted: Thu Feb 02, 2017 4:18 pm
by highness
Understood that this isn't a normal support question, but I am *VERY* appreciative for the assist, Trevor.

Please feel free to lock this topic.