2020-10-15 09:08:23 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
SERVER=${1:-'localhost:8080'}
|
|
|
|
|
2020-10-23 10:06:51 +01:00
|
|
|
NAME=testAlert-$RANDOM
|
|
|
|
FINGERPRINT=$(date +%s | md5sum | cut -f1 -d' ')
|
2020-10-15 09:08:23 +01:00
|
|
|
URL="http://${SERVER}/alert"
|
2020-10-23 10:06:51 +01:00
|
|
|
BOLD=$(tput bold)
|
|
|
|
NORMAL=$(tput sgr0)
|
2020-10-15 09:08:23 +01:00
|
|
|
|
|
|
|
call_alertmanager() {
|
2020-10-23 10:06:51 +01:00
|
|
|
VALUE=${1}
|
|
|
|
curl -v "${URL}" --header 'Expect:' --header 'Content-type: application/json' --data @<(cat <<EOF
|
2020-10-15 09:08:23 +01:00
|
|
|
{
|
|
|
|
"receiver": "alertify",
|
2020-10-23 10:06:51 +01:00
|
|
|
"status": "${STATUS}",
|
2020-10-15 09:08:23 +01:00
|
|
|
"alerts": [
|
|
|
|
{
|
|
|
|
"status": "${STATUS}",
|
2020-10-23 10:06:51 +01:00
|
|
|
"labels": {
|
|
|
|
"alertname": "${NAME}",
|
|
|
|
"id": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
|
|
|
|
"instance": "localhost:1234",
|
|
|
|
"job": "test_job",
|
|
|
|
"name": "testserver",
|
|
|
|
"priority": "1",
|
|
|
|
"severity": "low",
|
|
|
|
"value": "${VALUE}"
|
|
|
|
},
|
|
|
|
"annotations": {
|
|
|
|
"description": "testserver: unhealthy",
|
|
|
|
"summary": "Server unhealthy"
|
|
|
|
},
|
2020-10-15 09:08:23 +01:00
|
|
|
"startsAt": "${START}",
|
2020-10-23 10:06:51 +01:00
|
|
|
"endsAt": "${END}",
|
|
|
|
"generatorURL": "http://example.com/some/url",
|
|
|
|
"fingerprint": "${FINGERPRINT}"
|
2020-10-15 09:08:23 +01:00
|
|
|
}
|
2020-10-23 10:06:51 +01:00
|
|
|
],
|
|
|
|
"groupLabels": {
|
|
|
|
"alertname": "${NAME}",
|
|
|
|
"id": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
|
|
|
|
"instance": "localhost:1234",
|
|
|
|
"job": "test_job",
|
|
|
|
"name": "testserver",
|
|
|
|
"priority": "1",
|
|
|
|
"severity": "low",
|
|
|
|
"value": "${VALUE}"
|
|
|
|
},
|
|
|
|
"commonLabels": {
|
|
|
|
"alertname": "${NAME}",
|
|
|
|
"id": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
|
|
|
|
"instance": "localhost:1234",
|
|
|
|
"job": "test_job",
|
|
|
|
"name": "testserver",
|
|
|
|
"priority": "1",
|
|
|
|
"severity": "low",
|
|
|
|
"value": "${VALUE}"
|
|
|
|
},
|
|
|
|
"commonAnnotations": {
|
|
|
|
"description": "testserver: unhealthy",
|
|
|
|
"summary": "Server unhealthy"
|
|
|
|
},
|
|
|
|
"externalURL": "http://1ff297bc31a0:9093",
|
|
|
|
"version": "4",
|
|
|
|
"groupKey": "{}:{alertname=\"${NAME}\", id=\"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b\", instance=\"localhost:1234\", job=\"test_job\", name=\"testserver\", priority=\"1\", severity=\"low\", value=\"${VALUE}\"}",
|
|
|
|
"truncatedAlerts": 0
|
2020-10-15 09:08:23 +01:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-10-23 10:06:51 +01:00
|
|
|
echo "${BOLD}Firing alert ${NAME} ${NORMAL}"
|
2020-10-15 09:08:23 +01:00
|
|
|
STATUS='firing'
|
|
|
|
START=$(date --rfc-3339=seconds | sed 's/ /T/')
|
|
|
|
END="0001-01-01T00:00:00Z"
|
|
|
|
call_alertmanager 42
|
|
|
|
echo -e "\n"
|
|
|
|
|
2020-10-23 10:06:51 +01:00
|
|
|
echo "${BOLD}Press enter to resolve alert ${NAME} ${NORMAL}"
|
2020-10-15 09:08:23 +01:00
|
|
|
read -r
|
|
|
|
|
|
|
|
|
2020-10-23 10:06:51 +01:00
|
|
|
echo "${BOLD}Sending resolved ${NORMAL}"
|
2020-10-15 09:08:23 +01:00
|
|
|
STATUS='resolved'
|
|
|
|
END=$(date --rfc-3339=seconds | sed 's/ /T/')
|
|
|
|
call_alertmanager 0
|
|
|
|
echo -e "\n"
|