Line 1... |
Line 1... |
1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
|
2 |
|
3 |
#
|
3 |
#
|
4 |
# Script that checks if given sites are up and sends an e-mail if they are not.
|
4 |
# Script that checks if given sites are up and sends an e-mail if the are not.
|
5 |
# You should not run this script on the same servers your monitoring,
|
5 |
# You should not run this script on the same servers your monitoring,
|
6 |
# neither should your e-mail account reside on a server behind same firewall as the sites your checking.
|
6 |
# neither should your e-mail account reside on a server behind same firewall as the sites your checking.
|
7 |
#
|
7 |
#
|
8 |
# Developer: oSource Development
|
8 |
# Developer: oSource Development
|
9 |
# DevTeam: Marcus Uddenhed
|
9 |
# DevTeam: Marcus Uddenhed
|
10 |
# Version: 0.5.0
|
10 |
# Version: 0.6.1
|
11 |
# Web: http://www.osource.se
|
11 |
# Web: http://www.osource.se
|
12 |
# Updated: 2017-08-31
|
12 |
# Updated: 2017-10-30
|
13 |
#
|
13 |
#
|
14 |
# Requires: mailx (http://heirloom.sourceforge.net/mailx.html)
|
14 |
# Requires: heirloom-mailx (http://heirloom.sourceforge.net/mailx.html)
|
15 |
#
|
15 |
#
|
16 |
# Licensed under BSDL license, see license information on our homepage.
|
16 |
# Licensed under BSDL license, see license information on our homepage.
|
17 |
#
|
17 |
#
|
18 |
|
18 |
|
19 |
#### Global variables ####
|
19 |
#### Global variables ####
|
20 |
# Sites
|
20 |
# Sites
|
21 |
checkSite[1]="https://"; # Add sites that you want to monitor, can be as many as you want.
|
21 |
checkSite[1]="http://" # Add sites that you want to monitor, can be as many as you want.
|
22 |
checkSite[2]="http://";
|
22 |
checkSite[2]="https://"
|
23 |
|
23 |
|
24 |
# Retries
|
24 |
# Retries
|
25 |
rInterval=8 # How many times should it retry until it set the site as down.
|
25 |
rInterval=8 # How many times should it retry until it set the site as down.
|
26 |
rTime=20 # How many seconds shold it wait between retries.
|
26 |
rTime=20 # How many seconds shold it wait between retries.
|
27 |
|
27 |
|
28 |
# Mail
|
28 |
# Mail
|
29 |
sendMail=yes # Should i send an e-mail with failed sites.
|
29 |
sendMail=yes # Should i send an e-mail with failed sites.
|
30 |
mailFrom="" # From whom shall this mail be sent?
|
30 |
mailFrom="" # From whom shall this mail be sent?
|
31 |
mailTo="" # To whom shall the mail be sent? Seperate recipients with a ","
|
31 |
mailTo="" # To whom shall the mail be sent?
|
32 |
smtpHost="" # The SMTP mail server that is going to process the mail.
|
32 |
smtpHost="" # The SMTP mail server that is going to process the mail.
|
33 |
smtpAuth=yes # Does the SMTP mail server require authentication(yes/no).
|
33 |
smtpAuth=yes # Does the SMTP mail server require authentication(yes/no).
|
34 |
smtpUser="" # Username if smtpAuth is set to yes.
|
34 |
smtpUser="" # Username if smtpAuth is set to yes.
|
35 |
smtpPass="" # password if smtpAuth is set to yes.
|
35 |
smtpPass="" # password if smtpAuth is set to yes.
|
36 |
smtpPort=587 # Standard for non authenticated SMTP is 25, 587 is for authenticated SMTP.
|
36 |
smtpPort=587 # Standard for non authenticated SMTP is 25, 587 is for authenticated SMTP.
|
- |
|
37 |
mailBin="heirloom-mailx" # executable file for mailx.
|
37 |
|
38 |
|
38 |
# Logging
|
39 |
# Logging
|
39 |
logStatus=yes # Should we log to local logfile(yes/no).
|
40 |
logStatus=yes # Should we log to local logfile(yes/no).
|
40 |
logPath="/var/log" # Where should we put the log file(omit the traling slash).
|
41 |
logPath="/var/log" # Where should we put the log file(omit the traling slash).
|
41 |
logName="oSiteChecker.log" # name of log file.
|
42 |
logName="oSiteChecker.log" # name of log file.
|
Line 137... |
Line 138... |
137 |
echo "Regards" >> $tmpPath/mailbody.txt
|
138 |
echo "Regards" >> $tmpPath/mailbody.txt
|
138 |
echo "" >> $tmpPath/mailbody.txt
|
139 |
echo "" >> $tmpPath/mailbody.txt
|
139 |
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
|
140 |
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
|
140 |
|
141 |
|
141 |
# Send data
|
142 |
# Send data
|
142 |
MAILRC=/dev/null mailx -n
|
143 |
MAILRC=/dev/null $mailBin -n
|
143 |
if [ $smtpAuth = "no" ]
|
144 |
if [ $smtpAuth = "no" ]
|
144 |
then
|
145 |
then
|
145 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort mailx -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
146 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
146 |
fi
|
147 |
fi
|
147 |
if [ $smtpAuth = "yes" ]
|
148 |
if [ $smtpAuth = "yes" ]
|
148 |
then
|
149 |
then
|
149 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort smtp-auth-user=$smtpUser smtp-auth-password=$smtpPass smtp-use-starttls=yes ssl-verify=ignore smtp-auth=login mailx -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
150 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort smtp-auth-user=$smtpUser smtp-auth-password=$smtpPass smtp-use-starttls=yes ssl-verify=ignore smtp-auth=login $mailBin -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
150 |
fi
|
151 |
fi
|
151 |
|
152 |
|
152 |
# Remove temporary mailbody.txt file
|
153 |
# Remove temporary mailbody.txt file
|
153 |
rm $tmpPath/mailbody.txt
|
154 |
rm $tmpPath/mailbody.txt
|
154 |
else
|
155 |
else
|
Line 183... |
Line 184... |
183 |
echo "Regards" >> $tmpPath/mailbody.txt
|
184 |
echo "Regards" >> $tmpPath/mailbody.txt
|
184 |
echo "" >> $tmpPath/mailbody.txt
|
185 |
echo "" >> $tmpPath/mailbody.txt
|
185 |
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
|
186 |
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
|
186 |
|
187 |
|
187 |
# Send data
|
188 |
# Send data
|
188 |
MAILRC=/dev/null mailx -n
|
189 |
MAILRC=/dev/null $mailBin -n
|
189 |
if [ $smtpAuth = "no" ]
|
190 |
if [ $smtpAuth = "no" ]
|
190 |
then
|
191 |
then
|
191 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort mailx -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
192 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
192 |
fi
|
193 |
fi
|
193 |
if [ $smtpAuth = "yes" ]
|
194 |
if [ $smtpAuth = "yes" ]
|
194 |
then
|
195 |
then
|
195 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort smtp-auth-user=$smtpUser smtp-auth-password=$smtpPass smtp-use-starttls=yes ssl-verify=ignore smtp-auth=login mailx -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
196 |
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort smtp-auth-user=$smtpUser smtp-auth-password=$smtpPass smtp-use-starttls=yes ssl-verify=ignore smtp-auth=login $mailBin -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
|
196 |
fi
|
197 |
fi
|
197 |
|
198 |
|
198 |
# Remove temporary mailbody.txt file
|
199 |
# Remove temporary mailbody.txt file
|
199 |
rm $tmpPath/mailbody.txt
|
200 |
rm $tmpPath/mailbody.txt
|
200 |
}
|
201 |
}
|
201 |
|
202 |
|
- |
|
203 |
script_help() {
|
- |
|
204 |
echo "Usage: oSiteChecker.sh <parameter>"
|
- |
|
205 |
echo ""
|
- |
|
206 |
echo "Parameters:"
|
- |
|
207 |
echo "--check Does a test connection to pre-configured sites and test to see if they are responding."
|
- |
|
208 |
echo "--mail-test Does a test on the mail function to see if all mail related settings are okay."
|
- |
|
209 |
}
|
- |
|
210 |
|
202 |
case $1 in
|
211 |
case $1 in
|
203 |
--check)
|
212 |
--check)
|
204 |
check_sites
|
213 |
check_sites
|
205 |
;;
|
214 |
;;
|
206 |
--mail-test)
|
215 |
--mail-test)
|