Subversion Repositories oSiteChecker

Compare Revisions

Ignore whitespace Rev 2 → Rev 3

/branches/0.6.x/changelog.txt
0,0 → 1,15
2017-10-30 Marcus Uddenhed <marcus@osource.se>
 
* readme.txt (file): Change information and version number.
* oSiteChecker.sh (mail): Fixed pointer to mailx binary.
* oSiteChecker.sh (general): Default values for authenticated mail & logging is set to yes, time to use secure settings.
 
2017-08-30 Marcus Uddenhed <marcus@osource.se>
 
* readme.txt (file): Created.
 
* oSiteChecker.sh (file): Created.
* license.txt (file): Created.
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: branches/0.6.x/license.txt
===================================================================
--- branches/0.6.x/license.txt (nonexistent)
+++ branches/0.6.x/license.txt (revision 3)
@@ -0,0 +1,19 @@
+Copyright 2017 oSource Development
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
+from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
/branches/0.6.x/license.txt
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: branches/0.6.x/oSiteChecker.sh
===================================================================
--- branches/0.6.x/oSiteChecker.sh (nonexistent)
+++ branches/0.6.x/oSiteChecker.sh (revision 3)
@@ -0,0 +1,221 @@
+#!/bin/bash
+
+#
+# Script that checks if given sites are up and sends an e-mail if the are not.
+# You should not run this script on the same servers your monitoring,
+# neither should your e-mail account reside on a server behind same firewall as the sites your checking.
+#
+# Developer: oSource Development
+# DevTeam: Marcus Uddenhed
+# Version: 0.6.1
+# Web: http://www.osource.se
+# Updated: 2017-10-30
+#
+# Requires: heirloom-mailx (http://heirloom.sourceforge.net/mailx.html)
+#
+# Licensed under BSDL license, see license information on our homepage.
+#
+
+#### Global variables ####
+# Sites
+checkSite[1]="http://" # Add sites that you want to monitor, can be as many as you want.
+checkSite[2]="https://"
+
+# Retries
+rInterval=8 # How many times should it retry until it set the site as down.
+rTime=20 # How many seconds shold it wait between retries.
+
+# Mail
+sendMail=yes # Should i send an e-mail with failed sites.
+mailFrom="" # From whom shall this mail be sent?
+mailTo="" # To whom shall the mail be sent?
+smtpHost="" # The SMTP mail server that is going to process the mail.
+smtpAuth=yes # Does the SMTP mail server require authentication(yes/no).
+smtpUser="" # Username if smtpAuth is set to yes.
+smtpPass="" # password if smtpAuth is set to yes.
+smtpPort=587 # Standard for non authenticated SMTP is 25, 587 is for authenticated SMTP.
+mailBin="heirloom-mailx" # executable file for mailx.
+
+# Logging
+logStatus=yes # Should we log to local logfile(yes/no).
+logPath="/var/log" # Where should we put the log file(omit the traling slash).
+logName="oSiteChecker.log" # name of log file.
+
+#### Do not edit anything below unless you know what you are doing. ####
+
+check_sites() {
+ # Declare $is variable
+ is=0
+
+ # Start control
+ for i in "${checkSite[@]}"
+ do
+ CURL=$(curl -s --head $i)
+ if echo $CURL | grep "200 OK" > /dev/null
+ then
+ # add entry to log file if logging enabled
+ if [ $logStatus == "yes" ]
+ then
+ echo `date +%F` `date +%T` "$i" "Host up" >> $logPath/$logName
+ else
+ # if logging set to no send to null
+ echo "" > /dev/null
+ fi
+ else
+ # Collect all sites that do not respond as they should for further processing.
+ siteArray[ $is ]="${i}"
+ (( is++ ))
+ fi
+ done
+
+ # Check to see if any sites been reported as down.
+ if [ ${#siteArray[@]} -ne 0 ]
+ then
+ # Test each failed site in a given amount of times.
+ for ((n=1;n<=$rInterval;n++))
+ do
+ # Go through failed sites again to eliminate temporary glicthes.
+ for i in "${siteArray[@]}"
+ do
+ CURL=$(curl -s --head $i)
+ if echo $CURL | grep "200 OK" > /dev/null
+ then
+ # remove succesful sites from array.
+ delete=(${i})
+ siteArray=( "${siteArray[@]/$delete}" )
+ else
+ # Keeps failed site in array.
+ echo "" > /dev/null
+ fi
+ done
+
+ # Clean empty lines in siteArray
+ tmpArray=()
+ for value in "${siteArray[@]}"
+ do
+ [[ $value != "" ]] && tmpArray+=($value)
+ done
+ siteArray=("${tmpArray[@]}")
+ unset tmpArray
+
+ # Debug
+ #for i in "${siteArray[@]}"
+ #do
+ # echo ${i}
+ #done
+
+ # Sleeps for an amount of time between checking site status again.
+ sleep $rTime
+ done
+ fi
+
+ # notification action
+ if [ ${#siteArray[@]} -ne 0 ]
+ then
+ #echo ${#siteArray[@]}
+ # Send an email with status
+ if [ $sendMail == "yes" ]
+ then
+ # Temp path for mailbody.txt
+ tmpPath=/tmp
+
+ # Set mail subject
+ mailSubject="Connectivity test failed"
+
+ # Build mail body
+ echo "Hi" > $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "One or more servers is not responding as the should, see complete list below." >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ for i in "${siteArray[@]}"
+ do
+ echo ${i} >> $tmpPath/mailbody.txt
+ done
+ #echo "Test - Array size:" ${#siteArray[@]} >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Regards" >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
+
+ # Send data
+ MAILRC=/dev/null $mailBin -n
+ if [ $smtpAuth = "no" ]
+ then
+ env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
+ fi
+ if [ $smtpAuth = "yes" ]
+ then
+ 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
+ fi
+
+ # Remove temporary mailbody.txt file
+ rm $tmpPath/mailbody.txt
+ else
+ echo "" > /dev/null
+ fi
+
+ # add entry to log file if logging enabled
+ if [ $logStatus == "yes" ]
+ then
+ for i in "${siteArray[@]}"
+ do
+ echo `date +%F` `date +%T` ${i} "Host down" >> $logPath/$logName
+ done
+ fi
+ fi
+}
+
+mail_test() {
+ # Temp path for mailbody.txt
+ tmpPath=/tmp
+
+ # Set mail subject
+ mailSubject="Mail test"
+
+ # Build mail body
+ echo "Hi" > $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "This is a test mail to see that the mail function works." >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Regards" >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
+
+ # Send data
+ MAILRC=/dev/null $mailBin -n
+ if [ $smtpAuth = "no" ]
+ then
+ env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
+ fi
+ if [ $smtpAuth = "yes" ]
+ then
+ 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
+ fi
+
+ # Remove temporary mailbody.txt file
+ rm $tmpPath/mailbody.txt
+}
+
+script_help() {
+ echo "Usage: oSiteChecker.sh <parameter>"
+ echo ""
+ echo "Parameters:"
+ echo "--check Does a test connection to pre-configured sites and test to see if they are responding."
+ echo "--mail-test Does a test on the mail function to see if all mail related settings are okay."
+}
+
+case $1 in
+ --check)
+ check_sites
+ ;;
+ --mail-test)
+ mail_test
+ ;;
+ *)
+ script_help
+ ;;
+esac
/branches/0.6.x/oSiteChecker.sh
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/0.6.x/readme.txt
===================================================================
--- branches/0.6.x/readme.txt (nonexistent)
+++ branches/0.6.x/readme.txt (revision 3)
@@ -0,0 +1,24 @@
+Release notes for oSiteChecker v0.6.1 2017-10-30
+================================================
+
+Overview:
+Script to monitor site status from remote location. The script checks given sites in given intervals and can send mail when one or more sites are down,
+the script can log the information into a log file to for statistical analysis later on if desired.
+
+Purpose:
+Monitor given sites and alert when down.
+
+Issue Summary:
+* None at this time
+
+Notes:
+This script has been tested on Rasbian on a Raspberry PI, but should work on other Linux/Unix as long as Mailx dependency is met.
+
+More info about heirloom-mailx (http://heirloom.sourceforge.net/mailx.html)
+
+Disclaimer:
+This software is released with the BSDL license and the license is in the license.txt
+file that should accompany this software.
+
+Contact:
+https://www.osource.se/
\ No newline at end of file
/branches/0.6.x/readme.txt
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: tags/0.6.1/oSiteChecker_0.6.1.tar.gz
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: tags/0.6.1/oSiteChecker_0.6.1.tar.gz
===================================================================
--- tags/0.6.1/oSiteChecker_0.6.1.tar.gz (nonexistent)
+++ tags/0.6.1/oSiteChecker_0.6.1.tar.gz (revision 3)
/tags/0.6.1/oSiteChecker_0.6.1.tar.gz
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: tags/0.6.1/src/changelog.txt
===================================================================
--- tags/0.6.1/src/changelog.txt (nonexistent)
+++ tags/0.6.1/src/changelog.txt (revision 3)
@@ -0,0 +1,15 @@
+2017-10-30 Marcus Uddenhed <marcus@osource.se>
+
+ * readme.txt (file): Change information and version number.
+
+ * oSiteChecker.sh (mail): Fixed pointer to mailx binary.
+
+ * oSiteChecker.sh (general): Default values for authenticated mail & logging is set to yes, time to use secure settings.
+
+2017-08-30 Marcus Uddenhed <marcus@osource.se>
+
+ * readme.txt (file): Created.
+
+ * oSiteChecker.sh (file): Created.
+
+ * license.txt (file): Created.
/tags/0.6.1/src/changelog.txt
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: tags/0.6.1/src/license.txt
===================================================================
--- tags/0.6.1/src/license.txt (nonexistent)
+++ tags/0.6.1/src/license.txt (revision 3)
@@ -0,0 +1,19 @@
+Copyright 2017 oSource Development
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
+from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
/tags/0.6.1/src/license.txt
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: tags/0.6.1/src/oSiteChecker.sh
===================================================================
--- tags/0.6.1/src/oSiteChecker.sh (nonexistent)
+++ tags/0.6.1/src/oSiteChecker.sh (revision 3)
@@ -0,0 +1,221 @@
+#!/bin/bash
+
+#
+# Script that checks if given sites are up and sends an e-mail if the are not.
+# You should not run this script on the same servers your monitoring,
+# neither should your e-mail account reside on a server behind same firewall as the sites your checking.
+#
+# Developer: oSource Development
+# DevTeam: Marcus Uddenhed
+# Version: 0.6.1
+# Web: http://www.osource.se
+# Updated: 2017-10-30
+#
+# Requires: heirloom-mailx (http://heirloom.sourceforge.net/mailx.html)
+#
+# Licensed under BSDL license, see license information on our homepage.
+#
+
+#### Global variables ####
+# Sites
+checkSite[1]="http://" # Add sites that you want to monitor, can be as many as you want.
+checkSite[2]="https://"
+
+# Retries
+rInterval=8 # How many times should it retry until it set the site as down.
+rTime=20 # How many seconds shold it wait between retries.
+
+# Mail
+sendMail=yes # Should i send an e-mail with failed sites.
+mailFrom="" # From whom shall this mail be sent?
+mailTo="" # To whom shall the mail be sent?
+smtpHost="" # The SMTP mail server that is going to process the mail.
+smtpAuth=yes # Does the SMTP mail server require authentication(yes/no).
+smtpUser="" # Username if smtpAuth is set to yes.
+smtpPass="" # password if smtpAuth is set to yes.
+smtpPort=587 # Standard for non authenticated SMTP is 25, 587 is for authenticated SMTP.
+mailBin="heirloom-mailx" # executable file for mailx.
+
+# Logging
+logStatus=yes # Should we log to local logfile(yes/no).
+logPath="/var/log" # Where should we put the log file(omit the traling slash).
+logName="oSiteChecker.log" # name of log file.
+
+#### Do not edit anything below unless you know what you are doing. ####
+
+check_sites() {
+ # Declare $is variable
+ is=0
+
+ # Start control
+ for i in "${checkSite[@]}"
+ do
+ CURL=$(curl -s --head $i)
+ if echo $CURL | grep "200 OK" > /dev/null
+ then
+ # add entry to log file if logging enabled
+ if [ $logStatus == "yes" ]
+ then
+ echo `date +%F` `date +%T` "$i" "Host up" >> $logPath/$logName
+ else
+ # if logging set to no send to null
+ echo "" > /dev/null
+ fi
+ else
+ # Collect all sites that do not respond as they should for further processing.
+ siteArray[ $is ]="${i}"
+ (( is++ ))
+ fi
+ done
+
+ # Check to see if any sites been reported as down.
+ if [ ${#siteArray[@]} -ne 0 ]
+ then
+ # Test each failed site in a given amount of times.
+ for ((n=1;n<=$rInterval;n++))
+ do
+ # Go through failed sites again to eliminate temporary glicthes.
+ for i in "${siteArray[@]}"
+ do
+ CURL=$(curl -s --head $i)
+ if echo $CURL | grep "200 OK" > /dev/null
+ then
+ # remove succesful sites from array.
+ delete=(${i})
+ siteArray=( "${siteArray[@]/$delete}" )
+ else
+ # Keeps failed site in array.
+ echo "" > /dev/null
+ fi
+ done
+
+ # Clean empty lines in siteArray
+ tmpArray=()
+ for value in "${siteArray[@]}"
+ do
+ [[ $value != "" ]] && tmpArray+=($value)
+ done
+ siteArray=("${tmpArray[@]}")
+ unset tmpArray
+
+ # Debug
+ #for i in "${siteArray[@]}"
+ #do
+ # echo ${i}
+ #done
+
+ # Sleeps for an amount of time between checking site status again.
+ sleep $rTime
+ done
+ fi
+
+ # notification action
+ if [ ${#siteArray[@]} -ne 0 ]
+ then
+ #echo ${#siteArray[@]}
+ # Send an email with status
+ if [ $sendMail == "yes" ]
+ then
+ # Temp path for mailbody.txt
+ tmpPath=/tmp
+
+ # Set mail subject
+ mailSubject="Connectivity test failed"
+
+ # Build mail body
+ echo "Hi" > $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "One or more servers is not responding as the should, see complete list below." >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ for i in "${siteArray[@]}"
+ do
+ echo ${i} >> $tmpPath/mailbody.txt
+ done
+ #echo "Test - Array size:" ${#siteArray[@]} >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Regards" >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
+
+ # Send data
+ MAILRC=/dev/null $mailBin -n
+ if [ $smtpAuth = "no" ]
+ then
+ env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
+ fi
+ if [ $smtpAuth = "yes" ]
+ then
+ 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
+ fi
+
+ # Remove temporary mailbody.txt file
+ rm $tmpPath/mailbody.txt
+ else
+ echo "" > /dev/null
+ fi
+
+ # add entry to log file if logging enabled
+ if [ $logStatus == "yes" ]
+ then
+ for i in "${siteArray[@]}"
+ do
+ echo `date +%F` `date +%T` ${i} "Host down" >> $logPath/$logName
+ done
+ fi
+ fi
+}
+
+mail_test() {
+ # Temp path for mailbody.txt
+ tmpPath=/tmp
+
+ # Set mail subject
+ mailSubject="Mail test"
+
+ # Build mail body
+ echo "Hi" > $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "This is a test mail to see that the mail function works." >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Regards" >> $tmpPath/mailbody.txt
+ echo "" >> $tmpPath/mailbody.txt
+ echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
+
+ # Send data
+ MAILRC=/dev/null $mailBin -n
+ if [ $smtpAuth = "no" ]
+ then
+ env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
+ fi
+ if [ $smtpAuth = "yes" ]
+ then
+ 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
+ fi
+
+ # Remove temporary mailbody.txt file
+ rm $tmpPath/mailbody.txt
+}
+
+script_help() {
+ echo "Usage: oSiteChecker.sh <parameter>"
+ echo ""
+ echo "Parameters:"
+ echo "--check Does a test connection to pre-configured sites and test to see if they are responding."
+ echo "--mail-test Does a test on the mail function to see if all mail related settings are okay."
+}
+
+case $1 in
+ --check)
+ check_sites
+ ;;
+ --mail-test)
+ mail_test
+ ;;
+ *)
+ script_help
+ ;;
+esac
/tags/0.6.1/src/oSiteChecker.sh
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: tags/0.6.1/src/readme.txt
===================================================================
--- tags/0.6.1/src/readme.txt (nonexistent)
+++ tags/0.6.1/src/readme.txt (revision 3)
@@ -0,0 +1,24 @@
+Release notes for oSiteChecker v0.6.1 2017-10-30
+================================================
+
+Overview:
+Script to monitor site status from remote location. The script checks given sites in given intervals and can send mail when one or more sites are down,
+the script can log the information into a log file to for statistical analysis later on if desired.
+
+Purpose:
+Monitor given sites and alert when down.
+
+Issue Summary:
+* None at this time
+
+Notes:
+This script has been tested on Rasbian on a Raspberry PI, but should work on other Linux/Unix as long as Mailx dependency is met.
+
+More info about heirloom-mailx (http://heirloom.sourceforge.net/mailx.html)
+
+Disclaimer:
+This software is released with the BSDL license and the license is in the license.txt
+file that should accompany this software.
+
+Contact:
+https://www.osource.se/
\ No newline at end of file
/tags/0.6.1/src/readme.txt
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt (revision 2)
+++ trunk/changelog.txt (revision 3)
@@ -1,3 +1,11 @@
+2017-10-30 Marcus Uddenhed <marcus@osource.se>
+
+ * readme.txt (file): Change information and version number.
+
+ * oSiteChecker.sh (mail): Fixed pointer to mailx binary.
+
+ * oSiteChecker.sh (general): Default values for authenticated mail & logging is set to yes, time to use secure settings.
+
2017-08-30 Marcus Uddenhed <marcus@osource.se>
* readme.txt (file): Created.
/trunk/oSiteChecker.sh
1,17 → 1,17
#!/bin/bash
 
#
# Script that checks if given sites are up and sends an e-mail if they are not.
# Script that checks if given sites are up and sends an e-mail if the are not.
# You should not run this script on the same servers your monitoring,
# neither should your e-mail account reside on a server behind same firewall as the sites your checking.
#
# Developer: oSource Development
# DevTeam: Marcus Uddenhed
# Version: 0.5.0
# Version: 0.6.1
# Web: http://www.osource.se
# Updated: 2017-08-31
# Updated: 2017-10-30
#
# Requires: mailx (http://heirloom.sourceforge.net/mailx.html)
# Requires: heirloom-mailx (http://heirloom.sourceforge.net/mailx.html)
#
# Licensed under BSDL license, see license information on our homepage.
#
18,195 → 18,204
 
#### Global variables ####
# Sites
checkSite[1]="https://"; # Add sites that you want to monitor, can be as many as you want.
checkSite[2]="http://";
checkSite[1]="http://" # Add sites that you want to monitor, can be as many as you want.
checkSite[2]="https://"
 
# Retries
rInterval=8 # How many times should it retry until it set the site as down.
rTime=20 # How many seconds shold it wait between retries.
rInterval=8 # How many times should it retry until it set the site as down.
rTime=20 # How many seconds shold it wait between retries.
 
# Mail
sendMail=yes # Should i send an e-mail with failed sites.
mailFrom="" # From whom shall this mail be sent?
mailTo="" # To whom shall the mail be sent? Seperate recipients with a ","
smtpHost="" # The SMTP mail server that is going to process the mail.
smtpAuth=yes # Does the SMTP mail server require authentication(yes/no).
smtpUser="" # Username if smtpAuth is set to yes.
smtpPass="" # password if smtpAuth is set to yes.
smtpPort=587 # Standard for non authenticated SMTP is 25, 587 is for authenticated SMTP.
sendMail=yes # Should i send an e-mail with failed sites.
mailFrom="" # From whom shall this mail be sent?
mailTo="" # To whom shall the mail be sent?
smtpHost="" # The SMTP mail server that is going to process the mail.
smtpAuth=yes # Does the SMTP mail server require authentication(yes/no).
smtpUser="" # Username if smtpAuth is set to yes.
smtpPass="" # password if smtpAuth is set to yes.
smtpPort=587 # Standard for non authenticated SMTP is 25, 587 is for authenticated SMTP.
mailBin="heirloom-mailx" # executable file for mailx.
 
# Logging
logStatus=yes # Should we log to local logfile(yes/no).
logPath="/var/log" # Where should we put the log file(omit the traling slash).
logName="oSiteChecker.log" # name of log file.
logStatus=yes # Should we log to local logfile(yes/no).
logPath="/var/log" # Where should we put the log file(omit the traling slash).
logName="oSiteChecker.log" # name of log file.
 
#### Do not edit anything below unless you know what you are doing. ####
 
check_sites() {
# Declare $is variable
is=0
# Declare $is variable
is=0
 
# Start control
for i in "${checkSite[@]}"
do
CURL=$(curl -s --head $i)
if echo $CURL | grep "200 OK" > /dev/null
then
# add entry to log file if logging enabled
if [ $logStatus == "yes" ]
then
echo `date +%F` `date +%T` "$i" "Host up" >> $logPath/$logName
else
# if logging set to no send to null
echo "" > /dev/null
fi
else
# Collect all sites that do not respond as they should for further processing.
siteArray[ $is ]="${i}"
(( is++ ))
fi
done
# Start control
for i in "${checkSite[@]}"
do
CURL=$(curl -s --head $i)
if echo $CURL | grep "200 OK" > /dev/null
then
# add entry to log file if logging enabled
if [ $logStatus == "yes" ]
then
echo `date +%F` `date +%T` "$i" "Host up" >> $logPath/$logName
else
# if logging set to no send to null
echo "" > /dev/null
fi
else
# Collect all sites that do not respond as they should for further processing.
siteArray[ $is ]="${i}"
(( is++ ))
fi
done
 
# Check to see if any sites been reported as down.
if [ ${#siteArray[@]} -ne 0 ]
then
# Test each failed site in a given amount of times.
for ((n=1;n<=$rInterval;n++))
do
# Go through failed sites again to eliminate temporary glicthes.
for i in "${siteArray[@]}"
do
CURL=$(curl -s --head $i)
if echo $CURL | grep "200 OK" > /dev/null
then
# remove succesful sites from array.
delete=(${i})
siteArray=( "${siteArray[@]/$delete}" )
else
# Keeps failed site in array.
echo "" > /dev/null
fi
done
if [ ${#siteArray[@]} -ne 0 ]
then
# Test each failed site in a given amount of times.
for ((n=1;n<=$rInterval;n++))
do
# Go through failed sites again to eliminate temporary glicthes.
for i in "${siteArray[@]}"
do
CURL=$(curl -s --head $i)
if echo $CURL | grep "200 OK" > /dev/null
then
# remove succesful sites from array.
delete=(${i})
siteArray=( "${siteArray[@]/$delete}" )
else
# Keeps failed site in array.
echo "" > /dev/null
fi
done
 
# Clean empty lines in siteArray
tmpArray=()
for value in "${siteArray[@]}"
do
[[ $value != "" ]] && tmpArray+=($value)
done
siteArray=("${tmpArray[@]}")
unset tmpArray
# Clean empty lines in siteArray
tmpArray=()
for value in "${siteArray[@]}"
do
[[ $value != "" ]] && tmpArray+=($value)
done
siteArray=("${tmpArray[@]}")
unset tmpArray
 
# Debug
#for i in "${siteArray[@]}"
#do
# echo ${i}
#done
# Debug
#for i in "${siteArray[@]}"
#do
# echo ${i}
#done
 
# Sleeps for an amount of time between checking site status again.
sleep $rTime
done
fi
# Sleeps for an amount of time between checking site status again.
sleep $rTime
done
fi
 
# notification action
if [ ${#siteArray[@]} -ne 0 ]
then
#echo ${#siteArray[@]}
# Send an email with status
if [ $sendMail == "yes" ]
then
# Temp path for mailbody.txt
tmpPath=/tmp
# notification action
if [ ${#siteArray[@]} -ne 0 ]
then
#echo ${#siteArray[@]}
# Send an email with status
if [ $sendMail == "yes" ]
then
# Temp path for mailbody.txt
tmpPath=/tmp
 
# Set mail subject
mailSubject="Connectivity test failed"
# Set mail subject
mailSubject="Connectivity test failed"
 
# Build mail body
echo "Hi" > $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "One or more servers is not responding as the should, see complete list below." >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
for i in "${siteArray[@]}"
do
echo ${i} >> $tmpPath/mailbody.txt
done
#echo "Test - Array size:" ${#siteArray[@]} >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Regards" >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
# Build mail body
echo "Hi" > $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "One or more servers is not responding as the should, see complete list below." >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
for i in "${siteArray[@]}"
do
echo ${i} >> $tmpPath/mailbody.txt
done
#echo "Test - Array size:" ${#siteArray[@]} >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Regards" >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
 
# Send data
MAILRC=/dev/null mailx -n
if [ $smtpAuth = "no" ]
then
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort mailx -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
fi
if [ $smtpAuth = "yes" ]
then
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
fi
# Send data
MAILRC=/dev/null $mailBin -n
if [ $smtpAuth = "no" ]
then
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
fi
if [ $smtpAuth = "yes" ]
then
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
fi
 
# Remove temporary mailbody.txt file
rm $tmpPath/mailbody.txt
else
echo "" > /dev/null
fi
# Remove temporary mailbody.txt file
rm $tmpPath/mailbody.txt
else
echo "" > /dev/null
fi
 
# add entry to log file if logging enabled
if [ $logStatus == "yes" ]
then
for i in "${siteArray[@]}"
do
echo `date +%F` `date +%T` ${i} "Host down" >> $logPath/$logName
done
fi
fi
# add entry to log file if logging enabled
if [ $logStatus == "yes" ]
then
for i in "${siteArray[@]}"
do
echo `date +%F` `date +%T` ${i} "Host down" >> $logPath/$logName
done
fi
fi
}
 
mail_test() {
# Temp path for mailbody.txt
tmpPath=/tmp
# Temp path for mailbody.txt
tmpPath=/tmp
 
# Set mail subject
mailSubject="Mail test"
# Set mail subject
mailSubject="Mail test"
 
# Build mail body
echo "Hi" > $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "This is a test mail to see that the mail function works." >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Regards" >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
# Build mail body
echo "Hi" > $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "This is a test mail to see that the mail function works." >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Sent:" `date +%Y-%m-%d` `date +%H:%M` >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Regards" >> $tmpPath/mailbody.txt
echo "" >> $tmpPath/mailbody.txt
echo "Your $(cat /etc/hostname) server." >> $tmpPath/mailbody.txt
 
# Send data
MAILRC=/dev/null mailx -n
if [ $smtpAuth = "no" ]
then
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort mailx -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
fi
if [ $smtpAuth = "yes" ]
then
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
fi
# Send data
MAILRC=/dev/null $mailBin -n
if [ $smtpAuth = "no" ]
then
env MAILRC=/dev/null from=$mailFrom smtp=$smtpHost:$smtpPort $mailBin -v -n -s "$mailSubject" $mailTo <$tmpPath/mailbody.txt
fi
if [ $smtpAuth = "yes" ]
then
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
fi
 
# Remove temporary mailbody.txt file
rm $tmpPath/mailbody.txt
# Remove temporary mailbody.txt file
rm $tmpPath/mailbody.txt
}
 
script_help() {
echo "Usage: oSiteChecker.sh <parameter>"
echo ""
echo "Parameters:"
echo "--check Does a test connection to pre-configured sites and test to see if they are responding."
echo "--mail-test Does a test on the mail function to see if all mail related settings are okay."
}
 
case $1 in
--check)
check_sites
;;
--check)
check_sites
;;
--mail-test)
mail_test
mail_test
;;
*)
script_help
;;
esac
*)
script_help
;;
esac
/trunk/readme.txt
1,4 → 1,4
Release notes for oSiteChecker v0.5.0 2017-08-30
Release notes for oSiteChecker v0.6.1 2017-10-30
================================================
 
Overview:
14,7 → 14,7
Notes:
This script has been tested on Rasbian on a Raspberry PI, but should work on other Linux/Unix as long as Mailx dependency is met.
 
More info about mailx (http://heirloom.sourceforge.net/mailx.html)
More info about heirloom-mailx (http://heirloom.sourceforge.net/mailx.html)
 
Disclaimer:
This software is released with the BSDL license and the license is in the license.txt
21,5 → 21,4
file that should accompany this software.
 
Contact:
https://dev.osource.se/
https://www.osource.se/index.php/development/ositechecker/
https://www.osource.se/