-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-definitions.sh
executable file
·155 lines (117 loc) · 4.7 KB
/
create-definitions.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
HAWKULAR_URL="http://localhost:8080/hawkular/alerts"
DEMO_TENANT="my-organization"
HEADER_JSON="Content-Type: application/json"
HEADER_TENANT="Hawkular-Tenant: $DEMO_TENANT"
function create_email_action() {
## Check email plugin is installed
local response=$(curl --write-out %{http_code} --silent --output /dev/null $HAWKULAR_URL/plugins/email)
if [ "$response" == "200" ];
then
echo "email plugin installed"
else
echo "email plugin not present - aborting..."
exit 1
fi
## Clean old email action
response=$(curl --write-out %{http_code} --silent --output /dev/null -H "$HEADER_TENANT" $HAWKULAR_URL/actions/email/email-to-admin-group)
if [ "$response" == "404" ];
then
echo "email-to-admin-group action is not present"
else
echo "deleting old email-to-admin-group action"
response=$(curl -X DELETE --write-out %{http_code} --silent --output /dev/null -H "$HEADER_TENANT" $HAWKULAR_URL/actions/email/email-to-admin-group)
fi
## Create new email action
local action="{\"actionPlugin\":\"email\","
action="$action \"actionId\":\"email-to-admin-group\","
action="$action \"to\":\"[email protected]\","
action="$action \"cc\":\"[email protected]\","
action="$action \"template.hawkular.url\":\"http://www.hawkular.org\"}"
local response=$(curl -X POST --write-out %{http_code} --silent --output /dev/null -H "$HEADER_JSON" -H "$HEADER_TENANT" --data "$action" $HAWKULAR_URL/actions)
if [ "$response" == "200" ];
then
echo "email action created"
else
echo "email action not created - aborting..."
exit 1
fi
}
function create_trigger() {
## Clean old trigger definition
local response=$(curl --write-out %{http_code} --silent --output /dev/null -H "$HEADER_TENANT" $HAWKULAR_URL/triggers/trigger-for-poc)
if [ "$response" == "404" ];
then
echo "trigger-for-poc trigger is not present"
else
echo "deleting old trigger-for-poc trigger"
response=$(curl -X DELETE --write-out %{http_code} --silent --output /dev/null -H "$HEADER_TENANT" $HAWKULAR_URL/triggers/trigger-for-poc)
fi
## Create new trigger
local trigger="{\"name\":\"trigger-for-poc\","
trigger="$trigger \"description\":\"Trigger for PoC\","
trigger="$trigger \"actions\":{\"email\":[\"email-to-admin-group\"]},"
trigger="$trigger \"firingMatch\":\"ALL\","
trigger="$trigger \"autoResolveMatch\":\"ALL\","
trigger="$trigger \"id\":\"trigger-for-poc\","
trigger="$trigger \"enabled\":true,"
trigger="$trigger \"autoDisable\":false,"
trigger="$trigger \"autoEnable\":false,"
trigger="$trigger \"autoResolve\":false,"
trigger="$trigger \"autoResolveAlerts\":false,"
trigger="$trigger \"severity\":\"HIGH\"}"
response=$(curl -X POST --write-out %{http_code} --silent --output /dev/null -H "$HEADER_JSON" -H "$HEADER_TENANT" --data "$trigger" $HAWKULAR_URL/triggers)
if [ "$response" == "200" ];
then
echo "trigger-for-poc trigger created"
else
echo "trigger-for-poc trigger not created - aborting..."
exit 1
fi
}
function create_conditions() {
## Create first condition
local cond1="{\"triggerMode\":\"FIRING\","
cond1="$cond1 \"type\":\"THRESHOLD\","
cond1="$cond1 \"dataId\":\"data-x\","
cond1="$cond1 \"operator\":\"LT\","
cond1="$cond1 \"threshold\":5}";
local response=$(curl -X POST --write-out %{http_code} --silent --output /dev/null -H "$HEADER_JSON" -H "$HEADER_TENANT" --data "$cond1" $HAWKULAR_URL/triggers/trigger-for-poc/conditions)
if [ "$response" == "200" ];
then
echo "condition1 created"
else
echo "condition1 not created - aborting..."
exit 1
fi
## Create a second conditions
local cond2="{\"triggerMode\":\"FIRING\","
cond2="$cond2 \"type\":\"THRESHOLD\","
cond2="$cond2 \"dataId\":\"data-y\","
cond2="$cond2 \"operator\":\"GT\","
cond2="$cond2 \"threshold\":5}";
response=$(curl -X POST --write-out %{http_code} --silent --output /dev/null -H "$HEADER_JSON" -H "$HEADER_TENANT" --data "$cond2" $HAWKULAR_URL/triggers/trigger-for-poc/conditions)
if [ "$response" == "200" ];
then
echo "condition2 created"
else
echo "condition2 not created - aborting..."
exit 1
fi
## Create a dampening condition
local damp="{\"type\":\"STRICT\","
damp="$damp \"evalTrueSetting\":2,"
damp="$damp \"evalTotalSetting\":2}"
response=$(curl -X POST --write-out %{http_code} --silent --output /dev/null -H "$HEADER_JSON" -H "$HEADER_TENANT" --data "$damp" $HAWKULAR_URL/triggers/trigger-for-poc/dampenings)
if [ "$response" == "200" ];
then
echo "dampening created"
else
echo "dampening not created - aborting..."
exit 1
fi
}
## Main
create_email_action;
create_trigger;
create_conditions;