def create_and_link_downtimes(self, raw_objects, all_obj): #first service for obj_cfg in raw_objects['servicedowntime']: print "Managing", obj_cfg host_name = obj_cfg['host_name'] service_description = obj_cfg['service_description'] srv = all_obj['service'].find_srv_by_name_and_hostname( host_name, service_description) print "Find my service", srv if srv is not None: dwn = Downtime(srv, int(obj_cfg['start_time']), int(obj_cfg['end_time']), to_bool(obj_cfg['fixed']), int(obj_cfg['triggered_by']), int(obj_cfg['duration']), obj_cfg['author'], obj_cfg['comment']) print "Created dwn", dwn srv.add_downtime(dwn) #then hosts for obj_cfg in raw_objects['hostdowntime']: print "Managing", obj_cfg host_name = obj_cfg['host_name'] hst = all_obj['host'].find_by_name(host_name) print "Find my host", hst if hst is not None: dwn = Downtime(hst, int(obj_cfg['start_time']), int(obj_cfg['end_time']), to_bool(obj_cfg['fixed']), int(obj_cfg['triggered_by']), int(obj_cfg['duration']), obj_cfg['author'], obj_cfg['comment']) print "Created dwn", dwn hst.add_downtime(dwn)
def get_launch(): print "Got forms in /newhosts/launch page" names = app.request.forms.get('names', '') use_nmap = to_bool(app.request.forms.get('use_nmap', '0')) use_vmware = to_bool(app.request.forms.get('use_vmware', '0')) print "Got in request form" print names print 'nmap?', use_nmap print 'vmware?', use_vmware # We are putting a ask ask in the database i = random.randint(1, 65535) scan_ask = { '_id': i, 'names': names, 'use_nmap': use_nmap, 'use_vmware': use_vmware, 'state': 'pending', 'creation': int(time.time()) } print "Saving", scan_ask, "in", app.db.scans r = app.db.scans.save(scan_ask) # We just want the id as string, not the object print "We create the scan", i app.ask_new_scan(i) return {'app': app}
def get_launch(): user = app.get_user_auth() if not user: redirect("/user/login") print "Got forms in /newhosts/launch page" names = app.request.forms.get('names', '') use_nmap = to_bool(app.request.forms.get('use_nmap', '0')) use_vmware = to_bool(app.request.forms.get('use_vmware', '0')) print "Got in request form" print names print 'nmap?', use_nmap print 'vmware?', use_vmware # We are putting a ask ask in the database i = random.randint(1, 65535) scan_ask = {'_id': i, 'names': names, 'use_nmap': use_nmap, 'use_vmware': use_vmware, 'state': 'pending', 'creation': int(time.time())} print "Saving", scan_ask, "in", app.db.scans r = app.db.scans.save(scan_ask) # We just want the id as string, not the object print "We create the scan", i app.ask_new_scan(i) return {'app': app, 'user': user}
def create_and_link_comments(self, raw_objects, all_obj): #first service for obj_cfg in raw_objects['servicecomment']: #print "Managing", obj_cfg host_name = obj_cfg['host_name'] service_description = obj_cfg['service_description'] srv = all_obj['service'].find_srv_by_name_and_hostname( host_name, service_description) #print "Find my service", srv if srv is not None: cmd = Comment(srv, to_bool(obj_cfg['persistent']), obj_cfg['author'], obj_cfg['comment_data'], 1, int(obj_cfg['entry_type']), int(obj_cfg['source']), to_bool(obj_cfg['expires']), int(obj_cfg['expire_time'])) #print "Created cmd", cmd srv.add_comment(cmd) #then hosts for obj_cfg in raw_objects['hostcomment']: #print "Managing", obj_cfg host_name = obj_cfg['host_name'] hst = all_obj['host'].find_by_name(host_name) #print "Find my host", hst if hst is not None: cmd = Comment(hst, to_bool(obj_cfg['persistent']), obj_cfg['author'], obj_cfg['comment_data'], 1, int(obj_cfg['entry_type']), int(obj_cfg['source']), to_bool(obj_cfg['expires']), int(obj_cfg['expire_time'])) #print "Created cmd", cmd hst.add_comment(cmd)
def get_launch(): user = app.get_user_auth() if not user: redirect("/user/login") print "Got forms in /newhosts/launch page" names = app.request.forms.get('names', '') runners = [] for (k,v) in app.request.forms.iteritems(): print "DUMP OF K, V FOR LAUNCH", k, v print k.startswith('enable-runner-') if k.startswith('enable-runner-'): r_name = k[len('enable-runner-'):] print "NAME", r_name, v, to_bool(v) if to_bool(v): runners.append(r_name) print "Selected runners", runners print "Got in request form" print names # We are putting a ask ask in the database i = random.randint(1, 65535) scan_ask = {'_id': i, 'names': names, 'runners': runners, 'state': 'pending', 'creation': int(time.time())} print "Saving", scan_ask, "in", app.db.scans r = app.db.scans.save(scan_ask) # We just want the id as string, not the object print "We create the scan", i app.ask_new_scan(i) return {'app': app, 'user': user}
def _parse_conf(self, mod_conf): self.high_availability = to_bool(getattr(mod_conf, 'high_availability', 'false')) if not self.high_availability: self.stand_alone = getattr(mod_conf, 'stand_alone', '') if not self.stand_alone: logger.error('[Mongodb-Notification-Broker] Mongodb is ' 'configured with high availability be false but ' 'stand_alone is not configured') raise Exception('[Mongodb-Notification-Broker] Configuration ' 'Error') else: replica_set_str = getattr(mod_conf, 'replica_set', '') self._set_replica_set(replica_set_str) self.database = getattr(mod_conf, 'database', 'shinken_broker_notification') self.username = getattr(mod_conf, 'username', 'shinken_broker_notification') self.password = getattr(mod_conf, 'password', 'shinken_broker_notification') self.url_options = getattr(mod_conf, 'url_options', '') try: self.retry_per_log = int(getattr(mod_conf, 'retry_per_log')) except: self.retry_per_log = 5 try: self.queue_size = int(getattr(mod_conf, 'queue_size')) except: self.queue_size = 10000
def create_and_link_comments(self, raw_objects, all_obj): # first service for obj_cfg in raw_objects['servicecomment']: #print "Managing", obj_cfg host_name = obj_cfg['host_name'] service_description = obj_cfg['service_description'] srv = all_obj['service'].find_srv_by_name_and_hostname(host_name, service_description) #print "Find my service", srv if srv is not None: cmd = Comment(srv, to_bool(obj_cfg['persistent']), obj_cfg['author'], obj_cfg['comment_data'], 1, int(obj_cfg['entry_type']), int(obj_cfg['source']), to_bool(obj_cfg['expires']), int(obj_cfg['expire_time'])) #print "Created cmd", cmd srv.add_comment(cmd) # then hosts for obj_cfg in raw_objects['hostcomment']: #print "Managing", obj_cfg host_name = obj_cfg['host_name'] hst = all_obj['host'].find_by_name(host_name) #print "Find my host", hst if hst is not None: cmd = Comment(hst, to_bool(obj_cfg['persistent']), obj_cfg['author'], obj_cfg['comment_data'], 1, int(obj_cfg['entry_type']), int(obj_cfg['source']), to_bool(obj_cfg['expires']), int(obj_cfg['expire_time'])) #print "Created cmd", cmd hst.add_comment(cmd)
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.plugins = [] # mongodb://host1,host2,host3/?safe=true;w=2;wtimeoutMS=2000 self.mongodb_uri = getattr(modconf, "mongodb_uri", None) self.replica_set = getattr(modconf, "replica_set", None) if self.replica_set and not ReplicaSetConnection: logger.error( "[LogStoreMongoDB] Can not initialize LogStoreMongoDB module with " "replica_set because your pymongo lib is too old. " "Please install it with a 2.x+ version from " "https://github.com/mongodb/mongo-python-driver/downloads" ) return None self.database = getattr(modconf, "database", "logs") self.collection = getattr(modconf, "collection", "logs") self.use_aggressive_sql = True self.mongodb_fsync = to_bool(getattr(modconf, "mongodb_fsync", "True")) max_logs_age = getattr(modconf, "max_logs_age", "365") maxmatch = re.match(r"^(\d+)([dwmy]*)$", max_logs_age) if maxmatch is None: logger.warning( "[LogStoreMongoDB] Wrong format for max_logs_age. Must be <number>[d|w|m|y] or <number> and not %s" % max_logs_age ) return None else: if not maxmatch.group(2): self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == "d": self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == "w": self.max_logs_age = int(maxmatch.group(1)) * 7 elif maxmatch.group(2) == "m": self.max_logs_age = int(maxmatch.group(1)) * 31 elif maxmatch.group(2) == "y": self.max_logs_age = int(maxmatch.group(1)) * 365 self.use_aggressive_sql = getattr(modconf, "use_aggressive_sql", "1") == "1" # This stack is used to create a full-blown select-statement self.mongo_filter_stack = LiveStatusMongoStack() # This stack is used to create a minimal select-statement which # selects only by time >= and time <= self.mongo_time_filter_stack = LiveStatusMongoStack() self.is_connected = DISCONNECTED self.backlog = [] # Now sleep one second, so that won't get lineno collisions with the last second time.sleep(1) self.lineno = 0
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.plugins = [] # mongodb://host1,host2,host3/?safe=true;w=2;wtimeoutMS=2000 self.mongodb_uri = getattr(modconf, 'mongodb_uri', None) self.replica_set = getattr(modconf, 'replica_set', None) if self.replica_set and not ReplicaSetConnection: logger.error( '[LogStoreMongoDB] Can not initialize LogStoreMongoDB module with ' 'replica_set because your pymongo lib is too old. ' 'Please install it with a 2.x+ version from ' 'https://github.com/mongodb/mongo-python-driver/downloads') return None self.database = getattr(modconf, 'database', 'logs') self.collection = getattr(modconf, 'collection', 'logs') self.use_aggressive_sql = True self.mongodb_fsync = to_bool(getattr(modconf, 'mongodb_fsync', "True")) max_logs_age = getattr(modconf, 'max_logs_age', '365') maxmatch = re.match(r'^(\d+)([dwmy]*)$', max_logs_age) if maxmatch is None: logger.warning( '[LogStoreMongoDB] Wrong format for max_logs_age. Must be <number>[d|w|m|y] or <number> and not %s' % max_logs_age) return None else: if not maxmatch.group(2): self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == 'd': self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == 'w': self.max_logs_age = int(maxmatch.group(1)) * 7 elif maxmatch.group(2) == 'm': self.max_logs_age = int(maxmatch.group(1)) * 31 elif maxmatch.group(2) == 'y': self.max_logs_age = int(maxmatch.group(1)) * 365 self.use_aggressive_sql = (getattr(modconf, 'use_aggressive_sql', '1') == '1') # This stack is used to create a full-blown select-statement self.mongo_filter_stack = LiveStatusMongoStack() # This stack is used to create a minimal select-statement which # selects only by time >= and time <= self.mongo_time_filter_stack = LiveStatusMongoStack() self.is_connected = DISCONNECTED self.backlog = [] # Now sleep one second, so that won't get lineno collisions with the last second time.sleep(1) self.lineno = 0
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.plugins = [] # mongodb://host1,host2,host3/?safe=true;w=2;wtimeoutMS=2000 self.mongodb_uri = getattr(modconf, 'mongodb_uri', None) self.database = getattr(modconf, 'database', 'logs') self.collection = getattr(modconf, 'collection', 'logs') self.username = getattr(modconf, 'username', '') self.password = getattr(modconf, 'password', '') self.replica_set = getattr(modconf, 'replica_set', None) if self.replica_set and not ReplicaSetConnection: logger.error('[LogStoreMongoDB] Can not initialize LogStoreMongoDB module with ' 'replica_set because your pymongo lib is too old. ' 'Please install it with a 2.x+ version from ' 'https://github.com/mongodb/mongo-python-driver/downloads') return None self.use_aggressive_sql = True self.mongodb_fsync = to_bool(getattr(modconf, 'mongodb_fsync', "True")) max_logs_age = getattr(modconf, 'max_logs_age', '365') maxmatch = re.match(r'^(\d+)([dwmy]*)$', max_logs_age) if maxmatch is None: logger.warning('[LogStoreMongoDB] Wrong format for max_logs_age. Must be <number>[d|w|m|y] or <number> and not %s' % max_logs_age) return None else: if not maxmatch.group(2): self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == 'd': self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == 'w': self.max_logs_age = int(maxmatch.group(1)) * 7 elif maxmatch.group(2) == 'm': self.max_logs_age = int(maxmatch.group(1)) * 31 elif maxmatch.group(2) == 'y': self.max_logs_age = int(maxmatch.group(1)) * 365 self.use_aggressive_sql = (getattr(modconf, 'use_aggressive_sql', '1') == '1') # This stack is used to create a full-blown select-statement self.mongo_filter_stack = LiveStatusMongoStack() # This stack is used to create a minimal select-statement which # selects only by time >= and time <= self.mongo_time_filter_stack = LiveStatusMongoStack() self.is_connected = DISCONNECTED self.backlog = [] # Now sleep one second, so that won't get lineno collisions with the last second time.sleep(1) self.lineno = 0
def create_and_link_downtimes(self, raw_objects, all_obj): # first service for obj_cfg in raw_objects['servicedowntime']: print "Managing", obj_cfg host_name = obj_cfg['host_name'] service_description = obj_cfg['service_description'] srv = all_obj['service'].find_srv_by_name_and_hostname(host_name, service_description) print "Find my service", srv if srv is not None: dwn = Downtime(srv, int(obj_cfg['start_time']), int(obj_cfg['end_time']), to_bool(obj_cfg['fixed']), int(obj_cfg['triggered_by']), int(obj_cfg['duration']), obj_cfg['author'], obj_cfg['comment']) print "Created dwn", dwn srv.add_downtime(dwn) # then hosts for obj_cfg in raw_objects['hostdowntime']: print "Managing", obj_cfg host_name = obj_cfg['host_name'] hst = all_obj['host'].find_by_name(host_name) print "Find my host", hst if hst is not None: dwn = Downtime(hst, int(obj_cfg['start_time']), int(obj_cfg['end_time']), to_bool(obj_cfg['fixed']), int(obj_cfg['triggered_by']), int(obj_cfg['duration']), obj_cfg['author'], obj_cfg['comment']) print "Created dwn", dwn hst.add_downtime(dwn)
def __init__(self, mod_conf): try: import pymongo except ImportError: logger.error('[WebUI-mongo-logs] Can not import pymongo' 'Please install it with a 3.x+ version from ' 'https://pypi.python.org/pypi/pymongo') raise BaseModule.__init__(self, mod_conf) self.uri = getattr(mod_conf, 'uri', 'mongodb://localhost') logger.info('[mongo-logs] mongo uri: %s', self.uri) self.replica_set = getattr(mod_conf, 'replica_set', None) if self.replica_set and int(pymongo.version[0]) < 3: logger.error('[mongo-logs] Can not initialize module with ' 'replica_set because your pymongo lib is too old. ' 'Please install it with a 3.x+ version from ' 'https://pypi.python.org/pypi/pymongo') return None self.database = getattr(mod_conf, 'database', 'shinken') self.username = getattr(mod_conf, 'username', None) self.password = getattr(mod_conf, 'password', None) logger.info('[mongo-logs] database: %s, username: %s', self.database, self.username) self.commit_period = int(getattr(mod_conf, 'commit_period', '10')) logger.info('[mongo-logs] periodical commit period: %ds', self.commit_period) self.commit_volume = int(getattr(mod_conf, 'commit_volume', '1000')) logger.info('[mongo-logs] periodical commit volume: %d lines', self.commit_volume) self.db_test_period = int(getattr(mod_conf, 'db_test_period', '0')) logger.info('[mongo-logs] periodical DB connection test period: %ds', self.db_test_period) self.logs_collection = getattr(mod_conf, 'logs_collection', 'logs') logger.info('[mongo-logs] logs collection: %s', self.logs_collection) self.hav_collection = getattr(mod_conf, 'hav_collection', 'availability') logger.info('[mongo-logs] hosts availability collection: %s', self.hav_collection) self.mongodb_fsync = to_bool(getattr(mod_conf, 'mongodb_fsync', "True")) max_logs_age = getattr(mod_conf, 'max_logs_age', '365') maxmatch = re.match(r'^(\d+)([dwmy]*)$', max_logs_age) if not maxmatch: logger.error('[mongo-logs] Wrong format for max_logs_age. Must be <number>[d|w|m|y] or <number> and not %s' % max_logs_age) return None else: if not maxmatch.group(2): self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == 'd': self.max_logs_age = int(maxmatch.group(1)) elif maxmatch.group(2) == 'w': self.max_logs_age = int(maxmatch.group(1)) * 7 elif maxmatch.group(2) == 'm': self.max_logs_age = int(maxmatch.group(1)) * 31 elif maxmatch.group(2) == 'y': self.max_logs_age = int(maxmatch.group(1)) * 365 logger.info('[mongo-logs] max_logs_age: %s', self.max_logs_age) self.services_cache = {} services_filter = getattr(mod_conf, 'services_filter', '') logger.info('[mongo-logs] services filtering: %s', services_filter) self.filter_service_description = None self.filter_service_criticality = None if services_filter: # Decode services filter services_filter = [s for s in services_filter.split(',')] for rule in services_filter: rule = rule.strip() if not rule: continue logger.info('[mongo-logs] services filtering rule: %s', rule) elts = rule.split(':', 1) t = 'service_description' if len(elts) > 1: t = elts[0].lower() s = elts[1].lower() if t == 'service_description': self.filter_service_description = rule logger.info('[mongo-logs] services will be filtered by description: %s', self.filter_service_description) if t == 'bp' or t == 'bi': self.filter_service_criticality = s logger.info('[mongo-logs] services will be filtered by criticality: %s', self.filter_service_criticality) # Elasticsearch configuration part ... prepare next version ! # self.elasticsearch_uri = getattr(mod_conf, 'elasticsearch_uri', None) # if self.elasticsearch_uri: # try: # import rawes # from rawes.elastic_exception import ElasticException # except ImportError: # logger.error('[mongo-logs] Can not import rawes library. Data will not be sent to your configured ElasticSearch: %s', self.elasticsearch_uri) # self.elasticsearch_uri = None # else: # logger.info('[mongo-logs] data will be sent to ElasticSearch: %s', self.elasticsearch_uri) self.is_connected = DISCONNECTED self.logs_cache = deque() self.availability_cache = {} self.availability_cache_backlog = []
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.plugins = [] self.modconf = modconf # Web server configuration self.host = getattr(modconf, 'host', '0.0.0.0') self.port = int(getattr(modconf, 'port', '7767')) logger.info("[WebUI] server: %s:%d", self.host, self.port) self.endpoint = getattr(modconf, 'endpoint', None) if self.endpoint: if self.endpoint.endswith('/'): self.endpoint = self.endpoint[:-1] logger.info("[WebUI] configured endpoint: %s", self.endpoint) logger.warning("[WebUI] endpoint feature is not implemented! WebUI is served from root URL: http://%s:%d/", self.host, self.port) self.endpoint = None self.auth_secret = resolve_auth_secret(modconf) # TODO : common preferences self.play_sound = to_bool(getattr(modconf, 'play_sound', '0')) # TODO : common preferences self.login_text = getattr(modconf, 'login_text', None) # TODO : common preferences self.company_logo = getattr(modconf, 'company_logo', 'default_company') if self.company_logo == '': # Set a dummy value if webui.cfg value is empty to force using the default logo ... self.company_logo = 'abcdef' # TODO : common preferences self.gravatar = to_bool(getattr(modconf, 'gravatar', '0')) # TODO : common preferences self.allow_html_output = to_bool(getattr(modconf, 'allow_html_output', '0')) # TODO : common preferences #self.max_output_length = int(getattr(modconf, 'max_output_length', '100')) # TODO : common preferences self.refresh_period = int(getattr(modconf, 'refresh_period', '60')) # Use element tag as image or use text self.tag_as_image = to_bool(getattr(modconf, 'tag_as_image', '0')) # Manage user's ACL self.manage_acl = to_bool(getattr(modconf, 'manage_acl', '1')) self.allow_anonymous = to_bool(getattr(modconf, 'allow_anonymous', '0')) # Advanced options self.http_backend = getattr(modconf, 'http_backend', 'auto') self.remote_user_enable = getattr(modconf, 'remote_user_enable', '0') self.remote_user_variable = getattr(modconf, 'remote_user_variable', 'X_REMOTE_USER') self.serveropts = {} umask = getattr(modconf, 'umask', None) if umask is not None: self.serveropts['umask'] = int(umask) bindAddress = getattr(modconf, 'bindAddress', None) if bindAddress: self.serveropts['bindAddress'] = str(bindAddress) # Apache htpasswd file for authentication self.htpasswd_file = getattr(modconf, 'htpasswd_file', None) if self.htpasswd_file: if not os.path.exists(self.htpasswd_file): logger.warning("[WebUI] htpasswd file '%s' does not exist.", self.htpasswd_file) self.htpasswd_file = None # Load the config dir and make it an absolute path self.config_dir = getattr(modconf, 'config_dir', 'share') self.config_dir = os.path.abspath(self.config_dir) logger.info("[WebUI] Config dir: %s", self.config_dir) # Load the share dir and make it an absolute path self.share_dir = getattr(modconf, 'share_dir', 'share') self.share_dir = os.path.abspath(self.share_dir) logger.info("[WebUI] Share dir: %s", self.share_dir) # Load the photo dir and make it an absolute path self.photo_dir = getattr(modconf, 'photos_dir', 'photos') self.photo_dir = os.path.abspath(self.photo_dir) logger.info("[WebUI] Photo dir: %s", self.photo_dir) self.user_picture = '' # @mohierf: still useful ? No value in webui.cfg, so always False ... # self.embeded_graph = to_bool(getattr(modconf, 'embeded_graph', '0')) # Look for an additional pages dir self.additional_plugins_dir = getattr(modconf, 'additional_plugins_dir', '') if self.additional_plugins_dir: self.additional_plugins_dir = os.path.abspath(self.additional_plugins_dir) logger.info("[WebUI] Additional plugins dir: %s", self.additional_plugins_dir) # Web UI timezone self.timezone = getattr(modconf, 'timezone', 'Europe/Paris') if self.timezone: logger.info("[WebUI] Setting our timezone to %s", self.timezone) os.environ['TZ'] = self.timezone time.tzset() logger.info("[WebUI] parameter timezone: %s", self.timezone) # Visual alerting thresholds # Used in the dashboard view to select background color for percentages self.hosts_states_warning = int(getattr(modconf, 'hosts_states_warning', '95')) self.hosts_states_critical = int(getattr(modconf, 'hosts_states_critical', '90')) self.services_states_warning = int(getattr(modconf, 'services_states_warning', '95')) self.services_states_critical = int(getattr(modconf, 'services_states_critical', '90')) # Web UI information self.app_version = getattr(modconf, 'about_version', WEBUI_VERSION) self.app_copyright = getattr(modconf, 'about_copyright', WEBUI_COPYRIGHT) self.app_release = getattr(modconf, 'about_release', WEBUI_RELEASENOTES) # We will save all widgets self.widgets = {} # We need our regenerator now (before main) so if we are in a scheduler, # rg will be able to skip some broks self.rg = Regenerator() # My bottle object ... self.bottle = bottle bottle.BaseTemplate.defaults['app'] = self
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.plugins = [] self.modconf = modconf # Web server configuration self.host = getattr(modconf, 'host', '0.0.0.0') self.port = int(getattr(modconf, 'port', '7767')) logger.info("[WebUI] server: %s:%d", self.host, self.port) self.endpoint = getattr(modconf, 'endpoint', None) if self.endpoint: if self.endpoint.endswith('/'): self.endpoint = self.endpoint[:-1] logger.info("[WebUI] configured endpoint: %s", self.endpoint) logger.warning( "[WebUI] endpoint feature is not implemented! WebUI is served from root URL: http://%s:%d/", self.host, self.port) self.endpoint = None # Build session cookie self.session_cookie = getattr(modconf, 'cookie_name', 'user') self.auth_secret = resolve_auth_secret(modconf) logger.info("[WebUI] cookie: %s", self.session_cookie) # TODO : common preferences self.play_sound = to_bool(getattr(modconf, 'play_sound', '0')) # TODO : common preferences self.login_text = getattr(modconf, 'login_text', None) # TODO : common preferences self.company_logo = getattr(modconf, 'company_logo', 'default_company') if self.company_logo == '': # Set a dummy value if webui.cfg value is empty to force using the default logo ... self.company_logo = 'abcdef' # TODO : common preferences self.gravatar = to_bool(getattr(modconf, 'gravatar', '0')) # TODO : common preferences self.allow_html_output = to_bool( getattr(modconf, 'allow_html_output', '0')) # TODO : common preferences #self.max_output_length = int(getattr(modconf, 'max_output_length', '100')) # TODO : common preferences self.refresh_period = int(getattr(modconf, 'refresh_period', '60')) self.refresh = False if self.refresh_period == 0 else True # Use element tag as image or use text self.tag_as_image = to_bool(getattr(modconf, 'tag_as_image', '0')) # Manage user's ACL self.manage_acl = to_bool(getattr(modconf, 'manage_acl', '1')) self.allow_anonymous = to_bool(getattr(modconf, 'allow_anonymous', '0')) # Allow to customize default downtime duration self.default_downtime_hours = int( getattr(modconf, 'default_downtime_hours', '48')) self.shinken_downtime_fixed = int( getattr(modconf, 'shinken_downtime_fixed', '1')) self.shinken_downtime_trigger = int( getattr(modconf, 'shinken_downtime_trigger', '0')) self.shinken_downtime_duration = int( getattr(modconf, 'shinken_downtime_duration', '0')) # Allow to customize default acknowledge parameters self.default_ack_sticky = int( getattr(modconf, 'default_ack_sticky', '2')) self.default_ack_notify = int( getattr(modconf, 'default_ack_notify', '1')) self.default_ack_persistent = int( getattr(modconf, 'default_ack_persistent', '1')) # Advanced options self.http_backend = getattr(modconf, 'http_backend', 'auto') self.remote_user_enable = getattr(modconf, 'remote_user_enable', '0') self.remote_user_variable = getattr(modconf, 'remote_user_variable', 'X_REMOTE_USER') self.serveropts = {} umask = getattr(modconf, 'umask', None) if umask is not None: self.serveropts['umask'] = int(umask) bindAddress = getattr(modconf, 'bindAddress', None) if bindAddress: self.serveropts['bindAddress'] = str(bindAddress) # Apache htpasswd file for authentication self.htpasswd_file = getattr(modconf, 'htpasswd_file', None) if self.htpasswd_file: if not os.path.exists(self.htpasswd_file): logger.warning("[WebUI] htpasswd file '%s' does not exist.", self.htpasswd_file) self.htpasswd_file = None # Alignak backend for authentication self.frontend = None self.alignak_backend_objects = False self.alignak_backend_endpoint = getattr(modconf, 'alignak_backend_endpoint', None) if frontend_available and self.alignak_backend_endpoint: self.frontend = FrontEnd() if self.frontend: self.frontend.configure(self.alignak_backend_endpoint) logger.info("[WebUI] alignak backend: %s", self.frontend.url_endpoint_root) self.alignak_backend_objects = to_bool( getattr(modconf, 'alignak_backend_objects', '0')) # Load the config dir and make it an absolute path self.config_dir = getattr(modconf, 'config_dir', 'share') self.config_dir = os.path.abspath(self.config_dir) logger.info("[WebUI] Config dir: %s", self.config_dir) # Load the share dir and make it an absolute path self.share_dir = getattr(modconf, 'share_dir', 'share') self.share_dir = os.path.abspath(self.share_dir) logger.info("[WebUI] Share dir: %s", self.share_dir) # Load the photo dir and make it an absolute path self.photo_dir = getattr(modconf, 'photos_dir', 'photos') self.photo_dir = os.path.abspath(self.photo_dir) logger.info("[WebUI] Photo dir: %s", self.photo_dir) # User information self.user_session = None self.user_info = None # @mohierf: still useful ? No value in webui.cfg, so always False ... # self.embeded_graph = to_bool(getattr(modconf, 'embeded_graph', '0')) # Look for an additional pages dir self.additional_plugins_dir = getattr(modconf, 'additional_plugins_dir', '') if self.additional_plugins_dir: self.additional_plugins_dir = os.path.abspath( self.additional_plugins_dir) logger.info("[WebUI] Additional plugins dir: %s", self.additional_plugins_dir) # Web UI timezone self.timezone = getattr(modconf, 'timezone', 'Europe/Paris') if self.timezone: logger.info("[WebUI] Setting our timezone to %s", self.timezone) os.environ['TZ'] = self.timezone time.tzset() logger.info("[WebUI] parameter timezone: %s", self.timezone) # Visual alerting thresholds # Used in the dashboard view to select background color for percentages self.hosts_states_warning = int( getattr(modconf, 'hosts_states_warning', '95')) self.hosts_states_critical = int( getattr(modconf, 'hosts_states_critical', '90')) self.services_states_warning = int( getattr(modconf, 'services_states_warning', '95')) self.services_states_critical = int( getattr(modconf, 'services_states_critical', '90')) # Web UI information self.app_version = getattr(modconf, 'about_version', WEBUI_VERSION) self.app_copyright = getattr(modconf, 'about_copyright', WEBUI_COPYRIGHT) # We will save all widgets self.widgets = {} # We need our regenerator now (before main) so if we are in a scheduler, # rg will be able to skip some broks self.rg = None if not self.alignak_backend_objects: self.rg = Regenerator() # My bottle object ... self.bottle = bottle bottle.BaseTemplate.defaults['app'] = self
def __init__(self, modconf): BaseModule.__init__(self, modconf) self.plugins = [] self.modconf = modconf # Web server configuration self.host = getattr(modconf, 'host', '0.0.0.0') self.port = int(getattr(modconf, 'port', '7767')) self.auth_secret = getattr(modconf, 'auth_secret', 'secret').encode('utf8', 'replace') # TODO : common preferences self.play_sound = to_bool(getattr(modconf, 'play_sound', '0')) # TODO : common preferences self.login_text = getattr(modconf, 'login_text', None) # TODO : common preferences self.company_logo = getattr(modconf, 'company_logo', 'default_company') if self.company_logo == '': # Set a dummy value if webui.cfg value is empty to force using the default logo ... self.company_logo = 'abcdef' # TODO : common preferences self.gravatar = to_bool(getattr(modconf, 'gravatar', '0')) # TODO : common preferences self.allow_html_output = to_bool( getattr(modconf, 'allow_html_output', '0')) # TODO : common preferences #self.max_output_length = int(getattr(modconf, 'max_output_length', '100')) # TODO : common preferences self.refresh_period = int(getattr(modconf, 'refresh_period', '60')) # Use element tag as image or use text self.tag_as_image = to_bool(getattr(modconf, 'tag_as_image', '0')) # Manage user's ACL self.manage_acl = to_bool(getattr(modconf, 'manage_acl', '1')) self.allow_anonymous = to_bool(getattr(modconf, 'allow_anonymous', '0')) # Advanced options self.http_backend = getattr(modconf, 'http_backend', 'auto') self.remote_user_enable = getattr(modconf, 'remote_user_enable', '0') self.remote_user_variable = getattr(modconf, 'remote_user_variable', 'X_REMOTE_USER') self.serveropts = {} umask = getattr(modconf, 'umask', None) if umask is not None: self.serveropts['umask'] = int(umask) bindAddress = getattr(modconf, 'bindAddress', None) if bindAddress: self.serveropts['bindAddress'] = str(bindAddress) # Apache htpasswd file for authentication self.htpasswd_file = getattr(modconf, 'htpasswd_file', '/etc/shinken/htpasswd.users') logger.info("[WebUI] htpasswd file: %s", self.htpasswd_file) if self.htpasswd_file: if not os.path.exists(self.htpasswd_file): logger.warning("[WebUI] htpasswd file '%s' does not exist.", self.htpasswd_file) self.htpasswd_file = None # Load the config dir and make it an absolute path self.config_dir = getattr(modconf, 'config_dir', 'share') self.config_dir = os.path.abspath(self.config_dir) logger.info("[WebUI] Config dir: %s", self.config_dir) # Load the share dir and make it an absolute path self.share_dir = getattr(modconf, 'share_dir', 'share') self.share_dir = os.path.abspath(self.share_dir) logger.info("[WebUI] Share dir: %s", self.share_dir) # Load the photo dir and make it an absolute path self.photo_dir = getattr(modconf, 'photos_dir', 'photos') self.photo_dir = os.path.abspath(self.photo_dir) logger.info("[WebUI] Photo dir: %s", self.photo_dir) self.user_picture = '' # @mohierf: still useful ? No value in webui.cfg, so always False ... # self.embeded_graph = to_bool(getattr(modconf, 'embeded_graph', '0')) # Look for an additional pages dir self.additional_plugins_dir = getattr(modconf, 'additional_plugins_dir', '') if self.additional_plugins_dir: self.additional_plugins_dir = os.path.abspath( self.additional_plugins_dir) logger.info("[WebUI] Additional plugins dir: %s", self.additional_plugins_dir) # Web UI timezone self.timezone = getattr(modconf, 'timezone', 'Europe/Paris') if self.timezone: logger.info("[WebUI] Setting our timezone to %s", self.timezone) os.environ['TZ'] = self.timezone time.tzset() logger.info("[WebUI] parameter timezone: %s", self.timezone) # Visual alerting thresholds # Used in the dashboard view to select background color for percentages self.hosts_states_warning = int( getattr(modconf, 'hosts_states_warning', '95')) self.hosts_states_critical = int( getattr(modconf, 'hosts_states_critical', '90')) self.services_states_warning = int( getattr(modconf, 'services_states_warning', '95')) self.services_states_critical = int( getattr(modconf, 'services_states_critical', '90')) # Web UI information self.app_version = getattr(modconf, 'about_version', WEBUI_VERSION) self.app_copyright = getattr(modconf, 'about_copyright', WEBUI_COPYRIGHT) self.app_release = getattr(modconf, 'about_release', WEBUI_RELEASENOTES) # We will save all widgets self.widgets = {} # We need our regenerator now (before main) so if we are in a scheduler, # rg will be able to skip some broks self.rg = Regenerator() # My bottle object ... self.bottle = bottle bottle.BaseTemplate.defaults['app'] = self