#!/bin/bash
#set -x
#
# J.Ramsay 07/01/2021
#
# iscsi-check.shl: used to check if server filesystem is in read-only mode and
# send text messages to one or more administrators
#
# set cron as shown below along with correct path to run check every 15 minutes
# */15 * * * * /usr/local/bin/iscsi-check.shl >/dev/null 2>&1
#
# command separated list of users to notify
NOTIFY="jramsay,chouck,levans,mhizny"
#
#================= PLEASE DO NOT MODIFY BELOW THIS LINE ========================
#
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$HOME/bin
TEST_FILE="/u01/app/oracle/.read-write"
send_notification() {
  local NOTIFY=$1
  local mesg=$2
  IFS=$','
  for user in $NOTIFY; do
    curl -X POST https://buapps.binghamton.edu/banner/sms/sms-web.php \
    -H "Content-Type: application/json" -d '{"username":"'$user'","message":"'$mesg'"}'
  done
  unset IFS
}
touch $TEST_FILE >/dev/null 2>&1
if test $? -ne 0; then
  send_notification ${NOTIFY:="jramsay"} "VM: $(hostname -s) iSCSI is in read-only mode."
else
  rm $TEST_FILE
fi
#===============================================================================
exit 0
