From e0a5c30453368eeb0acfceec917184c9e0c28fa7 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Thu, 5 May 2022 14:11:15 -0400 Subject: [PATCH 1/4] We should now be ignoring the CSS file --- failover/README.md | 8 ++++++++ failover/rsync_xi.sh | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/failover/README.md b/failover/README.md index ed66ec0..0387ea1 100644 --- a/failover/README.md +++ b/failover/README.md @@ -21,3 +21,11 @@ Failover from primary Nagios XI to secondary Nagios XI is a Disaster Recovery ef * Make sure any ramdisk (such as /ramdisk) is copied if it exists * Note that any gearman addons such as /etc/mod_gearman or whatever are NOT copied as part of this procedure. These types of things need to be set up on both boxes the same way before this process is set up. + +## Running from cron +The synchronization script should run on the primary at regular intervals to keep the secondary as up-to-date as possible. It is recommended to run the script from cron to accomplish this. At the simplest level, one could do this: +* */30 * * * * /home/nagios/bin/SYNC >> /home/nagios/sync.log + +To include a timestamp, this would work: + +* */30 * * * * (date; /home/nagios/bin/SYNC) >> /home/nagios/sync.log diff --git a/failover/rsync_xi.sh b/failover/rsync_xi.sh index 9f599eb..2533d1f 100755 --- a/failover/rsync_xi.sh +++ b/failover/rsync_xi.sh @@ -18,6 +18,7 @@ execute="-n" syncfile="" isP=/bin/false isS=/bin/false +rsync_opts="-a --delete --delete-after --rsync-path=\"sudo /bin/rsync\" --exclude=/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css" # Import Nagios XI and xi-sys.cfg config vars . $BASEDIR/../var/xi-sys.cfg @@ -120,8 +121,8 @@ do_rsync() { verbose "Syncing $*..." src="$1" [ ! -e "$src" ] && warning " OK: No such file or directory: $src" && return - [ -d "$src" ] && sudo rsync -a --delete --delete-after --rsync-path="sudo /bin/rsync" ${execute} ${src}/ nagios@${sName}:${src}/ - [ -f "$src" ] && sudo rsync -a --delete --delete-after --rsync-path="sudo /bin/rsync" ${execute} ${src} nagios@${sName}:${src} + [ -d "$src" ] && sudo rsync ${rsync_opts} ${execute} ${src}/ nagios@${sName}:${src}/ + [ -f "$src" ] && sudo rsync ${rsync_opts} ${execute} ${src} nagios@${sName}:${src} } do_backup_files() { -- 2.40.1 From c4bb0d893caf4963cd439d2b10d8d17b21498990 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Thu, 5 May 2022 14:27:50 -0400 Subject: [PATCH 2/4] Update cron job information to include date and time statements in crontab --- failover/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/failover/README.md b/failover/README.md index 0387ea1..732f654 100644 --- a/failover/README.md +++ b/failover/README.md @@ -28,4 +28,4 @@ The synchronization script should run on the primary at regular intervals to kee To include a timestamp, this would work: -* */30 * * * * (date; /home/nagios/bin/SYNC) >> /home/nagios/sync.log +* */30 * * * * (date; time /home/nagios/bin/SYNC; echo "") >> /home/nagios/sync.log -- 2.40.1 From b5256e83eacadee8e28f08a9a66c24c57763810f Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Mon, 13 Jun 2022 14:13:42 -0400 Subject: [PATCH 3/4] Update failover/failover.sh Removed header.css code, added code to skip the sync if the sync file doesn't exist, and sleep for 2 seconds before trying to start Nagios. --- failover/failover.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/failover/failover.sh b/failover/failover.sh index d1f2182..7f889be 100755 --- a/failover/failover.sh +++ b/failover/failover.sh @@ -86,18 +86,21 @@ do_secondary() { warning "The primary (${primary}) is on the network but --force specified. Proceeding anyway." fi fi - verbose "Expanding package from the primary" + verbose "Checking for package from the primary" syncfile=$(basename `ls -tr1 ${backupDir}/${syncname}* | tail -1`) + if [ -r "$syncfile" ]; then + verbose " Sync file found (/store/backups/nagiosxi/$syncfile). Continuing." + /home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "/store/backups/nagiosxi/$syncfile" + else + warning " No sync file found. Continuing to activate Nagios." + fi [ -z "$syncfile" ] && error "No sync file ($syncfile) found." && exit 2 - /home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "/store/backups/nagiosxi/$syncfile" if [ $? -eq 0 ]; then sleep 2 - if [ -r "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.secondary" -a -w "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css" ]; then - cp /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.secondary /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css - fi chmod 0640 /usr/local/nagiosxi/var/keys/xi.key chown nagios:nagios /usr/local/nagiosxi/var/keys/xi.key verbose "This is intended to be manually executed when needed, so we assume you want to start Nagios..." -n + sleep 2 start_nagios rm -f ${syncfile} verbose "Done." -- 2.40.1 From 6434c592f6b99c1f83fcb7199fe5ded422b69a08 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Mon, 11 Jul 2022 14:06:28 -0400 Subject: [PATCH 4/4] Finally getting the right combination to skip CSS headers --- failover/failover.sh | 17 ++++++----------- failover/rsync_xi.sh | 11 ++++++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/failover/failover.sh b/failover/failover.sh index 7f889be..f7b4060 100755 --- a/failover/failover.sh +++ b/failover/failover.sh @@ -69,10 +69,6 @@ do_primary() { [ $? -ne 0 ] && error "Cannot ping ${secondary}. Use --noping to continue wihout ping." && exit verbose "Creating package to send to secondary" /home/nagios/bin/rsync_xi.sh --prepend ${syncname} --primary "${primary}" --secondary "${secondary}" $extraCmd - if [ -r "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.primary" -a -w "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css" ]; then - verbose "Copying local gradient files" - cp /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.primary /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css - fi } do_secondary() { @@ -88,21 +84,20 @@ do_secondary() { fi verbose "Checking for package from the primary" syncfile=$(basename `ls -tr1 ${backupDir}/${syncname}* | tail -1`) - if [ -r "$syncfile" ]; then - verbose " Sync file found (/store/backups/nagiosxi/$syncfile). Continuing." - /home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "/store/backups/nagiosxi/$syncfile" + fullfile="/store/backups/nagiosxi/$syncfile" + if [ -f "$fullfile" ]; then + verbose " Sync file found ($fullfile). Continuing." + /home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "$fullfile" else warning " No sync file found. Continuing to activate Nagios." fi - [ -z "$syncfile" ] && error "No sync file ($syncfile) found." && exit 2 if [ $? -eq 0 ]; then - sleep 2 chmod 0640 /usr/local/nagiosxi/var/keys/xi.key chown nagios:nagios /usr/local/nagiosxi/var/keys/xi.key verbose "This is intended to be manually executed when needed, so we assume you want to start Nagios..." -n - sleep 2 + sleep 5 start_nagios - rm -f ${syncfile} + rm -f ${fullfile} verbose "Done." fi } diff --git a/failover/rsync_xi.sh b/failover/rsync_xi.sh index 2533d1f..43cc9bd 100755 --- a/failover/rsync_xi.sh +++ b/failover/rsync_xi.sh @@ -18,7 +18,7 @@ execute="-n" syncfile="" isP=/bin/false isS=/bin/false -rsync_opts="-a --delete --delete-after --rsync-path=\"sudo /bin/rsync\" --exclude=/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css" +rsync_opts="-a --delete --delete-after" # Import Nagios XI and xi-sys.cfg config vars . $BASEDIR/../var/xi-sys.cfg @@ -118,11 +118,12 @@ workDir=$rootdir/$name mkdir -p $workDir do_rsync() { - verbose "Syncing $*..." + verbose "Syncing $1 (Excluding ${2:-nothing})..." src="$1" + [ -n "$2" ] && exclude="--exclude $2" || exclude="" [ ! -e "$src" ] && warning " OK: No such file or directory: $src" && return - [ -d "$src" ] && sudo rsync ${rsync_opts} ${execute} ${src}/ nagios@${sName}:${src}/ - [ -f "$src" ] && sudo rsync ${rsync_opts} ${execute} ${src} nagios@${sName}:${src} + [ -d "$src" ] && sudo /usr/bin/rsync --rsync-path="sudo /bin/rsync" ${rsync_opts} ${exclude} ${execute} ${src}/ nagios@${sName}:${src}/ + [ -f "$src" ] && sudo /usr/bin/rsync --rsync-path="sudo /bin/rsync" ${rsync_opts} ${exclude} ${execute} ${src} nagios@${sName}:${src} } do_backup_files() { @@ -151,7 +152,7 @@ do_rsync $httpdconfdir/nrdp.conf do_rsync $httpdconfdir/ssl.conf do_rsync /usr/local/nagios do_rsync /usr/local/nagiosmobile -do_rsync /usr/local/nagiosxi +do_rsync /usr/local/nagiosxi custom-includes/css/ do_rsync /usr/local/nagvis do_rsync /usr/local/nrdp do_rsync /usr/share/snmp -- 2.40.1