Delete Parent Host without affecting Child

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
pradeepanan
Posts: 41
Joined: Wed Sep 30, 2015 1:58 pm

Delete Parent Host without affecting Child

Post by pradeepanan »

Hi All,

I am trying to delete the host which is no longer valid. But I can see the there lots of child host associated to it. Could someone guide me how could I delete parent which have no impact on child?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Delete Parent Host without affecting Child

Post by rkennedy »

You would need to remove the relationship before deleting the parent, that way the child can remain. Nagios will not let you delete an object that still has a relationship established.
Former Nagios Employee
User avatar
nozlaf
Posts: 172
Joined: Sun Nov 09, 2014 9:50 pm
Location: Victoria, Australia

Re: Delete Parent Host without affecting Child

Post by nozlaf »

pradeepanan wrote: Could someone guide me how could I delete parent which have no impact on child?
just search your configs for where that parent is declared and replace it automatically with nothing, then you can delete the parent

if you are using a config management tool it should do this automatically
Looking forward to seeing you all at #NagiosCon2019?
-Dedicated Lover of Nconf,PNP4Nagios and Nagvis
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Delete Parent Host without affecting Child

Post by rkennedy »

Thanks @nozlaf!

@pradeepanan - let us know if you have any further questions.
Former Nagios Employee
pradeepanan
Posts: 41
Joined: Wed Sep 30, 2015 1:58 pm

Re: Delete Parent Host without affecting Child

Post by pradeepanan »

Sorry for delayed response. I understood we need to remove relationship to delete paent. However my eventual goal is to delete and parent and assign all the child host to new parent. So is there a way to do that without editing each child host to point to new parent?
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Delete Parent Host without affecting Child

Post by Box293 »

A sed command would work.

Assuming the new parent exists, something like:

Code: Select all

sed -i 's/the_original_parent_name/the_new_parent_name/g' /usr/local/nagios/etc/*.cfg
That command may very well replace the original host as well, you may need to go back and change it back to be correct.

sed is pretty powerful, make a copy of your configs and test/play with your configs before doing it in production. Depending on how many relationships you need to update, it might be quicker to manually do it compared to learning how to make the sed command work correctly.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
pradeepanan
Posts: 41
Joined: Wed Sep 30, 2015 1:58 pm

Re: Delete Parent Host without affecting Child

Post by pradeepanan »

Thats great. Thanks a lot. I did another thing which worked as well. Updated the database with new parent instead old one and did export. So editing *.cfg and database both same?

If am not wrong, when we do export, the database will be updated and it overrides the .cfg file with whatever new on the database. Is my understanding right?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Delete Parent Host without affecting Child

Post by rkennedy »

pradeepanan wrote:Thats great. Thanks a lot. I did another thing which worked as well. Updated the database with new parent instead old one and did export. So editing *.cfg and database both same?

If am not wrong, when we do export, the database will be updated and it overrides the .cfg file with whatever new on the database. Is my understanding right?
Could you please clarify? Core doesn't use a database at all, it uses flat files to organize configuration. If you're using ndo, then yes, the database will overwrite the configuration files.
Former Nagios Employee
pradeepanan
Posts: 41
Joined: Wed Sep 30, 2015 1:58 pm

Re: Delete Parent Host without affecting Child

Post by pradeepanan »

Yes am using ndo. So when I do export from config tool, it will first update the database and then, the database will override the config file?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Delete Parent Host without affecting Child

Post by rkennedy »

Could you please clarify what you mean by an 'export'? If you're making changes using the Core Config Manager, it will first update the database, which then on an apply configuration will write out FROM the database TO flat files.
Former Nagios Employee
Locked