Automate daily mass delete hosts
-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Re: Automate daily mass delete hosts
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!
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
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!
[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.
Re: Automate daily mass delete hosts
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.
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/
https://www.mcapra.com/
-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Re: Automate daily mass delete hosts
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...
In my example there is not a 'Dependent relationship' that should prohibit deletion...
Re: Automate daily mass delete hosts
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.
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/
https://www.mcapra.com/
Re: Automate daily mass delete hosts
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:
but I was able to delete it just fine via the REST API.
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:
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
Nagios XI 5.2.0
Re: Automate daily mass delete hosts
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:
Looking at the task, I see this:
https://assets.nagios.com/downloads/nag ... NGES-5.TXT- Fixed API not deleting some hosts correctly [TPS#8500] -BH
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
got it, thanks lmiltchev! as always very much appreciate your inputs on this forum
Re: Automate daily mass delete hosts
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.