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 """ BaseModule.__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__) self.url = getattr(mod_conf, "api_url", "http://localhost:5000") self.backend = Backend(self.url) self.backend.token = getattr(mod_conf, "token", "") self.backend_connected = False if self.backend.token == "": self.getToken( getattr(mod_conf, "username", ""), getattr(mod_conf, "password", ""), getattr(mod_conf, "allowgeneratetoken", False), )
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 """ BaseModule.__init__(self, mod_conf) # pylint: disable=global-statement global logger logger = logging.getLogger('alignak.module.%s' % self.alias) logger.setLevel(getattr(mod_conf, 'log_level', logging.INFO)) logger.debug("inner properties: %s", self.__dict__) logger.debug("received configuration: %s", mod_conf.__dict__) self.client_processes = int(getattr(mod_conf, 'client_processes', 1)) logger.info("Number of processes used by backend client: %s", self.client_processes) self.backend_count = int(getattr(mod_conf, 'backend_count', '50')) logger.info("backend pagination count: %d items", self.backend_count) logger.info("StatsD configuration: %s:%s, prefix: %s, enabled: %s", getattr(mod_conf, 'statsd_host', 'localhost'), int(getattr(mod_conf, 'statsd_port', '8125')), getattr(mod_conf, 'statsd_prefix', 'alignak'), (getattr(mod_conf, 'statsd_enabled', '0') != '0')) self.statsmgr = Stats() self.statsmgr.register( self.alias, 'module', statsd_host=getattr(mod_conf, 'statsd_host', 'localhost'), statsd_port=int(getattr(mod_conf, 'statsd_port', '8125')), statsd_prefix=getattr(mod_conf, 'statsd_prefix', 'alignak'), statsd_enabled=(getattr(mod_conf, 'statsd_enabled', '0') != '0')) self.url = getattr(mod_conf, 'api_url', 'http://localhost:5000') logger.info("Alignak backend endpoint: %s", self.url) self.backend = Backend(self.url, self.client_processes) self.backend.token = getattr(mod_conf, 'token', '') self.backend_connected = False self.backend_errors_count = 0 self.backend_username = getattr(mod_conf, 'username', '') self.backend_password = getattr(mod_conf, 'password', '') self.backend_generate = getattr(mod_conf, 'allowgeneratetoken', False) if not self.backend.token: logger.warning( "no user token configured. " "It is recommended to set a user token rather than a user login " "in the configuration. Trying to get a token from the provided " "user login information...") self.getToken() else: self.backend_connected = True
def __init__(self, mod_conf): BaseModule.__init__(self, mod_conf) self.version = "2.0.0" self.datasource_file = getattr(mod_conf, 'datasource', None) self.db_host = getattr(mod_conf, 'db_host', "127.0.0.1") self.db_port = to_int(getattr(mod_conf, 'db_port', 6379)) self.db_name = getattr(mod_conf, 'db_name', 'booster_snmp') self.loaded_by = getattr(mod_conf, 'loaded_by', None) self.datasource = None self.db_client = None self.i_am_dying = False
def __init__(self, mod_conf): BaseModule.__init__(self, mod_conf) self.url = getattr(mod_conf, 'api_url', 'http://localhost:5000') self.ref_live = { 'host': {}, 'service': {} } self.mapping = { 'host': {}, 'service': {} } self.hosts = {} self.services = {}
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.url = getattr(modconf, 'api_url', 'http://localhost:5000') self.config = {'commands': [], 'timeperiods': [], 'hosts': [], 'hostgroups': [], 'services': [], 'contacts': []} self.backend_ids = {'commands': {}, 'timeperiods': {}, 'hosts': {}, 'hostgroups': {}, 'contacts': {}}
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 """ BaseModule.__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__) self.host = getattr(mod_conf, 'host', '127.0.0.1') if self.host == '*': self.host = '' self.port = int(getattr(mod_conf, 'port', '5667')) self.backlog = int(getattr(mod_conf, 'backlog', '10')) self.buffer_length = int(getattr(mod_conf, 'buffer_length', '4096')) self.payload_length = int(getattr(mod_conf, 'payload_length', '-1')) self.encryption_method = int(getattr(mod_conf, 'encryption_method', '0')) self.password = getattr(mod_conf, 'password', '') if self.password == "" and self.encryption_method != 0: logger.error("No password specified whereas an encryption method is defined") logger.warning("Setting password to 'dummy' to avoid crash!") self.password = "******" self.max_packet_age = min(int(getattr(mod_conf, 'max_packet_age', '30')), 900) self.check_future_packet = bool(getattr(mod_conf, 'check_future_packet', 'False')) self.output_decoding = getattr(mod_conf, 'output_decoding', 'UTF-8') self.rng = random.Random(self.password) logger.info( "configuration, allowed hosts : '%s'(%s), buffer length: %s, " "payload length: %s, encryption: %s, max packet age: %s, check future packet: %s, " "backlog: %d", self.host, self.port, self.buffer_length, self.payload_length, self.encryption_method, self.max_packet_age, self.check_future_packet, self.backlog)
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 """ BaseModule.__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__) self.host = getattr(mod_conf, 'host', '127.0.0.1') if self.host == '*': self.host = '' self.port = int(getattr(mod_conf, 'port', '5667')) self.backlog = int(getattr(mod_conf, 'backlog', '10')) self.buffer_length = int(getattr(mod_conf, 'buffer_length', '4096')) self.payload_length = int(getattr(mod_conf, 'payload_length', '-1')) self.encryption_method = int(getattr(mod_conf, 'encryption_method', '0')) self.password = getattr(mod_conf, 'password', '') if self.password == "" and self.encryption_method != 0: logger.error("No password specified whereas an encryption method is defined") logger.warning("Setting password to 'dummy' to avoid crash!") self.password = "******" self.max_packet_age = min(int(getattr(mod_conf, 'max_packet_age', '30')), 900) self.check_future_packet = bool(getattr(mod_conf, 'check_future_packet', 'False')) self.output_decoding = getattr(mod_conf, 'output_decoding', 'UTF-8') self.rng = random.Random(self.password) logger.info("configuration, allowed hosts : '%s'(%s), buffer length: %s, " "payload length: %s, encryption: %s, max packet age: %s, " "check future packet: %s, backlog: %d", self.host, self.port, self.buffer_length, self.payload_length, self.encryption_method, self.max_packet_age, self.check_future_packet, self.backlog)
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 """ BaseModule.__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__) self.url = getattr(mod_conf, 'api_url', 'http://localhost:5000') self.backend = Backend(self.url) self.backend.token = getattr(mod_conf, 'token', '') self.backend_connected = False if self.backend.token == '': self.getToken(getattr(mod_conf, 'username', ''), getattr(mod_conf, 'password', ''), getattr(mod_conf, 'allowgeneratetoken', False)) self.logged_in = self.backendConnection() self.ref_live = { 'host': {}, 'service': {} } self.mapping = { 'host': {}, 'service': {} } self.hosts = {} self.services = {} self.loaded_hosts = False self.loaded_services = False
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 """ BaseModule.__init__(self, mod_conf) global logger # Update the logger to include the module alias in the logger name logger = logging.getLogger('alignak.module.%s' % self.alias) # Dump module inner properties and received configuration in the log logger.debug("inner properties: %s", self.__dict__) logger.debug("received configuration: %s", mod_conf.__dict__) # Options are the variables defined in the module configuration file self.option_1 = getattr(mod_conf, 'option_1', None) self.option_2 = getattr(mod_conf, 'option_2', None) self.option_3 = getattr(mod_conf, 'option_3', None)
def __init__(self, mod_conf): BaseModule.__init__(self, mod_conf)
def __init__(self, mod_conf): # pylint: disable=too-many-branches """Module initialization mod_conf is a dictionary that contains: - all the variables declared in the module configuration - a 'properties' value that is the module properties as defined globally in this file :param mod_conf: module configuration file as a dictionary """ BaseModule.__init__(self, mod_conf) # pylint: disable=global-statement global logger logger = logging.getLogger('alignak.module.%s' % self.alias) logger.setLevel(getattr(mod_conf, 'log_level', logging.INFO)) logger.debug("inner properties: %s", self.__dict__) logger.debug("received configuration: %s", mod_conf.__dict__) logger.info("loaded by the %s '%s'", self.my_daemon.type, self.my_daemon.name) # Output file target self.output_file = getattr(mod_conf, 'output_file', '') if 'ALIGNAK_HOSTS_STATS_FILE' in os.environ: self.output_file = os.environ['ALIGNAK_HOSTS_STATS_FILE'] # Graphite / InfluxDB targets self.graphite_enabled = (getattr(mod_conf, 'graphite_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'graphite_enabled', '0'), bool): self.graphite_enabled = getattr(mod_conf, 'graphite_enabled') self.influxdb_enabled = (getattr(mod_conf, 'influxdb_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'influxdb_enabled', '0'), bool): self.influxdb_enabled = getattr(mod_conf, 'influxdb_enabled') if self.influxdb_enabled and not influxdb_lib: logger.info( "Sending metrics to InfluxDB is enabled but the influxdb Python " "library is not installed. You should 'pip install influxdb'! " "As of now, sending to influxdb is disabled.") self.influxdb_enabled = False logger.info( "targets configuration: graphite: %s, influxdb: %s, file: %s", self.graphite_enabled, self.influxdb_enabled, self.output_file) if self.output_file: logger.warning( "Storing metrics in an output file is configured. Do not forget " "to regularly clean this file to avoid important disk usage!") self.enabled = getattr(mod_conf, 'enabled', '0') != '0' if isinstance(getattr(mod_conf, 'enabled', '0'), bool): self.enabled = getattr(mod_conf, 'enabled') if not self.output_file and not self.graphite_enabled and not self.influxdb_enabled: logger.warning( "The metrics sending module is enabled but no target is defined. You " "should set one of the 'output_file', or 'graphite_enabled' or " "'influxdb_enabled' parameter to specify where the metrics " "must be pushed! As of now, the module is disabled.") self.enabled = False # Hosts and services internal cache # - contain the hosts and services names and specific parameters # - updated with the initial hosts/services status broks self.hosts_cache = {} self.services_cache = {} # Do not ignore unknown hosts/services. If set, this parameter will make the module # ignore the provided broks until the initial status broks are received # Then the module will only manage metrics if hosts/services are known in the internal cache self.ignore_unknown = getattr(mod_conf, 'ignore_unknown', '1') == '1' if isinstance(getattr(mod_conf, 'ignore_unknown', '0'), bool): self.ignore_unknown = getattr(mod_conf, 'ignore_unknown') logger.info("ignoring unknown: %s", self.ignore_unknown) # Separate performance data multiple values self.multiple_values = re.compile(r'_(\d+)$') # Internal metrics cache self.my_metrics = [] self.metrics_flush_count = int( getattr(mod_conf, 'metrics_flush_count', '256')) self.last_failure = 0 self.metrics_flush_pause = int( os.getenv('ALIGNAK_STATS_FLUSH_PAUSE', '10')) self.log_metrics_flush_pause = False # Specific filter for host and services names for Graphite self.illegal_char_hostname = re.compile(r'[^a-zA-Z0-9_\-]') # Graphite target self.graphite_host = getattr(mod_conf, 'graphite_host', 'localhost') self.graphite_port = int(getattr(mod_conf, 'graphite_port', '2004')) self.carbon = None logger.info("graphite host/port: %s:%d", self.graphite_host, self.graphite_port) # optional prefix / suffix in graphite for Alignak data source self.graphite_data_source = \ sanitize_name(getattr(mod_conf, 'graphite_data_source', '')) self.graphite_prefix = getattr(mod_conf, 'graphite_prefix', '') self.realms_prefix = (getattr(mod_conf, 'realms_prefix', '0') != '0') if isinstance(getattr(mod_conf, 'realms_prefix', '0'), bool): self.realms_prefix = getattr(mod_conf, 'realms_prefix') logger.info("graphite prefix: %s, realm prefix: %s data source: %s", self.graphite_prefix, self.realms_prefix, self.graphite_data_source) if self.graphite_enabled and not self.graphite_host: logger.warning( "Graphite host name is not set, no metrics will be sent to Graphite!" ) self.graphite_enabled = False # InfluxDB target self.influxdb_host = getattr(mod_conf, 'influxdb_host', 'localhost') self.influxdb_port = int(getattr(mod_conf, 'influxdb_port', '8086')) self.influxdb_database = getattr(mod_conf, 'influxdb_database', 'alignak') # Default is empty - do not used authenticated connection self.influxdb_username = getattr(mod_conf, 'influxdb_username', '') self.influxdb_password = getattr(mod_conf, 'influxdb_password', '') # Default is empty - do not use a specific retention self.influxdb_retention_name = \ getattr(mod_conf, 'influxdb_retention_name', '') self.influxdb_retention_duration = \ getattr(mod_conf, 'influxdb_retention_duration', 'INF') self.influxdb_retention_replication = \ getattr(mod_conf, 'influxdb_retention_replication', '1') self.influx = None logger.info("influxdb host/port: %s:%d", self.influxdb_host, self.influxdb_port) logger.info("influxdb database: %s, retention: %s:%s:%s", self.influxdb_database, self.influxdb_retention_name, self.influxdb_retention_duration, self.influxdb_retention_replication) # optional tags list in influxdb for Alignak data source self.influxdb_tags = getattr(mod_conf, 'influxdb_tags', None) if self.influxdb_tags: tags_list = {} tags = self.influxdb_tags.split(',') for tag in tags: if '=' in tag: tag = tag.split('=') tags_list[tag[0]] = tag[1] if tags_list: self.influxdb_tags = tags_list logger.info("influxdb tags: %s", self.influxdb_tags) if self.influxdb_enabled and not self.influxdb_host: logger.warning( "InfluxDB host name is not set, no metrics will be sent to InfluxDB!" ) self.influxdb_enabled = False # Used to reset check time into the scheduled time. # Carbon/graphite does not like latency data and creates blanks in graphs # Every data with "small" latency will be considered create at scheduled time self.ignore_latency_limit = int( getattr(mod_conf, 'ignore_latency_limit', '0')) if self.ignore_latency_limit < 0: self.ignore_latency_limit = 0 # service name to use for host check self.hostcheck = sanitize_name( getattr(mod_conf, 'host_check', 'hostcheck')) # Send warning, critical, min, max self.send_warning = bool(getattr(mod_conf, 'send_warning', False)) logger.info("send warning metrics: %d", self.send_warning) self.send_critical = bool(getattr(mod_conf, 'send_critical', False)) logger.info("send critical metrics: %d", self.send_critical) self.send_min = bool(getattr(mod_conf, 'send_min', False)) logger.info("send min metrics: %d", self.send_min) self.send_max = bool(getattr(mod_conf, 'send_max', False)) logger.info("send max metrics: %d", self.send_max) if not self.enabled: logger.warning( "inner metrics module is loaded but is not enabled.") return logger.info("metrics module is loaded and enabled")
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.hosts_cache = {} self.services_cache = {} # Separate perfdata multiple values self.multival = re_compile(r'_(\d+)$') # Specific filter to allow metrics to include '.' for Graphite self.illegal_char_metric = re_compile(r'[^a-zA-Z0-9_.\-]') # Specific filter for host and services names for Graphite self.illegal_char_hostname = re_compile(r'[^a-zA-Z0-9_\-]') self.host = getattr(modconf, 'host', 'localhost') self.port = int(getattr(modconf, 'port', '2003')) logger.info("[Graphite] Configuration - host/port: %s:%d", self.host, self.port) # Connection and cache management self.con = None self.cache_max_length = int(getattr(modconf, 'cache_max_length', '1000')) logger.info('[Graphite] Configuration - maximum cache size: %d packets', self.cache_max_length) self.cache_commit_volume = int(getattr(modconf, 'cache_commit_volume', '100')) logger.info('[Graphite] Configuration - maximum cache commit volume: %d packets', self.cache_commit_volume) self.cache = deque(maxlen=self.cache_max_length) # Used to reset check time into the scheduled time. # Carbon/graphite does not like latency data and creates blanks in graphs # Every data with "small" latency will be considered create at scheduled time self.ignore_latency_limit = int(getattr(modconf, 'ignore_latency_limit', '0')) if self.ignore_latency_limit < 0: self.ignore_latency_limit = 0 # service name to use for host check self.hostcheck = getattr(modconf, 'hostcheck', '') # optional "sub-folder" in graphite to signal shinken data source self.graphite_data_source = self.illegal_char_metric.sub('_', getattr(modconf, 'graphite_data_source', '')) logger.info("[Graphite] Configuration - Graphite data source: %s", self.graphite_data_source) # optional perfdatas to be filtered self.filtered_metrics = {} filters = getattr(modconf, 'filter', []) if isinstance(filters, str) or isinstance(filters, unicode): filters = [filters] for filter in filters: try: filtered_service, filtered_metric = filter.split(':') self.filtered_metrics[filtered_service] = [] if filtered_metric: self.filtered_metrics[filtered_service] = filtered_metric.split(',') except: logger.warning("[Graphite] Configuration - ignoring badly declared filtered " "metric: %s", filter) for service in self.filtered_metrics: logger.info("[Graphite] Configuration - Filtered metrics: %s - %s", service, self.filtered_metrics[service]) # Send warning, critical, min, max self.send_warning = bool(getattr(modconf, 'send_warning', False)) logger.info("[Graphite] Configuration - send warning metrics: %d", self.send_warning) self.send_critical = bool(getattr(modconf, 'send_critical', False)) logger.info("[Graphite] Configuration - send critical metrics: %d", self.send_critical) self.send_min = bool(getattr(modconf, 'send_min', False)) logger.info("[Graphite] Configuration - send min metrics: %d", self.send_min) self.send_max = bool(getattr(modconf, 'send_max', False)) logger.info("[Graphite] Configuration - send max metrics: %d", self.send_max)
def __init__(self, mod_conf): """Module initialization mod_conf is a dictionary that contains: - all the variables declared in the module configuration - a 'properties' value that is the module properties as defined globally in this file :param mod_conf: module configuration file as a dictionary """ BaseModule.__init__(self, mod_conf) # pylint: disable=global-statement global logger logger = logging.getLogger('alignak.module.%s' % self.alias) logger.setLevel(getattr(mod_conf, 'log_level', logging.INFO)) logger.debug("inner properties: %s", self.__dict__) logger.info("received configuration: %s", mod_conf.__dict__) logger.info("loaded by the %s '%s'", self.my_daemon.type, self.my_daemon.name) stats_host = getattr(mod_conf, 'statsd_host', 'localhost') stats_port = int(getattr(mod_conf, 'statsd_port', '8125')) stats_prefix = getattr(mod_conf, 'statsd_prefix', 'alignak') statsd_enabled = (getattr(mod_conf, 'statsd_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'statsd_enabled', '0'), bool): statsd_enabled = getattr(mod_conf, 'statsd_enabled') graphite_enabled = (getattr(mod_conf, 'graphite_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'graphite_enabled', '0'), bool): graphite_enabled = getattr(mod_conf, 'graphite_enabled') logger.info( "StatsD configuration: %s:%s, prefix: %s, enabled: %s, graphite: %s", stats_host, stats_port, stats_prefix, statsd_enabled, graphite_enabled) self.statsmgr = Stats() # Configure our Stats manager if not graphite_enabled: self.statsmgr.register(self.alias, 'module', statsd_host=stats_host, statsd_port=stats_port, statsd_prefix=stats_prefix, statsd_enabled=statsd_enabled) else: self.statsmgr.connect(self.alias, 'module', host=stats_host, port=stats_port, prefix=stats_prefix, enabled=True) self.enabled = getattr(mod_conf, 'enabled', '0') != '0' if isinstance(getattr(mod_conf, 'enabled', '0'), bool): self.enabled = getattr(mod_conf, 'enabled') self.retention_file = getattr(mod_conf, 'retention_file', None) if not self.enabled: logger.warning( "inner retention module is loaded but is not enabled.") return if not self.retention_file: self.retention_file = os.path.join(tempfile.gettempdir(), 'alignak-retention-%s.json') if '%s' in self.retention_file: self.retention_file = self.retention_file % self.my_daemon.name logger.info("inner retention module, enabled: %s, retention file: %s", self.enabled, self.retention_file)
def __init__(self, mod_conf): # pylint: disable=too-many-branches """Module initialization mod_conf is a dictionary that contains: - all the variables declared in the module configuration - a 'properties' value that is the module properties as defined globally in this file :param mod_conf: module configuration file as a dictionary """ BaseModule.__init__(self, mod_conf) # pylint: disable=global-statement global logger logger = logging.getLogger('alignak.module.%s' % self.alias) logger.setLevel(getattr(mod_conf, 'log_level', logging.INFO)) logger.debug("inner properties: %s", self.__dict__) logger.debug("received configuration: %s", mod_conf.__dict__) logger.info("loaded by the %s '%s'", self.my_daemon.type, self.my_daemon.name) # Output file target self.output_file = getattr(mod_conf, 'output_file', '') if 'ALIGNAK_HOSTS_STATS_FILE' in os.environ: self.output_file = os.environ['ALIGNAK_HOSTS_STATS_FILE'] # Graphite / InfluxDB targets self.graphite_enabled = (getattr(mod_conf, 'graphite_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'graphite_enabled', '0'), bool): self.graphite_enabled = getattr(mod_conf, 'graphite_enabled') self.influxdb_enabled = (getattr(mod_conf, 'influxdb_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'influxdb_enabled', '0'), bool): self.influxdb_enabled = getattr(mod_conf, 'influxdb_enabled') if self.influxdb_enabled and not influxdb_lib: logger.info("Sending metrics to InfluxDB is enabled but the influxdb Python " "library is not installed. You should 'pip install influxdb'! " "As of now, sending to influxdb is disabled.") self.influxdb_enabled = False logger.info("targets configuration: graphite: %s, influxdb: %s, file: %s", self.graphite_enabled, self.influxdb_enabled, self.output_file) if self.output_file: logger.warning("Storing metrics in an output file is configured. Do not forget " "to regularly clean this file to avoid important disk usage!") self.enabled = getattr(mod_conf, 'enabled', '0') != '0' if isinstance(getattr(mod_conf, 'enabled', '0'), bool): self.enabled = getattr(mod_conf, 'enabled') if not self.output_file and not self.graphite_enabled and not self.influxdb_enabled: logger.warning("The metrics sending module is enabled but no target is defined. You " "should set one of the 'output_file', or 'graphite_enabled' or " "'influxdb_enabled' parameter to specify where the metrics " "must be pushed! As of now, the module is disabled.") self.enabled = False # Hosts and services internal cache # - contain the hosts and services names and specific parameters # - updated with the initial hosts/services status broks self.hosts_cache = {} self.services_cache = {} # Do not ignore unknown hosts/services. If set, this parameter will make the module # ignore the provided broks until the initial status broks are received # Then the module will only manage metrics if hosts/services are known in the internal cache self.ignore_unknown = getattr(mod_conf, 'ignore_unknown', '1') == '1' if isinstance(getattr(mod_conf, 'ignore_unknown', '0'), bool): self.ignore_unknown = getattr(mod_conf, 'ignore_unknown') logger.info("ignoring unknown: %s", self.ignore_unknown) # Separate performance data multiple values self.multiple_values = re.compile(r'_(\d+)$') # Internal metrics cache self.my_metrics = [] self.metrics_flush_count = int(getattr(mod_conf, 'metrics_flush_count', '256')) self.last_failure = 0 self.metrics_flush_pause = int(os.getenv('ALIGNAK_STATS_FLUSH_PAUSE', '10')) self.log_metrics_flush_pause = False # Specific filter for host and services names for Graphite self.illegal_char_hostname = re.compile(r'[^a-zA-Z0-9_\-]') # Graphite target self.graphite_host = getattr(mod_conf, 'graphite_host', 'localhost') self.graphite_port = int(getattr(mod_conf, 'graphite_port', '2004')) self.carbon = None logger.info("graphite host/port: %s:%d", self.graphite_host, self.graphite_port) # optional prefix / suffix in graphite for Alignak data source self.graphite_data_source = \ sanitize_name(getattr(mod_conf, 'graphite_data_source', '')) self.graphite_prefix = getattr(mod_conf, 'graphite_prefix', '') self.realms_prefix = (getattr(mod_conf, 'realms_prefix', '0') != '0') if isinstance(getattr(mod_conf, 'realms_prefix', '0'), bool): self.realms_prefix = getattr(mod_conf, 'realms_prefix') logger.info("graphite prefix: %s, realm prefix: %s data source: %s", self.graphite_prefix, self.realms_prefix, self.graphite_data_source) if self.graphite_enabled and not self.graphite_host: logger.warning("Graphite host name is not set, no metrics will be sent to Graphite!") self.graphite_enabled = False # InfluxDB target self.influxdb_host = getattr(mod_conf, 'influxdb_host', 'localhost') self.influxdb_port = int(getattr(mod_conf, 'influxdb_port', '8086')) self.influxdb_database = getattr(mod_conf, 'influxdb_database', 'alignak') # Default is empty - do not used authenticated connection self.influxdb_username = getattr(mod_conf, 'influxdb_username', '') self.influxdb_password = getattr(mod_conf, 'influxdb_password', '') # Default is empty - do not use a specific retention self.influxdb_retention_name = \ getattr(mod_conf, 'influxdb_retention_name', '') self.influxdb_retention_duration = \ getattr(mod_conf, 'influxdb_retention_duration', 'INF') self.influxdb_retention_replication = \ getattr(mod_conf, 'influxdb_retention_replication', '1') self.influx = None logger.info("influxdb host/port: %s:%d", self.influxdb_host, self.influxdb_port) logger.info("influxdb database: %s, retention: %s:%s:%s", self.influxdb_database, self.influxdb_retention_name, self.influxdb_retention_duration, self.influxdb_retention_replication) # optional tags list in influxdb for Alignak data source self.influxdb_tags = getattr(mod_conf, 'influxdb_tags', None) if self.influxdb_tags: tags_list = {} tags = self.influxdb_tags.split(',') for tag in tags: if '=' in tag: tag = tag.split('=') tags_list[tag[0]] = tag[1] if tags_list: self.influxdb_tags = tags_list logger.info("influxdb tags: %s", self.influxdb_tags) if self.influxdb_enabled and not self.influxdb_host: logger.warning("InfluxDB host name is not set, no metrics will be sent to InfluxDB!") self.influxdb_enabled = False # Used to reset check time into the scheduled time. # Carbon/graphite does not like latency data and creates blanks in graphs # Every data with "small" latency will be considered create at scheduled time self.ignore_latency_limit = int(getattr(mod_conf, 'ignore_latency_limit', '0')) if self.ignore_latency_limit < 0: self.ignore_latency_limit = 0 # service name to use for host check self.hostcheck = sanitize_name(getattr(mod_conf, 'host_check', 'hostcheck')) # Send warning, critical, min, max self.send_warning = bool(getattr(mod_conf, 'send_warning', False)) logger.info("send warning metrics: %d", self.send_warning) self.send_critical = bool(getattr(mod_conf, 'send_critical', False)) logger.info("send critical metrics: %d", self.send_critical) self.send_min = bool(getattr(mod_conf, 'send_min', False)) logger.info("send min metrics: %d", self.send_min) self.send_max = bool(getattr(mod_conf, 'send_max', False)) logger.info("send max metrics: %d", self.send_max) if not self.enabled: logger.warning("inner metrics module is loaded but is not enabled.") return logger.info("metrics module is loaded and enabled")
def __init__(self, mod_conf): # pylint: disable=too-many-branches """Module initialization mod_conf is a dictionary that contains: - all the variables declared in the module configuration - a 'properties' value that is the module properties as defined globally in this file If some environment variables exist the metrics they will take precedence over the configuration parameters 'ALIGNAK_RETENTION_DIR' the retention files directory 'ALIGNAK_RETENTION_FILE' the retention unique file for the current scheduler :param mod_conf: module configuration file as a dictionary """ BaseModule.__init__(self, mod_conf) # pylint: disable=global-statement global logger logger = logging.getLogger('alignak.module.%s' % self.alias) logger.setLevel(getattr(mod_conf, 'log_level', logging.INFO)) logger.debug("inner properties: %s", self.__dict__) logger.info("received configuration: %s", mod_conf.__dict__) logger.info("loaded by the %s '%s'", self.my_daemon.type, self.my_daemon.name) stats_host = getattr(mod_conf, 'statsd_host', 'localhost') stats_port = int(getattr(mod_conf, 'statsd_port', '8125')) stats_prefix = getattr(mod_conf, 'statsd_prefix', 'alignak') statsd_enabled = (getattr(mod_conf, 'statsd_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'statsd_enabled', '0'), bool): statsd_enabled = getattr(mod_conf, 'statsd_enabled') graphite_enabled = (getattr(mod_conf, 'graphite_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'graphite_enabled', '0'), bool): graphite_enabled = getattr(mod_conf, 'graphite_enabled') logger.info("StatsD configuration: %s:%s, prefix: %s, enabled: %s, graphite: %s", stats_host, stats_port, stats_prefix, statsd_enabled, graphite_enabled) self.statsmgr = Stats() # Configure our Stats manager if not graphite_enabled: self.statsmgr.register(self.alias, 'module', statsd_host=stats_host, statsd_port=stats_port, statsd_prefix=stats_prefix, statsd_enabled=statsd_enabled) else: self.statsmgr.connect(self.alias, 'module', host=stats_host, port=stats_port, prefix=stats_prefix, enabled=True) self.enabled = getattr(mod_conf, 'enabled', '0') != '0' if isinstance(getattr(mod_conf, 'enabled', '0'), bool): self.enabled = getattr(mod_conf, 'enabled') if not self.enabled: logger.warning("inner retention module is loaded but is not enabled.") return self.retention_dir = getattr(mod_conf, 'retention_dir', None) if os.getenv('ALIGNAK_RETENTION_DIR', None): self.retention_dir = os.getenv('ALIGNAK_RETENTION_DIR', None) if not self.retention_dir: self.retention_dir = tempfile.gettempdir() if '%s' in self.retention_dir: self.retention_dir = self.retention_dir % self.my_daemon.name self.retention_file = getattr(mod_conf, 'retention_file', None) logger.info("inner retention module, retention file: %s", self.retention_file) if os.getenv('ALIGNAK_RETENTION_FILE', None): self.retention_file = os.getenv('ALIGNAK_RETENTION_FILE', None) if self.retention_file is None: self.retention_file = os.path.join(self.retention_dir, 'alignak-retention-%s.json') if '%s' in self.retention_file: self.retention_file = self.retention_file % self.my_daemon.name if self.retention_dir and not os.path.isdir(self.retention_dir): logger.info("The configured state retention directory (%s) does not exist. " "Trying to create....", self.retention_dir) try: os.makedirs(self.retention_dir) logger.error("Retention directory created.") except OSError as exp: logger.error("Directory creation failed because: %s", str(exp)) self.retention_dir = '/tmp' logger.info("The retention directory is set to: %s", self.retention_dir) logger.info("inner retention module, enabled: %s, retention dir: %s, retention file: %s", self.enabled, self.retention_dir, self.retention_file) if not self.retention_file: logger.info("The retention file is set as an empty file. The module will " "create a file for each host in the retention directory.") else: logger.info("The retention file is set as a unique scheduler file. " "The module will create one file for each scheduler " "with all hosts in the retention directory.")
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 """ BaseModule.__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__) self.my_arbiter = None self.bypass_verify_mode = int(getattr(mod_conf, 'bypass_verify_mode', 0)) == 1 logger.info("bypass objects loading when Arbiter is in verify mode: %s", self.bypass_verify_mode) self.verify_modification = int(getattr(mod_conf, 'verify_modification', 5)) logger.info("configuration reload check period: %s minutes", self.verify_modification) self.action_check = int(getattr(mod_conf, 'action_check', 15)) logger.info("actions check period: %s seconds", self.action_check) self.daemons_state = int(getattr(mod_conf, 'daemons_state', 60)) logger.info("daemons state update period: %s seconds", self.daemons_state) self.next_check = 0 self.next_action_check = 0 self.next_daemons_state = 0 # Configuration load/reload self.backend_date_format = "%a, %d %b %Y %H:%M:%S GMT" self.time_loaded_conf = datetime.utcnow().strftime(self.backend_date_format) self.configuration_reload_required = False self.configuration_reload_changelog = [] self.configraw = {} self.highlevelrealm = { 'level': 30000, 'name': '' } self.daemonlist = {'arbiter': {}, 'scheduler': {}, 'poller': {}, 'reactionner': {}, 'receiver': {}, 'broker': {}} self.config = {'commands': [], 'timeperiods': [], 'hosts': [], 'hostgroups': [], 'services': [], 'contacts': [], 'contactgroups': [], 'servicegroups': [], 'realms': [], 'hostdependencies': [], 'hostescalations': [], 'servicedependencies': [], 'serviceescalations': [], 'triggers': []} self.default_tp_always = None self.default_tp_never = None self.default_host_check_command = None self.default_service_check_command = None self.default_user = None self.alignak_configuration = {}
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.surveil_api_url = getattr(modconf, 'surveil_api_url', None) self.surveil_auth_url = getattr(modconf, 'surveil_auth_url', None) self.surveil_version = getattr(modconf, 'surveil_version', None) self.surveil_client = None
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 """ BaseModule.__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__) self.my_arbiter = None # Alignak backend importation script is running self.backend_import = False if 'ALIGNAK_BACKEND_IMPORT_RUN' in os.environ and os.environ['ALIGNAK_BACKEND_IMPORT_RUN']: logger.info("Alignak backend importation script is active.") self.backend_import = True self.url = getattr(mod_conf, 'api_url', 'http://localhost:5000') self.backend = Backend(self.url) self.backend.token = getattr(mod_conf, 'token', '') self.backend_connected = False if self.backend.token == '': self.getToken(getattr(mod_conf, 'username', ''), getattr(mod_conf, 'password', ''), getattr(mod_conf, 'allowgeneratetoken', False)) self.bypass_verify_mode = int(getattr(mod_conf, 'bypass_verify_mode', 0)) == 1 logger.info( "bypass objects loading when Arbiter is in verify mode: %s", self.bypass_verify_mode ) self.verify_modification = int(getattr(mod_conf, 'verify_modification', 5)) logger.info( "configuration reload check period: %s minutes", self.verify_modification ) self.action_check = int(getattr(mod_conf, 'action_check', 15)) logger.info( "actions check period: %s seconds", self.action_check ) self.next_check = 0 self.next_action_check = 0 self.time_loaded_conf = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT") self.configraw = {} self.config = {'commands': [], 'timeperiods': [], 'hosts': [], 'hostgroups': [], 'services': [], 'contacts': [], 'contactgroups': [], 'servicegroups': [], 'realms': [], 'hostdependencies': [], 'hostescalations': [], 'servicedependencies': [], 'serviceescalations': [], 'triggers': []}
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 """ BaseModule.__init__(self, mod_conf) # pylint: disable=global-statement global logger logger = logging.getLogger('alignak.module.%s' % self.alias) logger.setLevel(getattr(mod_conf, 'log_level', logging.INFO)) logger.debug("inner properties: %s", self.__dict__) logger.debug("received configuration: %s", mod_conf.__dict__) self.client_processes = int(getattr(mod_conf, 'client_processes', 1)) logger.info("Number of processes used by backend client: %s", self.client_processes) self.default_realm = None logger.info("StatsD configuration: %s:%s, prefix: %s, enabled: %s", getattr(mod_conf, 'statsd_host', 'localhost'), int(getattr(mod_conf, 'statsd_port', '8125')), getattr(mod_conf, 'statsd_prefix', 'alignak'), (getattr(mod_conf, 'statsd_enabled', '0') != '0')) self.statsmgr = Stats() self.statsmgr.register( self.alias, 'module', statsd_host=getattr(mod_conf, 'statsd_host', 'localhost'), statsd_port=int(getattr(mod_conf, 'statsd_port', '8125')), statsd_prefix=getattr(mod_conf, 'statsd_prefix', 'alignak'), statsd_enabled=(getattr(mod_conf, 'statsd_enabled', '0') != '0')) self.url = getattr(mod_conf, 'api_url', 'http://localhost:5000') logger.info("Alignak backend endpoint: %s", self.url) self.backend_connected = False self.backend_connection_retry_planned = 0 try: self.backend_connection_retry_delay = int( getattr(mod_conf, 'backend_connection_retry_delay', '10')) except ValueError: self.backend_connection_retry_delay = 10 logger.info("backend connection retry delay: %.2f seconds", self.backend_connection_retry_delay) self.backend_errors_count = 0 self.backend_username = getattr(mod_conf, 'username', '') self.backend_password = getattr(mod_conf, 'password', '') self.backend_generate = getattr(mod_conf, 'allowgeneratetoken', False) self.backend_count = int(getattr(mod_conf, 'backend_count', '50')) logger.info("backend pagination count: %d items", self.backend_count) self.backend_token = getattr(mod_conf, 'token', '') self.backend = Backend(self.url, self.client_processes) self.manage_update_program_status = getattr(mod_conf, 'update_program_status', '0') == '1' logger.info("manage update_program_status broks: %s", self.manage_update_program_status) # Log in to the backend self.logged_in = False self.backend_connected = self.backend_connection() # Get the default realm self.default_realm = self.get_default_realm() self.ref_live = {'host': {}, 'service': {}, 'user': {}} self.mapping = {'host': {}, 'service': {}, 'user': {}} # Objects reference self.load_protect_delay = int( getattr(mod_conf, 'load_protect_delay', '300')) self.last_load = 0 # Backend to be posted data self.logcheckresults = []
def __init__(self, mod_conf): """Module initialization mod_conf is a dictionary that contains: - all the variables declared in the module configuration - a 'properties' value that is the module properties as defined globally in this file :param mod_conf: module configuration file as a dictionary """ BaseModule.__init__(self, mod_conf) # pylint: disable=global-statement global logger logger = logging.getLogger('alignak.module.%s' % self.alias) logger.setLevel(getattr(mod_conf, 'log_level', logging.INFO)) logger.debug("inner properties: %s", self.__dict__) logger.info("received configuration: %s", mod_conf.__dict__) logger.info("loaded by the %s '%s'", self.my_daemon.type, self.my_daemon.name) stats_host = getattr(mod_conf, 'statsd_host', 'localhost') stats_port = int(getattr(mod_conf, 'statsd_port', '8125')) stats_prefix = getattr(mod_conf, 'statsd_prefix', 'alignak') statsd_enabled = (getattr(mod_conf, 'statsd_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'statsd_enabled', '0'), bool): statsd_enabled = getattr(mod_conf, 'statsd_enabled') graphite_enabled = (getattr(mod_conf, 'graphite_enabled', '0') != '0') if isinstance(getattr(mod_conf, 'graphite_enabled', '0'), bool): graphite_enabled = getattr(mod_conf, 'graphite_enabled') logger.info("StatsD configuration: %s:%s, prefix: %s, enabled: %s, graphite: %s", stats_host, stats_port, stats_prefix, statsd_enabled, graphite_enabled) self.statsmgr = Stats() # Configure our Stats manager if not graphite_enabled: self.statsmgr.register(self.alias, 'module', statsd_host=stats_host, statsd_port=stats_port, statsd_prefix=stats_prefix, statsd_enabled=statsd_enabled) else: self.statsmgr.connect(self.alias, 'module', host=stats_host, port=stats_port, prefix=stats_prefix, enabled=True) self.enabled = getattr(mod_conf, 'enabled', '0') != '0' if isinstance(getattr(mod_conf, 'enabled', '0'), bool): self.enabled = getattr(mod_conf, 'enabled') # Hosts and services internal cache # Do not ignore unknown hosts/services. If set, this parameter will make the module # ignore the provided broks until the initial status broks are received self.ignore_unknown = getattr(mod_conf, 'ignore_unknown', '1') == '1' logger.info("ignoring unknown: %s", self.ignore_unknown) if isinstance(getattr(mod_conf, 'ignore_unknown', '0'), bool): self.ignore_unknown = getattr(mod_conf, 'ignore_unknown') logger.info("ignoring unknown: %s", self.ignore_unknown) self.hosts_cache = {} self.services_cache = {} # Separate performance data multiple values self.multival = re.compile(r'_(\d+)$') # Graphite socket connection and cache management # self.con = None # Graphite connection self.outer_stats = Stats() # Graphite connection self.carbon = None self.my_metrics = [] self.metrics_flush_count = int(getattr(mod_conf, 'metrics_flush_count', '64')) # Specific filter to allow metrics to include '.' for Graphite self.illegal_char_metric = re.compile(r'[^a-zA-Z0-9_.\-]') # Specific filter for host and services names for Graphite self.illegal_char_hostname = re.compile(r'[^a-zA-Z0-9_\-]') self.host = getattr(mod_conf, 'graphite_host', 'localhost') self.port = int(getattr(mod_conf, 'graphite_port', '2004')) self.prefix = getattr(mod_conf, 'graphite_prefix', '') logger.info("graphite host/port: %s:%d, prefix: %s, flush every %d metrics", self.host, self.port, self.prefix, self.metrics_flush_count) if not self.host: logger.warning("Graphite host name is not set, no metrics will be sent to Graphite!") self.output_file = getattr(mod_conf, 'output_file', '') if 'ALIGNAK_HOSTS_STATS_FILE' in os.environ: self.output_file = os.environ['ALIGNAK_HOSTS_STATS_FILE'] if self.output_file: logger.info("output file: %s", self.output_file) # Used to reset check time into the scheduled time. # Carbon/graphite does not like latency data and creates blanks in graphs # Every data with "small" latency will be considered create at scheduled time self.ignore_latency_limit = int(getattr(mod_conf, 'ignore_latency_limit', '0')) if self.ignore_latency_limit < 0: self.ignore_latency_limit = 0 # service name to use for host check self.hostcheck = getattr(mod_conf, 'hostcheck', '') # optional "sub-folder" in graphite for Alignak data source self.graphite_data_source = \ self.illegal_char_metric.sub('_', getattr(mod_conf, 'graphite_data_source', '')) logger.info("graphite data source: %s", self.graphite_data_source) # Send warning, critical, min, max self.send_warning = bool(getattr(mod_conf, 'send_warning', False)) logger.info("send warning metrics: %d", self.send_warning) self.send_critical = bool(getattr(mod_conf, 'send_critical', False)) logger.info("send critical metrics: %d", self.send_critical) self.send_min = bool(getattr(mod_conf, 'send_min', False)) logger.info("send min metrics: %d", self.send_min) self.send_max = bool(getattr(mod_conf, 'send_max', False)) logger.info("send max metrics: %d", self.send_max) if not self.enabled: logger.warning("inner metrics module is loaded but is not enabled.") return logger.info("metrics module is loaded and enabled")
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.url = getattr(modconf, 'api_url', 'http://localhost:5000')