45 lines
1014 B
Bash
Executable File
45 lines
1014 B
Bash
Executable File
#!/bin/bash
|
|
|
|
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
# Load configuration
|
|
set -o allexport
|
|
source ${script_dir}/config/monitoring
|
|
set +o allexport
|
|
|
|
# Import logging functionality
|
|
logfile=${script_dir}/log/monitoring.log
|
|
log_identifier="MON"
|
|
source ${script_dir}/functions/logging.sh
|
|
|
|
problems=0
|
|
|
|
log "Starting monitoring run"
|
|
|
|
for ssh_host in $SSH_MONITORING
|
|
do
|
|
if [[ $(nc -w 2 ${ssh_host//:/ } <<< "\0" ) =~ "OpenSSH" ]] ; then
|
|
log "[SSH] [OK] ${ssh_host} is reachable"
|
|
else
|
|
log_echo "[SSH] [FAIL] ${ssh_host} not reachable"
|
|
problems=1
|
|
fi
|
|
done
|
|
|
|
for http_host in $HTTP_MONITORING
|
|
do
|
|
status_code=$(curl --write-out %{http_code} --silent --output /dev/null $http_host)
|
|
if [[ "$status_code" -eq 200 ]] ; then
|
|
log "[WEB] [OK] ${http_host}"
|
|
else
|
|
log_echo "[WEB] [FAIL] ${http_host} status code is ${status_code}"
|
|
problems=1
|
|
fi
|
|
done
|
|
|
|
if [[ "$problems" -eq "0" ]]; then
|
|
log "Monitoring Run Successful"
|
|
else
|
|
log "Monitoring Run Failed"
|
|
fi
|