forked from thinkst/canary-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert_management.sh
85 lines (73 loc) · 1.93 KB
/
alert_management.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#Constants
DOMAIN=""
AUTH_KEY=""
SAVE=true
DELETE=true
FILEDATE=`date "+%Y%m%d%H%M%S"`
FILENAME=$FILEDATE-$DOMAIN-export.json
echo -e "\nThinkst Canary Alert Management"
usage()
{
echo -e "\nBy default, this script will save, acknowledge and then delete your alerts"
echo "Results are saved to the current working directory in JSON"
echo -e "\t-d Domain of your Canary Console"
echo -e "\t-a Auth Token for the Canary API"
echo -e "\t-s Don't save the incidents (just acknowledge and delete)"
echo -e "\t-r Don't remove the incidents (just acknowledge)"
exit -1
}
while getopts "hd:a:rs" opt; do
case $opt in
h)
usage
;;
d)
DOMAIN="${OPTARG}"
;;
a)
AUTH_KEY="${OPTARG}"
;;
r)
DELETE=false
;;
s)
SAVE=false
;;
\?)
echo -e "\nInvalid Option: -${OPTARG}" 1>&2
usage
exit -1
;;
esac
done
shift $((OPTIND-1))
ping_console() {
ping=$(curl -s "https://${DOMAIN}.canary.tools/api/v1/ping?auth_token=${AUTH_KEY}" | jq -r ".result")
if [ ${ping} != "success" ]; then
echo -e "\nConnection to the Console unsuccessful"
exit -1
fi
echo -e "\nConnection to the Console successful"
}
save_incidents(){
echo -e "\nSaving the incidents"
curl -s -X GET "https://${DOMAIN}.canary.tools/api/v1/incidents/unacknowledged?auth_token=${AUTH_KEY}" | jq '.incidents | .[]' >> ${FILENAME}
echo "Incidents saved to ${PWD}/${FILENAME}"
}
acknowledge_incidents() {
echo -e "\nThe following incidents have been acknowledged:"
curl -s -X POST "https://${DOMAIN}.canary.tools/api/v1/incidents/acknowledge?auth_token=${AUTH_KEY}" | jq '.keys[]'
}
delete_incidents() {
echo -e "\nThe following incidents have been deleted:"
curl -s -X POST "https://${DOMAIN}.canary.tools/api/v1/incidents/delete?auth_token=${AUTH_KEY}" | jq '.keys[]'
}
ping_console
if [ ${SAVE} == true ]; then
save_incidents
fi
acknowledge_incidents
if [ ${DELETE} == true ]; then
delete_incidents
fi