Example #1
0
def initialized_db_connection(database_url, apply_migrations):
    connection = regular_connect(database_url)
    cleanup_database(connection)
    connection.close()
    if apply_migrations:
        migrate_database_up(database_url)
    conn = regular_connect(database_url)
    yield conn
    conn.close()
Example #2
0
 def func(args):
     connection = regular_connect(args.postgres_connection_url)
     last_received_at = None
     while True:
         if not last_received_at:
             last_events = select_latest_events(connection, limit=3)
         else:
             last_events = select_latest_events(
                 connection, min_received_at=last_received_at)
         for event in reversed(last_events):
             print(event.format(args.format_str))
         if last_events:
             last_received_at = max(e.received_at for e in last_events)
         time.sleep(args.poll_interval)
 def func(args):
     clean_logger.info(
         "Beginning log cleaning process. Purge interval: {0}".format(
             args.purge_interval))
     conn = regular_connect(args.postgres_connection_url)
     try:
         clean_logger.debug("Database transaction opened..")
         with conn as transaction:
             clean_logger.debug("Transaction opened..")
             event_deleted_count = delete_old_system_events(
                 transaction, args.purge_interval)
             clean_logger.info(
                 "{0} system events purged from database.".format(
                     event_deleted_count))
     finally:
         clean_logger.debug("Closing database connection.")
         conn.close()
     clean_logger.info(
         "Database old events clean-up completed successfully!")
 def func(args):
     connection = regular_connect(args.postgres_connection_url)
     logging.info("Search Results:")
     for event in reversed(search_system_events(
         connection,
         opt_facility=args.facility,
         opt_priority=args.priority,
         opt_from_host=args.from_host,
         opt_event_source=args.event_source,
         opt_syslog_tag_search=args.syslog_tag,
         opt_message_search=args.message,
         opt_start_received_at=args.start_received_at,
         opt_end_received_at=args.end_received_at,
         opt_start_device_reported_time=args.start_device_reported_time,
         opt_end_device_reported_time=args.end_device_reported_time,
         limit=args.limit,
         offset=args.offset
     )):
         print(event.format(args.format_str))
Example #5
0
def database_connection(database_url):
    connection = regular_connect(database_url)
    cleanup_database(connection)
    yield connection
    connection.close()