COLOR is added to PLUGIN_RESULT line if expected

This commit is contained in:
Jeremy Gardais 2021-01-13 12:06:55 +01:00
parent b6eb13621d
commit 19c1756bef
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 33 additions and 18 deletions

View File

@ -17,9 +17,18 @@ readonly XYMON_GROUPNAME="xymon"
# By default, don't empty files newer than 10hours (600 minutes)
readonly DEFAULT_MTIME_MINUTES="600"
## Colors {{{
readonly PURPLE='\033[1;35m'
## }}}
# Temp files
readonly TEMP_MACO_UPDATE="${XYMONTMP}/${MACHINEDOTS}.${TEST}.maco_update"
# define colours for graphics {{{
# Comment these out if using older BB versions
CLEAR_PIC="&clear"
RED_PIC="&red"
YELLOW_PIC="&yellow"
GREEN_PIC="&green"
UNKNOWN_PIC="&purple"
# }}}
# }}}
@ -108,30 +117,36 @@ get_maco_update() {
maco_update_script_path="/opt/repos/ipr.scripts/cluster/maco.check.update.sh"
maco_update_script_options="--simulate"
## Run update_script and store result in PLUGIN_RESULT file
## Run update_script and store result in TEMP_MACO_UPDATE file
debug_message "get_maco_update \
Run \"${maco_update_script_path}\" script with \"${maco_update_script_options}\" options."
sh "${maco_update_script_path}" "${maco_update_script_options}" >> "${PLUGIN_RESULT}"
sh "${maco_update_script_path}" "${maco_update_script_options}" >> "${TEMP_MACO_UPDATE}"
}
# }}}
# Analyze maco result to define colors to send to Xymon {{{
analyze_maco_status() {
analyze_maco_update() {
debug_message "analyze_maco_status \
Try to detect Maco update with ${PLUGIN_RESULT} content."
debug_message "analyze_maco_update \
Try to detect Maco update with ${TEMP_MACO_UPDATE} content."
if grep -qE '^Local.* up to date.*' "${PLUGIN_RESULT}"
if grep -qE '^Local.* up to date.*' "${TEMP_MACO_UPDATE}"
then
echo "3&green Maco is uptodate" >> "${PLUGIN_STATE}"
elif grep -qE '^Latest.* available.*' "${PLUGIN_RESULT}"
## Add color and message to PLUGIN_RESULT for detailed informations
sed "s/^/\&${GREEN_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
## Add information to PLUGIN_STATE
echo "3${GREEN_PIC} Maco is uptodate" >> "${PLUGIN_STATE}"
elif grep -qE '^Latest.* available.*' "${TEMP_MACO_UPDATE}"
then
echo "2&yellow Maco needs upgrade" >> "${PLUGIN_STATE}"
elif grep -qE '^Urgent.* available.*' "${PLUGIN_RESULT}"
sed "s/^/\&${YELLOW_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
echo "2${YELLOW_PIC} Maco needs upgrade" >> "${PLUGIN_STATE}"
elif grep -qE '^Urgent.* available.*' "${TEMP_MACO_UPDATE}"
then
echo "1&red Maco needs urgent upgrade" >> "${PLUGIN_STATE}"
sed "s/^/\&${RED_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
echo "1${RED_PIC} Maco needs urgent upgrade" >> "${PLUGIN_STATE}"
else
echo "4&clear Maco update state is unknown" >> "${PLUGIN_STATE}"
sed "s/^/\&${CLEAR_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
echo "4${CLEAR_PIC} Maco update state is unknown" >> "${PLUGIN_STATE}"
fi
}
@ -148,14 +163,14 @@ send_result_to_xymon_server() {
==================== Detailed status ====================
&${COLOR} $(cat ${PLUGIN_RESULT})"
$(cat ${PLUGIN_RESULT})"
# For testing only
#echo "$XYMON ${XYMSRV} status ${MACHINE}.${TEST} ${COLOR} ${SUBJECT}
#==================== Detailed status ====================
#&${COLOR} $(cat ${PLUGIN_RESULT})" > /tmp/xymon.maco.tmp
#$(cat ${PLUGIN_RESULT})" > /tmp/xymon.maco.tmp
}
# }}}
@ -174,7 +189,7 @@ main() { # {{{
# If previous state is empty
## analyze Maco's result
is_file_empty "${PLUGIN_STATE}" \
&& analyze_maco_status
&& analyze_maco_update
# Send data to Xymon server
## and exit