Update error codes and delete source file if its successfuly restored

2021
Eric Loyd 6 years ago
parent dd93f9740d
commit c5d35bacde

@ -1,2 +1,10 @@
# Princeton # Princeton
## Files that need to be copied to /usr/local/nagios/libexec:
* pu-notify-all-emails
## Files that need contents imported into XI:
* new_commands.cfg
## Also See failover/README.md

@ -30,7 +30,7 @@ done
do_nothing() { do_nothing() {
echo "We are not the primary or secondary. Doing nothing." echo "We are not the primary or secondary. Doing nothing."
exit exit 1
} }
do_primary() { do_primary() {
@ -44,8 +44,11 @@ do_secondary() {
syncfile=`ls -tr1 /store/backups/nagiosxi/ | tail -1` syncfile=`ls -tr1 /store/backups/nagiosxi/ | tail -1`
[ -z "$syncfile" ] && echo "No sync file ($syncfile) found." && exit 2 [ -z "$syncfile" ] && echo "No sync file ($syncfile) found." && exit 2
./restore_xi.sh /store/backups/nagiosxi/$syncfile ./restore_xi.sh /store/backups/nagiosxi/$syncfile
./nagios_startstop.sh stop if [ $? -eq 0 ]; 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 ./nagios_startstop.sh stop
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
rm -f ${syncfile}
fi
} }
case "$hostname" in case "$hostname" in
@ -53,3 +56,5 @@ case "$hostname" in
$secondary) do_secondary;; $secondary) do_secondary;;
*) do_nothing *) do_nothing
esac esac
exit 0

@ -46,9 +46,7 @@ fi
############################## ##############################
# MAKE TEMP RESTORE DIRECTORY # MAKE TEMP RESTORE DIRECTORY
############################## ##############################
#ts=`echo $backupfile | cut -d . -f 1`
ts=`date +%s` ts=`date +%s`
echo "TS=$ts"
mydir=${rootdir}/${ts}-restore mydir=${rootdir}/${ts}-restore
mkdir -p $mydir mkdir -p $mydir
if [ ! -d $mydir ]; then if [ ! -d $mydir ]; then
@ -60,22 +58,10 @@ fi
############################## ##############################
# UNZIP BACKUP # UNZIP BACKUP
############################## ##############################
echo "Extracting backup to $mydir..."
cd $mydir cd $mydir
tar xzfps $backupfile tar xzfps $backupfile
# Change to subdirectory
cd `ls` cd `ls`
# Make sure we have some directories here...
backupdir=`pwd` backupdir=`pwd`
echo "In $backupdir..."
#if [ ! -f nagiosxi.tar.gz ]; then
# echo "Unable to find files to restore in $backupdir"
# exit 1
#fi
echo "Backup files look okay. Preparing to restore..."
############################## ##############################
@ -92,7 +78,7 @@ rootdir=/
. $BASEDIR/../var/xi-sys.cfg . $BASEDIR/../var/xi-sys.cfg
php $BASEDIR/import_xiconfig.php > $BASEDIR/config.dat php $BASEDIR/import_xiconfig.php > $BASEDIR/config.dat
. $BASEDIR/config.dat . $BASEDIR/config.dat
rm -rf $BASEDIR/config.dat rm -f $BASEDIR/config.dat
# Overwrite the mysqlpass with the hardcoded one at the top # Overwrite the mysqlpass with the hardcoded one at the top
mysqlpass="$themysqlpass" mysqlpass="$themysqlpass"
@ -113,7 +99,7 @@ mysql -h "$ndoutils_dbserver" --port="$ndoutils_dbport" -u root --password=$mysq
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error restoring MySQL database 'nagios' - check the password in this script!" echo "Error restoring MySQL database 'nagios' - check the password in this script!"
exit; exit $res;
fi fi
if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; then if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; then
nagiosql_dbport=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f2 -d":"` nagiosql_dbport=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f2 -d":"`
@ -126,7 +112,7 @@ mysql -h "$nagiosql_dbserver" --port="$nagiosql_dbport" -u root --password=$mysq
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error restoring MySQL database 'nagiosql' - check the password in this script!" echo "Error restoring MySQL database 'nagiosql' - check the password in this script!"
exit; exit $res;
fi fi
# Only restore PostgresQL if we are still using it # Only restore PostgresQL if we are still using it
if [ "$cfg__db_info__nagiosxi__dbtype" == "pgsql" ]; then if [ "$cfg__db_info__nagiosxi__dbtype" == "pgsql" ]; then
@ -154,7 +140,7 @@ host all all ::1/128 trust" > $pghba
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error restoring PostgresQL database 'nagiosxi' !" echo "Error restoring PostgresQL database 'nagiosxi' !"
exit; exit $res;
fi fi
$BASEDIR/manage_services.sh restart postgresql $BASEDIR/manage_services.sh restart postgresql
if [ "$dist" == "el7" ] || [ "$dist" == "el8" ]; then if [ "$dist" == "el7" ] || [ "$dist" == "el8" ]; then
@ -190,7 +176,7 @@ else
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error restoring MySQL database 'nagiosxi' !" echo "Error restoring MySQL database 'nagiosxi' !"
exit; exit $res;
fi fi
fi fi
} }

@ -38,7 +38,7 @@ while [ -n "$1" ]; do
;; ;;
-h | --help) -h | --help)
usage usage
exit 0 exit 1
;; ;;
-n | --name) -n | --name)
fullname=$2 fullname=$2
@ -149,7 +149,7 @@ mysqldump -h "$ndoutils_dbserver" --port="$ndoutils_dbport" -u $cfg__db_info__nd
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error backing up MySQL database 'nagios' - check the password in this script!" | tee -a $SBLOG echo "Error backing up MySQL database 'nagios' - check the password in this script!" | tee -a $SBLOG
rm -r $mydir rm -rf $mydir
exit $res; exit $res;
fi fi
if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; then if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; then
@ -163,7 +163,7 @@ mysqldump -h "$nagiosql_dbserver" --port="$nagiosql_dbport" -u $cfg__db_info__na
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error backing up MySQL database 'nagiosql' - check the password in this script!" | tee -a $SBLOG echo "Error backing up MySQL database 'nagiosql' - check the password in this script!" | tee -a $SBLOG
rm -r $mydir rm -rf $mydir
exit $res; exit $res;
fi fi
# Only backup PostgresQL if we are still using it # Only backup PostgresQL if we are still using it
@ -177,7 +177,7 @@ if [ $cfg__db_info__nagiosxi__dbtype == "pgsql" ]; then
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error backing up PostgresQL database 'nagiosxi' !" | tee -a $SBLOG echo "Error backing up PostgresQL database 'nagiosxi' !" | tee -a $SBLOG
rm -r $mydir rm -rf $mydir
exit $res; exit $res;
fi fi
else else
@ -192,7 +192,7 @@ else
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
echo "Error backing up MySQL database 'nagiosxi' - check the password in this script!" | tee -a $SBLOG echo "Error backing up MySQL database 'nagiosxi' - check the password in this script!" | tee -a $SBLOG
rm -r $mydir rm -rf $mydir
exit $res; exit $res;
fi fi
fi fi
@ -202,7 +202,7 @@ fi
############################## ##############################
echo "Compressing backup..." echo "Compressing backup..."
tar czfp $name.tar.gz $name tar czfp $name.tar.gz $name
rm -rf $name rm -f $name
# Change ownership # Change ownership
chown $nagiosuser:$nagiosgroup $name.tar.gz chown $nagiosuser:$nagiosgroup $name.tar.gz
@ -219,8 +219,9 @@ else
echo "BACKUP FAILED" echo "BACKUP FAILED"
echo "===============" echo "==============="
echo "File was not created at $rootdir/$name.tar.gz" echo "File was not created at $rootdir/$name.tar.gz"
rm -r $mydir rm -rf $mydir
exit 1; exit 1;
fi fi
do_rsync $rootdir/$name.tar.gz do_rsync $rootdir/$name.tar.gz
exit 0

@ -0,0 +1,19 @@
define command {
command_name notify-host-by-email-address-1
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTADDRESS1$
}
define command {
command_name notify-service-by-email-address-1
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTADDRESS1$
}
define command {
command_name pu-notify-service-by-email-all
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | $USER1$/pu-notify-all-emails -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -t $CONTACTEMAIL$:$_HOSTALT_CONTACT$,$CONTACTADDRESS1$
}
define command {
command_name pu-notify-host-by-email-all
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$:$_HOSTALT_CONTACT$,$CONTACTADDRESS1$
}

@ -0,0 +1,44 @@
#!/bin/sh
#
# Command to send to multiple email addreses simultaneously, separated by commas.
# However, if any email address has a colon in it, then the second email address overrides the first
#
# Ex:
# user1@example.com,user2@example.com:user3@example.com,user4@example.com
#
# This will send to user1, user3 (overriding user2), and user4.
#
# Command line definition from Nagios:
# /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | \
# $USER1$/pu-notify-all-emails -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" \
# -t $CONTACTEMAIL$:$_HOSTALT_CONTACT$,$CONTACTADDRESS1$
PATH=/usr/bin:/bin
subject=""
sendto=""
# Get params for subject and receiver
while [ -n "$1" ]; do
case "$1" in
-s) subject="$2"; shift 2;;
-t) sendto="$2"; shift 2;;
*) shift 1;;
esac
done
# If we have a blank subject or a blank receiver, then exit
[ -z "$subject" -o -z "$sendto" ] && exit
output=""
output=`cat`
OLD_FS=$IFS
IFS=,
for receiver in $sendto; do
[ -z "$receiver" ] && continue
override=`echo $receiver | cut -d ":" -f 2`
[ -n "$override" ] && receiver=$override
echo "$output" | /bin/mail -s "$subject" $receiver
done
IFS=$OLD_FS
Loading…
Cancel
Save