Automate daily mass delete hosts
-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Automate daily mass delete hosts
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!
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!
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Automate daily mass delete hosts
Create a script to look through your hosts and use the method described here:
https://assets.nagios.com/downloads/nag ... gement.pdf
https://assets.nagios.com/downloads/nag ... gement.pdf
-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Re: Automate daily mass delete hosts
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!
#!/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!
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Automate daily mass delete hosts
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-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Re: Automate daily mass delete hosts
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
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
You do not have the required permissions to view the files attached to this post.
Re: Automate daily mass delete hosts
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?
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?
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
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
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
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.
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.
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
we've removed the lock files and still are having the issue
Re: Automate daily mass delete hosts
I tried your script, and it worked for me, but I had to change this:
to this:
as ./nagiosql_delete_host.php is not a full path.
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.shCode: 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.shas ./nagiosql_delete_host.php is not a full path.
Be sure to check out our Knowledgebase for helpful articles and solutions!