Hi,
What is the recommended way to locate hosts and services that have _no_ groups (host, contact, service) assigned?
Is there perhaps some report for this (I can't find one), or maybe this needs to be done via SQL query?
Thanks,
Otto
Finding hosts and services not in groups
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Finding hosts and services not in groups
We don't have a report for that, you could either program something through the API or, here is a few sample queries that I think will get you close
Services not in service groups
Hosts not in host groups
Code: Select all
mysql -pnagiosxi nagiosCode: Select all
SELECT o.name1 as host_name, o.name2 AS service_description
FROM nagios_objects o
WHERE o.object_id NOT IN (SELECT service_object_id from nagios_servicegroup_members)
AND is_active=1
AND objecttype_id=2;Code: Select all
SELECT o.name1 as host_name
FROM nagios_objects o
WHERE o.object_id NOT IN (SELECT host_object_id from nagios_hostgroup_members)
AND is_active=1
AND objecttype_id=1;Re: Finding hosts and services not in groups
Thanks!
Could you please show how to find hosts and services with no Contact Groups defined too?
Could you please show how to find hosts and services with no Contact Groups defined too?
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Finding hosts and services not in groups
Sureottow wrote:Thanks!
Could you please show how to find hosts and services with no Contact Groups defined too?
Code: Select all
SELECT o.name1 as contact
FROM nagios_objects o
WHERE o.object_id NOT IN (SELECT contact_object_id from nagios_contactgroup_members)
AND is_active=1
AND objecttype_id=10;Re: Finding hosts and services not in groups
I am sorry but I just tested the above and it does not show the hosts or services I have 0 contact groups defined for.
MariaDB [nagios]> SELECT o.name1 as contact FROM nagios_objects o WHERE o.object_id NOT IN (SELECT contact_object_id from nagios_contactgroup_members) AND is_active=1 AND objecttype_id=10;
Empty set (0.01 sec)
MariaDB [nagios]> SELECT o.name1 as contact FROM nagios_objects o WHERE o.object_id NOT IN (SELECT contact_object_id from nagios_contactgroup_members) AND is_active=1 AND objecttype_id=10;
Empty set (0.01 sec)
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Finding hosts and services not in groups
Sorry I misread your question the above was for contacts not in a contact group... For the hosts and services with no Contact Groups defined you would use a different database to grab from the CCM.ottow wrote:I am sorry but I just tested the above and it does not show the hosts or services I have 0 contact groups defined for.
MariaDB [nagios]> SELECT o.name1 as contact FROM nagios_objects o WHERE o.object_id NOT IN (SELECT contact_object_id from nagios_contactgroup_members) AND is_active=1 AND objecttype_id=10;
Empty set (0.01 sec)
use nagiosql;
Hosts with no contact groups
Code: Select all
SELECT host_name
FROM tbl_host, tbl_lnkHostToContactgroup
WHERE tbl_host.id NOT IN (SELECT tbl_lnkHostToContactgroup.idMaster from tbl_lnkHostToContactgroup)
GROUP BY host_name;Code: Select all
SELECT tbl_host.host_name, service_description
FROM tbl_host, tbl_service, tbl_lnkServiceToContactgroup, tbl_lnkServiceToHost
WHERE tbl_service.id NOT IN (SELECT tbl_lnkServiceToContactgroup.idMaster from tbl_lnkServiceToContactgroup)
AND tbl_service.id = tbl_lnkServiceToHost.idMaster
AND tbl_host.id = tbl_lnkServiceToHost.idSlave
GROUP BY tbl_host.host_name, service_description;Re: Finding hosts and services not in groups
Excellent, this works as expected. Tank you very much!!
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Finding hosts and services not in groups
No problemottow wrote:Excellent, this works as expected. Tank you very much!!
Locking thread