commit ba7c20d1f89d69daa0105dfef80e2e5b621482fd Author: Alexander Tomokhov Date: Tue Dec 12 04:44:56 2023 +0400 query-all-services.sh and systemctl-failed.sh diff --git a/query-all-services.sh b/query-all-services.sh new file mode 100755 index 0000000..b455745 --- /dev/null +++ b/query-all-services.sh @@ -0,0 +1,93 @@ +#! /usr/bin/env bash + +set -o pipefail +set -o errexit +set -o nounset + +: ${DOMAIN:?specify domain name} + +readonly AUTH_HEADER="Authorization: Bearer du-dummy-api-token" +readonly QUERY='query AllServices { + services { + allServices { + id + isEnabled + status + } + } +}' + +# shellcheck disable=SC2116 +# shellcheck disable=SC2086 +REQUEST=$(cat << EOF +{ + "query": "$(echo $QUERY)", + "variables": null, + "operationName": "AllServices" +} +EOF +) +readonly REQUEST + +# TODO fix jitsi "isEnabled" expected response value +EXPECTED_RESPONSE=$(cat << EOF +{ + "data": { + "services": { + "allServices": [ + { + "id": "bitwarden", + "isEnabled": true, + "status": "ACTIVE" + }, + { + "id": "gitea", + "isEnabled": true, + "status": "ACTIVE" + }, + { + "id": "email", + "isEnabled": true, + "status": "ACTIVE" + }, + { + "id": "nextcloud", + "isEnabled": true, + "status": "ACTIVE" + }, + { + "id": "pleroma", + "isEnabled": true, + "status": "ACTIVE" + }, + { + "id": "ocserv", + "isEnabled": true, + "status": "ACTIVE" + }, + { + "id": "jitsi", + "isEnabled": false, + "status": "ACTIVE" + } + ] + } + } +} +EOF +) +readonly EXPECTED_RESPONSE + +received_response="$(curl -s "https://api.$DOMAIN/graphql" --compressed \ +-H 'Content-Type: application/json' \ +--data-raw "$REQUEST" -k -H "$AUTH_HEADER" | jq --sort-keys)" + +jq <<<"$received_response" + +if [ "$EXPECTED_RESPONSE" == "$received_response" ]; then + echo -e "\e[1;32mOK" +else + echo -e "\e[1;31mFAIL: response does not match!" + exit 1 +fi + diff --git a/systemctl-failed.sh b/systemctl-failed.sh new file mode 100755 index 0000000..5622693 --- /dev/null +++ b/systemctl-failed.sh @@ -0,0 +1,29 @@ +#! /usr/bin/env bash + +set -o pipefail +set -o errexit +set -o nounset + +: ${DOMAIN:?specify domain name} + +EXPECTED_RESPONSE="[]" +received_response="$(\ + ssh -o StrictHostKeyChecking=no -lroot "$DOMAIN" systemctl --state=activating,failed -o json \ + | jq --sort-keys)" + +jq . <(printf "%s" "$received_response") + +if diff --color <(printf "%s\n" "$EXPECTED_RESPONSE") <(printf "%s\n" "$received_response") 2>/dev/null +then + echo -e "\e[1;32mOK" +else + echo -e "\e[1;31mFAIL: response does not match!" + if type jd > /dev/null; then + jd -color <(printf "%s" "$EXPECTED_RESPONSE") <(printf "%s" "$received_response") + else + echo "expected:" + printf "%s" "$EXPECTED_RESPONSE" + fi + exit 1 +fi +