Esempio n. 1
0
 def __init__(self, config):
     self.config = config
     self.dbengine = get_engine(config)
     self.beanstalk_host = os.environ.get("BEANSTALK_HOST", config.defaults.get('beanstalk_host', 'localhost'))
     self.beanstalk_port = int(os.environ.get("BEANSTALK_PORT", config.defaults.get('beanstalk_port', 11300)))
     self.beanstalk = beanstalkc.Connection(
         host=self.beanstalk_host,
         port=self.beanstalk_port
     )
     self.msg_num = 0
     self.sum_time = time.time()
Esempio n. 2
0
    def __init__(self, config=None,  **kwargs):
        self.config = config

        try:
            if 'TZ' not in os.environ:
                os.environ["TZ"] = config.defaults.tz
            time.tzset()
        except:
            pass


        self.db = scoped_session(sessionmaker(bind=get_engine(self.config), autocommit=False, autoflush=True))

        settings = dict(
            cookie_secret=os.environ.get('cookie_secret', "12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo="),
            login_url="/login",
            template_path=os.path.join(os.path.dirname(__file__), "views"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            db_engine = get_engine(self.config),
            api_secret=config.defaults.secret,
            debug=config.defaults.debug,
            db=self.db,
            xheaders=True,
        )

        self.cache = CacheManager(**parse_cache_config_options({
            'cache.type': 'file',
            'cache.data_dir': '/tmp/cache/data',
            'cache.lock_dir': '/tmp/cache/lock'
        }))

        self.tp_lookup = TemplateLookup(directories=[settings['template_path']],
                                        default_filters=['decode.utf8'],
                                        input_encoding='utf-8',
                                        output_encoding='utf-8',
                                        encoding_errors='replace',
                                        module_directory="/tmp/toughlogger")

        self.init_permit()
        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
Esempio n. 3
0
def run():
    parser = argparse.ArgumentParser()
    parser.add_argument('-serv', '--serv', action='store_true', default=False, dest='serv', help='run logger')
    parser.add_argument('-syslogd', '--syslogd', action='store_true', default=False, dest='syslogd', help='run syslogd')
    parser.add_argument('-t', '--tcp', action='store_true', default=False, dest='tcp',help='run syslogd via tcp')
    parser.add_argument('-u', '--udp', action='store_true', default=False, dest='udp', help='run syslogd via udp')
    parser.add_argument('-ttask', '--table_task', action='store_true', default=False, dest='table_task',help='run table task')
    parser.add_argument('-wtask', '--write_task', action='store_true', default=False, dest='write_task',help='run write task')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-port', '--port', type=int, default=0, dest='port', help='admin port')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-x', '--xdebug', action='store_true', default=False, dest='xdebug', help='xdebug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughlogger.conf", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.Config(args.conf)

    if args.debug or args.xdebug:
        config.defaults.debug = True

    if args.port > 0:
        config.server.port = int(args.port)

    if args.serv:
        from toughlogger.console import logger_app
        logger_app.run(config)

    if args.syslogd:
        from toughlogger.syslog import udp_server, tcp_server
        if args.tcp:
            tcp_server.run(config)
        if args.udp:
            udp_server.run(config)

    if args.table_task:
        from toughlogger.syslog import table_task
        table_task.run(config)

    if args.write_task:
        from toughlogger.syslog import write_task
        write_task.run(config)


    if args.initdb:
        init_db.update(get_engine(config))
Esempio n. 4
0
 def __init__(self, config):
     self.dbengine = get_engine(config)
     self.sql_tpl = 'mysql' in self.dbengine.driver and mysql_create_sql_tpl or create_sql_tpl