Last active
July 18, 2024 07:30
-
-
Save carinadigital/fd2960fdccd77dbdabc849656c43a070 to your computer and use it in GitHub Desktop.
Send a dummy alert to Alertmanager. Based on https://gist.github.com/cherti/61ec48deaaab7d288c9fcf17e700853a by @cherti
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
name=fooAlert-$RANDOM | |
url='http://localhost:9093/api/v1/alerts' | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
generate_post_data() { | |
cat <<EOF | |
[{ | |
"status": "$1", | |
"labels": { | |
"alertname": "${name}", | |
"service": "my-service", | |
"severity":"warning", | |
"instance": "${name}.example.net", | |
"namespace": "foo-bar", | |
"label_costcentre": "FOO" | |
}, | |
"annotations": { | |
"summary": "High latency is high!" | |
}, | |
"generatorURL": "http://local-example-alert/$name" | |
$2 | |
$3 | |
}] | |
EOF | |
} | |
echo "${bold}Firing alert ${name} ${normal}" | |
printf -v startsAt ',"startsAt" : "%s"' $(date --rfc-3339=seconds | sed 's/ /T/') | |
POSTDATA=$(generate_post_data 'firing' "${startsAt}") | |
curl $url --data "$POSTDATA" --trace-ascii /dev/stdout | |
echo -e "\n" | |
echo "${bold}Press enter to resolve alert ${name} ${normal}" | |
read | |
echo "${bold}Sending resolved ${normal}" | |
printf -v endsAt ',"endsAt" : "%s"' $(date --rfc-3339=seconds | sed 's/ /T/') | |
POSTDATA=$(generate_post_data 'firing' "${startsAt}" "${endsAt}") | |
curl $url --data "$POSTDATA" --trace-ascii /dev/stdout | |
echo -e "\n" |
very useful - thank you!
extremely useful, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My five cents https://github.com/alexanderfefelov/docker-backpack/blob/master/prometheus/alertmanager/utils/emit-alerts.sh