SQL/API query to find disabled hosts and services?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
ottow
Posts: 44
Joined: Wed Nov 15, 2017 3:45 am

SQL/API query to find disabled hosts and services?

Post by ottow »

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
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: SQL/API query to find disabled hosts and services?

Post by benjaminsmith »

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.

Code: Select all

# login into mysql
MySQL -u root -p
use nagiosql;
For hosts:

Code: Select all

SELECT host_name
FROM tbl_host
WHERE active = '0';
For services:

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;
--Benjamin
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.
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!
ottow
Posts: 44
Joined: Wed Nov 15, 2017 3:45 am

Re: SQL/API query to find disabled hosts and services?

Post by ottow »

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.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: SQL/API query to find disabled hosts and services?

Post by benjaminsmith »

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.

Code: Select all

describe tbl_host;
describe tbl_service;
Host Queries

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;
Services

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;
Regards,
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!
SteveBeauchemin
Posts: 524
Joined: Mon Oct 14, 2013 7:19 pm

Re: SQL/API query to find disabled hosts and services?

Post by SteveBeauchemin »

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
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
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?

Post by scottwilkerson »

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

Code: Select all

/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=16
/nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=16
Or they can be queried through the host/service status API by appending the following to the URL

Code: Select all

&active_checks_enabled=0
Or they could disable notifications through the UI, and not in the CCM, these can be found by navigating to the following URLs

Code: Select all

/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=4096
/nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=4096
Or they can be queried through the host/service status API by appending the following to the URL

Code: Select all

&notifications_enabled=0
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ottow
Posts: 44
Joined: Wed Nov 15, 2017 3:45 am

Re: SQL/API query to find disabled hosts and services?

Post by ottow »

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
You may want to take a look at https://support.nagios.com/forum/viewto ... 16&t=59669 too then.
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?

Post by scottwilkerson »

ottow wrote:
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
You may want to take a look at https://support.nagios.com/forum/viewto ... 16&t=59669 too then.
My approach is a script that runs these queries weekly and e-mails the results to the Nagios Admins for them to fix.
Thanks @ottow
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ottow
Posts: 44
Joined: Wed Nov 15, 2017 3:45 am

Re: SQL/API query to find disabled hosts and services?

Post by ottow »

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 URLs

Code: Select all

/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=16
/nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=16
Or they can be queried through the host/service status API by appending the following to the URL

Code: Select all

&active_checks_enabled=0
Or they could disable notifications through the UI, and not in the CCM, these can be found by navigating to the following URLs

Code: Select all

/nagiosxi/includes/components/xicore/status.php?show=services&serviceattr=4096
/nagiosxi/includes/components/xicore/status.php?show=hosts&hostattr=4096
Or they can be queried through the host/service status API by appending the following to the URL

Code: Select all

&notifications_enabled=0
This is another good point, although I am unable to figure out how to set up the API query properly.

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?

Post by scottwilkerson »

I'm not familiar with what you are running after the curl command, that is not part of the Nagios XI API
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked