static const char* prompt = "o\")~ ";
+static const std::map<std::string, clear_counter_type_t> counter_name_to_id =
+{
+ {"daq", clear_counter_type_t::TYPE_DAQ},
+ {"module", clear_counter_type_t::TYPE_MODULE},
+ {"appid", clear_counter_type_t::TYPE_APPID},
+ {"file_id", clear_counter_type_t::TYPE_FILE_ID},
+ {"snort", clear_counter_type_t::TYPE_SNORT},
+ {"ha", clear_counter_type_t::TYPE_HA},
+ {"all", clear_counter_type_t::TYPE_ALL}
+};
+
const char* get_prompt()
{ return prompt; }
static bool use_shell(const SnortConfig* sc)
return 0;
}
+int convert_counter_type(const char* type)
+{
+ auto it = counter_name_to_id.find(type);
+ if ( it != counter_name_to_id.end() )
+ return it->second;
+ else
+ return clear_counter_type_t::TYPE_INVALID;
+}
+
int main_reset_stats(lua_State* L)
{
ControlConn* ctrlcon = ControlConn::query_from_lua(L);
- int type = luaL_optint(L, 1, 0);
+ const char* command;
+ int type;
+ if ( lua_gettop(L) == 0 )
+ command = "all";
+ else
+ command = luaL_checkstring(L, 1);
ctrlcon->respond("== clearing stats\n");
- main_broadcast_command(new ACResetStats(static_cast<clear_counter_type_t>(type)), ctrlcon);
+ if ((type = convert_counter_type(command)) != clear_counter_type_t::TYPE_INVALID)
+ main_broadcast_command(new ACResetStats(static_cast<clear_counter_type_t>(type)), ctrlcon);
+ else
+ LogRespond(ctrlcon, "Available options to use: all, daq, module, appid, file_id, snort, ha\n");
return 0;
}
int main_resume(lua_State* = nullptr);
int main_quit(lua_State* = nullptr);
int main_help(lua_State* = nullptr);
+int convert_counter_type(const char* type);
#ifdef SHELL
int main_dump_plugins(lua_State* = nullptr);
typedef enum clear_counter_type
{
- TYPE_UNKNOWN=-1,
+ TYPE_INVALID=-1,
TYPE_DAQ=0,
TYPE_MODULE,
TYPE_APPID,
TYPE_FILE_ID,
TYPE_SNORT,
- TYPE_HA
+ TYPE_HA,
+ TYPE_ALL
} clear_counter_type_t;
// FIXIT-M Will replace this vector with an unordered map of
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
+static const Parameter reset_stat_param[] =
+{
+ { "type", Parameter::PT_STRING, nullptr, nullptr, "possible type can be: daq|module|appid|file_id|snort|ha|all." },
+ { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+};
+
static const Command snort_cmds[] =
{
{ "set_watchdog_params", main_set_watchdog_params, s_watchdog, "set watchdog parameters" },
{ "dump_stats", main_dump_stats, nullptr, "show summary statistics" },
{ "dump_heap_stats", main_dump_heap_stats, nullptr, "show heap statistics" },
- { "reset_stats", main_reset_stats, nullptr, "clear summary statistics" },
+ { "reset_stats", main_reset_stats, reset_stat_param, "clear summary statistics. "
+ "Type can be: daq|module|appid|file_id|snort|ha|all. reset_stats() without a parameter clears all statistics."},
{ "rotate_stats", main_rotate_stats, nullptr, "roll perfmonitor log files" },
{ "reload_config", main_reload_config, s_reload_w_path, "load new configuration" },
{ "reload_policy", main_reload_policy, s_reload, "reload part or all of the default policy" },
void ModuleManager::reset_stats(clear_counter_type_t type)
{
- if ( type != TYPE_MODULE and type != TYPE_UNKNOWN )
+ if ( type != TYPE_MODULE and type != TYPE_ALL )
{
ModHook* mh = get_hook(clear_counter_type_string_map[type]);
if ( mh and mh->mod )
}
}
- if ( type == TYPE_UNKNOWN or !ignore )
+ if ( type == TYPE_ALL or !ignore )
{
lock_guard<mutex> lock(stats_mutex);
mh->mod->reset_stats();
}
}
}
- if ( type == TYPE_DAQ or type == TYPE_UNKNOWN )
+ if ( type == TYPE_DAQ or type == TYPE_ALL )
{
lock_guard<mutex> lock(stats_mutex);
PacketManager::reset_stats();