options.region = getConfig("region", "", options.configfile) # How long to sleep between polling options.sleep_time = getConfig("sleep_time", 0.1, options.configfile) if __name__ == "__main__": # configure ourselves parser = OptionParser() parser.add_option("-c", dest="configfile", default=sys.argv[0].replace(".py", ".conf"), help="configuration file to use") (options, args) = parser.parse_args() initConfig() initLogger(options) # open ES connection globally so we don't waste time opening it per message es = esConnect() try: main() except KeyboardInterrupt as e: logger.info("Exiting worker") if options.esbulksize != 0: es.finish_bulk() except Exception as e: if options.esbulksize != 0: es.finish_bulk() raise
# plugin options # secs to pass before checking for new/updated plugins # seems to cause memory leaks.. # regular updates are disabled for now, # though we set the frequency anyway. options.plugincheckfrequency = getConfig('plugincheckfrequency', 120, options.configfile) if __name__ == '__main__': # configure ourselves parser = OptionParser() parser.add_option("-c", dest='configfile', default=sys.argv[0].replace('.py', '.conf'), help="configuration file to use") (options, args) = parser.parse_args() initConfig() initLogger(options) # open ES connection globally so we don't waste time opening it per message es = esConnect() pluginList = registerPlugins() try: main() except KeyboardInterrupt as e: logger.info("Exiting worker") if options.esbulksize != 0: es.finish_bulk() except Exception as e: if options.esbulksize != 0: es.finish_bulk()
def initConfig(): # output our log to stdout or syslog options.output = getConfig('output', 'stdout', options.configfile) # syslog hostname options.sysloghostname = getConfig('sysloghostname', 'localhost', options.configfile) # syslog port options.syslogport = getConfig('syslogport', 514, options.configfile) # elastic search server settings options.esservers = list(getConfig('esservers', 'http://localhost:9200', options.configfile).split(',')) options.mongohost = getConfig('mongohost', 'localhost', options.configfile) options.mongoport = getConfig('mongoport', 3001, options.configfile) if __name__ == '__main__': parser = OptionParser() parser.add_option( "-c", dest='configfile', default=sys.argv[0].replace('.py', '.conf'), help="configuration file to use") (options, args) = parser.parse_args() initConfig() initLogger() main()