This repository has been archived by the owner on Nov 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
alerta.yaml
372 lines (348 loc) · 10.4 KB
/
alerta.yaml
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
---
AWSTemplateFormatVersion: "2010-09-09"
Metadata:
License: Apache-2.0
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Network Configuration"
Parameters:
- VpcId
- Subnets
- Label:
default: "Amazon EC2 Configuration"
Parameters:
- InstanceType
- KeyName
- SSHLocation
- Label:
default: "Alerta Configuration"
Parameters:
- SecretKey
- AllowedDomain
- TrackingId
- Label:
default: "Database Configuration"
Parameters:
- DBName
- DBUser
- DBPassword
- DBInstanceClass
- DBAllocatedStorage
- MultiAZ
ParameterLabels:
VpcId:
default: "Which VPC should this be deployed to?"
Description: Alerta monitoring system and web console
Parameters:
VpcId:
Description: VPC ID
Type: AWS::EC2::VPC::Id
Subnets:
Description: Subnets for ELB and instances
Type: List<AWS::EC2::Subnet::Id>
InstanceType:
Description: EC2 instance type
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.small
- t2.medium
ConstraintDescription: must be a valid EC2 instance type.
KeyName:
Description: Name of an existing EC2 KeyPair for SSH access
Type: AWS::EC2::KeyPair::KeyName
Default: bootstrap
SSHLocation:
Description: The IP address range that can be used to SSH to the EC2 instances
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x
SecretKey:
Description: Application secret key eg. any random string
Type: String
AllowedDomain:
Description: Allowed email domain eg. gmail.com or example.com
Type: String
Default: '*'
TrackingId:
Description: Google analytics tracking Id
Type: String
Default: ''
DBName:
Type: String
Description: Postgres database name
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric
characters.
Default: monitoring
MaxLength: 63
MinLength: 1
DBUser:
Type: String
Description: Username for database access
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric
characters.
MaxLength: 63
MinLength: 1
DBPassword:
Type: String
Description: Password for database access
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: must contain only alphanumeric characters (min. 8 characters)
MinLength: 8
NoEcho: true
DBInstanceClass:
ConstraintDescription: must select a valid database instance type.
Default: db.t2.micro
Description: The database instance type
Type: String
DBAllocatedStorage:
ConstraintDescription: must be between 20 and 1024Gb.
Default: 20
Description: The size of the database (Gb)
MaxValue: 1024
MinValue: 20
Type: Number
MultiAZ:
Type: String
Description: Multi-AZ master database
AllowedValues:
- true
- false
ConstraintDescription: must be true or false.
Default: false
Mappings:
RegionMap:
'ap-northeast-1':
AMI: 'ami-08847abae18baa040'
'ap-northeast-2':
AMI: 'ami-012566705322e9a8e'
'ap-south-1':
AMI: 'ami-00b6a8a2bd28daf19'
'ap-southeast-1':
AMI: 'ami-01da99628f381e50a'
'ap-southeast-2':
AMI: 'ami-00e17d1165b9dd3ec'
'ca-central-1':
AMI: 'ami-ce1b96aa'
'eu-central-1':
AMI: 'ami-0f5dbc86dd9cbf7a8'
'eu-west-1':
AMI: 'ami-0bdb1d6c15a40392c'
'eu-west-2':
AMI: 'ami-e1768386'
'eu-west-3':
AMI: 'ami-06340c8c12baa6a09'
'sa-east-1':
AMI: 'ami-0ad7b0031d41ed4b9'
'us-east-1':
AMI: 'ami-04681a1dbd79675a5'
'us-east-2':
AMI: 'ami-0cf31d971a3ca20d6'
'us-west-1':
AMI: 'ami-0782017a917e973e7'
'us-west-2':
AMI: 'ami-6cd6f714'
Resources:
PublicLoadBalancer:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
Scheme: internet-facing
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
Subnets: !Ref Subnets
CrossZone: true
Listeners:
- Protocol: HTTP
LoadBalancerPort: '80'
InstancePort: '80'
HealthCheck:
Target: HTTP:80/api/_
Timeout: '5'
Interval: '10'
UnhealthyThreshold: '2'
HealthyThreshold: '2'
AutoscalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: !Ref Subnets
AvailabilityZones: !GetAZs ''
LaunchConfigurationName: !Ref WebServerLaunchConfig
MinSize: '1'
MaxSize: '2'
HealthCheckType: ELB
HealthCheckGracePeriod: 300
LoadBalancerNames:
- !Ref PublicLoadBalancer
Tags:
- Key: Name
PropagateAtLaunch: true
Value: Alerta
WebServerLaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
AWS::CloudFormation::Init:
config:
packages:
yum:
httpd: []
mod_wsgi: []
python:
alerta-server: ["<6.0"]
alerta: []
sources:
/var/www/alerta: https://github.com/alerta/angular-alerta-webui/tarball/master
files:
/etc/httpd/conf.d/wsgi.conf:
content: |
Listen 8080
<VirtualHost *:8080>
ServerName ec2.local.alerta.io
WSGIDaemonProcess alerta processes=5 threads=5
WSGIProcessGroup alerta
# WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/api.wsgi
WSGIPassAuthorization On
</VirtualHost>
<VirtualHost *:80>
ProxyPass /api http://localhost:8080
ProxyPassReverse /api http://localhost:8080
DocumentRoot /var/www/alerta/app
</VirtualHost>
/var/www/api.wsgi:
content: |
from alerta import app as application
/etc/alertad.conf:
content: !Sub |
DEBUG=True
SECRET_KEY='${SecretKey}'
AUTH_REQUIRED=True
ALLOWED_EMAIL_DOMAINS=['${AllowedDomain}']
DATABASE_URL='postgres://${DBUser}:${DBPassword}@${Database.Endpoint.Address}:${Database.Endpoint.Port}/${DBName}'
/var/www/alerta/app/config.js:
content: !Sub |
'use strict';
angular.module('config', [])
.constant('config', {
'endpoint' : '/api',
'provider' : 'basic',
'tracking_id' : '${TrackingId}'
});
/etc/cfn/cfn-hup.conf:
content: !Sub |
[main]
stack=${AWS::StackId}
region=${AWS::Region}
interval=1
mode: '000400'
owner: root
group: root
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.EC2Instance.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource WebServerLaunchConfig --region ${AWS::Region}
runas=root
mode: '000400'
owner: root
group: root
services:
sysvinit:
httpd:
enabled: 'true'
ensureRunning: 'true'
cfn-hup:
enabled: 'true'
ensureRunning: 'true'
files:
- /etc/cfn/cfn-hup.conf
- /etc/cfn/hooks.d/cfn-auto-reloader.conf
Properties:
ImageId: !FindInMap [RegionMap, !Ref 'AWS::Region', AMI]
InstanceType: !Ref InstanceType
SecurityGroups:
- !Ref WebServerSecurityGroup
KeyName: !Ref KeyName
UserData:
'Fn::Base64': !Sub |
#!/bin/bash -ex
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource WebServerLaunchConfig --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource AutoScalingGroup --region ${AWS::Region}
LoadBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: worldwide HTTP access
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
VpcId: !Ref VpcId
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: ELB HTTP access and restricted SSH access
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
SourceSecurityGroupId: !Ref LoadBalancerSecurityGroup
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref SSHLocation
VpcId: !Ref VpcId
DatabaseSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: database vpc subnets
SubnetIds: !Ref Subnets
Database:
Type: AWS::RDS::DBInstance
Properties:
DBName: !Ref DBName
Engine: Postgres
DBInstanceClass: !Ref DBInstanceClass
AllocatedStorage: !Ref DBAllocatedStorage
MasterUsername: !Ref DBUser
MasterUserPassword: !Ref DBPassword
MultiAZ: !Ref MultiAZ
DBSubnetGroupName:
Ref: DatabaseSubnetGroup
VPCSecurityGroups:
- !Ref DatabaseSecurityGroup
Tags:
- Key: "Name"
Value: "Alerta Database"
DeletionPolicy: "Snapshot"
DatabaseSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Open database for access
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 5432
ToPort: 5432
SourceSecurityGroupId:
Ref: WebServerSecurityGroup
VpcId: !Ref VpcId
Outputs:
AlertaURL:
Description: Alerta Web UI
Value: !Sub "http://${PublicLoadBalancer.DNSName}"
AlertaApiEndpoint:
Description: Alerta API Endpoint
Value: !Sub "http://${PublicLoadBalancer.DNSName}/api"