/** * Register loggers to the IronBee engine. * * @param[out] manager The manager. * @param[in] ib The configured engine. * @param[in] cbdata @ref module_data_t. * * @returns * - IB_OK On success. * - Other on fatal errors. */ static ib_status_t engine_postconfig_fn( ib_manager_t *manager, ib_engine_t *ib, void *cbdata ) { assert(manager != NULL); assert(ib != NULL); assert(cbdata != NULL); int rv; ib_status_t rc; module_data_t *mod_data = (module_data_t *)cbdata; ib_logger_format_t *txlog_format; rc = ib_logger_fetch_format( ib_engine_logger_get(ib), TXLOG_FORMAT_FN_NAME, &txlog_format); if (rc == IB_OK) { /* Register the IronBee Transaction Log logger. */ ib_logger_writer_add( ib_engine_logger_get(ib), NULL, /* Open. */ NULL, /* Callback data. */ NULL, /* Close. */ NULL, /* Callback data. */ NULL, /* Reopen. */ NULL, /* Callback data. */ txlog_format, /* Format - This does all the work. */ txlog_record, /* Record. */ mod_data /* Callback data. */ ); /* Open logfile for txlog */ rv = TSTextLogObjectCreate(mod_data->txlogfile, 0, &mod_data->txlogger); if (rv != TS_SUCCESS) { mod_data->txlogger = NULL; TSError("[ironbee] Failed to create transaction log \"%s\": %d", mod_data->txlogfile, rv); } else { /* 60 seconds */ TSTextLogObjectRollingIntervalSecSet(mod_data->txlogger, 60); /* 5 MB - This API seems not to exist yet (TS-3059). */ //TSTextLogObjectRollingSizeMbSet(mod_data->txlogger, 5); /* 3:00 am */ TSTextLogObjectRollingOffsetHrSet(mod_data->txlogger, 3); /* 3 = time or size */ TSTextLogObjectRollingEnabledSet(mod_data->txlogger, 3); } } else { ib_log_notice(ib, "No transaction logger available."); } return IB_OK; }
TEST_F(TxLogTest, BlockResponse) { ib_logger_format_t *format; std::string config = std::string( "LogLevel INFO\n" "LoadModule \"ibmod_htp.so\"\n" "LoadModule \"ibmod_rules.so\"\n" "LoadModule \"ibmod_txlog.so\"\n" "AuditLogBaseDir .\n" "SensorId B9C1B52B-C24A-4309-B9F9-0EF4CD577A3E\n" "SensorName UnitTesting\n" "SensorHostname unit-testing.sensor.tld\n" "<Site test-site>\n" " SiteId AAAABBBB-1111-2222-3333-000000000000\n" " Hostname UnitTest\n" " Action id:1 rev:1 phase:response block:immediate event\n" "</Site>\n" ); configureIronBeeByString(config.c_str()); ASSERT_EQ( IB_OK, ib_logger_fetch_format( ib_engine_logger_get(ib_engine), TXLOG_FORMAT_FN_NAME, &format) ); ASSERT_EQ( IB_OK, ib_logger_writer_add( ib_engine_logger_get(ib_engine), NULL, NULL, /* Open. */ NULL, NULL, /* Close. */ NULL, NULL, /* Reopen. */ format, /* Format. */ test_record_handler, NULL /* Record. */ ) ); performTx(); ASSERT_TRUE(ib_tx); std::cout << "Log string is: " << test_log.str(); }
/** * Initialize a new server plugin module instance. * * @param[in] ib Engine this module is operating on. * @param[in] module This module structure. * @param[in] cbdata The server plugin module data. * * @returns * - IB_OK On success. * - Other on error. */ static ib_status_t init_module( ib_engine_t *ib, ib_module_t *module, void *cbdata ) { assert(ib != NULL); assert(module != NULL); assert(cbdata != NULL); module_data_t *mod_data = (module_data_t *)cbdata; ib_logger_writer_add( ib_engine_logger_get(ib), NULL, /* Open. */ NULL, /* Callback data. */ NULL, /* Close. */ mod_data, /* Callback data. */ NULL, /* Reopen. */ NULL, /* Callback data. */ logger_format, /* Format - This does all the work. */ mod_data, /* Callback data. */ NULL, /* Record. */ NULL /* Callback data. */ ); return IB_OK; }
/** * Register loggers to the IronBee engine. * * @param[out] manager The manager. * @param[in] ib The unconfigured engine. * @param[in] cbdata @ref module_data_t. * * @returns * - IB_OK On success. * - Other on fatal errors. */ static ib_status_t engine_preconfig_fn( ib_manager_t *manager, ib_engine_t *ib, void *cbdata ) { assert(manager != NULL); assert(ib != NULL); assert(cbdata != NULL); ib_status_t rc; ib_logger_format_t *iblog_format; module_data_t *mod_data = (module_data_t *)cbdata; /* Clear all existing loggers. */ rc = ib_logger_writer_clear(ib_engine_logger_get(ib)); if (rc != IB_OK) { return rc; } rc = ib_logger_format_create( ib_engine_logger_get(ib), &iblog_format, logger_format, mod_data, NULL, NULL); if (rc != IB_OK) { return rc; } /* Register the IronBee logger. */ ib_logger_writer_add( ib_engine_logger_get(ib), NULL, /* Open. */ NULL, /* Callback data. */ logger_close, /* Close. */ mod_data, /* Callback data. */ NULL, /* Reopen. */ NULL, /* Callback data. */ iblog_format, /* Format - This does all the work. */ NULL, /* Record. */ NULL /* Callback data. */ ); return IB_OK; }
/** * Initialize a new server plugin module instance. * * @param[in] ib Engine this module is operating on. * @param[in] module This module structure. * @param[in] cbdata The server plugin module data. * * @returns * - IB_OK On success. * - Other on error. */ static ib_status_t init_module( ib_engine_t *ib, ib_module_t *module, void *cbdata ) { ib_status_t rc; assert(ib != NULL); assert(module != NULL); assert(cbdata != NULL); module_data_t *mod_data = (module_data_t *)cbdata; ib_logger_format_t *logger; rc = ib_logger_format_create( ib_engine_logger_get(ib), &logger, logger_format, mod_data, NULL, NULL); if (rc != IB_OK) { return IB2NG(rc); } ib_logger_writer_add( ib_engine_logger_get(ib), NULL, /* Open. */ NULL, /* Callback data. */ NULL, /* Close. */ mod_data, /* Callback data. */ NULL, /* Reopen. */ NULL, /* Callback data. */ logger, /* Format - This does all the work. */ NULL, /* Record. */ NULL /* Callback data. */ ); return IB_OK; }