def test_non_critical_is_warning(self, sess): alarm = post_to_slack.Alarm( json.dumps({ "AlarmName": "sierra_bibs_merger_queue_dlq_not_empty", "NewStateReason": "Threshold Crossed: 1 datapoint [1.0 (01/01/01 12:00:00)] was greater than or equal to the threshold (1.0).", })) payload = post_to_slack.prepare_slack_payload( alarm=alarm, bitly_access_token=access_token, sess=sess) assert payload["username"] == "cloudwatch-warning" assert payload["icon_emoji"] == ":warning:" assert payload["attachments"][0]["color"] == "warning"
def test_critical_is_alarm(self, sess): alarm = post_to_slack.Alarm( json.dumps({ "AlarmName": "api_remus_v1-alb-target-500-errors", "NewStateReason": "Threshold Crossed: 1 datapoint [1.0 (01/01/01 12:00:00)] was greater than or equal to the threshold (1.0).", })) payload = post_to_slack.prepare_slack_payload( alarm=alarm, bitly_access_token=access_token, sess=sess) assert payload["username"] == "cloudwatch-alarm" assert payload["icon_emoji"] == ":rotating_light:" assert payload["attachments"][0]["color"] == "danger"
def test_non_critical_is_warning(self, sess): alarm = post_to_slack.Alarm( json.dumps({ 'AlarmName': 'sierra_bibs_merger_queue_dlq_not_empty', 'NewStateReason': 'Threshold Crossed: 1 datapoint [1.0 (01/01/01 12:00:00)] was greater than or equal to the threshold (1.0).', })) payload = post_to_slack.prepare_slack_payload( alarm=alarm, bitly_access_token=access_token, sess=sess) assert payload['username'] == 'cloudwatch-warning' assert payload['icon_emoji'] == ':warning:' assert payload['attachments'][0]['color'] == 'warning'
def test_critical_is_alarm(self, sess): alarm = post_to_slack.Alarm( json.dumps({ 'AlarmName': 'api_remus_v1-alb-target-500-errors', 'NewStateReason': 'Threshold Crossed: 1 datapoint [1.0 (01/01/01 12:00:00)] was greater than or equal to the threshold (1.0).', })) payload = post_to_slack.prepare_slack_payload( alarm=alarm, bitly_access_token=access_token, sess=sess) assert payload['username'] == 'cloudwatch-alarm' assert payload['icon_emoji'] == ':rotating_light:' assert payload['attachments'][0]['color'] == 'danger'
def test_including_cloudwatch_messages(self, sess): # Populate the CloudWatch log stream with a bunch of logs, then # we'll check we get something broadly sensible at the end. client = boto3.client("logs") client.create_log_group(logGroupName="platform/loris") client.create_log_stream(logGroupName="platform/loris", logStreamName="logstream001") def _event(minute, status_code): return { "timestamp": datetime_to_cloudwatch_ts( dt.datetime(2000, 1, 1, 12, minute, 0, 0)), "message": f"[Mon Jan 1 12:{minute}:00 2001] GET /V0{status_code}.jpg/full/300,/0/default.jpg => generated 1000 bytes in 10 msecs (HTTP/1.0 {status_code})", } client.put_log_events( logGroupName="platform/loris", logStreamName="logstream001", logEvents=[ _event(minute=minute, status_code=status_code) for minute, status_code in enumerate( [ 200, 200, 500, 200, 500, 500, 200, 500, 200, 200, 500, 200 ], start=22, ) ], ) alarm = post_to_slack.Alarm( json.dumps({ "AlarmName": "loris-alb-target-500-errors", "NewStateReason": "Threshold Crossed: 1 datapoint [4.0 (01/01/01 12:00:00)] was greater than or equal to the threshold (1.0).", })) post_to_slack.prepare_slack_payload(alarm=alarm, bitly_access_token=access_token, sess=sess)
def test_human_reason(self, alarm_data, expected_reason): a = post_to_slack.Alarm(json.dumps(alarm_data)) assert a.human_reason() == expected_reason