query-all-services.sh and systemctl-failed.sh

master
Alexander Tomokhov 2023-12-12 04:44:56 +04:00
commit ba7c20d1f8
2 changed files with 122 additions and 0 deletions

93
query-all-services.sh Executable file
View File

@ -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

29
systemctl-failed.sh Executable file
View File

@ -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