Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Commit

Permalink
Issue #187 EFA Service Monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shawniverson committed Jan 11, 2016
1 parent 9d54df9 commit a37afb6
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Issue #148 Enhancement - Allow message view from quarantine reports directly
Issue #162 Enhancement - Upgrade Webmin (to 1.770-1)
Issue #176 Enhancement - Add quarantine cleanup options to EFA-Configure
Issue #179 Enhancement - Get webinterface to work with https by default
Issue #187 Enhancement - EFA service Monitoring
Issue #190 Enhancement - EFA-Init link test
Issue #191 Enhancement - Redirect postfix notifications from postmaster to postmaster email
Issue #192 Enhancement - EFA Update Now option
Expand Down
18 changes: 10 additions & 8 deletions build/EFA/EFA-Configure
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ shopt -s extglob
. /var/EFA/lib/EFA-Configure/func_askmalwarepatrol
. /var/EFA/lib/EFA-Configure/func_askrecursion
. /var/EFA/lib/EFA-Configure/func_retention
. /var/EFA/lib/EFA-Configure/func_maintenance

# +---------------------------------------------------+

Expand All @@ -69,14 +70,14 @@ show_menu() {
func_echo-header
echo -e "Please choose an option:"
echo -e " "
echo -e "0) Logout 7) Auto Update"
echo -e "1) Shell 8) Mail Settings"
echo -e "2) Reboot system 9) Spam Settings"
echo -e "3) Halt system 10) Mysql Recovery"
echo -e "4) IP Settings 11) Apache Settings"
echo -e "5) Tunables 12) Virus Settings"
echo -e "6) MailWatch Settings 13) System Restore"
echo -e " 14) Update Now"
echo -e "0) Logout 8) Mail Settings"
echo -e "1) Shell 9) Spam Settings"
echo -e "2) Reboot system 10) Mysql Recovery"
echo -e "3) Halt system 11) Apache Settings"
echo -e "4) IP Settings 12) Virus Settings"
echo -e "5) Tunables 13) System Restore"
echo -e "6) MailWatch Settings 14) Update Now"
echo -e "7) Auto Update 15) Maintenance Mode"
echo -e ""
echo -e -n "$green[EFA]$clean : "
local choice
Expand All @@ -97,6 +98,7 @@ show_menu() {
12) func_virus-settings ;;
13) func_system-restore ;;
14) func_update-now ;;
15) func_maintenance-mode ;;
*) echo -e "Error \"$choice\" is not an option..." && sleep 2
esac
done
Expand Down
110 changes: 110 additions & 0 deletions build/EFA/EFA-Monitor-cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
# +--------------------------------------------------------------------+
# EFA Monitor cron
# Version 20151212
# +--------------------------------------------------------------------+
# Copyright (C) 2012~2015 http://www.efa-project.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# +--------------------------------------------------------------------+

# +--------------------------------------------------------------------+
# EFA Monitor Cron Script
# Set to run at a regular interval (i.e. every minute)
# +--------------------------------------------------------------------+

# +--------------------------------------------------------------------+
# Configurable Variables
# +--------------------------------------------------------------------+
MaxRestartAttempts=3
# Monitored Service Array (daemon=sysv)
MonitoredServices=("mysqld=mysqld" "MailScanner=MailScanner" "qmgr=postfix" "master=postfix" "pickup=postfix" "httpd=httpd" "miniserv.pl=webmin" "clamd=clamd" "unbound=unbound" "saslauthd=saslauthd" "sqlgrey=sqlgrey" "dccifd=adcc")
# Enable restart expiry (1 day)
RestartExpiry=1
AttemptsFile="/var/EFA/EFAmonitor"
ADMINEMAIL="`cat /etc/EFA-Config | grep ADMINEMAIL | sed 's/.*://'`"
MAILFROM="$ADMINEMAIL"
MAILTO="$ADMINEMAIL"
MAILSUBJECT="EFA Monitor ALERT"
SENDMAIL="/usr/lib/sendmail"
TMPMAIL="/tmp/tempmail"

# +--------------------------------------------------------------------+

# +--------------------------------------------------------------------+
# Check Services Function
# +--------------------------------------------------------------------+
function CheckServices() {
for monitoredService in ${MonitoredServices[@]}; do
# Load attempts, or create if not present
[[ -x $AttemptsFile ]] || ( touch $AttemptsFile )
mDaemon=$(echo $monitoredService | awk -F'=' '{print $1}')
mService=$(echo $monitoredService | awk -F'=' '{print $2}')
serviceCheck=$(ps -C $mDaemon --no-heading)
dateStamp=$(date +%Y%m%d)
if [[ -z "$serviceCheck" ]]; then
# Service is not running!
# Check # of attempts, if present
serviceAttempts=$(grep -e "^$mService=" $AttemptsFile | awk -F'=' '{print $2}')
if [[ -z "$serviceAttempts" || "$serviceAttempts" -le "$MaxRestartAttempts" ]]; then
# Start Service
/sbin/service $mService start
# Increment restart attempts
attemptCount=$(grep -e "^$mService=" $AttemptsFile | awk -F'=' '{print $2}')
if [[ -z $attemptCount ]]; then
attemptCount=1
echo "$mService=$attemptCount" >> $AttemptsFile
echo "date$mService=$dateStamp" >> $AttemptsFile
else
attemptCount=$(($attemptCount+1))
sed -i "/^$mService=/ c\\$mService=$attemptCount" $AttemptsFile
sed -i "/^date$mService=/ c\date$mService=$dateStamp" $AttemptsFile
fi
AlertOnFailure
fi
else
if [[ "$RestartExpiry" -eq "1" ]]; then
checkDate=$(grep -e "^date$mService=" $AttemptsFile | awk -F'=' '{print $2}')

if [[ -n "$checkDate" && "$checkDate" -ne "$dateStamp" ]]; then
sed -i "/^$mService=/d" $AttemptsFile
sed -i "/^date$mService=/d" $AttemptsFile
fi
fi
fi
done
}

# +--------------------------------------------------------------------+
# Alert On Failure Notification Function
# +--------------------------------------------------------------------+
function AlertOnFailure() {
logger -p "daemon.alert" "EFA Monitor ALERT: Service $mService down and restarted ( $attemptCount attempts in past day, max attempts is $MaxRestartAttempts )"
echo "From: $MAILFROM" > $TMPMAIL
echo "To: $MAILTO" >> $TMPMAIL
echo "Reply-To: $MAILFROM" >> $TMPMAIL
echo "Subject: $MAILSUBJECT" >> $TMPMAIL
echo "" >> $TMPMAIL
echo "Service $mService down and restarted ( $attemptCount attempts in past day, max attempts is $MaxRestartAttempts )" >> $TMPMAIL
echo "" >> $TMPMAIL
echo "Please examine your EFA logs and resources to determine cause of failure." >> $TMPMAIL
cat $TMPMAIL | $SENDMAIL -t
rm $TMPMAIL
}
# +--------------------------------------------------------------------+

# +--------------------------------------------------------------------+
# Main Function
# +--------------------------------------------------------------------+
CheckServices
60 changes: 60 additions & 0 deletions build/EFA/lib-EFA-Configure/func_maintenance
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# +---------------------------------------------------+
# Function to toggle EFA Monitor for Maintenance
# +---------------------------------------------------+
func_maintenance-mode() {
func_echo-header
echo -e "$green[EFA]$clean - Maintenance Mode"
echo -e ""
echo -e "$green[EFA]$clean This option will toggle EFA Monitor to allow for Maintenance"
echo -e ""
[[ -f /etc/cron.d/EFA-Monitor.cron ]] && modeStatus="0" || modeStatus="1"

if [[ "$modeStatus" -eq "0" ]]; then
echo -en "$green[EFA]$clean : Enter EFA Maintenance Mode? (y/N):"
read MAINTENANCE

FLAG=1
while [ $FLAG -eq 1 ]
do
if [[ $MAINTENANCE =~ ^[yY]$ ]]; then
mv -f /etc/cron.d/EFA-Monitor.cron /var/EFA
echo -e ""
echo -e "$green[EFA]$clean Maintenance mode is $green ENABLED $clean"
echo -e ""
FLAG=0
elif [[ -z "$MAINTENANCE" || $MAINTENANCE =~ ^[nN]$ ]]; then
echo -e ""
echo -e "$green[EFA]$clean No action taken"
else
echo -e "$red[ERROR]$clean Invalid input
echo -en "$green[EFA]$clean : Enter EFA Maintenance Mode? (y/N):"
read MAINTENANCE
fi
done
else
echo -en "$green[EFA]$clean : Exit EFA Maintenance Mode? (Y/n):"
read MAINTENANCE

FLAG=1
while [ $FLAG -eq 1 ]
do
if [[ -z "$MAINTENANCE" || $MAINTENANCE =~ ^[yY]$ ]]; then
[[ -f /var/EFA/EFA-Monitor.cron ]] && ( mv -f /var/EFA/EFA-Monitor.cron /etc/cron.d ) || ( echo "* * * * * root /usr/sbin/EFA-Monitor-cron" > /etc/cron.d/EFA-Monitor.cron )
echo -e ""
echo -e "$green[EFA]$clean Maintenance mode is $green DISABLED $clean"
echo -e ""
FLAG=0
elif [[ $MAINTENANCE =~ ^[nN]$ ]]; then
echo -e ""
echo -e "$green[EFA]$clean No action taken"
else
echo -e "$red[ERROR]$clean Invalid input
echo -en "$green[EFA]$clean : Exit EFA Maintenance Mode? (Y/n):"
read MAINTENANCE
fi
done
fi
pause

}
# +---------------------------------------------------+
3 changes: 2 additions & 1 deletion build/EFA/lib-EFA-Configure/libraries-filelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ func_askmaxsizemailwatch
func_askhighspammailwatch
func_askmalwarepatrol
func_askrecursion
func_retention
func_retention
func_maintenance
4 changes: 4 additions & 0 deletions build/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,10 @@ func_cron () {
chmod 700 /etc/cron.daily/EFA-Backup-cron
# Remove the raid-check util (Issue #102)
rm -f /etc/cron.d/raid-check
# Issue #187 EFA service Monitoring
usr/bin/wget --no-check-certificate -O /usr/sbin/EFA-Monitor-cron $gitdlurl/EFA/EFA-Monitor-cron
chmod 700 /usr/sbin/EFA-Monitor-cron
echo "* * * * * root /usr/sbin/EFA-Monitor-cron" > /etc/cron.d/EFA-Monitor.cron
}
# +---------------------------------------------------+

Expand Down
7 changes: 6 additions & 1 deletion update/versions/EFA-Version-Upgrade-3.0.0.9
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ EOF
if [[ -z $CHECKEXCLUDE ]]; then
echo "exclude=$yumexclude" >> /etc/yum.conf
fi

# Issue #162 Upgrade Webmin
# Pulled from EFA Repo during yum update
# Just call update-webmin to cleanup modules
update-webmin

# Issue #187 EFA service Monitoring
cp $STAGING/Scripts/EFA-Monitor-cron /usr/sbin
chmod 700 /usr/sbin/EFA-Monitor-cron
echo "* * * * * root /usr/sbin/EFA-Monitor-cron" > /etc/cron.d/EFA-Monitor.cron

echo "$VERSION update is complete"
echo ""
echo "" >> $TMPMAIL
Expand Down

0 comments on commit a37afb6

Please sign in to comment.