# Path: monasca_notification/notification.py
# class Notification(object):
#     def __init__(self, id, type, name, address, period, retry_count, alarm):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def to_json(self):
# 
# Path: monasca_notification/plugins/email_notifier.py
# CONF = cfg.CONF
# EMAIL_SINGLE_HOST_BASE = u'''On host "{hostname}" for target "{target_host}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_MULTIPLE_HOST_BASE = u'''On host "{hostname}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_NO_HOST_BASE = u'''On multiple hosts {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# Alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions
# {metric_dimensions}'''
# class EmailNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config=None):
#     def statsd_name(self):
#     def send_notification(self, notification):
#     def _sendmail(self, notification, msg):
#     def _email_error(self, notification):
#     def _smtp_connect(self):
#     def _create_msg(self, hostname, notification, targethost=None):
#     def _get_link_url(self, metric, timestamp_ms):
# def _format_dimensions(notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/plugins/pagerduty_notifier.py
# CONF = cfg.CONF
# VALID_HTTP_CODES = [200, 201, 204]
# class PagerdutyNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config):
#     def statsd_name(self):
#     def send_notification(self, notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/plugins/webhook_notifier.py
# CONF = cfg.CONF
# class WebhookNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config_dict):
#     def statsd_name(self):
#     def send_notification(self, notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/types/notifiers.py
# CONF = cfg.CONF
# def init(statsd_obj):
# def load_plugins():
# def enabled_notifications():
# def config():
# def send_notifications(notifications):
# def send_single_notification(notification):
# 
# Path: tests/base.py
# class DisableStatsdFixture(fixtures.Fixture):
# class ConfigFixture(oo_cfg.Config):
# class BaseTestCase(oslotest_base.BaseTestCase):
# class PluginTestCase(BaseTestCase):
#     def setUp(self):
#     def __init__(self):
#     def setUp(self):
#     def _clean_config_loaded_flag():
#     def setUp(self):
#     def conf_override(**kw):
#     def conf_default(**kw):
#     def setUp(self, register_opts=None):


import contextlib
import time
from unittest import mock
from monasca_notification import notification as m_notification
from monasca_notification.plugins import email_notifier
from monasca_notification.plugins import pagerduty_notifier
from monasca_notification.plugins import webhook_notifier
from monasca_notification.types import notifiers
from tests import base
        notifications = [
            m_notification.Notification(0, 'email', 'email notification',
                                        'me@here.com', 0, 0, alarm({})),
            m_notification.Notification(1, 'email', 'email notification',
                                        'foo@here.com', 0, 0, alarm({})),
            m_notification.Notification(2, 'email', 'email notification',
                                        'bar@here.com', 0, 0, alarm({}))
        ]

        notifiers.send_notifications(notifications)

        self.assertEqual(self.statsd.timer.timer_calls['email_time_start'], 3)
        self.assertEqual(self.statsd.timer.timer_calls['email_time_stop'], 3)
        self.assertEqual(self.statsd.counter.counter, 3)

    def test_plugin_load(self):
        self.conf_override(
            group='notification_types',
            enabled=[
                'monasca_notification.plugins.hipchat_notifier:HipChatNotifier',
                'monasca_notification.plugins.slack_notifier:SlackNotifier'
            ]
        )

        notifiers.init(self.statsd)
        notifiers.load_plugins()
        notifiers.config()

        self.assertEqual(len(notifiers.possible_notifiers), 2)
        self.assertItemsEqual(['hipchat', 'slack'],

# Path: monasca_notification/notification.py
# class Notification(object):
#     def __init__(self, id, type, name, address, period, retry_count, alarm):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def to_json(self):
# 
# Path: monasca_notification/plugins/email_notifier.py
# CONF = cfg.CONF
# EMAIL_SINGLE_HOST_BASE = u'''On host "{hostname}" for target "{target_host}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_MULTIPLE_HOST_BASE = u'''On host "{hostname}" {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions:
# {metric_dimensions}'''
# EMAIL_NO_HOST_BASE = u'''On multiple hosts {message}
# 
# Alarm "{alarm_name}" transitioned to the {state} state at {timestamp} UTC
# Alarm_id: {alarm_id}
# 
# Lifecycle state: {lifecycle_state}
# Link: {link}
# Link to Grafana: {grafana_url}
# 
# With dimensions
# {metric_dimensions}'''
# class EmailNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config=None):
#     def statsd_name(self):
#     def send_notification(self, notification):
#     def _sendmail(self, notification, msg):
#     def _email_error(self, notification):
#     def _smtp_connect(self):
#     def _create_msg(self, hostname, notification, targethost=None):
#     def _get_link_url(self, metric, timestamp_ms):
# def _format_dimensions(notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/plugins/pagerduty_notifier.py
# CONF = cfg.CONF
# VALID_HTTP_CODES = [200, 201, 204]
# class PagerdutyNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config):
#     def statsd_name(self):
#     def send_notification(self, notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/plugins/webhook_notifier.py
# CONF = cfg.CONF
# class WebhookNotifier(abstract_notifier.AbstractNotifier):
#     def __init__(self, log):
#     def config(self, config_dict):
#     def statsd_name(self):
#     def send_notification(self, notification):
# def register_opts(conf):
# def list_opts():
# 
# Path: monasca_notification/types/notifiers.py
# CONF = cfg.CONF
# def init(statsd_obj):
# def load_plugins():
# def enabled_notifications():
# def config():
# def send_notifications(notifications):
# def send_single_notification(notification):
# 
# Path: tests/base.py
# class DisableStatsdFixture(fixtures.Fixture):
# class ConfigFixture(oo_cfg.Config):
# class BaseTestCase(oslotest_base.BaseTestCase):
# class PluginTestCase(BaseTestCase):
#     def setUp(self):
#     def __init__(self):
#     def setUp(self):
#     def _clean_config_loaded_flag():
#     def setUp(self):
#     def conf_override(**kw):
#     def conf_default(**kw):
#     def setUp(self, register_opts=None):


# Path: tests/test_notifiers.py
import contextlib
import time
from unittest import mock
from monasca_notification import notification as m_notification
from monasca_notification.plugins import email_notifier
from monasca_notification.plugins import pagerduty_notifier
from monasca_notification.plugins import webhook_notifier
from monasca_notification.types import notifiers
from tests import base

        notifications = [
            m_notification.Notification(0, 'email', 'email notification',
                                        'me@here.com', 0, 0, alarm({})),
            m_notification.Notification(1, 'email', 'email notification',
                                        'foo@here.com', 0, 0, alarm({})),
            m_notification.Notification(2, 'email', 'email notification',
                                        'bar@here.com', 0, 0, alarm({}))
        ]

        notifiers.send_notifications(notifications)

        self.assertEqual(self.statsd.timer.timer_calls['email_time_start'], 3)
        self.assertEqual(self.statsd.timer.timer_calls['email_time_stop'], 3)
        self.assertEqual(self.statsd.counter.counter, 3)

    def test_plugin_load(self):
        self.conf_override(
            group='notification_types',
            enabled=[
                'monasca_notification.plugins.hipchat_notifier:HipChatNotifier',
                'monasca_notification.plugins.slack_notifier:SlackNotifier'
            ]
        )

        notifiers.init(self.statsd)
        notifiers.load_plugins()
        notifiers.config()

        self.assertEqual(len(notifiers.possible_notifiers), 2)
        self.assertItemsEqual(['hipchat', 'slack'],

                              notifiers.configured_notifiers)