alertify/test.sh

89 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2020-10-15 09:08:23 +01:00
#!/usr/bin/env bash
SERVER=${1:-'localhost:8080'}
NAME=testAlert-$RANDOM
FINGERPRINT=$(date +%s | md5sum | cut -f1 -d' ')
2020-10-15 09:08:23 +01:00
URL="http://${SERVER}/alert"
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
2020-10-15 09:08:23 +01:00
call_alertmanager() {
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",
"status": "${STATUS}",
2020-10-15 09:08:23 +01:00
"alerts": [
{
"status": "${STATUS}",
"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}",
"endsAt": "${END}",
"generatorURL": "http://example.com/some/url",
"fingerprint": "${FINGERPRINT}"
2020-10-15 09:08:23 +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
)
}
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"
echo "${BOLD}Press enter to resolve alert ${NAME} ${NORMAL}"
2020-10-15 09:08:23 +01:00
read -r
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"