Check if normal update is pending

This commit is contained in:
Jeremy Gardais 2021-01-13 12:40:03 +01:00
parent cc83325ed9
commit d8ecdc01e1
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 31 additions and 5 deletions

View File

@ -17,10 +17,13 @@ readonly XYMON_GROUPNAME="xymon"
# 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"
# Maco
readonly MACO_LOCAL_DIR="/opt/maco"
readonly MACO_PENDING_UPDATE_FILE="${MACO_LOCAL_DIR}/.maco.upgrade"
# Temp files # Temp files
readonly TEMP_MACO_UPDATE="${XYMONTMP}/${MACHINEDOTS}.${TEST}.maco_update" 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"
@ -135,18 +138,38 @@ Try to detect Maco update with ${TEMP_MACO_UPDATE} content."
## 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} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
## Add information to PLUGIN_STATE ## Add information to PLUGIN_STATE
echo "3${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.*' "${TEMP_MACO_UPDATE}"
then then
sed "s/^/\&${YELLOW_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}" sed "s/^/\&${YELLOW_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
echo "2${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.*' "${TEMP_MACO_UPDATE}"
then then
sed "s/^/\&${RED_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}" sed "s/^/\&${RED_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
echo "1${RED_PIC} Maco needs urgent upgrade" >> "${PLUGIN_STATE}" echo "16${RED_PIC} Maco needs urgent upgrade" >> "${PLUGIN_STATE}"
else else
sed "s/^/\&${CLEAR_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}" sed "s/^/\&${CLEAR_PIC} /" "${TEMP_MACO_UPDATE}" >> "${PLUGIN_RESULT}"
echo "4${CLEAR_PIC} Maco update state is unknown" >> "${PLUGIN_STATE}" echo "46${CLEAR_PIC} Maco update state is unknown" >> "${PLUGIN_STATE}"
fi
}
# }}}
# Verify if a normal Maco update is planned {{{
check_pending_update() {
if [ -f "${MACO_PENDING_UPDATE_FILE}" ]; then
debug_message "check_pending_update \
A normal Maco update is planned."
## Add color and message to PLUGIN_RESULT for detailed informations
echo "${YELLOW_PIC} A normal update is planned (${MACO_PENDING_UPDATE_FILE} file exists)." >> "${PLUGIN_RESULT}"
## Add information to PLUGIN_STATE
echo "24${YELLOW_PIC} A normal update is planned" >> "${PLUGIN_STATE}"
else
debug_message "check_pending_update \
No Maco normal update is planned."
## Add color and message to PLUGIN_RESULT for detailed informations
echo "${GREEN_PIC} No Maco normal update is planned (${MACO_PENDING_UPDATE_FILE} file doesn't exists)." >> "${PLUGIN_RESULT}"
## No need to add information to PLUGIN_STATE
fi fi
} }
@ -187,6 +210,9 @@ main() { # {{{
get_maco_update get_maco_update
## Analyze Maco update result (add color,…) ## Analyze Maco update result (add color,…)
analyze_maco_update analyze_maco_update
## Check for pending update for Maco
check_pending_update
fi fi
# Send data to Xymon server # Send data to Xymon server