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