API: Restoring to Last Good Configuration Snapshot

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

API: Restoring to Last Good Configuration Snapshot

Post 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
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: API: Restoring to Last Good Configuration Snapshot

Post 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.
Former Nagios employee
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post by MrWoodward »

Thanks for the help. I'll take a look and get back to you.

Cheers.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post 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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post 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
Last edited by MrWoodward on Tue Feb 20, 2018 12:23 pm, edited 1 time in total.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
MrWoodward
Posts: 66
Joined: Fri Jan 06, 2017 1:58 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post 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.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: API: Restoring to Last Good Configuration Snapshot

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked