Created
March 28, 2023 14:16
-
-
Save r3code/20b7aa697c48b7707f329857cf623d73 to your computer and use it in GitHub Desktop.
Sending Alertmanager test alert and resolution over API
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
#!/bin/bash | |
# set your AlertManager server url | |
alertmanager_url='http://localhost:9093' | |
url="$alertmanager_url/api/v1/alerts" | |
# Script will prompt you for alert params, if you hit ENTER without entering a value it uses a [default] value | |
# alert params | |
default_name="alert_$RANDOM" | |
read -p "Enter alertname [$default_name]: " alertname | |
alertname=${name:-$default_name} | |
read -p "Enter service name [test_service]: " service | |
service=${service:-test_service} | |
read -p "Enter severity [warning]: " severity | |
severity=${severity:-warning} | |
read -p "Enter summary [Test service alert]: " summary | |
summary=${summary:-Test service alert} | |
description="example alert description" | |
alerts="[{ | |
\"status\": \"firing\", | |
\"labels\": { | |
\"alertname\": \"$alertname\", | |
\"service\": \"$service\", | |
\"severity\":\"$severity\", | |
\"instance\": \"$alertname.example.net\", | |
}, | |
\"annotations\": { | |
\"summary\": \"$summary\", | |
\"description\": \"$description\", | |
\"grafana_dashboard_link\": \"https://grafana.my.domain/d/<dashboards-folder>/<dashboard-name>?from=now-6h/m&to=now-1m/m&var-service=<service_name>&var-some_var=<some_var_value>\" | |
}, | |
\"generatorURL\": \"http://prometheus.int.example.net/<generating_expression>\" | |
}]" | |
echo "Fire up an alert $alertname for $service" | |
curl -XPOST $url -d "$alerts" | |
echo "" | |
echo "Press enter to send an alert resolution for $alertname for $service" | |
read | |
alerts=${alerts/\"firing\"/\"resolved\"} | |
echo "sending resolve" | |
curl -XPOST $url -d "$alerts" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment