Automate daily mass delete hosts

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
nagwindmon
Posts: 92
Joined: Mon Dec 01, 2014 3:39 pm

Re: Automate daily mass delete hosts

Post by nagwindmon »

will try to run my script with advised changes... in meantime what would you recommend for deleting hosts by utilizing XI scripts as I do now or REST API?
if REST API is preferred way do you mind to provide a sample how would I run it by cron?

Thanks!
nagwindmon
Posts: 92
Joined: Mon Dec 01, 2014 3:39 pm

Re: Automate daily mass delete hosts

Post by nagwindmon »

a quick update: using XI scripts is pretty much direct deletes into database so may not be a best practice so made an attempt to utilize REST API delete and got the following error:

[nagios@esu4v385 nagios]$ curl -k -XDELETE "http://esu4v385/nagiosxi/api/v1/config/ ... CVT3511956"
{
"error": "Host cannot be deleted using this method. Must be deleted through the CCM."
}


but the host looks like does not have any services or any other dependencies:

Please advise!
You do not have the required permissions to view the files attached to this post.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Automate daily mass delete hosts

Post by mcapra »

Since that Host object has relationships with both the DRT_CVT and MCY-708-CST Hostgroups, you will first need to eliminate those dependencies before you can delete the Host object.

Since the API doesn't currently allow you to cherry-pick specific hosts out of hostgroups, you would essentially need to GET those hostgroups, modify them to not include CVT3511956, then delete and re-create them.
Former Nagios employee
https://www.mcapra.com/
nagwindmon
Posts: 92
Joined: Mon Dec 01, 2014 3:39 pm

Re: Automate daily mass delete hosts

Post by nagwindmon »

where do you see item labeled as 'Dependent relationship' in the output?
In my example there is not a 'Dependent relationship' that should prohibit deletion...
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Automate daily mass delete hosts

Post by mcapra »

That aside, @lmiltchev tested this and even if there is a host->hostgroup and hostgroup->host dependency for a given host it shouldn't affect API deletion. I didn't have any problems deleting a host in that configuration.

You could try adding force=1 to your API request and see if that makes a difference. Your assessment is correct as far as I can tell that there shouldn't be any relationships preventing this host from being deleted.
Former Nagios employee
https://www.mcapra.com/
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Automate daily mass delete hosts

Post by lmiltchev »

Thanks @mcapra!

nagwindmon, what is the Nagios XI version that you are currently using? It is possible that this is a bug with API, that was fixed in the later versions.

My test host was added to 3 hostgroups:
example01.PNG
but I was able to delete it just fine via the REST API.

Code: Select all

[root@main-nagios-xi ~]# curl -XDELETE "http://x.x.x.x/nagiosxi/api/v1/config/host?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1&host_name=test&applyconfig=1"
{
    "success": "Removed test from the system. Config applied, Nagios Core was restarted."
}
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
nagwindmon
Posts: 92
Joined: Mon Dec 01, 2014 3:39 pm

Re: Automate daily mass delete hosts

Post by nagwindmon »

Nagios XI 5.2.0
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Automate daily mass delete hosts

Post by lmiltchev »

There were MANY, MANY bug fixes, and added features since 5.2.0. I would strongly recommend upgrading to the latest. You particular issue was probably fixed in 5.2.8. I see this in the changelog:
- Fixed API not deleting some hosts correctly [TPS#8500] -BH
https://assets.nagios.com/downloads/nag ... NGES-5.TXT

Looking at the task, I see this:
Description: Using rest Api cannot delete a host that is a member of a hostgroup

Steps To Reproduce:

1) Add a host and put it in a hostgroup
2) Try to delete the host using this cmd

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

3) results in -

"error": "Host cannot be deleted using this method. Must be deleted through the CCM."
Be sure to check out our Knowledgebase for helpful articles and solutions!
nagwindmon
Posts: 92
Joined: Mon Dec 01, 2014 3:39 pm

Re: Automate daily mass delete hosts

Post by nagwindmon »

got it, thanks lmiltchev! as always very much appreciate your inputs on this forum
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Automate daily mass delete hosts

Post by cdienger »

Did you have any other questions or are we okay closing this?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked