Page 1 of 1
Delete Parent Host without affecting Child
Posted: Tue Jul 05, 2016 7:40 am
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?
Re: Delete Parent Host without affecting Child
Posted: Tue Jul 05, 2016 9:45 am
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.
Re: Delete Parent Host without affecting Child
Posted: Thu Jul 07, 2016 3:42 am
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
Re: Delete Parent Host without affecting Child
Posted: Thu Jul 07, 2016 11:43 am
by rkennedy
Thanks @nozlaf!
@pradeepanan - let us know if you have any further questions.
Re: Delete Parent Host without affecting Child
Posted: Tue Jul 26, 2016 11:42 am
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?
Re: Delete Parent Host without affecting Child
Posted: Wed Jul 27, 2016 12:02 am
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.
Re: Delete Parent Host without affecting Child
Posted: Wed Jul 27, 2016 8:01 am
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?
Re: Delete Parent Host without affecting Child
Posted: Wed Jul 27, 2016 9:36 am
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.
Re: Delete Parent Host without affecting Child
Posted: Wed Jul 27, 2016 10:04 am
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?
Re: Delete Parent Host without affecting Child
Posted: Wed Jul 27, 2016 1:51 pm
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.