Skip to content

Commit

Permalink
first try for sns alert.
Browse files Browse the repository at this point in the history
  • Loading branch information
fractos committed Sep 27, 2018
1 parent fd7ebdc commit 32b0521
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ENV CONNECTION_TIMEOUT_SECONDS 10
WORKDIR /opt/app
CMD ["python3", "-u", "main.py"]

COPY app/requirements.txt /opt/app/
COPY requirements.txt /opt/app/
RUN pip3 install --no-cache-dir -r /opt/app/requirements.txt

COPY app /opt/app/
15 changes: 14 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sqlite3
import signal
import os
import boto3
import settings

requested_to_quit = False
Expand Down Expand Up @@ -252,7 +253,19 @@ def alert_slack(message, alert):

def alert_sns(message, alert):
logger.info('alert_sns: %s' % message)
pass

sns_client = boto3.client('sns', alert['region'])

sns_message = {
'timestamp': time.time(),
'message': message
}

_ = sns_client.publish(
TopicArn=alert['arn'],
Message=json.dumps(sns_message)
)



if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions app/requirements.txt → requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
logzero
requests
python-dateutil
boto3

0 comments on commit 32b0521

Please sign in to comment.