diff options
author | 2024-06-09 19:08:08 +0100 | |
---|---|---|
committer | 2024-06-10 17:36:08 +0200 | |
commit | 8fc0504b09e74d6c1a1265e75af4f8a55f02a088 (patch) | |
tree | 63abde30877397449b2b577eb86d8f692200fbef /kubernetes/namespaces/monitoring/prometheus | |
parent | Add Alert for Prometheus config reload failure (diff) |
Add reloader hook configmap to reload prometheus on change
Diffstat (limited to 'kubernetes/namespaces/monitoring/prometheus')
-rw-r--r-- | kubernetes/namespaces/monitoring/prometheus/reloader-script.yaml | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/kubernetes/namespaces/monitoring/prometheus/reloader-script.yaml b/kubernetes/namespaces/monitoring/prometheus/reloader-script.yaml new file mode 100644 index 0000000..6aae9b3 --- /dev/null +++ b/kubernetes/namespaces/monitoring/prometheus/reloader-script.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: prometheus-reloader-script + namespace: monitoring +data: + hook.sh: |- + #!/bin/sh + + set -exo pipefail + + # Endpoint to call to reload Prometheus + RELOAD_URL="http://localhost:9090/-/reload" + # Icon for the webhook + PROMETHEUS_ICON_URL="https://static-00.iconduck.com/assets.00/prometheus-icon-511x512-1vmxbcxr.png" + + echo "Detected change in mounted configmaps, reloading Prometheus..." + + # Make a temporary store to keep any errors + RESPONSE_STORE="$(mktemp)" + + # Attempt the reload, writing the response to the tempfile and the reload HTTP + # code to the variable + RELOAD_RESULT="$(curl -o "$RESPONSE_STORE" -X POST $RELOAD_URL -s -w "%{http_code}")" + + # Parse and filter the response body into a JSON string + RESPONSE_CONTENT="$(cat "$RESPONSE_STORE")" + FILTERED_BODY="$(echo "$RESPONSE_CONTENT" | jq -Rsa)" + + # Send a notification based on pass/failure + if [ $RELOAD_RESULT -eq 200 ]; then + BODY='{"username": "Prometheus Reloader", "embeds": [{ "title": "Prometheus Config Reload Succeeded", "description": "No errors.", "color": 6663286 } ], "avatar_url": "'"$PROMETHEUS_ICON_URL"'" }' + else + BODY='{"username": "Prometheus Reloader", "embeds": [{ "title": "Prometheus Config Reload Failed", "description": '"$FILTERED_BODY"', "color": 12799052 } ], "avatar_url": "'"$PROMETHEUS_ICON_URL"'" }' + fi; + + # Send the webhook + curl -X POST -H "Content-Type: application/json" "$RELOADER_DISCORD_HOOK" -d "$BODY" |