More readable while loop

This commit is contained in:
Jeremy Gardais 2020-06-10 16:11:17 +02:00
parent 2dd8aa2ecc
commit 4baaabd346
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 20 additions and 22 deletions

View File

@ -168,47 +168,45 @@ get_status()
### Check queue instance states
###
queueTriggered=false;
# Queueset=$(${QHOST} -h ${MACHINEDOTS} -q | tail +5 | awk '{ print $1 }')
${QHOST} -h "${MACHINEDOTS}" -q | tail +5 > "${PLUGIN_RESULT}.QSTATE"
Queueset=$(< "${PLUGIN_RESULT}.QSTATE" awk '{ print $1 }')
for Qset in $Queueset; do
# qstate=$(${QHOST} -q -h "${MACHINEDOTS}" | tail +5 | grep " $Qset" | awk '{print $4}')
qstate=$(grep " $Qset" "${PLUGIN_RESULT}.QSTATE" | awk '{print $4}')
while IFS= read -r _LINE; do
queue=$(printf -- '%s' "${_LINE}" | awk '{ print $1 }')
qstate=$(printf -- '%s' "${_LINE}" | awk '{ print $4 }')
# Order determines more significant alert status
if [ "$(echo "${qstate}" | grep -c d)" != "0" ]; then
echo "4&clear $Qset@$HOST is DISABLED" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$CLEAR_PIC $Qset@$HOST is DISABLED")
echo "4&clear $queue@$HOST is DISABLED" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$CLEAR_PIC $queue@$HOST is DISABLED")
queueTriggered=true;
elif [ "$(echo "${qstate}" | grep -c E)" != "0" ]; then
echo "1&red $Qset@$HOST is in ERROR!" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$RED_PIC $Qset@$HOST is in ERROR!")
echo "1&red $queue@$HOST is in ERROR!" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$RED_PIC $queue@$HOST is in ERROR")
queueTriggered=true;
elif [ "$(echo "${qstate}" | grep -c c)" != "0" ]; then
echo "2&yellow $Qset@$HOST has an ambigious configuration!" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST has an ambigious configuration!")
echo "2&yellow $queue@$HOST has an ambigious configuration!" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $queue@$HOST has an ambigious configuration!")
queueTriggered=true;
elif [ "$(echo "${qstate}" | grep -c a)" != "0" ] || \
[ "$(echo "${qstate}" | grep -c A)" != "0" ]; then
echo "2&yellow $Qset@$HOST is in ALARM" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is in ALARM<BR>$Qset")
echo "2&yellow $queue@$HOST is in ALARM" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $queue@$HOST is in ALARM")
elif [ "$(echo "${qstate}" | grep -c s)" != "0" ] || \
[ "$(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")
echo "2&yellow $queue@$HOST is SUSPENDED" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $queue@$HOST is SUSPENDED")
elif [ "$(echo "${qstate}" | grep -c u)" != "0" ]; then
echo "2&yellow $Qset@$HOST is UNAVAILABLE" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $Qset@$HOST is UNAVAILABLE!")
echo "2&yellow $queue@$HOST is UNAVAILABLE" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$YELLOW_PIC $queue@$HOST is UNAVAILABLE!")
queueTriggered=true;
elif [ "$qstate" = "" ]; then
echo "3&green $Qset@$HOST is OK" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$GREEN_PIC $Qset@$HOST is OK")
echo "3&green $queue@$HOST is OK" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$GREEN_PIC $queue@$HOST is OK")
else
echo "5&purple $Qset@$HOST is UNKNOWN" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$UNKNOWN_PIC $Qset@$HOST is UNKNOWN")
echo "5&purple $queue@$HOST is UNKNOWN" >> "${PLUGIN_STATE}"
queueMsg=$(echo "$queueMsg<BR>$UNKNOWN_PIC $queue@$HOST is UNKNOWN")
queueTriggered=true;
fi
done
done < "${PLUGIN_RESULT}.QSTATE"
if [ -f "${PLUGIN_RESULT}.QSTATE" ]; then
rm -f -- "${PLUGIN_RESULT}.QSTATE"