Page 1 of 1

Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 3:52 pm
by jkinning
I have a test server that over time has accumulated items that are no longer present. What is the best method to wipe everything out so I can start new without completely re-installing Nagios XI?

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 3:56 pm
by rkennedy
This should do the trick -

Code: Select all

cd /usr/local/nagiosxi/scripts/
./restore_defaults.sh
I believe this was fixed in recent versions, so depending what version the test server is on you may need to upgrade. (or pull the script from the latest)

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 4:25 pm
by SteveBeauchemin
Just read this post and read the shell file contents.

I immediately changed some system settings.

Do not even accidentally run this

Code: Select all

chmod 640 /usr/local/nagiosxi/scripts/restore_defaults.sh
I also edited the file and put the 2nd line to be the single word "exit"

Code: Select all

 vi restore_defaults.sh
#!/bin/bash
exit
# to use this script, uncomment the exit above - this is DANGEROUS
You folks are a little too trusting for me. :shock:

Steve B

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 4:34 pm
by dwhitfield
@jkinning, I assume danger is averted due to this being a test box. Are we ready to lock this up?

@SteveBeauchemin, I definitely see your point, though I don't think we want to make it hard for people. I can put in a feature request if you like.

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 5:06 pm
by SteveBeauchemin
No need to change anything. What I typically do for shell scripts to make then just a little harder to 'accidentally' run, it to change the permissions to 640. then, you can still run it if you want by putting sh in front of it.

Code: Select all

-rw-r-----  1 nagios nagios    841 Feb 15 15:20 restore_defaults.sh
This will run if I type

Code: Select all

sh restore_defaults.sh
but will not run as

Code: Select all

/usr/local/nagiosxi/scripts/restore_defaults.sh
or
./restore_defaults.sh
Safe enough for me. I'm just hoping no one else learns the hard way.

Thanks

Steve B

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 5:11 pm
by dwhitfield
Fair enough. We'll wait on the OP to lock.

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 5:12 pm
by rkennedy
SteveBeauchemin wrote:No need to change anything. What I typically do for shell scripts to make then just a little harder to 'accidentally' run, it to change the permissions to 640. then, you can still run it if you want by putting sh in front of it.

Code: Select all

-rw-r-----  1 nagios nagios    841 Feb 15 15:20 restore_defaults.sh
This will run if I type

Code: Select all

sh restore_defaults.sh
but will not run as

Code: Select all

/usr/local/nagiosxi/scripts/restore_defaults.sh
or
./restore_defaults.sh
Safe enough for me. I'm just hoping no one else learns the hard way.

Thanks

Steve B
Fair point. Some scripts have sanity checking built in to confirm they meant to run them. I've added a BR for this, to have simple logic added to 'confirm' -

Code: Select all

NEW TASK ID 11065 created - Nagios XI Bug Report: Add sanity checking to restore_defaults.sh

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 5:54 pm
by jkinning
Yes, you can lock this one up.

Thanks!

Re: Test Server Clear all Host and Services

Posted: Wed Feb 15, 2017 5:56 pm
by rkennedy
Will do!

/locked