Test Server Clear all Host and Services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Test Server Clear all Host and Services

Post 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?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Test Server Clear all Host and Services

Post 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)
Former Nagios Employee
SteveBeauchemin
Posts: 524
Joined: Mon Oct 14, 2013 7:19 pm

Re: Test Server Clear all Host and Services

Post 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
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Test Server Clear all Host and Services

Post 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.
SteveBeauchemin
Posts: 524
Joined: Mon Oct 14, 2013 7:19 pm

Re: Test Server Clear all Host and Services

Post 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
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Test Server Clear all Host and Services

Post by dwhitfield »

Fair enough. We'll wait on the OP to lock.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Test Server Clear all Host and Services

Post 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
Former Nagios Employee
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Re: Test Server Clear all Host and Services

Post by jkinning »

Yes, you can lock this one up.

Thanks!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Test Server Clear all Host and Services

Post by rkennedy »

Will do!

/locked
Former Nagios Employee
Locked