Page 1 of 2

can't decommission host via api

Posted: Thu Apr 28, 2016 11:47 am
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,

Re: can't decommission host via api

Posted: Thu Apr 28, 2016 1:26 pm
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.

Re: can't decommission host via api

Posted: Tue May 10, 2016 8:45 pm
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."
}

Re: can't decommission host via api

Posted: Wed May 11, 2016 9:53 am
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.

Re: can't decommission host via api

Posted: Wed May 11, 2016 11:31 am
by bwallace
Just filed a bug report for this - TASK ID 8500 -
Were there any other questions, or may we lock this thread?

Re: can't decommission host via api

Posted: Wed May 11, 2016 12:23 pm
by doneil326
ok so then the bug will be fixed in a later version and we will be able to do this?

Re: can't decommission host via api

Posted: Wed May 11, 2016 1:24 pm
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.

Re: can't decommission host via api

Posted: Wed May 11, 2016 2:11 pm
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,

Re: can't decommission host via api

Posted: Wed May 11, 2016 2:26 pm
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

Re: can't decommission host via api

Posted: Wed May 11, 2016 2:45 pm
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.