Rename get_maco_update to check_maco_version

This commit is contained in:
Jeremy Gardais 2021-01-14 12:04:36 +01:00
parent 3b29544775
commit f92520577f
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 19 additions and 21 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# This script will check: # This script will check:
## if upgrade is available for local Maco script (green or yellow) ## every 10hours if upgrade is available for local Maco script (green or yellow)
## if normal upgrade is planned (green or yellow) ## if normal upgrade is planned (green or yellow)
## if urgent upgrade is planned (green or yellow) ## if urgent upgrade is planned (green or yellow)
## status of the last update (green, yellow or red) ## status of the last update (green, yellow or red)
@ -17,6 +17,7 @@ readonly PLUGIN_RESULT="${XYMONTMP}/${MACHINEDOTS}.${TEST}.plugin_result"
readonly PLUGIN_STATE="${XYMONTMP}/${MACHINEDOTS}.${TEST}.plugin_state" readonly PLUGIN_STATE="${XYMONTMP}/${MACHINEDOTS}.${TEST}.plugin_state"
readonly XYMON_USERNAME="xymon" readonly XYMON_USERNAME="xymon"
readonly XYMON_GROUPNAME="xymon" readonly XYMON_GROUPNAME="xymon"
readonly MACO_VERSION_RESULT="${XYMONTMP}/${MACHINEDOTS}.${TEST}.maco_version"
# By default, don't empty files newer than 10hours (600 minutes) # By default, don't empty files newer than 10hours (600 minutes)
readonly DEFAULT_MTIME_MINUTES="600" readonly DEFAULT_MTIME_MINUTES="600"
@ -27,9 +28,6 @@ readonly MACO_PENDING_UPDATE_FILE="${MACO_LOCAL_DIR}/.maco.upgrade"
readonly MACO_PENDING_URGENT_UPDATE_FILE="${MACO_LOCAL_DIR}/.maco.urgent.upgrade" readonly MACO_PENDING_URGENT_UPDATE_FILE="${MACO_LOCAL_DIR}/.maco.urgent.upgrade"
readonly MACO_STATUS_FILE="/var/fr.univ-rennes1.ipr.maco.machinestate.txt" readonly MACO_STATUS_FILE="/var/fr.univ-rennes1.ipr.maco.machinestate.txt"
# Temp files
readonly TEMP_MACO_UPDATE="${XYMONTMP}/${MACHINEDOTS}.${TEST}.maco_update"
# define colours for graphics {{{ # define colours for graphics {{{
# Comment these out if using older BB versions # Comment these out if using older BB versions
CLEAR_PIC="&clear" CLEAR_PIC="&clear"
@ -137,16 +135,16 @@ add_header()
#echo "<BLOCKQUOTE>" #echo "<BLOCKQUOTE>"
} }
# }}} # }}}
# Get Maco update state {{{ # Compare current Maco version to last available version {{{
get_maco_update() { check_maco_version() {
maco_update_script_path="/opt/repos/ipr.scripts/cluster/maco.check.update.sh" maco_update_script_path="/opt/repos/ipr.scripts/cluster/maco.check.update.sh"
maco_update_script_options="--simulate" maco_update_script_options="--simulate"
## Run update_script and store result in TEMP_MACO_UPDATE file ## Run update_script and store result in MACO_VERSION_RESULT file
debug_message "get_maco_update \ debug_message "check_maco_version \
Run \"${maco_update_script_path}\" script with \"${maco_update_script_options}\" options." Run \"${maco_update_script_path}\" script with \"${maco_update_script_options}\" options."
sh "${maco_update_script_path}" "${maco_update_script_options}" >> "${TEMP_MACO_UPDATE}" sh "${maco_update_script_path}" "${maco_update_script_options}" >> "${MACO_VERSION_RESULT}"
} }
# }}} # }}}
@ -154,24 +152,24 @@ Run \"${maco_update_script_path}\" script with \"${maco_update_script_options}\"
analyze_maco_update() { analyze_maco_update() {
debug_message "analyze_maco_update \ debug_message "analyze_maco_update \
Try to detect Maco update with ${TEMP_MACO_UPDATE} content." Try to detect Maco update with ${MACO_VERSION_RESULT} content."
if grep -qE '^Local.* up to date.*' "${TEMP_MACO_UPDATE}" if grep -qE '^Local.* up to date.*' "${MACO_VERSION_RESULT}"
then then
## Add color and message to PLUGIN_RESULT for detailed informations ## Add color and message to PLUGIN_RESULT for detailed informations
sed "s/^/\&${GREEN_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}" sed "s/^/\&${GREEN_PIC} /" "${MACO_VERSION_RESULT}" >> "${PLUGIN_RESULT}"
## Add information to PLUGIN_STATE ## Add information to PLUGIN_STATE
echo "36${GREEN_PIC} Maco is uptodate" >> "${PLUGIN_STATE}" echo "36${GREEN_PIC} Maco is uptodate" >> "${PLUGIN_STATE}"
elif grep -qE '^Latest.* available.*' "${TEMP_MACO_UPDATE}" elif grep -qE '^Latest.* available.*' "${MACO_VERSION_RESULT}"
then then
sed "s/^/\&${YELLOW_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}" sed "s/^/\&${YELLOW_PIC} /" "${MACO_VERSION_RESULT}" >> "${PLUGIN_RESULT}"
echo "26${YELLOW_PIC} Maco needs upgrade" >> "${PLUGIN_STATE}" echo "26${YELLOW_PIC} Maco needs upgrade" >> "${PLUGIN_STATE}"
elif grep -qE '^Urgent.* available.*' "${TEMP_MACO_UPDATE}" elif grep -qE '^Urgent.* available.*' "${MACO_VERSION_RESULT}"
then then
sed "s/^/\&${YELLOW_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}" sed "s/^/\&${YELLOW_PIC} /" "${MACO_VERSION_RESULT}" >> "${PLUGIN_RESULT}"
echo "25${YELLOW_PIC} Maco needs urgent upgrade" >> "${PLUGIN_STATE}" echo "25${YELLOW_PIC} Maco needs urgent upgrade" >> "${PLUGIN_STATE}"
else else
sed "s/^/\&${CLEAR_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}" sed "s/^/\&${CLEAR_PIC} /" "${MACO_VERSION_RESULT}" >> "${PLUGIN_RESULT}"
echo "46${CLEAR_PIC} Maco update state is unknown" >> "${PLUGIN_STATE}" echo "46${CLEAR_PIC} Maco update state is unknown" >> "${PLUGIN_STATE}"
fi fi
@ -281,12 +279,12 @@ main() { # {{{
# Create or empty previous file only if too old # Create or empty previous file only if too old
regenerate_if_too_old "${PLUGIN_RESULT}" regenerate_if_too_old "${PLUGIN_RESULT}"
regenerate_if_too_old "${PLUGIN_STATE}" regenerate_if_too_old "${PLUGIN_STATE}"
regenerate_if_too_old "${TEMP_MACO_UPDATE}" regenerate_if_too_old "${MACO_VERSION_RESULT}"
## If TEMP_MACO_UPDATE file is empty ## If MACO_VERSION_RESULT file is empty
if is_file_empty "${TEMP_MACO_UPDATE}"; then if is_file_empty "${MACO_VERSION_RESULT}"; then
## (re)check Maco update ## (re)check Maco update
get_maco_update check_maco_version
fi fi
## If any previous file is empty ## If any previous file is empty