Service Delete API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Service Delete API

Post by dh0125e »

We do not directly align hosts to any of our services, all services are aligned with hostgroups. How do I delete a service via the REST API? The call REQUIRES host_name based upon the documentation and what I could find in the php back end.

I currently have automations in place that will push new and updated services across our infrastructure as required, however I need to now have the ability to remove out dated services faster.

I found some posts from 2011 that said it was in progress ... I really hope it's done?
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: Service Delete API

Post by dh0125e »

Hi Nagios Team, any thoughts on this or should I open a ticket?
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Service Delete API

Post by cdienger »

Use the endpoint config/service/<config_name>/<service_description> and you don't need to pass the hostname:

Code: Select all

curl -XDELETE "http://xi_ip/nagiosxi/api/v1/config/service/localhost/PING?apikey=apikey&pretty=1&service_description=PING&applyconfig=1"
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: Service Delete API

Post by dh0125e »

I'm assuming the service description in the URL doesn't need to be there twice? I'll be testing this shortly.
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: Service Delete API

Post by dh0125e »

Hmm something is wrong, it still doesn't appear to be working for me. I've got this deployed to a host because of testing however it won't delete when the URL is being used. I'm using a complicated service_description as it matches reality. The configname and description are being looked up from the host that it's attempting to delete the item from, the only manipulation to the name / description was making it URL friendly.

Doing DELETE to:https://XIHOST:443/nagiosxi/api/v1/conf ... PIGOESHERE :: with:null
Post Processing Output: {
"error": "Could not remove services. Failed services may not exist.",
"services": [

],
"failed": [
"Linux_Baseline - SomethingSomethig - __ Goes Here"
]
}

-----

Service Definition
define service {
host_name localhost
service_description SomethingSomethig - __ Goes Here
use <TEMPLATE Name>
check_command check_tcp!5693!!!!!!!
register 1
}
dchurch
Posts: 858
Joined: Wed Oct 07, 2020 12:46 pm
Location: Yo mama

Re: Service Delete API

Post by dchurch »

Try sending it with localhost instead of Linux_Baseline as the hostname, i.e. https://XIHOST:443/nagiosxi/api/v1/conf ... ]localhost[/u]/SomethingSomethig%20-%20__%20Goes%20Here?apikey=APIGOESHERE
If you didn't get an 8% raise over the course of the pandemic, you took a pay cut.

Discussion of wages is protected speech under the National Labor Relations Act, and no employer can tell you you can't disclose your pay with your fellow employees.
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: Service Delete API

Post by dh0125e »

Linux_Baseline is the confg_name in the monitor so I'm confused by that recommendation? There is no hostname part of the service definition.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Service Delete API

Post by cdienger »

Hey @dh0125e, it looks like I tested something incorrectly and this will not work. Sorry for the bad info. We can file a feature request for this though.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dh0125e
Posts: 40
Joined: Tue Aug 04, 2020 9:30 am

Re: Service Delete API

Post by dh0125e »

According to forum posts I found this was in the pipeline in 2011. Just confirming this has NOT been resolved? If not yes this needs to be an RFE.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Service Delete API

Post by ssax »

I labbed it up as well and it will not work without a host_name being passed as you original found, in the previous examples they are still passing a host_name but it's being pulled from the URL (config/service/localhost/PING). Whatever you set in bold there will be the host_name.

I've created a request for development to add this as a feature:

FR: XI - API - config/service DELETE - Add the ability to delete services by config_name and service description for services that are assigned via hostgroups

Please keep in mind that the decision to implement the enhancement is at the discretion of our development team.

Thank you! Sorry for any confusion!
Locked