Page 1 of 1
Service Delete API
Posted: Fri Dec 11, 2020 4:23 pm
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?
Re: Service Delete API
Posted: Mon Dec 14, 2020 9:38 am
by dh0125e
Hi Nagios Team, any thoughts on this or should I open a ticket?
Re: Service Delete API
Posted: Mon Dec 14, 2020 4:12 pm
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"
Re: Service Delete API
Posted: Mon Dec 14, 2020 4:50 pm
by dh0125e
I'm assuming the service description in the URL doesn't need to be there twice? I'll be testing this shortly.
Re: Service Delete API
Posted: Mon Dec 14, 2020 5:34 pm
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
}
Re: Service Delete API
Posted: Tue Dec 15, 2020 4:20 pm
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
Re: Service Delete API
Posted: Tue Dec 15, 2020 4:32 pm
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.
Re: Service Delete API
Posted: Wed Dec 16, 2020 4:49 pm
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.
Re: Service Delete API
Posted: Wed Dec 16, 2020 4:51 pm
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.
Re: Service Delete API
Posted: Wed Dec 16, 2020 4:52 pm
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!