コード例 #1
0
ファイル: ts_module.c プロジェクト: PutiZL/ironbee
/**
 * 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;
}
コード例 #2
0
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");
}