Created
December 1, 2024 12:41
-
-
Save iamjjanga-ouo/9c632c7210e0bc9150fcaf46ae0aecb7 to your computer and use it in GitHub Desktop.
[kubernetes/alertmanager]
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 default values | |
name=$RANDOM | |
url='https://alertmanager.local/api/v1/alerts' | |
summary='Testing summary!' | |
instance="$name.example.net" | |
default_severity='warning' | |
# Function to send alert | |
send_alert() { | |
local status=$1 | |
local custom_severity=$2 | |
local current_severity=${custom_severity:-$default_severity} | |
curl -XPOST $url -d "[ | |
{ | |
\"status\": \"$status\", | |
\"labels\": { | |
\"alertname\": \"$name\", | |
\"service\": \"my-service\", | |
\"severity\":\"$current_severity\", | |
\"instance\": \"$instance\" | |
}, | |
\"annotations\": { | |
\"summary\": \"$summary\" | |
}, | |
\"generatorURL\": \"https://prometheus.local/<generating_expression>\" | |
} | |
]" | |
echo "" | |
} | |
# Main script | |
echo "Firing up alert $name" | |
send_alert "firing" "$1" | |
read -p "Press enter to resolve alert" | |
echo "Sending resolve" | |
send_alert "resolved" "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment