can't decommission host via api

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

can't decommission host via api

Post by doneil326 »

hello i am trying to use the rest api to remove a host from nagiosxi 5.2.3 using this command

curl -XDELETE "https://nagios/nagiosxi/api/v1/config/h ... lyconfig=1"

and i get this error:

"error": "Host cannot be deleted using this method. Must be deleted through the CCM."

however there are no dependencies i can see that should blcok this:

Database Relationships for host:
lptls03.lifelock.ad

Items labeled as: 'Dependent relationships' will prohibit deletion
Object ID: 764 of table tbl_host:
Relation to Hostgroups, entry: prod-linux-servers
Relation to Hostgroups, entry: ncpa-agents
Relation to Hosttemplates, entry: ll_ncpa_host

Also, i need to know how to script disabling notification on a hosts and its services via the api, so that we don't have to applyconfig everytime we try to decommission a server. This causes a service disruption with our nagvis setup and we have this scheduled to happen daily.

Thanks,
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: can't decommission host via api

Post by rkennedy »

There is either a dependency, or possibly a bug that was fixed between 5.2.3 and 5.2.7. I just ran the exact command, on a newly created host on my machine, without issues. -

Code: Select all

[root@localhost ~]# curl -XDELETE "http://192.168.4.223/nagiosxi/api/v1/config/host?apikey=58fvbk58&pretty=1&host_name=test5&applyconfig=1"
{
    "success": "Removed test5 from the system. Config applied, Nagios Core was restarted."
}
I do see a few bugs were fixed with the API between these versions as well.

As for disabling notifications, it's still going to require an apply configuration regardless.
Former Nagios Employee
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: can't decommission host via api

Post by doneil326 »

i updated to 5.2.7 and it worked for a few days and now i am bback to the same error. here is the dependency list, there are none.

Items labeled as: 'Dependent relationships' will prohibit deletion
Object ID: 601 of table tbl_host:
Relation to Hostgroups, entry: dev-linux-servers
Relation to Hostgroups, entry: ncpa-agents
Relation to Hosttemplates, entry: ll_ncpa_host

curl -x https://proxy:3128 -k -XDELETE "https://nagiosxi.lifelock.com/nagiosxi/ ... t.fqdn.com"
{
"error": "Host cannot be deleted using this method. Must be deleted through the CCM."
}
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: can't decommission host via api

Post by lmiltchev »

If the host didn't have any hostgroups added to it, you would be able to delete it via the REST API. I can confirm that this is a bug. You can delete a host with one or more hostgroups added to it in the CCM but when you try to delete the same host via the REST API, it errors out...

We will be filing an internal bug report shortly.
Be sure to check out our Knowledgebase for helpful articles and solutions!
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: can't decommission host via api

Post by bwallace »

Just filed a bug report for this - TASK ID 8500 -
Were there any other questions, or may we lock this thread?
Be sure to check out the Knowledgebase for helpful articles and solutions!
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: can't decommission host via api

Post by doneil326 »

ok so then the bug will be fixed in a later version and we will be able to do this?
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: can't decommission host via api

Post by bwallace »

That is correct, it should be fixed in a later version although I have zero details regarding a timeline as the FR was filed only a few hours ago.
Be sure to check out the Knowledgebase for helpful articles and solutions!
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: can't decommission host via api

Post by doneil326 »

ok, is there a workaround to do this remotely? we have this built into our deocmmissioning process in our check_mk instance that we are migrating from and need to reproduce it in xi. can the cmd.cgi be used? i don't see any cmd_typ that supports deletion of a host. thanks,
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: can't decommission host via api

Post by lmiltchev »

You should be able to delete a host by running the following commands from the command line:

Code: Select all

cd /usr/local/nagiosxi/scripts
./nagiosql_delete_host.php --host=<config name>
./reconfigure_nagios.sh
where you substitute "config name" with the actual config name.

For example, if you had a host config called "testapihostapply.cfg" in the "/usr/local/nagios/etc/hosts/" directory, you would run:

Code: Select all

./nagiosql_delete_host.php --host=testapihostapply
For more information on the automated host management, please review our documentation on the topic here:
https://assets.nagios.com/downloads/nag ... gement.pdf
Be sure to check out our Knowledgebase for helpful articles and solutions!
doneil326
Posts: 82
Joined: Fri Aug 14, 2015 3:26 pm

Re: can't decommission host via api

Post by doneil326 »

right but we are trying to do this remotely from webservice without having to pass a key/pass to ssh to the box to run local commands.
Locked