Hosts not belonging to any hostgroup

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
bramassendorp
Posts: 28
Joined: Sun Jun 09, 2019 3:16 am

Hosts not belonging to any hostgroup

Post by bramassendorp »

Hi,

Is it possible to generate a list of hosts that are not member of any hostgroup?

Via the API I managed to get a list of hosts per hostgroup, but I also need a list of hosts that do not have any hostgroup.

Thnx.
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Hosts not belonging to any hostgroup

Post by gsmith »

Hi

From a CLI on your Nagios XI server please run:

Code: Select all

echo "select id, host_name from tbl_host where id not in (select idMaster from  tbl_lnkHostToHostgroup) order by host_name;" | mysql -u root -pnagiosxi nagiosql

Thanks
bramassendorp
Posts: 28
Joined: Sun Jun 09, 2019 3:16 am

Re: Hosts not belonging to any hostgroup

Post by bramassendorp »

gsmith wrote:Hi

From a CLI on your Nagios XI server please run:

Code: Select all

echo "select id, host_name from tbl_host where id not in (select idMaster from  tbl_lnkHostToHostgroup) order by host_name;" | mysql -u root -pnagiosxi nagiosql

Thanks
Hi,

Yes, that works, but only for hosts that where added via the host config, and not added via the hostgroup config.
We have a mixed situation, so I need a method to have a list with hosts without a host group, but not depending on what method it's added.

Thnx.
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Hosts not belonging to any hostgroup

Post by gsmith »

Hi

Please send me a database dump as follows:

To send us a database dump
1. mysqldump -uroot -pnagiosxi nagios > /tmp/nagios.sql
2. tar -cvzf /tmp/nagios.sql.tar.gz /tmpnagios.sql
3. Share the /tmpnagios.sql.tar.gz in a private message and then reply to this post to bring it up in the queue.


Also please give the names of a few hosts that were added via added via the hostgroup config so I can
refine the sql query.

Thanks
bramassendorp
Posts: 28
Joined: Sun Jun 09, 2019 3:16 am

Re: Hosts not belonging to any hostgroup

Post by bramassendorp »

gsmith wrote:Hi

Please send me a database dump as follows:

To send us a database dump
1. mysqldump -uroot -pnagiosxi nagios > /tmp/nagios.sql
2. tar -cvzf /tmp/nagios.sql.tar.gz /tmpnagios.sql
3. Share the /tmpnagios.sql.tar.gz in a private message and then reply to this post to bring it up in the queue.


Also please give the names of a few hosts that were added via added via the hostgroup config so I can
refine the sql query.

Thanks
Hi,

You got me on the right track, seems there are two tables, sounds this about right to you?

select id, host_name from tbl_host where id not in (select idMaster from tbl_lnkHostToHostgroup) and id not in (select idSlave from tbl_lnkHostgroupToHost) order by host_name;

btw, can you maybe explain what the difference is between the databases, I have the nagios, nagiosql and nagiosxi databases.
The above data I could also get from the nagios database, different tables but it could be done.

Can you explain which one best to use?

Thank you!
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Hosts not belonging to any hostgroup

Post by gsmith »

Hi

Yes it sounds like you have a good handle on it.

There are 3 databases. nagios and nagiosql existed for Nagios Core, and the
Nagios XI database was added for Nagios XI. You are correct, you could query on
just the nagios db to get what you need. You could think of the nagiosql database
as the equivalent of a set of foreign keys for the nagios db.

Please let me know if that answers your questions, if so I will lock this thread.

Thank you
bramassendorp
Posts: 28
Joined: Sun Jun 09, 2019 3:16 am

Re: Hosts not belonging to any hostgroup

Post by bramassendorp »

gsmith wrote:Hi

Yes it sounds like you have a good handle on it.

There are 3 databases. nagios and nagiosql existed for Nagios Core, and the
Nagios XI database was added for Nagios XI. You are correct, you could query on
just the nagios db to get what you need. You could think of the nagiosql database
as the equivalent of a set of foreign keys for the nagios db.

Please let me know if that answers your questions, if so I will lock this thread.

Thank you
Yes, all done, thnx!
Locked