/** * 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; }
static void protocol_init(int accept_port, int server_port ATS_UNUSED) { TSCont contp; int ret_val; /* create customized log */ ret_val = TSTextLogObjectCreate("protocol", TS_LOG_MODE_ADD_TIMESTAMP, &protocol_plugin_log); if (ret_val != TS_SUCCESS) { TSError("[protocol] Failed to create log"); } /* format of the log entries, for caching_status, 1 for HIT and 0 for MISS */ ret_val = TSTextLogObjectWrite(protocol_plugin_log, "timestamp filename servername caching_status\n\n"); if (ret_val != TS_SUCCESS) { TSError("[protocol] Failed to write into log"); } contp = TSContCreate(accept_handler, TSMutexCreate()); /* Accept network traffic from the accept_port. When there are requests coming in, contp's handler should be called, in this case, contp's handler is accept_event, see AcceptSM.c */ pending_action = TSNetAccept(contp, accept_port, -1, 1); }
static int ts_lua_log_object_creat(lua_State *L) { const char *log_name; size_t name_len; int log_mode; TSReturnCode error; log_name = luaL_checklstring(L, -2, &name_len); if (lua_isnil(L, 3)) { TSError("[ts_lua] No log name!!"); return -1; } else { log_mode = luaL_checknumber(L, 3); } error = TSTextLogObjectCreate(log_name, log_mode, &log); if (!log || error == TS_ERROR) { TSError("[ts_lua] Unable to create log <%s>", log_name); return -1; } return 0; }
/** Create and return top-level cont with no transient data * Sets up engine manager and kill-or-continue txn hook before launching * potentially-slow mainconfiguration in separate thread. */ static ib_status_t tsib_pre_init(TSCont *contp) { int rv; ib_status_t rc; TSCont cont; assert(contp != NULL); /* create a cont to fend off traffic while we read config */ *contp = cont = TSContCreate(ironbee_plugin, NULL); if (cont == NULL) { TSError("[ironbee] failed to create initial continuation: disabled"); return IB_EUNKNOWN; } if (module_data.allow_at_startup) { /* SSN_START doesn't use contdata; READ_REQUEST_HDR only needs non-null flag. * Using &module_data might let us clean up some tsib_api stuff in future. */ TSContDataSet(cont, &module_data); } else { /* NULL contdata signals the READ_REQUEST_HDR hook to reject requests */ TSContDataSet(cont, NULL); } TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont); if (!module_data.log_disable) { /* success is documented as TS_LOG_ERROR_NO_ERROR but that's undefined. * It's actually a TS_SUCCESS (proxy/InkAPI.cc line 6641). */ printf("Logging to \"%s\"\n", module_data.log_file); rv = TSTextLogObjectCreate(module_data.log_file, TS_LOG_MODE_ADD_TIMESTAMP, &module_data.logger); if (rv != TS_SUCCESS) { TSError("[ironbee] Error creating log file."); return IB_EUNKNOWN; } } /* Initialize IronBee (including util) */ rc = ib_initialize(); if (rc != IB_OK) { TSError("[ironbee] Error initializing IronBee: %s", ib_status_to_string(rc)); return rc; } /* Create the IronBee engine manager */ TSDebug("ironbee", "Creating IronBee engine manager"); rc = ib_manager_create(&(module_data.manager), /* Engine Manager */ &ibplugin, /* Server object */ module_data.max_engines); /* Default max */ if (rc != IB_OK) { TSError("[ironbee] Error creating IronBee engine manager: %s", ib_status_to_string(rc)); } return rc; }
/*------------------------------------------------------------------------- TSPluginInit Function called at plugin init time Input: argc number of args argv list vof args Output : Return Value: -------------------------------------------------------------------------*/ void TSPluginInit(int argc, const char *argv[]) { TSPluginRegistrationInfo info; int i; TSReturnCode retval; info.plugin_name = "psi"; info.vendor_name = "Apache"; info.support_email = ""; if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) { TSError("Plugin registration failed.\n"); } if (!check_ts_version()) { TSError("Plugin requires Traffic Server 3.0 or later\n"); return; } /* Initialize the psi directory = <plugin_path>/include */ sprintf(psi_directory, "%s/%s", TSPluginDirGet(), PSI_PATH); /* create an TSTextLogObject to log any psi include */ retval = TSTextLogObjectCreate("psi", TS_LOG_MODE_ADD_TIMESTAMP, &log); if (retval == TS_ERROR) { TSError("Failed creating log for psi plugin"); log = NULL; } /* Create working threads */ thread_init(); init_queue(&job_queue); for (i = 0; i < NB_THREADS; i++) { char *thread_name = (char *) TSmalloc(64); sprintf(thread_name, "Thread[%d]", i); if (!TSThreadCreate((TSThreadFunc) thread_loop, thread_name)) { TSError("[TSPluginInit] Error while creating threads"); return; } } TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(read_response_handler, TSMutexCreate())); TSDebug(DBG_TAG, "Plugin started"); }
static int ironbee_init(const char *configfile, const char *logfile) { /* grab from httpd module's post-config */ ib_status_t rc; // ib_provider_t *lpr; ib_cfgparser_t *cp; ib_context_t *ctx; int rv; rc = ib_initialize(); if (rc != IB_OK) { return rc; } ib_util_log_level(9); ib_trace_init(TRACEFILE); rc = ib_engine_create(&ironbee, &ibplugin); if (rc != IB_OK) { return rc; } rc = ib_provider_register(ironbee, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts", NULL, &ironbee_logger_iface, NULL); if (rc != IB_OK) { return rc; } ib_context_set_string(ib_context_engine(ironbee), IB_PROVIDER_TYPE_LOGGER, "ironbee-ts"); ib_context_set_num(ib_context_engine(ironbee), IB_PROVIDER_TYPE_LOGGER ".log_level", 4); rc = ib_engine_init(ironbee); if (rc != IB_OK) { return rc; } /* success is documented as TS_LOG_ERROR_NO_ERROR but that's undefined. * It's actually a TS_SUCCESS (proxy/InkAPI.cc line 6641). */ rv = TSTextLogObjectCreate(logfile, TS_LOG_MODE_ADD_TIMESTAMP, &ironbee_log); if (rv != TS_SUCCESS) { return IB_OK + rv; } rc = atexit(ibexit); if (rc != 0) { return IB_OK + rv; } ib_hook_register(ironbee, conn_opened_event, (ib_void_fn_t)ironbee_conn_init, NULL); ib_state_notify_cfg_started(ironbee); ctx = ib_context_main(ironbee); ib_context_set_string(ctx, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts"); ib_context_set_num(ctx, "logger.log_level", 4); rc = ib_cfgparser_create(&cp, ironbee); if (rc != IB_OK) { return rc; } if (cp != NULL) { // huh? ib_cfgparser_parse(cp, configfile); ib_cfgparser_destroy(cp); } ib_state_notify_cfg_finished(ironbee); return IB_OK; }
void TSPluginInit(int argc, const char *argv[]) { TSPluginRegistrationInfo info; TSCont main_cont, config_cont; plugin_state_t *pstate; invalidate_t *iptr = NULL; bool disable_timed_reload = false; TSDebug(LOG_PREFIX, "Starting plugin init"); pstate = (plugin_state_t *)TSmalloc(sizeof(plugin_state_t)); init_plugin_state_t(pstate); int c; static const struct option longopts[] = {{"config", required_argument, NULL, 'c'}, {"log", required_argument, NULL, 'l'}, {"disable-timed-reload", no_argument, NULL, 'd'}, {NULL, 0, NULL, 0}}; while ((c = getopt_long(argc, (char *const *)argv, "c:l:", longopts, NULL)) != -1) { switch (c) { case 'c': pstate->config_file = TSstrdup(optarg); break; case 'l': if (TS_SUCCESS == TSTextLogObjectCreate(optarg, TS_LOG_MODE_ADD_TIMESTAMP, &pstate->log)) { TSTextLogObjectRollingEnabledSet(pstate->log, 1); TSTextLogObjectRollingIntervalSecSet(pstate->log, LOG_ROLL_INTERVAL); TSTextLogObjectRollingOffsetHrSet(pstate->log, LOG_ROLL_OFFSET); } break; case 'd': disable_timed_reload = true; break; default: break; } } if (!pstate->config_file) { TSError("[regex_revalidate] Plugin requires a --config option along with a config file name"); free_plugin_state_t(pstate); return; } if (!load_config(pstate, &iptr)) { TSDebug(LOG_PREFIX, "Problem loading config from file %s", pstate->config_file); } else { pstate->invalidate_list = iptr; list_config(pstate, iptr); } info.plugin_name = LOG_PREFIX; info.vendor_name = "Apache Software Foundation"; info.support_email = "*****@*****.**"; if (TSPluginRegister(&info) != TS_SUCCESS) { TSError("[regex_revalidate] Plugin registration failed"); free_plugin_state_t(pstate); return; } else { TSDebug(LOG_PREFIX, "Plugin registration succeeded"); } if (!check_ts_version()) { TSError("[regex_revalidate] Plugin requires Traffic Server %d.%d.%d", TS_VERSION_MAJOR, TS_VERSION_MINOR, TS_VERSION_MICRO); free_plugin_state_t(pstate); return; } pcre_malloc = &ts_malloc; pcre_free = &ts_free; main_cont = TSContCreate(main_handler, NULL); TSContDataSet(main_cont, (void *)pstate); TSHttpHookAdd(TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, main_cont); config_cont = TSContCreate(config_handler, TSMutexCreate()); TSContDataSet(config_cont, (void *)pstate); TSMgmtUpdateRegister(config_cont, LOG_PREFIX); if (!disable_timed_reload) { TSContScheduleOnPool(config_cont, CONFIG_TMOUT, TS_THREAD_POOL_TASK); } TSDebug(LOG_PREFIX, "Plugin Init Complete"); }