From 8b79cd6fbcee488334a53d80118a181eff35e2b4 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 31 Oct 2023 21:54:21 +0100 Subject: [PATCH] working on watch-containers.sh --- watch-containers.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/watch-containers.sh b/watch-containers.sh index f74c5ec..8716aac 100755 --- a/watch-containers.sh +++ b/watch-containers.sh @@ -47,7 +47,7 @@ ONLY_IN_CURRENT=() # Print help information function print_help() { printf "%s\n\n%s\n%b\n\n%s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n" \ - "$DESCRIPTION" "Usage:" "$LIB_BOLD$EXECUTABLE $LIB_CLEAR" "Options:" \ + "$DESCRIPTION" "Usage:" "$LIB_BOLD$EXECUTABLE [healthchecks-url]$LIB_CLEAR" "Options:" \ "-s, --state" "Save current state to file and exit" \ "-h, --help" "Print help screen and exit" \ "-i, --info" "Print script information and exit" \ @@ -160,17 +160,24 @@ for I in "${CURRENT[@]}"; do fi done -# Print result -echo "Missing container(s): ${ONLY_IN_CACHE[@]}" -echo "New container(s): ${ONLY_IN_CURRENT[@]}" +# Construct result +if [[ -n "${ONLY_IN_CACHE[@]}" ]] && [[ -n "${ONLY_IN_CURRENT[@]}" ]]; then + RESULT=$(printf "Missing containers: %s\nNew containers: %s\n" "${ONLY_IN_CACHE[@]}" "${ONLY_IN_CURRENT[@]}") +elif [[ -n "${ONLY_IN_CACHE[@]}" ]]; then + RESULT=$(printf "Missing containers: %s\n" "${ONLY_IN_CACHE[@]}") +elif [[ -n "${ONLY_IN_CURRENT[@]}" ]]; then + RESULT=$(printf "New containers: %s\n" "${ONLY_IN_CURRENT[@]}") +fi -#if [[ -z "$1" ]]; then -# print_help -# exit 0 -#else - -#fi +# Post result to Healthchecks +if [[ -n "$1" ]]; then + if lib_is_url "$1"; then + lib_healthchecks "$1" "$RESULT" + fi +fi +# Print result to screen +printf "%s\n" "$RESULT" ## ## Here be dragons