# -*- coding: utf-8 -*-
from provider import ZabbixProvider
import logging

LOG = logging.getLogger(__name__)


class MySQLSingleZabbixProvider(ZabbixProvider):
    def create_database_monitors(self,):
        instances = self.get_all_instances()
        self._create_database_monitors(instances, dbtype='mysql', alarm='no')


class MySQLHighAvailabilityZabbixProvider(ZabbixProvider):
    def get_params_for_instance(self, instance, **kwargs):
        host = instance.dns
        kwargs['host'] = host

        if kwargs.get('healthcheck'):
            kwargs['healthcheck']['host'] = host
            kwargs['healthcheck_monitor']['host'] = host

        return kwargs

    def create_database_monitors(self, alarm='yes'):
        instances = self.get_database_instances()
        params = {'dbtype': 'mysql', 'healthcheck': {'port': '80',
                                                     'string': 'WORKING',
                                                     'uri': 'health-check/'
                                                     },
                  'healthcheck_monitor': {'port': '80', 'string': 'WORKING',
                                          'uri': 'health-check/monitor/'
                                          }
                  }

        self._create_database_monitors(instances, alarm=alarm, **params)

        del params['healthcheck']
        del params['healthcheck_monitor']

        instances = self.get_databaseinfra_secondary_ips()
        self._create_database_monitors(instances, **params)


class MongoDBSingleZabbixProvider(ZabbixProvider):
    def create_database_monitors(self, alarm='yes'):
        instances = self.get_all_instances()
        self._create_database_monitors(instances, dbtype='mongodb',
                                       alarm=alarm)


class MongoDBHighAvailabilityZabbixProvider(ZabbixProvider):
    def create_database_monitors(self, alarm='yes'):
        instances = self.get_database_instances()
        self._create_database_monitors(instances, dbtype='mongodb',
                                       alarm='yes')

        instances = self.get_non_database_instances()
        self._create_database_monitors(instances, dbtype='mongodb',
                                       alarm='yes', arbiter='1')


class RedisZabbixProvider(ZabbixProvider):
    def get_params_for_instance(self, instance, **kwargs):
        monitor_type = kwargs['monitor_type']
        del kwargs['monitor_type']

        kwargs = {"address": instance.dns,
                  "uri": "/health-check/{}/".format(monitor_type),
                  "var": monitor_type,
                  "notes": self.get_databaseifra_name()
                  }
        return kwargs


class RedisSingleZabbixProvider(RedisZabbixProvider):
    def create_database_monitors(self, alarm='yes'):
        instances = self.get_database_instances()
        self._create_web_monitors(monitor_type='redis-con',
                                  instances=instances, regexp='WORKING',
                                  alarm=alarm)

        self._create_web_monitors(monitor_type='redis-mem',
                                  instances=instances, regexp='WORKING',
                                  alarm=alarm)


class RedisHighAvailabilityZabbixProvider(RedisZabbixProvider):
    def create_database_monitors(self, alarm='yes'):
        instances = self.get_database_instances()

        self._create_web_monitors(monitor_type='redis-con',
                                  instances=instances, regexp='WORKING',
                                  alarm=alarm)

        self._create_web_monitors(monitor_type='redis-mem',
                                  instances=instances, regexp='WORKING',
                                  alarm=alarm)

        instances = self.get_non_database_instances()
        self._create_web_monitors(instances=instances, regexp='WORKING',
                                  monitor_type='sentinel-con', alarm=alarm
                                  )

@@ -22,16 +22,29 @@
 *-%0Afrom 
+dbaas_zabbix.
 provider

Fix import to work with python 3.4