SQL/API query to find disabled hosts and services?
SQL/API query to find disabled hosts and services?
Hi,
We are finding that despite repeated instructions to not do it, some of our admins like to disable hosts and services rather than use the Schedule Downtime feature.
This presents a problem if they forget to re-enable...
Could you please help us define a SQL or API query that will list all disabled Hosts and Services, so we can report on these?
Thanks,
Otto
We are finding that despite repeated instructions to not do it, some of our admins like to disable hosts and services rather than use the Schedule Downtime feature.
This presents a problem if they forget to re-enable...
Could you please help us define a SQL or API query that will list all disabled Hosts and Services, so we can report on these?
Thanks,
Otto
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: SQL/API query to find disabled hosts and services?
Hi Otto,
There maybe a few ways to tackle this one. Just to clarify, are these hosts and services being de-activated in the Core Configuration Manager (CCM)? It's also possible to turn off active/passive checks or notifications using the Command options for the host or service status detail page. Let me know.
If you're de-activating from the CCM, you can run the following query.
For hosts:
For services:
--Benjamin
There maybe a few ways to tackle this one. Just to clarify, are these hosts and services being de-activated in the Core Configuration Manager (CCM)? It's also possible to turn off active/passive checks or notifications using the Command options for the host or service status detail page. Let me know.
If you're de-activating from the CCM, you can run the following query.
Code: Select all
# login into mysql
MySQL -u root -p
use nagiosql;
Code: Select all
SELECT host_name
FROM tbl_host
WHERE active = '0';
Code: Select all
SELECT tbl_host.host_name, service_description FROM tbl_host, tbl_service, tbl_lnkServiceToHost WHERE tbl_service.active = '0' AND tbl_service.id = tbl_lnkServiceToHost.idMaster AND tbl_host.id = tbl_lnkServiceToHost.idSlave GROUP BY tbl_host.host_name, service_description;
Last edited by tgriep on Wed Feb 10, 2021 1:06 pm, edited 1 time in total.
Reason: Updated Query with some syntax changes and to show de-activated objects.
Reason: Updated Query with some syntax changes and to show de-activated objects.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: SQL/API query to find disabled hosts and services?
Thanks, this is what I was looking for but your answer also made me realize there are other ways admins could avoid following instructions to use Scheduled Downtime...
Subsequently, I'd appreciate if your could help with SQL queries listing Hosts and Services with Notifications disabled, and also Hosts and Services with disabled active/passive checks.
Subsequently, I'd appreciate if your could help with SQL queries listing Hosts and Services with Notifications disabled, and also Hosts and Services with disabled active/passive checks.
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: SQL/API query to find disabled hosts and services?
Hi @ottow,
The queries are very similar, just plugin in the options you want to pull from. You can run the following command to see all table structure.
Host Queries
Services
Regards,
Benjamin
The queries are very similar, just plugin in the options you want to pull from. You can run the following command to see all table structure.
Code: Select all
describe tbl_host;
describe tbl_service;
Code: Select all
#Host Active Checks Disabled
SELECT host_name
FROM tbl_host
WHERE active_checks_enabled = 0;
#Host Notifications Disabled
SELECT host_name
FROM tbl_host
WHERE notifications_enabled = 0;
Code: Select all
# ServiceNotifications Disabled
SELECT tbl_host.host_name, service_description FROM tbl_host, tbl_service, tbl_lnkServiceToHost WHERE tbl_service.notifications_enabled=0 AND tbl_service.id = tbl_lnkServiceToHost.idMaster AND tbl_host.id = tbl_lnkServiceToHost.idSlave GROUP BY tbl_host.host_name, service_description;
# Service Active Checks Disabled
SELECT tbl_host.host_name, service_description FROM tbl_host, tbl_service, tbl_lnkServiceToHost WHERE tbl_service.active_checks_enabled=0 AND tbl_service.id = tbl_lnkServiceToHost.idMaster AND tbl_host.id = tbl_lnkServiceToHost.idSlave GROUP BY tbl_host.host_name, service_description;
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
SteveBeauchemin
- Posts: 524
- Joined: Mon Oct 14, 2013 7:19 pm
Re: SQL/API query to find disabled hosts and services?
This is what I call a gem of a post.
I plan to take all those queries, turn them into what I call Finder tests. I'll make them special services that are not activated, but can be run from the GUI to see the result. Then, I can open the Finder service test in the CCM, click the "Run Check Command" button, and see on the spot if we have an issue of training to deal with.
Thanks.
Steve B
I plan to take all those queries, turn them into what I call Finder tests. I'll make them special services that are not activated, but can be run from the GUI to see the result. Then, I can open the Finder service test in the CCM, click the "Run Check Command" button, and see on the spot if we have an issue of training to deal with.
Thanks.
Steve B
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: SQL/API query to find disabled hosts and services?
It is also worth pointing out that users could just disable active checks through the UI, and not in the CCM, these can be found by navigating to the following URLs
Or they can be queried through the host/service status API by appending the following to the URL
Or they could disable notifications through the UI, and not in the CCM, these can be found by navigating to the following URLs
Or they can be queried through the host/service status API by appending the following to the URL
Code: Select all
/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=16
/nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=16Code: Select all
&active_checks_enabled=0Code: Select all
/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=4096
/nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=4096Code: Select all
¬ifications_enabled=0Re: SQL/API query to find disabled hosts and services?
You may want to take a look at https://support.nagios.com/forum/viewto ... 16&t=59669 too then.SteveBeauchemin wrote:This is what I call a gem of a post.
I plan to take all those queries, turn them into what I call Finder tests. I'll make them special services that are not activated, but can be run from the GUI to see the result. Then, I can open the Finder service test in the CCM, click the "Run Check Command" button, and see on the spot if we have an issue of training to deal with.
Thanks.
Steve B
My approach is a script that runs these queries weekly and e-mails the results to the Nagios Admins for them to fix.
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: SQL/API query to find disabled hosts and services?
Thanks @ottowottow wrote:You may want to take a look at https://support.nagios.com/forum/viewto ... 16&t=59669 too then.SteveBeauchemin wrote:This is what I call a gem of a post.
I plan to take all those queries, turn them into what I call Finder tests. I'll make them special services that are not activated, but can be run from the GUI to see the result. Then, I can open the Finder service test in the CCM, click the "Run Check Command" button, and see on the spot if we have an issue of training to deal with.
Thanks.
Steve B
My approach is a script that runs these queries weekly and e-mails the results to the Nagios Admins for them to fix.
Re: SQL/API query to find disabled hosts and services?
This is another good point, although I am unable to figure out how to set up the API query properly.scottwilkerson wrote:It is also worth pointing out that users could just disable active checks through the UI, and not in the CCM, these can be found by navigating to the following URLsOr they can be queried through the host/service status API by appending the following to the URLCode: Select all
/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=16 /nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=16Or they could disable notifications through the UI, and not in the CCM, these can be found by navigating to the following URLsCode: Select all
&active_checks_enabled=0Or they can be queried through the host/service status API by appending the following to the URLCode: Select all
/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=4096 /nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=4096Code: Select all
¬ifications_enabled=0
The following query works with 1 disabled notification. But not 2:
curl -XGET -k -L --silent "http://nagiosserver.corp.com/nagiosxi/a ... _enabled=0"| jq '.servicestatus.host_name, .servicestatus.name' |tr -d '"' |paste - -
And this works with 2 or more disabled notifications. But not with 1:
curl -XGET -k -L --silent "http://nagiosserver.corp.com/nagiosxi/a ... _enabled=0"| jq '.servicestatus[] | .host_name, .name' |tr -d '"' |paste - -
I am clearly missing something here...
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: SQL/API query to find disabled hosts and services?
I'm not familiar with what you are running after the curl command, that is not part of the Nagios XI API