· 7 years ago · Feb 20, 2018, 09:02 AM
1import boto3
2import datetime
3from datetime import timedelta
4from datetime import date
5import sys
6
7ACCESS_KEY = "AKIAIGUG5LNXEZG6LAEA"
8SECRET_KEY = "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"
9TOPIC_ARN = "arn:aws:sns:us-east-1:961701920393:ReportingPrometheusSilenceAlarms-SNSTopic-N553OOLRQPF9"
10ACTION = sys.argv[1]
11ALERT_MANAGER_DNS = "reporting-mon-01.aws-dev.perfectomobile.com"
12ALERTS_TO_DISABLE = "Exporter_Scrape_Error,Datain_Health"
13client = boto3.client(
14 'sns',
15 aws_access_key_id=ACCESS_KEY,
16 aws_secret_access_key=SECRET_KEY,
17)
18
19response = client.publish(
20 TopicArn=TOPIC_ARN,
21 Message='test',
22 MessageAttributes={
23 'Action': {
24 'DataType': 'String',
25 'StringValue': ACTION
26 },
27 'AlertManagerURL': {
28 'DataType': 'String',
29 'StringValue': ALERT_MANAGER_DNS
30 },
31 'AlertsToPause': {
32 'DataType': 'String',
33 'StringValue': ALERTS_TO_DISABLE
34 },
35 'Comment': {
36 'DataType': 'String',
37 'StringValue': 'Disabled by Lambda'
38 },
39 'endTime': {
40 'DataType': 'String',
41 'StringValue': ((datetime.datetime.now() + timedelta(hours=1.5)).isoformat())[:-6] + "361Z"
42 }
43 }
44)
45print("Response: {}".format(response))