# Path: mongodb_consistent_backup/Errors.py
# class NotifyError(Error):
#     """Raised when an notify operation failed in an expected but unrecoverable way"""
#     pass
# 
# class OperationError(Error):
#     """Raised when an operation failed in an expected but unrecoverable way"""
#     pass


import logging
import sys
from pyzabbix import ZabbixMetric, ZabbixSender
from mongodb_consistent_backup.Errors import NotifyError, OperationError
from mongodb_consistent_backup.Pipeline import Task




class Zabbix(Task):
    def __init__(self, manager, config, timer, base_dir, backup_dir, **kwargs):
        super(Zabbix, self).__init__(self.__class__.__name__, manager, config, timer, base_dir, backup_dir, **kwargs)
        self.server     = self.config.notify.zabbix.server
        self.port       = self.config.notify.zabbix.port
        self.use_config = self.config.notify.zabbix.use_config
        self.key        = self.config.notify.zabbix.key
        self.nodename   = self.config.notify.zabbix.node
        self.success    = 0
        self.failed     = 2

        req_attrs = ['key']
        for attr in req_attrs:
            if not getattr(self, attr):
                raise OperationError('Zabbix notifier module requires attribute: %s!' % attr)

        try:
            self.notifier = ZabbixSender(
                use_config=self._use_config(),
                zabbix_server=self.server,
                zabbix_port=self.port,
            )
        except Exception, e:
            logging.error("Error initiating ZabbixSender! Error: %s" % e)

# Path: mongodb_consistent_backup/Errors.py
# class NotifyError(Error):
#     """Raised when an notify operation failed in an expected but unrecoverable way"""
#     pass
# 
# class OperationError(Error):
#     """Raised when an operation failed in an expected but unrecoverable way"""
#     pass


# Path: mongodb_consistent_backup/Notify/Zabbix/Zabbix.py
import logging
import sys
from pyzabbix import ZabbixMetric, ZabbixSender
from mongodb_consistent_backup.Errors import NotifyError, OperationError
from mongodb_consistent_backup.Pipeline import Task





class Zabbix(Task):
    def __init__(self, manager, config, timer, base_dir, backup_dir, **kwargs):
        super(Zabbix, self).__init__(self.__class__.__name__, manager, config, timer, base_dir, backup_dir, **kwargs)
        self.server     = self.config.notify.zabbix.server
        self.port       = self.config.notify.zabbix.port
        self.use_config = self.config.notify.zabbix.use_config
        self.key        = self.config.notify.zabbix.key
        self.nodename   = self.config.notify.zabbix.node
        self.success    = 0
        self.failed     = 2

        req_attrs = ['key']
        for attr in req_attrs:
            if not getattr(self, attr):
                raise OperationError('Zabbix notifier module requires attribute: %s!' % attr)

        try:
            self.notifier = ZabbixSender(
                use_config=self._use_config(),
                zabbix_server=self.server,
                zabbix_port=self.port,
            )
        except Exception, e:
            logging.error("Error initiating ZabbixSender! Error: %s" % e)

            raise OperationError(e)