# Path: monitoring/alarms/constants.py
# URL_PREFIX = 'horizon:monitoring:alarms:'
# TEMPLATE_PREFIX = 'monitoring/alarms/'
# CRITICAL_ICON = prefix + 'monitoring/img/critical-icon.png'
# WARNING_ICON = prefix + 'monitoring/img/warning-icon.png'
# OK_ICON = prefix + 'monitoring/img/ok-icon.png'
# UNKNOWN_ICON = prefix + 'monitoring/img/unknown-icon.png'
# NOTFOUND_ICON = prefix + 'monitoring/img/notfound-icon.png'


import json
from django.conf import settings
from django import template
from django.urls import reverse
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _  # noqa
from django.utils.translation import ungettext_lazy
from horizon import tables
from monitoring.alarms import constants
from monitoring import api
from monitoring.overview import constants as ov_constants
def get_service(data):
    if len(data['metrics']) == 1 and 'service'in\
            data['metrics'][0]['dimensions']:
        return data['metrics'][0]['dimensions']['service']
    else:
        return ''


class ShowAlarmHistory(tables.LinkAction):
    name = 'history'
    verbose_name = _('Show History')
    classes = ('btn-edit',)

    def get_link_url(self, datum):
        return reverse(constants.URL_PREFIX + 'history',
                       args=(datum['alarm_definition']['id'], datum['id'], ))

    def allowed(self, request, datum=None):
        return True


class CreateAlarm(tables.LinkAction):
    name = "create_alarm"
    verbose_name = _("Create Alarm")
    classes = ("ajax-modal",)
    icon = "plus"
    policy_rules = (("alarm", "alarm:create"),)
    ajax = True

    def get_link_url(self):

# Path: monitoring/alarms/constants.py
# URL_PREFIX = 'horizon:monitoring:alarms:'
# TEMPLATE_PREFIX = 'monitoring/alarms/'
# CRITICAL_ICON = prefix + 'monitoring/img/critical-icon.png'
# WARNING_ICON = prefix + 'monitoring/img/warning-icon.png'
# OK_ICON = prefix + 'monitoring/img/ok-icon.png'
# UNKNOWN_ICON = prefix + 'monitoring/img/unknown-icon.png'
# NOTFOUND_ICON = prefix + 'monitoring/img/notfound-icon.png'


# Path: monitoring/alarms/tables.py
import json
from django.conf import settings
from django import template
from django.urls import reverse
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _  # noqa
from django.utils.translation import ungettext_lazy
from horizon import tables
from monitoring.alarms import constants
from monitoring import api
from monitoring.overview import constants as ov_constants

def get_service(data):
    if len(data['metrics']) == 1 and 'service'in\
            data['metrics'][0]['dimensions']:
        return data['metrics'][0]['dimensions']['service']
    else:
        return ''


class ShowAlarmHistory(tables.LinkAction):
    name = 'history'
    verbose_name = _('Show History')
    classes = ('btn-edit',)

    def get_link_url(self, datum):
        return reverse(constants.URL_PREFIX + 'history',
                       args=(datum['alarm_definition']['id'], datum['id'], ))

    def allowed(self, request, datum=None):
        return True


class CreateAlarm(tables.LinkAction):
    name = "create_alarm"
    verbose_name = _("Create Alarm")
    classes = ("ajax-modal",)
    icon = "plus"
    policy_rules = (("alarm", "alarm:create"),)
    ajax = True

    def get_link_url(self):

        return reverse(constants.URL_PREFIX + 'alarm_create',