Page 1 of 3
Automate daily mass delete hosts
Posted: Mon Mar 27, 2017 3:07 pm
by nagwindmon
hello Nagios team,
I have looked thru all related topics but none were recently posted so what would you recommend for most efficient and stable method to accomplish it at this time?
There is already a process in place generating .csv file every day containing host names that needs to be deleted, some days file is empty but other days something around 5 -10 hosts... and I want to automate this delete process.
These hosts do not have services attached to them, they are inheriting the services from the host group they belong to.
We're running Nagios XI 5.2.0
Thanks!
Re: Automate daily mass delete hosts
Posted: Mon Mar 27, 2017 3:11 pm
by scottwilkerson
Create a script to look through your hosts and use the method described here:
https://assets.nagios.com/downloads/nag ... gement.pdf
Re: Automate daily mass delete hosts
Posted: Mon Mar 27, 2017 5:46 pm
by nagwindmon
ok, I go ahead and create the following script:
#!/bin/bash
/bin/cat /usr/local/nagiosxi/scripts/delete-hosts.csv | while read LINE
do
Name=`/bin/echo $LINE | /bin/cut -d, -f1`
./nagiosql_delete_host.php --host=$Name
done
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh
Set up a cron job to run @9AM every day but please comment on above if you see anything that needs to be change/added.
Thanks!
Re: Automate daily mass delete hosts
Posted: Tue Mar 28, 2017 9:33 am
by scottwilkerson
I would change it to this
Code: Select all
#!/bin/bash
cd /usr/local/nagiosxi/scripts
/bin/cat delete-hosts.csv | while read LINE
do
Name=`/bin/echo $LINE | /bin/cut -d, -f1`
./nagiosql_delete_host.php --host=$Name
done
./reconfigure_nagios.sh
Re: Automate daily mass delete hosts
Posted: Wed Mar 29, 2017 10:50 am
by nagwindmon
Last couple of days was trying to figure out some odd conditions:
the script kicks off as a crontab and completes fine as if it has worked but the devices never got deleted and I can still search for them.
When I kick the script off manually hosts deleted as expected...
Also None of the devices I'm trying to delete have services attached to them, we are using hostgroups to inherit services.
Please see attached script and log files
Re: Automate daily mass delete hosts
Posted: Wed Mar 29, 2017 2:15 pm
by tgriep
What user account is the cron running as?
If you are using an account other that root, make sure that account can read the script and the csv file etc.
Can you post the cron entry you are using?
Re: Automate daily mass delete hosts
Posted: Wed Mar 29, 2017 2:26 pm
by nagwindmon
User account is "Nagios", permissions are wide open, full access to the file
cron entry:
00 11 * * 1-4 cd /usr/local/nagiosxi/scripts; ./delete-hosts.sh 2>>/var/log/nagios/delete-hosts-1100.err >> /var/log/nagios/delete-hosts-1100.log
Re: Automate daily mass delete hosts
Posted: Wed Mar 29, 2017 2:50 pm
by tgriep
This message from the log file
Another reconfigure process is still running, sleeping...
Is coming from a left over reconfigure_nagios.lock file left in the /usr/local/nagiosxi/scripts folder.
That lock file is used to keep multiple reconfigure_nagios.sh scripts from running at the same time and when the cron job ran, the lock file was present and the reconfigure didn't run and your hosts didn't get deleted.
Make sure the lock file is not in that folder when the cron runs.
Also, when a user runs an Apply Config in the GUI, it creates that lock file as well.
Re: Automate daily mass delete hosts
Posted: Wed Mar 29, 2017 2:55 pm
by nagwindmon
we've removed the lock files and still are having the issue
Re: Automate daily mass delete hosts
Posted: Wed Mar 29, 2017 3:51 pm
by lmiltchev
I tried your script, and it worked for me, but I had to change this:
Code: Select all
echo "START WHILE LOOP"
/bin/cat /esu4v385/Nagios/NagiosCSVs/Nagiosesu4v385Delete.csv | while read LINE
do
echo "LOOP ITERATION: $LINE"
Name=`/bin/echo $LINE | /bin/cut -d, -f1`
echo "RUN NAGIOSSQL_DELETE_HOST.PHP"
./nagiosql_delete_host.php --host=$Name
done
echo "CHANGE TO SCRIPTS DIR"
cd /usr/local/nagiosxi/scripts
echo "RUN RECONFIGURE_NAGIOS.SH"
./reconfigure_nagios.sh
to this:
Code: Select all
echo "CHANGE TO SCRIPTS DIR"
cd /usr/local/nagiosxi/scripts
echo "START WHILE LOOP"
/bin/cat /esu4v385/Nagios/NagiosCSVs/Nagiosesu4v385Delete.csv | while read LINE
do
echo "LOOP ITERATION: $LINE"
Name=`/bin/echo $LINE | /bin/cut -d, -f1`
echo "RUN NAGIOSSQL_DELETE_HOST.PHP"
./nagiosql_delete_host.php --host=$Name
done
echo "RUN RECONFIGURE_NAGIOS.SH"
./reconfigure_nagios.sh
as ./nagiosql_delete_host.php is not a full path.