Order alert status to get global color

This commit is contained in:
Jeremy Gardais 2020-06-10 15:57:38 +02:00
parent 8377f3ddce
commit 2dd8aa2ecc
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 16 additions and 16 deletions

View File

@ -53,6 +53,8 @@ readonly PLUGIN_NAME=$(basename "${0}")
readonly TEST="sge" readonly TEST="sge"
readonly PLUGIN_RESULT="${XYMONTMP}/${MACHINEDOTS}.${TEST}.plugin_result" readonly PLUGIN_RESULT="${XYMONTMP}/${MACHINEDOTS}.${TEST}.plugin_result"
readonly PLUGIN_STATE="${XYMONTMP}/${MACHINEDOTS}.${TEST}.plugin_state"
true > "${PLUGIN_STATE}"
readonly QSTAT=$(command -v qstat) readonly QSTAT=$(command -v qstat)
readonly QHOST=$(command -v qhost) readonly QHOST=$(command -v qhost)
@ -116,10 +118,6 @@ get_footer()
##### #####
get_status() get_status()
{ {
#####
##### Setup some variables for use later
#####
COLOR="green"
# Check defaults have been set # Check defaults have been set
if [ "${QSTAT}" = "" ]; then if [ "${QSTAT}" = "" ]; then
@ -177,32 +175,36 @@ get_status()
# qstate=$(${QHOST} -q -h "${MACHINEDOTS}" | tail +5 | grep " $Qset" | awk '{print $4}') # qstate=$(${QHOST} -q -h "${MACHINEDOTS}" | tail +5 | grep " $Qset" | awk '{print $4}')
qstate=$(grep " $Qset" "${PLUGIN_RESULT}.QSTATE" | awk '{print $4}') qstate=$(grep " $Qset" "${PLUGIN_RESULT}.QSTATE" | awk '{print $4}')
# Order determines more significant color status # Order determines more significant alert status
if [ "$(echo "${qstate}" | grep -c d)" != "0" ]; then if [ "$(echo "${qstate}" | grep -c d)" != "0" ]; then
COLOR="clear" echo "4&clear $Qset@$HOST is DISABLED" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$CLEAR_PIC $Qset@$HOST is DISABLED") queueMsg=$(echo "$queueMsg<BR>$CLEAR_PIC $Qset@$HOST is DISABLED")
queueTriggered=true; queueTriggered=true;
elif [ "$(echo "${qstate}" | grep -c E)" != "0" ]; then elif [ "$(echo "${qstate}" | grep -c E)" != "0" ]; then
COLOR="red" echo "1&red $Qset@$HOST is in ERROR!" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$RED_PIC $Qset@$HOST is in ERROR!") queueMsg=$(echo "$queueMsg<BR>$RED_PIC $Qset@$HOST is in ERROR!")
queueTriggered=true; queueTriggered=true;
elif [ "$(echo "${qstate}" | grep -c c)" != "0" ]; then elif [ "$(echo "${qstate}" | grep -c c)" != "0" ]; then
COLOR="yellow" echo "2&yellow $Qset@$HOST has an ambigious configuration!" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST has an ambigious configuration!") queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST has an ambigious configuration!")
queueTriggered=true; queueTriggered=true;
elif [ "$(echo "${qstate}" | grep -c a)" != "0" ] || \ elif [ "$(echo "${qstate}" | grep -c a)" != "0" ] || \
[ "$(echo "${qstate}" | grep -c A)" != "0" ]; then [ "$(echo "${qstate}" | grep -c A)" != "0" ]; then
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is in ALARM") echo "2&yellow $Qset@$HOST is in ALARM" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is in ALARM<BR>$Qset")
elif [ "$(echo "${qstate}" | grep -c s)" != "0" ] || \ elif [ "$(echo "${qstate}" | grep -c s)" != "0" ] || \
[ "$(echo "${qstate}" | grep -c S)" != "0" ]; then [ "$(echo "${qstate}" | grep -c S)" != "0" ]; then
echo "2&yellow $Qset@$HOST is SUSPENDED" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is SUSPENDED") queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is SUSPENDED")
elif [ "$(echo "${qstate}" | grep -c u)" != "0" ]; then elif [ "$(echo "${qstate}" | grep -c u)" != "0" ]; then
COLOR="yellow" echo "2&yellow $Qset@$HOST is UNAVAILABLE" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is UNAVAILABLE!") queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is UNAVAILABLE!")
queueTriggered=true; queueTriggered=true;
elif [ "$qstate" = "" ]; then elif [ "$qstate" = "" ]; then
echo "3&green $Qset@$HOST is OK" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$GREEN_PIC $Qset@$HOST is OK") queueMsg=$(echo "$queueMsg<BR>$GREEN_PIC $Qset@$HOST is OK")
else else
echo "5&purple $Qset@$HOST is UNKNOWN" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$UNKNOWN_PIC $Qset@$HOST is UNKNOWN") queueMsg=$(echo "$queueMsg<BR>$UNKNOWN_PIC $Qset@$HOST is UNKNOWN")
queueTriggered=true; queueTriggered=true;
fi fi
@ -216,11 +218,6 @@ get_status()
echo "$queueMsg" echo "$queueMsg"
get_footer get_footer
#####
##### Make sure to export COLOR so that it gets back to "central"
#####
export COLOR
##### #####
##### End of get_status proc ##### End of get_status proc
##### #####
@ -231,6 +228,9 @@ get_status()
##### #####
get_status > "${PLUGIN_RESULT}" get_status > "${PLUGIN_RESULT}"
# Set the global color according to the highest alert
COLOR=$(< "${PLUGIN_STATE}" awk '{print $1}' | sort | uniq | head -1 | cut -c3-)
# NOW USE THE XYMON COMMAND TO SEND THE DATA ACROSS # NOW USE THE XYMON COMMAND TO SEND THE DATA ACROSS
$XYMON "${XYMSRV}" "status ${MACHINE}.${TEST} ${COLOR} $($DATE) $(cat ${PLUGIN_RESULT})" $XYMON "${XYMSRV}" "status ${MACHINE}.${TEST} ${COLOR} $($DATE) $(cat ${PLUGIN_RESULT})"
#For testing only #For testing only
@ -241,7 +241,7 @@ get_status > "${PLUGIN_RESULT}"
# and may not actually run on every client # and may not actually run on every client
# #
if [ -f "${PLUGIN_RESULT}" ]; then if [ -f "${PLUGIN_RESULT}" ]; then
rm -f -- "${PLUGIN_RESULT}" rm -f -- "${PLUGIN_RESULT}" "${PLUGIN_STATE}"
fi fi
############################################## ##############################################
# end of script # end of script