Commit d9a300bb authored by R. van Elst's avatar R. van Elst
Browse files

Merge branch 'master' of github.com:RaymiiOrg/bash-http-monitoring

parents 7227fcb9 dfdb0f13
......@@ -2,7 +2,7 @@
![all is well image][1]
HTTP(s) monitoring dashboard webpage via shell script. Parallel checking, thus very fast, only dependencies are
HTTP(s) status dashboard webpage via shell script. Parallel checking, thus very fast, only dependencies are
curl, coreutils and bash (version 4 or above). For all of you who want a simple script with a nice webpage to check
a few websites. Perfect for a wall mounted monitoring display and a Raspberry Pi.
......@@ -73,6 +73,22 @@ Execute the script and send the output to a file in your webservers documentroot
View that file in a web browser.
#### OS X specifics
On Mac OS X the builtin bash version is too old and the bsd date utility does
not support the time in milliseconds option, so you have
to use [homebrew](https://brew.sh) to install coreutils and bash:
brew install bash coreutils curl
Then you have to run the script with that bash version:
/usr/local/Cellar/bash/#VERSION#/bin/bash
Also in the cronjob if you choose to set that up.
### Cronjob setup
If you want to set up a cronjob, send the output to a temp file and when finished, move that temp
......
......@@ -11,6 +11,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# helper functions
command_exists() {
# check if command exists and fail otherwise
command -v "$1" >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "I require '$1' but it's not installed. Please install it. Aborting."
exit 1
fi
}
# environment checks
[ "${BASH_VERSINFO:-0}" -lt 4 ] && { echo "I require at least Bash version 4. Aborting." >&2 ; exit 2; }
command_exists curl
case "$(uname -s)" in
Darwin*)
datecmd="gdate"
command_exists "${datecmd}"
;;
*)
datecmd="date"
esac
# Start of configuration.
#array names must not contain spaces, only a-ZA-Z.
......@@ -68,11 +91,11 @@ shopt -s nullglob
doRequest() {
name="${1}"
url="${2}"
checkStartTimeMs="$(date +%s%3N)" # epoch in microseconds, but last chars stripped so it's milliseconds
checkStartTimeMs="$(${datecmd} +%s%3N)" # epoch in microseconds, but last chars stripped so it's milliseconds
set +e # curl errors don't count for early exit, turn off e
checkStatusCode="$(curl --max-time "${defaultTimeOut}" --silent --show-error --insecure --output /dev/null --write-out "%{http_code}" "$url" --stderr "${tempfolder}/FAIL/${name}.error")"
set -e # turn e back on
checkEndTimeMs="$(date +%s%3N)"
checkEndTimeMs="$(${datecmd} +%s%3N)"
timeCheckTook="$((checkEndTimeMs-checkStartTimeMs))"
expectedStatusCode=${defaultExpectedStatusCode}
......@@ -310,7 +333,7 @@ writeFooter() {
# script start
# Total script duration timer
start=$(date +%s%3N)
start=$(${datecmd} +%s%3N)
tmpdir=$(mktemp -d)
tempfolder=${tmpdir:-/tmp/statusmon/}
......@@ -345,7 +368,7 @@ writeFailedChecks
writeOkayChecks
# stop the total timer
end=$(date +%s%3N)
end=$(${datecmd} +%s%3N)
runtime=$((end-start))
writeFooter
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment