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"