add max error and improve general behaviour
This commit is contained in:
+4
-2
@@ -1,5 +1,7 @@
|
|||||||
config.cfg
|
config.cfg
|
||||||
*.html
|
|
||||||
*.diff
|
|
||||||
sites/*.orig
|
sites/*.orig
|
||||||
sites/*.ignore
|
sites/*.ignore
|
||||||
|
sites/*.html
|
||||||
|
temp
|
||||||
|
count.log
|
||||||
|
monitor.log
|
||||||
|
|||||||
@@ -2,6 +2,19 @@ TOEMAIL=destination@email.com
|
|||||||
FREMAIL=sender@email.com
|
FREMAIL=sender@email.com
|
||||||
SENDMAILPATH=/usr/sbin/sendmail
|
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
|
NAME[0]=shortname1
|
||||||
HOST[0]=example.com
|
HOST[0]=example.com
|
||||||
|
|
||||||
|
|||||||
+64
-22
@@ -31,12 +31,12 @@ function mailsend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pingtest {
|
function pingtest {
|
||||||
ping -c3 -W3 -q $1
|
ping -c3 -W3 -q $1 >> /dev/null
|
||||||
STATUS=$(echo $?)
|
PSTATUS=$(echo $?)
|
||||||
}
|
}
|
||||||
|
|
||||||
function indextest {
|
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
|
if [ -e sites/"$CURHOST".ignore ]; then
|
||||||
CURIGN=$(cat sites/"$CURHOST".ignore)
|
CURIGN=$(cat sites/"$CURHOST".ignore)
|
||||||
@@ -44,36 +44,78 @@ function indextest {
|
|||||||
CURIGN="VeRy-UnLiKeLy-StRiNg-To-MaTcH"
|
CURIGN="VeRy-UnLiKeLy-StRiNg-To-MaTcH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
diff -qBb -I $CURIGN sites/"$CURHOST".orig "$CURHOST".html
|
diff -qBb -I "$CURIGN" sites/"$CURHOST".orig $TEMPDIR/"$CURHOST".html
|
||||||
STATUS=$(echo $?)
|
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
|
for ((i = 0; i < ${#NAME[*]}; i++)); do
|
||||||
CURNAME=${NAME[$i]}
|
CURNAME=${NAME[$i]}
|
||||||
CURHOST=${HOST[$i]}
|
CURHOST=${HOST[$i]}
|
||||||
|
|
||||||
## TEST PING
|
## TEST PING
|
||||||
pingtest $CURHOST
|
pingtest $CURHOST
|
||||||
if [ "$STATUS" != 0 ]; then
|
if [ "$PSTATUS" != 0 ]; then
|
||||||
mailsend "Ping error on $CURHOST" \
|
ERROR[$i]=$(expr ${ERROR[$i]} + 1)
|
||||||
"Ping was unsuccessful" \
|
echo "[WARNING] Ping to $CURHOST failed" >> $LOGFILE
|
||||||
"Check http://$CURHOST"
|
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
## TEST FOR CHANGED INDEX
|
## TEST FOR CHANGED INDEX (only if ping was successful)
|
||||||
indextest
|
if [ "$PSTATUS" = 0 ]; then
|
||||||
if [ "$STATUS" != 0 ]; then
|
indextest
|
||||||
diff -U 0 -Bb -I $CURIGN sites/"$CURHOST".orig "$CURHOST".html > "$CURHOST".diff
|
if [ "$ISTATUS" != 0 ]; then
|
||||||
|
ERROR[$i]=$(expr ${ERROR[$i]} + 1)
|
||||||
mailsend "Index error on $CURHOST" \
|
echo "[WARNING] Index check for $CURHOST failed" >> $LOGFILE
|
||||||
"Index on $CURHOST differs from original index: \n\n$(cat $CURHOST.diff)" \
|
diff -U 0 -Bb -I "$CURIGN" sites/"$CURHOST".orig $TEMPDIR/"$CURHOST".html > $TEMPDIR/"$CURHOST".diff
|
||||||
"Update original index: ssh://$CURNAME"
|
|
||||||
|
if [ "${ERROR[$i]}" -le "$MAXERROR" ]; then
|
||||||
rm "$CURHOST".diff
|
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
|
fi
|
||||||
rm "$CURHOST".html
|
|
||||||
|
|
||||||
done
|
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