counters: improve handling missing global config

Improve warnings when eve.stats can't work because of the global config
missing or disabled.

Issue warning if global config is missing but stats are still enabled due
to the legacy stats.log.

Issue clearer warning when stats are disabled and unix socket dump-counters
command is issued.

Warnings include links to docs.

Bug #2465.
pull/4252/head
Victor Julien 6 years ago
parent 2d381f93f3
commit 76e1836aed

@ -245,6 +245,14 @@ static void StatsInitCtxPreOutput(void)
SCLogDebug("Stats module has been disabled"); SCLogDebug("Stats module has been disabled");
SCReturn; SCReturn;
} }
/* warn if we are using legacy config to enable stats */
ConfNode *gstats = ConfGetNode("stats");
if (gstats == NULL) {
SCLogWarning(SC_ERR_STATS_LOG_GENERIC, "global stats config is missing. "
"Stats enabled through legacy stats.log. "
"See %s%s/configuration/suricata-yaml.html#stats", DOC_URL, DOC_VERSION);
}
const char *interval = ConfNodeLookupChildValue(stats, "interval"); const char *interval = ConfNodeLookupChildValue(stats, "interval");
if (interval != NULL) if (interval != NULL)
stats_tts = (uint32_t) atoi(interval); stats_tts = (uint32_t) atoi(interval);
@ -280,7 +288,7 @@ static void StatsInitCtxPostOutput(void)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!OutputStatsLoggersRegistered()) { if (stats_enabled && !OutputStatsLoggersRegistered()) {
stats_loggers_active = 0; stats_loggers_active = 0;
/* if the unix command socket is enabled we do the background /* if the unix command socket is enabled we do the background
@ -809,6 +817,10 @@ TmEcode StatsOutputCounterSocket(json_t *cmd,
json_t *message = NULL; json_t *message = NULL;
TmEcode r = TM_ECODE_OK; TmEcode r = TM_ECODE_OK;
if (!stats_enabled) {
r = TM_ECODE_FAILED;
message = json_string("stats are disabled in the config");
} else {
SCMutexLock(&stats_table_mutex); SCMutexLock(&stats_table_mutex);
if (stats_table.start_time == 0) { if (stats_table.start_time == 0) {
r = TM_ECODE_FAILED; r = TM_ECODE_FAILED;
@ -817,7 +829,7 @@ TmEcode StatsOutputCounterSocket(json_t *cmd,
message = StatsToJSON(&stats_table, JSON_STATS_TOTALS|JSON_STATS_THREADS); message = StatsToJSON(&stats_table, JSON_STATS_TOTALS|JSON_STATS_THREADS);
} }
SCMutexUnlock(&stats_table_mutex); SCMutexUnlock(&stats_table_mutex);
}
json_object_set_new(answer, "message", message); json_object_set_new(answer, "message", message);
return r; return r;
} }

@ -383,6 +383,14 @@ static void OutputStatsLogDeinit(OutputCtx *output_ctx)
static OutputInitResult OutputStatsLogInit(ConfNode *conf) static OutputInitResult OutputStatsLogInit(ConfNode *conf)
{ {
OutputInitResult result = { NULL, false }; OutputInitResult result = { NULL, false };
if (!StatsEnabled()) {
SCLogError(SC_ERR_STATS_LOG_GENERIC,
"stats.json: stats are disabled globally: set stats.enabled to true. "
"See %s%s/configuration/suricata-yaml.html#stats", DOC_URL, DOC_VERSION);
return result;
}
LogFileCtx *file_ctx = LogFileNewCtx(); LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) { if(file_ctx == NULL) {
SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx"); SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx");
@ -455,6 +463,14 @@ static OutputInitResult OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_
{ {
OutputInitResult result = { NULL, false }; OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data; OutputJsonCtx *ajt = parent_ctx->data;
if (!StatsEnabled()) {
SCLogError(SC_ERR_STATS_LOG_GENERIC,
"eve.stats: stats are disabled globally: set stats.enabled to true. "
"See %s%s/configuration/suricata-yaml.html#stats", DOC_URL, DOC_VERSION);
return result;
}
OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx)); OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx));
if (unlikely(stats_ctx == NULL)) if (unlikely(stats_ctx == NULL))
return result; return result;

Loading…
Cancel
Save