Skip to content

Instantly share code, notes, and snippets.

@iamjjanga-ouo
Created December 1, 2024 12:41
Show Gist options
  • Save iamjjanga-ouo/9c632c7210e0bc9150fcaf46ae0aecb7 to your computer and use it in GitHub Desktop.
Save iamjjanga-ouo/9c632c7210e0bc9150fcaf46ae0aecb7 to your computer and use it in GitHub Desktop.
[kubernetes/alertmanager]
#!/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