# Path: monitoring/api/client.py
# LOG = logging.getLogger(__name__)
# INSECURE = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
# CACERT = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
# KEYSTONE_SERVICE = 'identity'
# MONITORING_SERVICE = getattr(settings, 'MONITORING_SERVICE_TYPE', 'monitoring')
# VERSIONS = base.APIVersionManager(
#     MONITORING_SERVICE,
#     preferred_version=getattr(settings,
#                               'OPENSTACK_API_VERSIONS',
#                               {}).get(MONITORING_SERVICE, 2.0)
# )
# def _get_endpoint(request):
# def _get_auth_params_from_request(request):
# def _get_to_verify(insecure, cacert):
# def monascaclient(request, version=None):


from oslo_log import log
from openstack_dashboard.contrib.developer.profiler import api as profiler
from monitoring.api import client


@profiler.trace
def alarmdef_list_by_service(request, service_name, marker=None,
                             paginate=False):
    service_dim = {'service': service_name}
    result = client.monascaclient(request).alarm_definitions.list(
        dimensions=service_dim)
    return result['elements'] if type(result) is dict else result


@profiler.trace
def alarmdef_delete(request, alarm_id):
    return client.monascaclient(request).alarm_definitions.delete(
        alarm_id=alarm_id)


@profiler.trace
def alarmdef_history(request, alarm_id):
    return client.monascaclient(request).alarm_definitions.history(
        alarm_id=alarm_id)


@profiler.trace
def alarmdef_get(request, alarm_id):
    return client.monascaclient(request).alarm_definitions.get(alarm_id=alarm_id)


@profiler.trace
def alarmdef_get_by_name(request, name):

# Path: monitoring/api/client.py
# LOG = logging.getLogger(__name__)
# INSECURE = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
# CACERT = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
# KEYSTONE_SERVICE = 'identity'
# MONITORING_SERVICE = getattr(settings, 'MONITORING_SERVICE_TYPE', 'monitoring')
# VERSIONS = base.APIVersionManager(
#     MONITORING_SERVICE,
#     preferred_version=getattr(settings,
#                               'OPENSTACK_API_VERSIONS',
#                               {}).get(MONITORING_SERVICE, 2.0)
# )
# def _get_endpoint(request):
# def _get_auth_params_from_request(request):
# def _get_to_verify(insecure, cacert):
# def monascaclient(request, version=None):


# Path: monitoring/api/monitor.py
from oslo_log import log
from openstack_dashboard.contrib.developer.profiler import api as profiler
from monitoring.api import client



@profiler.trace
def alarmdef_list_by_service(request, service_name, marker=None,
                             paginate=False):
    service_dim = {'service': service_name}
    result = client.monascaclient(request).alarm_definitions.list(
        dimensions=service_dim)
    return result['elements'] if type(result) is dict else result


@profiler.trace
def alarmdef_delete(request, alarm_id):
    return client.monascaclient(request).alarm_definitions.delete(
        alarm_id=alarm_id)


@profiler.trace
def alarmdef_history(request, alarm_id):
    return client.monascaclient(request).alarm_definitions.history(
        alarm_id=alarm_id)


@profiler.trace
def alarmdef_get(request, alarm_id):
    return client.monascaclient(request).alarm_definitions.get(alarm_id=alarm_id)


@profiler.trace
def alarmdef_get_by_name(request, name):

    return client.monascaclient(request).alarm_definitions.list(