Last active
September 23, 2022 21:35
-
-
Save jrwarwick/3d88fcdaedd4c7b945c7a8886fe754ea to your computer and use it in GitHub Desktop.
spd-say from crontab + MS log collector failure monitor/notifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
#https://askubuntu.com/a/686944/234023 | |
if [ -z "$XDG_RUNTIME_DIR" ]; then | |
XDG_RUNTIME_DIR=/run/user/$(id -u) | |
if [ -d "$XDG_RUNTIME_DIR" ] && [ -w "$XDG_RUNTIME_DIR" ]; then | |
export XDG_RUNTIME_DIR | |
else | |
unset XDG_RUNTIME_DIR | |
fi | |
fi | |
CONTAINER_NAME=name_of_your_ms_logcollector_container | |
# General network connectvity check and report... | |
ETHERSTATUS=$(ip -4 -h -brief link show eno1 | sed 's/\s\+/ is /g' | cut -f 1,2,3 -d' ' | sed 's/^/ethernet interface <say-as interpret-as="verbatim">/;s/ is /<\/say-as> is /') | |
/usr/bin/ping -c 4 1.1.1.1 || ( | |
spd-say --sound-icon prompt | |
spd-say --wait --ssml "<speak><prosody rate=\"slow\">Attention: $HOSTNAME network connectivity degraded.</prosody> Please check network interfaces and reissue net-plan apply. <break strength=\"medium\" /> <emphasis level=\"strong\">${ETHERSTATUS}</emphasis> </speak>" | |
) | |
# Now the log collector (process in container) status itself | |
STATUS_REPORT=$(docker exec -t $CONTAINER_NAME collector_status -p | egrep -i 'status:|last connect' --color=NEVER | tr '\t\n\r' ' \t\t' | sed -r 's/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g' | sed 's/:[0-9]\{2\}//') | |
echo -e "$STATUS_REPORT" | grep -i "status: ok" | |
if [ $? -eq 0 ]; then | |
echo nominal | |
else | |
spd-say --sound-icon prompt | |
echo "Attention! $HOSTNAME Log Collector $STATUS_REPORT" | spd-say --pipe-mode --wait | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment