forked from stevage/MicroTardis-Harvest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_status.sh
executable file
·38 lines (33 loc) · 1007 Bytes
/
set_status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
NCSA_COMMAND_FILE="ncsa_cmd_file.txt"
die () {
echo >&2 "$@"
exit 1
}
if [ ! "$#" -eq 3 ]; then echo "Usage: set_status <thing> <status> <message>"; exit; fi
THING=$1
STATUS=$2
MESSAGE=$3
unset WASDOWN
if [ -e ${THING}_status_down.txt ]; then
WASDOWN=1
fi
rm -f ${THING}_status_*.txt
echo "${MESSAGE}" > ${THING}_status_${STATUS}.txt
# Write to format understood by Nagios NCSA. (As of Jan 2012 Nagios is not actually installed...)
EPOCHSECONDS=`date +%s`
STATUSCODE=3 # unknown
if [ ${STATUS} == "ok" ]; then
STATUSCODE=0
elif [ ${STATUS} == "warning" ]; then
STATUSCODE=1
elif [ ${STATUS} == "down" ]; then
STATUSCODE=2
fi
echo "[${EPOCHSECONDS}] PROCESS_SERVICE_CHECK_RESULT;ka1;${THING};${STATUSCODE};${MESSAGE}" >> ${NCSA_COMMAND_FILE}
if [ ${STATUS} == "down" ] && [ ! ${WASDOWN} ]; then
# Something is down that wasn't down before - email someone.
echo >&2 "$1 is $2: $3"
echo "$3\n" | mail -s "[MicroTardis] $1 is $2" [email protected]
fi
./make_status_html.sh