AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire service?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
eloyd
Cool Title Here
Posts: 2171
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire service?

Post by eloyd »

I'm going to reference viewtopic.php?p=341965&hilit=api+delete and say that we're doing similar things across a massive collection of customers' Nagios XI instances.
  • Service runs on hostgroup
  • Host gets added to hostgroup via template (or directly via .cfg file dropped into import directory)
  • Sometimes, individual hosts get added to the hosts list for a specific service
  • Never does a service get added to a single host if that service is the same as an existing service (other than the hostname, of course)
This is great for managing large installations where things need to be added dynamically (simply add a host, put the right template on it to add it to the right hostgroups, and it starts monitoring all the right services). This is not great for using the API to make changes. Plus, there is no way to disable a host or service configuration in the database via the API unless one directly modifies the database (no, No, NO!).

We've confirmed that if we have a host named HOSTA and a host named HOSTB and a service named SERVICEX that is configured to run on both HOSTA and HOSTB, using the API DELETE config/service command will delete the entire service, even if host_name=HOSTA on the API URL. This is bad thing #1.

We've also confirmed that there is no way (that we can figure out) through the API to mark SERVICEX as "not active." Nor can we mark only the HOSTB version of SERVICEX as inactive. Which is understandable, since it's a single service listed as running on multiple hosts.

It would be ideal if we could mark the service or host definition as active/inactive, just like one can on the GUI. This would solve @WillH's problems as well as ours, and let us do an end-run around some of other things that we currently have to do because of the hot mess that is Nagios Core configuration files.

Ideally, the entire thing would be rewritten so you could define an object that has your default monitoring stuff, then inherit that object on another object that defines a host, then have another object that inherits that object that defines a service, and so on. Object Oriented Configuration for monitoring, basically. Then one could easily insert something into the chain or override an instance of it, just like in any OOP language. But I digress.

In the short term, is there any way to use the API to disable something yet? If not, is there any way to delete a host from the list of hosts that the service runs on without deleting the entire service?
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
danderson
Posts: 224
Joined: Wed Aug 09, 2023 10:05 am

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by danderson »

Thanks for reaching out @eloyd,

So from what I understand about the problem you are having is that you have a service with a hostgroup instead of a host, and you want to disable that service check only for a specific host inside of that hostgroup.

You could try submitting a core command to disable that specific service.

Something like

Code: Select all

curl -XPOST "https://{hostname}/nagiosxi/api/v1/system/corecommand?apikey={APIKEY}" -d "cmd=DISABLE_SVC_CHECK;HOSTB;SERVICEX"
User avatar
eloyd
Cool Title Here
Posts: 2171
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by eloyd »

Yup, I could do that. But that's not what I'm asking for.

I'm asking for an API call that will let one toggle the "Active" flag of a config entry. Just like you can do from the XI GUI. Sending a Nagios Core command to disable the service checks simply stops the checks from happening, but leaves the entity configured. With all of the reporting and such that that implies. I'm looking for a way to flick the "Active" flag of something in the Nagios XI Core Configuration Manager so we can turn on/off entire parts of the monitoring and remove it from the running system, same as if you'd done it via the GUI.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
eloyd
Cool Title Here
Posts: 2171
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by eloyd »

Plus, this is still a problem:
We've confirmed that if we have a host named HOSTA and a host named HOSTB and a service named SERVICEX that is configured to run on both HOSTA and HOSTB, using the API DELETE config/service command will delete the entire service, even if host_name=HOSTA on the API URL. This is bad thing #1.
But we can live with that now that we understand it.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
gregbeyer
Posts: 147
Joined: Fri Sep 11, 2020 2:13 pm

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by gregbeyer »

Lacking an API call, you can disable a specific host from a service check via the GUI. Not sure if this scales for you, but worth throwing out.

CCM / Edit service / Managed Hosts. ADD the host(s) in question. Once added, click "!" next to them, to explicitly exclude them from the service check.

If you have a large number of hosts you need to do this for, you could add those hosts to a hostgroup, then do the same thing above, but Manage Hostgroups instead of Hosts.

Hope this helps.
User avatar
eloyd
Cool Title Here
Posts: 2171
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by eloyd »

I thought I was clear, but maybe I wasn't. You can do the same thing via the API if you know what the underlying config file should look like. But I don't think that the API DELETE command should delete the entire service check if only one host is specified, and more hosts are still listed on the service check.

I realize the API is a work in progress and has to deal with the CF that is Nagios Core configuration files, but it would be nice it there was a single approach that worked without having to double check edge cases before committing changes made via API calls.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
jsimon
Posts: 255
Joined: Wed Aug 23, 2023 11:27 am

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by jsimon »

Hi Eric,

I agree with you, there doesn't seem to be a way to disable a service via the API. I've made a feature request to add that functionality as well as adding a way to remove a service from a host without completely deleting the service via the API.
User avatar
eloyd
Cool Title Here
Posts: 2171
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by eloyd »

:thumbs_up: :-)
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by snapier3 »

jsimon wrote: Thu Oct 03, 2024 10:40 am Hi Eric,

I agree with you, there doesn't seem to be a way to disable a service via the API. I've made a feature request to add that functionality as well as adding a way to remove a service from a host without completely deleting the service via the API.
I went through this working out auto acknowledge bit with a notification handler project.

As you deploy one to many services you're writing the core configs based on the object definitions stored in CCM. There are still X thousands of config files written in core so I used the external command route to directly target the host/service in core.

https://assets.nagios.com/downloads/nag ... ternalcmds

DISABLE_SVC_CHECK <host_name>;<service_description>
This will temporarily disable checks of the specified service. Service checks are automatically re-enabled when Nagios restarts. Issuing this command will have the side effect of temporarily preventing notifications from being sent out for the service. It does not prevent notifications about the host from being sent out.

This should allow you to deal with the individual object.

--SN
User avatar
eloyd
Cool Title Here
Posts: 2171
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: AP: Is there a way to delete a host from the list of hosts that the service runs on without deleting the entire serv

Post by eloyd »

I am not looking for a way to temporarily disable service check execution. I am asking for a way to flip the active/inactive bit on the service, just like one can do in the GUI. Flipping it inactive will cause it to be ignored when XI Applies Configuration and it will not be written to the Nagios Core config files in the first place.

That's what I'm looking for. :-)
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Post Reply