Ejemplo n.º 1
0
    def __init__(self, mod_conf):
        """
        Module initialization

        mod_conf is a dictionary that contains:
        - all the variables declared in the module configuration file
        - a 'properties' value that is the module properties as defined globally in this file

        :param mod_conf: module configuration file as a dictionary
        """
        SnmpBooster.__init__(self, mod_conf)

        # pylint: disable=global-statement
        global logger
        logger = logging.getLogger('alignak.module.%s' % self.alias)

        logger.debug("inner properties: %s", self.__dict__)
        logger.debug("received configuration: %s", mod_conf.__dict__)
        logger.debug("loaded into: %s", self.loaded_into)

        self.last_check_mapping = {}
        self.offset_mapping = {}
    def __init__(self, mod_conf):
        SnmpBooster.__init__(self, mod_conf)
        self.nb_tick = 0

        # Read datasource files
        # Config validation
        current_file = None
        if not isinstance(self.datasource, dict):
            try:
                # Test if self.datasource_file, is file or directory
                # if file
                if os.path.isfile(self.datasource_file):
                    self.datasource = ConfigObj(self.datasource_file,
                                                interpolation='template')
                    logger.info("[SnmpBooster] [code 0902] Reading input "
                                "configuration file: "
                                "%s" % self.datasource_file)

                # if directory
                elif os.path.isdir(self.datasource_file):
                    if not self.datasource_file.endswith("/"):
                        self.datasource_file += "/"
                    files = glob.glob(os.path.join(self.datasource_file,
                                                   'Default*.ini')
                                      )
                    for current_file in files:
                        if self.datasource is None:
                            self.datasource = ConfigObj(current_file,
                                                        interpolation='template')
                        else:
                            ctemp = ConfigObj(current_file,
                                              interpolation='template')
                            self.datasource.merge(ctemp)
                            logger.info("[SnmpBooster] [code 0903] Reading "
                                        "input configuration file: "
                                        "%s" % current_file)
                else:
                    # Normal error with scheduler and poller module
                    # The configuration will be read in the database
                    raise IOError("[SnmpBooster] File or folder not "
                                  "found: %s" % self.datasource_file)

            # raise if reading error
            except Exception as exp:
                if current_file is not None:
                    error_message = ("[SnmpBooster] [code 0904] Datasource "
                                     "error while reading or merging in %s: "
                                     "`%s'" % (str(current_file), str(exp)))
                else:
                    error_message = ("[SnmpBooster] [code 0905] Datasource "
                                     "error while reading or merging: "
                                     "`%s'" % str(exp))
                logger.error(error_message)
                raise Exception(error_message)

        # Convert datasource to dict
        if isinstance(self.datasource, ConfigObj):
            try:
                self.datasource = self.datasource.dict()
            except Exception as exp:
                error_message = ("[SnmpBooster] [code 0906] Error during the "
                                 "config conversion: %s" % (str(exp)))
                logger.error(error_message)
                raise Exception(error_message)
    def __init__(self, mod_conf):
        """
        Module initialization

        mod_conf is a dictionary that contains:
        - all the variables declared in the module configuration file
        - a 'properties' value that is the module properties as defined globally in this file

        :param mod_conf: module configuration file as a dictionary
        """
        SnmpBooster.__init__(self, mod_conf)

        # pylint: disable=global-statement
        global logger
        logger = logging.getLogger('alignak.module.%s' % self.alias)

        logger.debug("inner properties: %s", self.__dict__)
        logger.debug("received configuration: %s", mod_conf.__dict__)
        logger.debug("loaded into: %s", self.loaded_into)

        self.nb_tick = 0

        # Read datasource files
        # Config validation
        current_file = None
        if not isinstance(self.datasource, dict):
            try:
                # Test if self.datasource_file, is file or directory
                # if file
                if os.path.isfile(self.datasource_file):
                    self.datasource = ConfigObj(self.datasource_file,
                                                interpolation='template')
                    logger.info("[SnmpBooster] [code 0902] Reading input "
                                "configuration file: "
                                "%s" % self.datasource_file)

                # if directory
                elif os.path.isdir(self.datasource_file):
                    if not self.datasource_file.endswith("/"):
                        self.datasource_file += "/"
                    files = glob.glob(
                        os.path.join(self.datasource_file, 'Default*.ini'))
                    for current_file in files:
                        if self.datasource is None:
                            self.datasource = ConfigObj(
                                current_file, interpolation='template')
                        else:
                            ctemp = ConfigObj(current_file,
                                              interpolation='template')
                            self.datasource.merge(ctemp)
                        logger.info("[SnmpBooster] [code 0903] Reading "
                                    "input configuration file: "
                                    "%s" % current_file)
                else:
                    # Normal error with scheduler and poller module
                    # The configuration will be read in the database
                    raise IOError("[SnmpBooster] File or folder not "
                                  "found: %s" % self.datasource_file)

            # raise if reading error
            except Exception as exp:
                if current_file is not None:
                    error_message = ("[SnmpBooster] [code 0904] Datasource "
                                     "error while reading or merging in %s: "
                                     "`%s'" % (str(current_file), str(exp)))
                else:
                    error_message = ("[SnmpBooster] [code 0905] Datasource "
                                     "error while reading or merging: "
                                     "`%s'" % str(exp))
                logger.error(error_message)
                raise Exception(error_message)

        # Convert datasource to dict
        if isinstance(self.datasource, ConfigObj):
            try:
                self.datasource = self.datasource.dict()
            except Exception as exp:
                error_message = ("[SnmpBooster] [code 0906] Error during the "
                                 "config conversion: %s" % (str(exp)))
                logger.error(error_message)
                raise Exception(error_message)
Ejemplo n.º 4
0
 def __init__(self, mod_conf):
     SnmpBooster.__init__(self, mod_conf)
     self.nb_tick = 0
    def __init__(self, mod_conf):
        SnmpBooster.__init__(self, mod_conf)
        self.nb_tick = 0

        # Read datasource files
        # Config validation
        current_file = None
        if not isinstance(self.datasource, dict):
            try:
                # Test if self.datasource_file, is file or directory
                # if file
                if os.path.isfile(self.datasource_file):
                    self.datasource = ConfigObj(self.datasource_file,
                                                interpolation='template')
                    logger.info("[SnmpBooster] [code 0902] Reading input "
                                "configuration file: "
                                "%s" % self.datasource_file)

                # if directory
                elif os.path.isdir(self.datasource_file):
                    if not self.datasource_file.endswith("/"):
                        self.datasource_file += "/"
                    files = glob.glob(
                        os.path.join(self.datasource_file, 'Default*.ini'))
                    for current_file in files:
                        if self.datasource is None:
                            self.datasource = ConfigObj(
                                current_file, interpolation='template')
                        else:
                            ctemp = ConfigObj(current_file,
                                              interpolation='template')
                            self.datasource.merge(ctemp)
                        logger.info("[SnmpBooster] [code 0903] Reading "
                                    "input configuration file: "
                                    "%s" % current_file)
                else:
                    # Normal error with scheduler and poller module
                    # The configuration will be read in the database
                    raise IOError("[SnmpBooster] File or folder not "
                                  "found: %s" % self.datasource_file)

            # raise if reading error
            except Exception as exp:
                if current_file is not None:
                    error_message = ("[SnmpBooster] [code 0904] Datasource "
                                     "error while reading or merging in %s: "
                                     "`%s'" % (str(current_file), str(exp)))
                else:
                    error_message = ("[SnmpBooster] [code 0905] Datasource "
                                     "error while reading or merging: "
                                     "`%s'" % str(exp))
                logger.error(error_message)
                raise Exception(error_message)

        # Convert datasource to dict
        if isinstance(self.datasource, ConfigObj):
            try:
                self.datasource = self.datasource.dict()
            except Exception as exp:
                error_message = ("[SnmpBooster] [code 0906] Error during the "
                                 "config conversion: %s" % (str(exp)))
                logger.error(error_message)
                raise Exception(error_message)
Ejemplo n.º 6
0
 def __init__(self, mod_conf):
     SnmpBooster.__init__(self, mod_conf)
     self.last_check_mapping = {}
     self.offset_mapping = {}
Ejemplo n.º 7
0
 def __init__(self, mod_conf):
     SnmpBooster.__init__(self, mod_conf)
 def __init__(self, mod_conf):
     SnmpBooster.__init__(self, mod_conf)
 def __init__(self, mod_conf):
     SnmpBooster.__init__(self, mod_conf)
     self.nb_tick = 0