fix vitrage webhook row replacement

fixes a bug that removes previous alarm state on alarm deactivate,
but fails to remove previous alarm state on alarm activate.
Can lead to an inactive alarm row not being replaced when the same
alarm activates.

Change-Id: I1dc7977d8355025d8f98c7931d0e8f765d692434
This commit is contained in:
Eric K 2018-07-25 09:42:55 -07:00
parent f15cdea39e
commit a7be8e89d6
1 changed files with 9 additions and 9 deletions

View File

@ -90,16 +90,16 @@ class VitrageDriver(datasource_driver.PushedDataSourceDriver):
@lockutils.synchronized('congress_vitrage_ds_data')
def _webhook_handler(self, payload):
tablename = 'alarms'
if payload['notification'] == 'vitrage.alarm.deactivate':
# remove alarm from table
row_id = payload['payload']['vitrage_id']
column_index_number_of_row_id = 4
to_remove = [row for row in self.state[tablename]
if row[column_index_number_of_row_id] == row_id]
for row in to_remove:
self.state[tablename].discard(row)
# add alarm to table
# remove previous alarms of same ID from table
row_id = payload['payload']['vitrage_id']
column_index_number_of_row_id = 4
to_remove = [row for row in self.state[tablename]
if row[column_index_number_of_row_id] == row_id]
for row in to_remove:
self.state[tablename].discard(row)
# add new alarm to table
translator = self.webhook_alarm_translator
row_data = VitrageDriver.convert_objs(
[payload['payload']], translator)