/
module.ftl
183 lines (177 loc) · 6.73 KB
/
module.ftl
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
[#ftl]
[@addModule
name="alarmslack"
description="Sends slack notifications based on cloudwatch alarms"
provider=AWS_PROVIDER
properties=[
{
"Names" : "slackChannel",
"Type" : STRING_TYPE,
"Description" : "The slack channel to send alerts to",
"Mandatory" : true
},
{
"Names" : "webHookUrl",
"Type" : STRING_TYPE,
"Description" : "The slack incoming webhook URL to use - Encryption is recommended",
"Mandatory" : true
},
{
"Names" : "alertSeverity",
"Type" : STRING_TYPE,
"Description" : "The lowest severity alerts to include in notifications",
"Default" : "info"
},
{
"Names" : "alertProfile",
"Type" : STRING_TYPE,
"Description" : "The alert profile id to use for enabling notifications",
"Default" : "default"
},
{
"Names" : "kmsPrefix",
"Type" : STRING_TYPE,
"Description" : "The KMS prefix used for encrypted values",
"Default" : "base64:"
},
{
"Names" : "lambdaSourceUrl",
"Type" : STRING_TYPE,
"Description" : "A URL to the lambda zip package for sending alerts",
"Default" : "https://github.com/hamlet-io/lambda-cloudwatch-slack/releases/download/v1.1.0/cloudwatch-slack.zip"
},
{
"Names" : "lambdaSourceHash",
"Type" : STRING_TYPE,
"Description" : "A sha1 hash of the lambda image to ensure its the right one",
"Default" : "8f194db4f6ed2b826387112df144f188451ba6db"
},
{
"Names" : "namePrefix",
"Type" : STRING_TYPE,
"Description" : "A prefix appended to component names and deployment units to ensure uniquness",
"Default" : "alarmslack"
},
{
"Names" : "tier",
"Type" : STRING_TYPE,
"Description" : "The tier to use to host the components",
"Default" : "mgmt"
}
]
/]
[#macro aws_module_alarmslack
slackChannel
webHookUrl
kmsPrefix
lambdaSourceUrl
lambdaSourceHash
namePrefix
tier
alertSeverity
alertProfile ]
[#local topicName = formatName(namePrefix, "topic" )]
[#local lambdaName = formatName(namePrefix, "lambda" )]
[#local product = getActiveLayer(PRODUCT_LAYER_TYPE) ]
[#local environment = getActiveLayer(ENVIRONMENT_LAYER_TYPE)]
[#local segment = getActiveLayer(SEGMENT_LAYER_TYPE)]
[#local namespace = formatName(product["Name"], environment["Name"], segment["Name"])]
[#local lambdaSettingNamespace = formatName(namespace, lambdaName)]
[@loadModule
settingSets=[
{
"Type" : "Settings",
"Scope" : "Products",
"Namespace" : lambdaSettingNamespace,
"Settings" : {
"SLACK_HOOK_URL" : webHookUrl,
"KMS_PREFIX" : kmsPrefix,
"SLACK_CHANNEL" : slackChannel,
"ENVIRONMENT" : namespace
}
}
]
blueprint={
"Tiers" : {
tier : {
"Components" : {
topicName : {
"topic" : {
"Instances" : {
"default" : {
"DeploymentUnits" : [ topicName ]
}
},
"Subscriptions" : {
"slack" : {
"Links" : {
"lambda" : {
"Tier" : tier,
"Component" : lambdaName,
"Function" : "send"
}
}
}
}
}
},
lambdaName : {
"Lambda" : {
"Instances" : {
"default" : {
"DeploymentUnits" : [ lambdaName ]
}
},
"Functions" : {
"send" : {
"Handler" : "cloudwatch-slack/lambda_function.lambda_handler",
"RunTime" : "python3.6",
"MemorySize" : 128,
"Timeout" : 15,
"VPCAccess" : false,
"PredefineLogGroup" : true
}
},
"Links" : {
"alerts" : {
"Tier" : tier,
"Component" : topicName,
"Direction" : "inbound",
"Role" : "invoke"
}
},
"Image" : {
"Source" : "url",
"UrlSource" : {
"Url" : lambdaSourceUrl,
"ImageHash" : lambdaSourceHash
}
}
}
}
}
}
},
"AlertRules" : {
"SlackNotify" : {
"Severity" : alertSeverity,
"Destinations" : {
"Links" : {
"alarm" : {
"Tier" : tier,
"Component" : topicName,
"Instance" : "",
"Version" : ""
}
}
}
}
},
"AlertProfiles" : {
alertProfile : {
"Rules" : ["SlackNotify" ]
}
}
}
/]
[/#macro]