Updated to new sql schema for alarm actions
This commit is contained in:
parent
a6ad1b1ed3
commit
f6c6acf4eb
@ -83,17 +83,15 @@ class AlarmProcessor(BaseProcessor):
|
||||
|
||||
try:
|
||||
with db_time.time():
|
||||
cur.execute("SELECT notification_method_id FROM alarm_action WHERE alarm_id = %s", alarm['alarmId'])
|
||||
ids = [row[0] for row in cur]
|
||||
if len(ids) == 1:
|
||||
cur.execute("SELECT name, type, address FROM notification_method WHERE id = %s", ids[0])
|
||||
elif len(ids) > 1:
|
||||
cur.execute(
|
||||
"SELECT name, type, address FROM notification_method WHERE id in (%s)", ','.join(ids))
|
||||
except MySQLdb.Error:
|
||||
log.exception('Error reading from mysql')
|
||||
|
||||
log.debug('Response from mysql')
|
||||
cur.execute("""SELECT name, type, address
|
||||
FROM alarm_action as aa
|
||||
JOIN notification_method as nm ON aa.action_id = nm.id
|
||||
WHERE aa.alarm_id = %s and aa.alarm_state = %s""",
|
||||
[alarm['alarmId'], alarm['newState']])
|
||||
except MySQLdb.Error as e:
|
||||
log.error('Mysql Error, %s' % e)
|
||||
notifications = []
|
||||
else:
|
||||
notifications = [
|
||||
Notification(row[1].lower(), partition, offset, row[0], row[2], alarm) for row in cur]
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
{"alarm-transitioned":{"tenantId":"0","alarmId":"0","alarmName":"test Alarm","oldState":"OK","newState":"ALARM","stateChangeReason":"I am alarming!","timestamp":1395245059}}
|
||||
{"alarm-transitioned":{"tenantId":"0","alarmId":"1","alarmName":"test Okay","oldState":"ALARM","newState":"OK","stateChangeReason":"Okay, I am not alarming.","timestamp":1395245059}}
|
||||
{"alarm-transitioned":{"tenantId":"0","alarmId":"2","alarmName":"test Undetermined","oldState":"OK","newState":"UNDETERMINED","stateChangeReason":"Well, maybe I am alarming.","timestamp":1395245059}}
|
||||
{"alarm-transitioned":{"tenantId":"0","alarmId":"0","alarmName":"test Alarm","oldState":"OK","newState":"ALARM","stateChangeReason":"I am alarming!","timestamp":1395346830}}
|
||||
{"alarm-transitioned":{"tenantId":"0","alarmId":"1","alarmName":"test Okay","oldState":"ALARM","newState":"OK","stateChangeReason":"Okay, I am not alarming.","timestamp":1395346830}}
|
||||
{"alarm-transitioned":{"tenantId":"0","alarmId":"2","alarmName":"test Undetermined","oldState":"OK","newState":"UNDETERMINED","stateChangeReason":"Well, maybe I am alarming.","timestamp":1395346830}}
|
||||
|
@ -5,7 +5,13 @@ INSERT INTO alarm (id, tenant_id, name, state, created_at, updated_at) VALUES ('
|
||||
INSERT INTO notification_method (id, tenant_id, name, type, address, created_at, updated_at)
|
||||
VALUES ('0', '0', 'test notification', 'EMAIL', 'me@here.com', NOW(), NOW());
|
||||
|
||||
INSERT INTO alarm_action (alarm_id, notification_method_id) VALUES ('0', '0');
|
||||
INSERT INTO alarm_action (alarm_id, notification_method_id) VALUES ('1', '0');
|
||||
INSERT INTO alarm_action (alarm_id, notification_method_id) VALUES ('2', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('0', 'OK', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('0', 'ALARM', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('0', 'UNDETERMINED', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('1', 'OK', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('1', 'ALARM', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('1', 'UNDETERMINED', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('2', 'OK', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('2', 'ALARM', '0');
|
||||
INSERT INTO alarm_action (alarm_id, alarm_state, action_id) VALUES ('2', 'UNDETERMINED', '0');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user