Skip to content

Instantly share code, notes, and snippets.

@cherti
Created December 9, 2016 13:47
Show Gist options
  • Save cherti/61ec48deaaab7d288c9fcf17e700853a to your computer and use it in GitHub Desktop.
Save cherti/61ec48deaaab7d288c9fcf17e700853a to your computer and use it in GitHub Desktop.
send a dummy alert to prometheus-alertmanager
#!/bin/bash
name=$RANDOM
url='http://localhost:9093/api/v1/alerts'
echo "firing up alert $name"
# change url o
curl -XPOST $url -d "[{
\"status\": \"firing\",
\"labels\": {
\"alertname\": \"$name\",
\"service\": \"my-service\",
\"severity\":\"warning\",
\"instance\": \"$name.example.net\"
},
\"annotations\": {
\"summary\": \"High latency is high!\"
},
\"generatorURL\": \"http://prometheus.int.example.net/<generating_expression>\"
}]"
echo ""
echo "press enter to resolve alert"
read
echo "sending resolve"
curl -XPOST $url -d "[{
\"status\": \"resolved\",
\"labels\": {
\"alertname\": \"$name\",
\"service\": \"my-service\",
\"severity\":\"warning\",
\"instance\": \"$name.example.net\"
},
\"annotations\": {
\"summary\": \"High latency is high!\"
},
\"generatorURL\": \"http://prometheus.int.example.net/<generating_expression>\"
}]"
echo ""
@nabouzidan-3as
Copy link

Thanks, this is very helpful!
Minor changes were needed to work with newer versions:

  • Change the API version of the alertmanager to v2.
  • Add a header to the curl calls:
-H "Content-Type: application/json"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment