def get(self, section, option): if not ENABLED: #self.logger.debug('sqlalchemy extension not enabled') return self.parentget(section, option) if not self.has_section('databaseconfig'): #self.logger.debug('no database configuration section') return self.parentget(section, option) if not self.has_option('databaseconfig', 'dbconnectstring'): #self.logger.debug('no db connect string') return self.parentget(section, option) connectstring = self.parentget('databaseconfig', 'dbconnectstring') if connectstring.strip() == '': #self.logger.debug('empty db connect string') return self.parentget(section, option) session = get_session(connectstring) query = self.parentget('databaseconfig', 'sql') if query.strip() == '': return self.parentget(section, option) sqlvalues = { 'section': section, 'option': option, } default_template_values(self.suspect, sqlvalues) result = None try: #self.logger.debug("Executing query '%s' with vars %s"%(query,sqlvalues)) result = session.execute(query, sqlvalues).first() except: trb = traceback.format_exc() self.logger.error("Error getting database config override: %s" % trb) session.remove() if result == None: #self.logger.debug('no result') return self.parentget(section, option) else: #self.logger.debug('result: '+result[0]) return result[0]
def get(self, section, option): if not ENABLED: #self.logger.debug('sqlalchemy extension not enabled') return self.parentget(section, option) if not self.has_section('databaseconfig'): #self.logger.debug('no database configuration section') return self.parentget(section, option) if not self.has_option('databaseconfig', 'dbconnectstring'): #self.logger.debug('no db connect string') return self.parentget(section, option) connectstring = self.parentget('databaseconfig', 'dbconnectstring') if connectstring.strip() == '': #self.logger.debug('empty db connect string') return self.parentget(section, option) session = get_session(connectstring) query = self.parentget('databaseconfig', 'sql') if query.strip() == '': return self.parentget(section, option) sqlvalues = { 'section': section, 'option': option, } default_template_values(self.suspect, sqlvalues) result = None try: #self.logger.debug("Executing query '%s' with vars %s"%(query,sqlvalues)) result = session.execute(query, sqlvalues).first() except: trb = traceback.format_exc() self.logger.error( "Error getting database config override: %s" % trb) session.remove() if result == None: #self.logger.debug('no result') return self.parentget(section, option) else: #self.logger.debug('result: '+result[0]) return result[0]
def get(self, section, option, **kwargs): if not SQL_EXTENSION_ENABLED or (not self.has_section('databaseconfig')) or (not self.has_option('databaseconfig', 'dbconnectstring')): return self.parentget(section, option, **kwargs) connectstring = self.parentget('databaseconfig', 'dbconnectstring') if connectstring.strip() == '': #self.logger.debug('empty db connect string') return self.parentget(section, option, **kwargs) session = get_session(connectstring) query = self.parentget('databaseconfig', 'sql') if query.strip() == '': return self.parentget(section, option, **kwargs) sqlvalues = { 'section': section, 'option': option, } default_template_values(self.suspect(), sqlvalues) result = None try: #self.logger.debug("Executing query '%s' with vars %s"%(query,sqlvalues)) result = session.execute(query, sqlvalues).first() except Exception: trb = traceback.format_exc() self.logger.error( "Error getting database config override: %s" % trb) session.remove() if result is None: #self.logger.debug('no result') return self.parentget(section, option, **kwargs) else: #self.logger.debug('result: '+result[0]) return result[0]
def lint(self): errors = 0 fc = FunkyConsole() self._lint_dependencies(fc) print(fc.strcolor('Loading extensions...', 'magenta')) exts = self.load_extensions() for ext in exts: (name, enabled, status) = ext pname = fc.strcolor(name, 'cyan') if enabled: penabled = fc.strcolor('enabled', 'green') else: penabled = fc.strcolor('disabled', 'red') print("%s: %s (%s)" % (pname, penabled, status)) print(fc.strcolor('Loading plugins...', 'magenta')) if not self.load_plugins(): print(fc.strcolor('At least one plugin failed to load', 'red')) print(fc.strcolor('Plugin loading complete', 'magenta')) print("Linting ", fc.strcolor("main configuration", 'cyan')) if not self.checkConfig(): print(fc.strcolor("ERROR", "red")) else: print(fc.strcolor("OK", "green")) trashdir = self.config.get('main', 'trashdir').strip() if trashdir != "": if not os.path.isdir(trashdir): print( fc.strcolor("Trashdir %s does not exist" % trashdir, 'red')) # sql config override sqlconfigdbconnectstring = self.config.get( 'databaseconfig', 'dbconnectstring') if sqlconfigdbconnectstring.strip() != '': print("") print("Linting ", fc.strcolor("sql configuration", 'cyan')) try: from fuglu.extensions.sql import get_session sess = get_session(sqlconfigdbconnectstring) tempsuspect = Suspect( '*****@*****.**', '*****@*****.**', '/dev/null') sqlvars = dict( section='testsection', option='testoption', scope='$GLOBAL') default_template_values(tempsuspect, sqlvars) sess.execute(self.config.get('databaseconfig', 'sql'), sqlvars) sess.remove() print(fc.strcolor("OK", 'green')) except Exception as e: print(fc.strcolor("Failed %s" % str(e), 'red')) allplugins = self.plugins + self.prependers + self.appenders for plugin in allplugins: print() print("Linting Plugin ", fc.strcolor(str(plugin), 'cyan'), 'Config section:', fc.strcolor(str(plugin.section), 'cyan')) try: result = plugin.lint() except Exception as e: CrashStore.store_exception() print("ERROR: %s" % e) result = False if result: print(fc.strcolor("OK", "green")) else: errors = errors + 1 print(fc.strcolor("ERROR", "red")) print("%s plugins reported errors." % errors) if self.config.getboolean('main', 'versioncheck'): check_version_status(lint=True)
def lint(self): errors = 0 fc = FunkyConsole() self._lint_dependencies(fc) print(fc.strcolor('Loading extensions...', 'magenta')) exts = self.load_extensions() for ext in exts: (name, enabled, status) = ext pname = fc.strcolor(name, 'cyan') if enabled: penabled = fc.strcolor('enabled', 'green') else: penabled = fc.strcolor('disabled', 'red') print("%s: %s (%s)" % (pname, penabled, status)) print(fc.strcolor('Loading plugins...', 'magenta')) if not self.load_plugins(): print(fc.strcolor('At least one plugin failed to load', 'red')) print(fc.strcolor('Plugin loading complete', 'magenta')) print("Linting ", fc.strcolor("main configuration", 'cyan')) if not self.checkConfig(): print(fc.strcolor("ERROR", "red")) else: print(fc.strcolor("OK", "green")) trashdir = self.config.get('main', 'trashdir').strip() if trashdir != "" and not os.path.isdir(trashdir): print(fc.strcolor("Trashdir %s does not exist" % trashdir, 'red')) # sql config override sqlconfigdbconnectstring = self.config.get('databaseconfig', 'dbconnectstring') if sqlconfigdbconnectstring.strip() != '': print() print("Linting ", fc.strcolor("sql configuration", 'cyan')) try: from fuglu.extensions.sql import get_session sess = get_session(sqlconfigdbconnectstring) tempsuspect = Suspect('*****@*****.**', '*****@*****.**', '/dev/null') sqlvars = dict(section='testsection', option='testoption', scope='$GLOBAL') default_template_values(tempsuspect, sqlvars) sess.execute(self.config.get('databaseconfig', 'sql'), sqlvars) sess.remove() print(fc.strcolor("OK", 'green')) except Exception as e: print(fc.strcolor("Failed %s" % str(e), 'red')) allplugins = self.plugins + self.prependers + self.appenders for plugin in allplugins: print() print("Linting Plugin ", fc.strcolor(str(plugin), 'cyan'), 'Config section:', fc.strcolor(str(plugin.section), 'cyan')) try: result = plugin.lint() except Exception as e: CrashStore.store_exception() print("ERROR: %s" % e) result = False if result: print(fc.strcolor("OK", "green")) else: errors = errors + 1 print(fc.strcolor("ERROR", "red")) print("%s plugins reported errors." % errors) if self.config.getboolean('main', 'versioncheck'): check_version_status(lint=True)
def lint(self): errors = 0 fc = FunkyConsole() self._lint_dependencies(fc) print(fc.strcolor('Loading extensions...', 'magenta')) exts = self.load_extensions() for ext in exts: (name, enabled, status) = ext pname = fc.strcolor(name, 'cyan') if enabled: penabled = fc.strcolor('enabled', 'green') else: penabled = fc.strcolor('disabled', 'red') print("%s: %s (%s)" % (pname, penabled, status)) print(fc.strcolor('Loading plugins...', 'magenta')) if not self.load_plugins(): print(fc.strcolor('At least one plugin failed to load', 'red')) errors +=1 print(fc.strcolor('Plugin loading complete', 'magenta')) print("Linting ", fc.strcolor("main configuration", 'cyan')) if not self.checkConfig(): print(fc.strcolor("ERROR", "red")) errors += 1 else: print(fc.strcolor("OK", "green")) trashdir = self.config.get('main', 'trashdir').strip() if trashdir != "" and not os.path.isdir(trashdir): print(fc.strcolor("Trashdir %s does not exist" % trashdir, 'red')) errors += 1 # sql config override sqlconfigdbconnectstring = self.config.get('databaseconfig', 'dbconnectstring') if sqlconfigdbconnectstring.strip() != '': print() print("Linting ", fc.strcolor("sql configuration", 'cyan')) try: from fuglu.extensions.sql import get_session sess = get_session(sqlconfigdbconnectstring) tempsuspect = Suspect( '*****@*****.**', '*****@*****.**', '/dev/null', att_cachelimit=self.config.getint('performance','att_mgr_cachesize')) sqlvars = dict( section='testsection', option='testoption', scope='$GLOBAL') default_template_values(tempsuspect, sqlvars) sess.execute(self.config.get('databaseconfig', 'sql'), sqlvars) sess.remove() print(fc.strcolor("OK", 'green')) except Exception as e: print(fc.strcolor("Failed %s" % str(e), 'red')) errors += 1 allplugins = self.plugins + self.prependers + self.appenders perrors = 0 for plugin in allplugins: print() print("Linting Plugin ", fc.strcolor(str(plugin), 'cyan'), 'Config section:', fc.strcolor(str(plugin.section), 'cyan')) try: result = plugin.lint() except Exception as e: CrashStore.store_exception() print("ERROR: %s" % e) result = False if result: print(fc.strcolor("OK", "green")) else: perrors += 1 errors += 1 print(fc.strcolor("ERROR", "red")) print("%s plugins reported errors." % perrors) if "milter" in self.config.get('main', 'incomingport') \ and self.config.get('performance', 'backend') != 'process': try: minfreethreads = self.config.getint('performance', 'minfreethreads') if minfreethreads < 1: print(fc.strcolor('\nMilter enabled with "thread" backend but "minfreethreads < 1"', 'yellow')) print("To keep milter responsive it is recommended to set minfreethreads >= 1\n" "to make fuglu more resonsive.\n") except (configparser.NoSectionError, configparser.NoOptionError): print(fc.strcolor('\nMilter enabled with "thread" backend but "minfreethreads is not defined!"', 'yellow')) print("To keep fuglu-milter responsive it is recommended to set minfreethreads >= 1\n") if self.config.getboolean('main', 'versioncheck'): check_version_status(lint=True) return errors