Skip to content

Commit

Permalink
Merge branch 'master' into oceanstor-alert
Browse files Browse the repository at this point in the history
  • Loading branch information
sushanthakumar authored Jun 26, 2020
2 parents 8d35194 + 8b8cbd4 commit ec2895f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion delfin/alert_manager/alert_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from delfin import db
from delfin import exception
from delfin.drivers import api as driver_manager
from delfin.exporter import base_exporter

LOG = log.getLogger(__name__)

Expand Down Expand Up @@ -50,4 +51,6 @@ def process_alert_info(self, alert):

def _export_alert_model(self, alert_model):
"""Exports the filled alert model to the export manager."""
LOG.info('Alert model to be exported: %s.', alert_model)

# Export to base exporter which handles dispatch for all exporters
base_exporter.dispatch_alert_model(alert_model)
22 changes: 22 additions & 0 deletions delfin/exporter/base_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def _dispatch_example(ext, data):
ext.obj.dispatch_data(data)


def _dispatch_alert(ext, alert_model):
ext.obj.dispatch_alert_model(alert_model)


# Task can call this function to report example data.
def dispatch_example_data(data):
"""
Expand All @@ -56,6 +60,16 @@ def dispatch_example_data(data):
export_manager.map(_dispatch_example, data)


def dispatch_alert_model(alert_model):
"""
:param alert_model: Alert model.
:type alert_model: dict
Redefine this in child classes.
"""
export_manager = ExportManager().export_manager
export_manager.map(_dispatch_alert, alert_model)


class BaseExampleExporter(object):
"""Base class for example exporter."""

Expand All @@ -66,3 +80,11 @@ def dispatch_data(self, data):
Redefine this in child classes.
"""
raise NotImplementedError

def dispatch_alert_model(self, alert_model):
"""Dispatch data to north bound platforms.
:param alert_model: Alert model.
:type alert_model: dict
Redefine this in child classes.
"""
raise NotImplementedError
10 changes: 10 additions & 0 deletions delfin/exporter/example_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def dispatch_data(self, data):
for name, value in sorted(data.items()):
LOG.info("example1: %s = %s" % (name, value))

def dispatch_alert_model(self, alert_model):
LOG.info("\nExample1Exporter: Exported Alert model..")
for name, value in sorted(alert_model.items()):
LOG.info("%s = %s" % (name, value))


class Example2Exporter(base_exporter.BaseExampleExporter):
def __init__(self):
Expand All @@ -38,3 +43,8 @@ def dispatch_data(self, data):
LOG.info("Example2: report data ...")
for name, value in sorted(data.items()):
LOG.info("example2: %s = %s" % (name, value))

def dispatch_alert_model(self, alert_model):
LOG.info("\nExample2Exporter: Exported Alert model..")
for name, value in sorted(alert_model.items()):
LOG.info("%s = %s" % (name, value))

0 comments on commit ec2895f

Please sign in to comment.