add max error and improve general behaviour
This commit is contained in:
+4
-2
@@ -1,5 +1,7 @@
|
||||
config.cfg
|
||||
*.html
|
||||
*.diff
|
||||
sites/*.orig
|
||||
sites/*.ignore
|
||||
sites/*.html
|
||||
temp
|
||||
count.log
|
||||
monitor.log
|
||||
|
||||
@@ -2,6 +2,19 @@ TOEMAIL=destination@email.com
|
||||
FREMAIL=sender@email.com
|
||||
SENDMAILPATH=/usr/sbin/sendmail
|
||||
|
||||
LOGFILE=monitor.log
|
||||
COUNTFILE=count.log
|
||||
TEMPDIR=temp
|
||||
|
||||
# This link is added if an index error appears.
|
||||
# You can use update-index-ssh-link.sh to open ssh:// links
|
||||
SSHCONN=ssh://user@host.tld
|
||||
|
||||
# Maximum $MAXERROR mails if an error occurs.
|
||||
# Will be reset after $RESET runs of script
|
||||
MAXERROR=3
|
||||
RESET=24
|
||||
|
||||
NAME[0]=shortname1
|
||||
HOST[0]=example.com
|
||||
|
||||
|
||||
+64
-22
@@ -31,12 +31,12 @@ function mailsend {
|
||||
}
|
||||
|
||||
function pingtest {
|
||||
ping -c3 -W3 -q $1
|
||||
STATUS=$(echo $?)
|
||||
ping -c3 -W3 -q $1 >> /dev/null
|
||||
PSTATUS=$(echo $?)
|
||||
}
|
||||
|
||||
function indextest {
|
||||
wget -q -T 5 -t 2 -U $(cat monitor-user-agent.txt) -O "$CURHOST".html http://"$CURHOST"
|
||||
wget -q -T 5 -t 2 -U $(cat monitor-user-agent.txt) -O $TEMPDIR/"$CURHOST".html http://"$CURHOST"
|
||||
|
||||
if [ -e sites/"$CURHOST".ignore ]; then
|
||||
CURIGN=$(cat sites/"$CURHOST".ignore)
|
||||
@@ -44,36 +44,78 @@ function indextest {
|
||||
CURIGN="VeRy-UnLiKeLy-StRiNg-To-MaTcH"
|
||||
fi
|
||||
|
||||
diff -qBb -I $CURIGN sites/"$CURHOST".orig "$CURHOST".html
|
||||
STATUS=$(echo $?)
|
||||
|
||||
diff -qBb -I "$CURIGN" sites/"$CURHOST".orig $TEMPDIR/"$CURHOST".html
|
||||
ISTATUS=$(echo $?)
|
||||
}
|
||||
|
||||
if [ ! -e count.txt ]; then
|
||||
touch $COUNTFILE
|
||||
fi
|
||||
source $COUNTFILE
|
||||
RUN=$(expr $RUN + 1)
|
||||
> $COUNTFILE
|
||||
|
||||
if [ ! -e $TEMPDIR ]; then
|
||||
mkdir $TEMPDIR
|
||||
fi
|
||||
|
||||
|
||||
for ((i = 0; i < ${#NAME[*]}; i++)); do
|
||||
CURNAME=${NAME[$i]}
|
||||
CURHOST=${HOST[$i]}
|
||||
|
||||
## TEST PING
|
||||
pingtest $CURHOST
|
||||
if [ "$STATUS" != 0 ]; then
|
||||
mailsend "Ping error on $CURHOST" \
|
||||
"Ping was unsuccessful" \
|
||||
"Check http://$CURHOST"
|
||||
if [ "$PSTATUS" != 0 ]; then
|
||||
ERROR[$i]=$(expr ${ERROR[$i]} + 1)
|
||||
echo "[WARNING] Ping to $CURHOST failed" >> $LOGFILE
|
||||
|
||||
if [ "${ERROR[$i]}" -le "$MAXERROR" ]; then
|
||||
mailsend "Ping error on $CURHOST" \
|
||||
"Ping was unsuccessful" \
|
||||
"Check http://$CURHOST"
|
||||
fi
|
||||
|
||||
else
|
||||
ERROR[$i]=$(expr ${ERROR[$i]} + 0)
|
||||
echo "[INFO] Ping to $CURHOST successful" >> $LOGFILE
|
||||
fi
|
||||
|
||||
## TEST FOR CHANGED INDEX
|
||||
indextest
|
||||
if [ "$STATUS" != 0 ]; then
|
||||
diff -U 0 -Bb -I $CURIGN sites/"$CURHOST".orig "$CURHOST".html > "$CURHOST".diff
|
||||
|
||||
mailsend "Index error on $CURHOST" \
|
||||
"Index on $CURHOST differs from original index: \n\n$(cat $CURHOST.diff)" \
|
||||
"Update original index: ssh://$CURNAME"
|
||||
|
||||
rm "$CURHOST".diff
|
||||
## TEST FOR CHANGED INDEX (only if ping was successful)
|
||||
if [ "$PSTATUS" = 0 ]; then
|
||||
indextest
|
||||
if [ "$ISTATUS" != 0 ]; then
|
||||
ERROR[$i]=$(expr ${ERROR[$i]} + 1)
|
||||
echo "[WARNING] Index check for $CURHOST failed" >> $LOGFILE
|
||||
diff -U 0 -Bb -I "$CURIGN" sites/"$CURHOST".orig $TEMPDIR/"$CURHOST".html > $TEMPDIR/"$CURHOST".diff
|
||||
|
||||
if [ "${ERROR[$i]}" -le "$MAXERROR" ]; then
|
||||
mailsend "Index error on $CURHOST" \
|
||||
"Index on $CURHOST differs from original index: \n\n$(cat $TEMPDIR/$CURHOST.diff)" \
|
||||
"Update original index: $SSHCONN"
|
||||
fi
|
||||
|
||||
else
|
||||
ERROR[$i]=$(expr ${ERROR[$i]} + 0)
|
||||
echo "[INFO] Index check for $CURHOST successful" >> $LOGFILE
|
||||
fi
|
||||
fi
|
||||
rm "$CURHOST".html
|
||||
|
||||
done
|
||||
|
||||
if [ -e $TEMPDIR ]; then
|
||||
rm -rf $TEMPDIR
|
||||
fi
|
||||
|
||||
if [ "$RUN" -le "$RESET" ]; then
|
||||
echo "RUN=$RUN" >> $COUNTFILE
|
||||
for ((i = 0; i < ${#ERROR[*]}; i++)); do
|
||||
echo "ERROR[$i]="${ERROR[$i]}"" >> $COUNTFILE
|
||||
done
|
||||
else
|
||||
echo "RUN=0" >> $COUNTFILE
|
||||
for ((i = 0; i < ${#ERROR[*]}; i++)); do
|
||||
echo "ERROR[$i]=0" >> $COUNTFILE
|
||||
> $LOGFILE
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user