in src/aws_interfaces/alarm_interface.py [0:0]
def create_alarm(self, alarmName, jobId, namespace, metricName, period, stat,
threshold, alarmType, evaluationPeriods, datapointsToAlarm,
alarmActions):
logging.info('Creating alarm: metric=%s, stat=%s, threshold=%s, type=%s',
metricName, stat, threshold, alarmType)
alarmBase = self._create_alarm_base(alarmName, jobId, namespace, metricName,
period, stat, evaluationPeriods,
datapointsToAlarm, alarmActions)
requestPayload = {
'Threshold': threshold,
**alarmBase
}
if alarmType == 'upper':
requestPayload['ComparisonOperator'] = 'GreaterThanThreshold'
else:
requestPayload['ComparisonOperator'] = 'LessThanThreshold'
try:
self.client.put_metric_alarm(**requestPayload)
except ClientError as e:
return False, str(e)
return True, None