Enhance event api allowing for different doctor alarm types

Change-Id: I78ea4875e4c724845a28706286a700c3037a6f7d
This commit is contained in:
Idan Hefetz 2017-11-21 09:59:19 +00:00
parent 1c3ed3ba78
commit 4f8787d0b8
3 changed files with 16 additions and 3 deletions

View File

@ -21,6 +21,9 @@ import socket
from vitrage.api_handler.apis.base import EntityGraphApisBase
from vitrage.common.constants import EventProperties
from vitrage.datasources.doctor.properties import DoctorDetails
from vitrage.datasources.doctor.properties import DoctorProperties
from vitrage.datasources.doctor.properties import DoctorStatus
from vitrage.messaging import get_transport
LOG = log.getLogger(__name__)
@ -40,11 +43,18 @@ class EventApis(EntityGraphApisBase):
EventProperties.TIME: event_time,
EventProperties.DETAILS: details}
if details.get(DoctorDetails.STATUS) == DoctorStatus.UP:
notification_type = DoctorProperties.CUSTOM_EVENT_UP
elif details.get(DoctorDetails.STATUS) == DoctorStatus.DOWN:
notification_type = DoctorProperties.CUSTOM_EVENT_DOWN
else:
raise Exception("Unknown status")
self.oslo_notifier.info(
ctxt={'message_id': uuidutils.generate_uuid(),
'publisher_id': self.publisher,
'timestamp': datetime.utcnow()},
event_type=event_type,
event_type=notification_type,
payload=event)
except Exception as e:
LOG.warning('Failed to post event %s. Exception: %s',

View File

@ -93,7 +93,7 @@ class DoctorDriver(AlarmDriverBase):
LOG.debug('Going to enrich event: %s', str(event))
event[DSProps.EVENT_TYPE] = event_type
event[DSProps.EVENT_TYPE] = event[EventProps.TYPE]
old_alarm = self._old_alarm(event)
if old_alarm and not self._status_changed(old_alarm, event):
@ -113,4 +113,5 @@ class DoctorDriver(AlarmDriverBase):
@staticmethod
def get_event_types():
return [DoctorProps.HOST_DOWN]
return [DoctorProps.CUSTOM_EVENT_DOWN,
DoctorProps.CUSTOM_EVENT_UP]

View File

@ -20,6 +20,8 @@ class DoctorProperties(object):
HOST_DOWN = 'compute.host.down'
HOST_TYPE = NOVA_HOST_DATASOURCE
UPDATE_TIME = 'update_time'
CUSTOM_EVENT_UP = 'vitrage.custom.event.up'
CUSTOM_EVENT_DOWN = 'vitrage.custom.event.down'
class DoctorDetails(object):