Page 1 of 2
API: Restoring to Last Good Configuration Snapshot
Posted: Wed Feb 14, 2018 1:40 pm
by MrWoodward
Is there a way using the Nagios XI API to restore to the "last good" configuration snapshot?
I found this page in your documentation, but didn't see any reference to the API.
https://support.nagios.com/kb/article.php?id=407
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Wed Feb 14, 2018 3:34 pm
by lmiltchev
Unfortunately, it is not possible to restore to a configuration snapshot via the REST API at this time. It would be a really cool feature. I am going to file an internal feature request for adding this functionality.
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Wed Feb 14, 2018 3:50 pm
by MrWoodward
Are there other ways to restore a configuration snapshot from the command-line of a Nagios server?
I'm attempting to create a Python script that runs on the Nagios server which (when detecting a certain state) can rollback/restore to the last good configuration snapshot.
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Wed Feb 14, 2018 5:15 pm
by tmcdonald
You could look at
/usr/local/nagiosxi/scripts/nagiosql_snapshot.sh:
Code: Select all
[root@localhost scripts]# pwd
/usr/local/nagiosxi/scripts
[root@localhost scripts]# bash nagiosql_snapshot.sh this_one_works
taking snapshot
Backup Complete.
[root@localhost scripts]# bash nagiosql_snapshot.sh this_one_works restore
Restoring NagiosQL snapshot
Removing old files from /usr/local/nagios/etc
NOM SNAPSHOT /usr/local/nagiosxi/nom/checkpoints/nagioscore/this_one_works.tar.gz NOT FOUND!
Restoring NagiosQL databases...
Restore Complete.
The error about the snapshot not being found can be ignored.
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Wed Feb 14, 2018 5:37 pm
by MrWoodward
Thanks for the help. I'll take a look and get back to you.
Cheers.
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Thu Feb 15, 2018 10:24 am
by lmiltchev
Sure. Let us know if this worked for you, so that we can lock the topic, and mark it as resolved. Thank you!
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Thu Feb 15, 2018 11:26 am
by MrWoodward
The exact command appears to be:
Code: Select all
sudo /usr/local/nagiosxi/scripts/nagiosql_snapshot.sh <some_number_here> restore
and the checkpoints can be found in:
Code: Select all
/usr/local/nagiosxi/nom/checkpoints/nagiosxi
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Thu Feb 15, 2018 12:44 pm
by lmiltchev
You are correct. I just tested the script. It seems like that you need to use a number only (timestamp portion), for example:
Code: Select all
/usr/local/nagiosxi/scripts/nagiosql_snapshot.sh 1518716128 restore
instead of the full file name (timestamp + _nagiosql.sql.gz at the end).
In addition to this, in order to complete the restore, you will need to run the reconfigure.sh script:
Code: Select all
/usr/local/nagiosxi/scripts/reconfigure_nagios.sh
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Thu Feb 15, 2018 3:59 pm
by MrWoodward
Oh, that's good to know.
I've found so far that this must be run as `root` as well. I tried running it as `nagios` user, but that error'd out on me.
Re: API: Restoring to Last Good Configuration Snapshot
Posted: Thu Feb 15, 2018 4:39 pm
by lmiltchev
I've found so far that this must be run as `root` as well. I tried running it as `nagios` user, but that error'd out on me.
The issue may be caused by wrong permissions on some of the files/directories. I can run these commands as nagios user just fine.
To start troubleshooting you can run:
Code: Select all
ls -la /usr/local/nagiosxi/nom/checkpoints
ls -la /usr/local/nagiosxi/nom/checkpoints/nagiosxi
ls -la /usr/local/nagiosxi/scripts
grep nag /etc/group
grep nagios /etc/passwd
chage nagios -l