bool removed = false;
};
-#endif
+#define LogRespond(cn, ...) if (cn) cn->respond(__VA_ARGS__); else LogMessage(__VA_ARGS__)
+#define LogfRespond(cn, fh, ...) if (cn) cn->respond(__VA_ARGS__); else LogMessage(fh, __VA_ARGS__)
+#endif
LogLabel("File Statistics");
LogLabel("file type stats (files)");
- LogMessage(" Type Download Upload \n");
+ LogLabel(" Type Download Upload ");
processed_total[0] = 0;
processed_total[1] = 0;
processed_data_total[0] = 0;
processed_data_total[1] = 0;
+ char buff[128];
for (unsigned i = 0; i < FILE_ID_MAX; i++)
{
std::string type_name = file_type_name(i);
if (type_name.length() &&
(file_totals.files_processed[i][0] || file_totals.files_processed[i][1] ))
{
- LogMessage("%12s(%3d) " FMTu64("-10") " " FMTu64("-10") " \n",
+ snprintf(buff, sizeof(buff), "%12s(%3d) " FMTu64("-10") " " FMTu64("-10") " ",
type_name.c_str(), i,
file_totals.files_processed[i][0],
file_totals.files_processed[i][1]);
+ LogText(buff);
processed_total[0]+= file_totals.files_processed[i][0];
processed_total[1]+= file_totals.files_processed[i][1];
}
}
- LogMessage(" Total " FMTu64("-10") " " FMTu64("-10") " \n",
+ snprintf(buff, sizeof(buff), " Total " FMTu64("-10") " " FMTu64("-10") " ",
processed_total[0], processed_total[1]);
+ LogText(buff);
LogLabel("file type stats (bytes)");
- LogMessage(" Type Download Upload \n");
+ LogLabel(" Type Download Upload ");
for (unsigned i = 0; i < FILE_ID_MAX; i++)
{
if (type_name.length() &&
(file_totals.files_processed[i][0] || file_totals.files_processed[i][1] ))
{
- LogMessage("%12s(%3d) " FMTu64("-10") " " FMTu64("-10") " \n",
+ snprintf(buff, sizeof(buff), "%12s(%3d) " FMTu64("-10") " " FMTu64("-10") " ",
type_name.c_str(), i,
file_totals.data_processed[i][0],
file_totals.data_processed[i][1]);
+ LogText(buff);
processed_data_total[0]+= file_totals.data_processed[i][0];
processed_data_total[1]+= file_totals.data_processed[i][1];
}
}
- LogMessage(" Total " FMTu64("-10") " " FMTu64("-10") " \n",
+ snprintf(buff, sizeof(buff), " Total " FMTu64("-10") " " FMTu64("-10") " ",
processed_data_total[0], processed_data_total[1]);
+ LogText(buff);
check_total = 0;
LogLabel("file signature stats");
- LogMessage(" Type Download Upload \n");
+ LogLabel(" Type Download Upload ");
processed_total[0] = 0;
processed_total[1] = 0;
if (type_name.length() &&
(file_totals.signatures_processed[i][0] || file_totals.signatures_processed[i][1] ))
{
- LogMessage("%12s(%3d) " FMTu64("-10") " " FMTu64("-10") " \n",
+ snprintf(buff, sizeof(buff), "%12s(%3d) " FMTu64("-10") " " FMTu64("-10") " ",
type_name.c_str(), i,
file_totals.signatures_processed[i][0], file_totals.signatures_processed[i][1]);
+ LogText(buff);
processed_total[0]+= file_totals.signatures_processed[i][0];
processed_total[1]+= file_totals.signatures_processed[i][1];
}
}
- LogMessage(" Total " FMTu64("-10") " " FMTu64("-10") " \n",
+ snprintf(buff, sizeof(buff), " Total " FMTu64("-10") " " FMTu64("-10") " ",
processed_total[0], processed_total[1]);
+ LogText(buff);
#if 0
LogLabel("file type verdicts"); // FIXIT-RC should be fixed
{
ControlConn* ctrlcon = ControlConn::query_from_lua(L);
send_response(ctrlcon, "== dumping stats\n");
- main_broadcast_command(new ACGetStats(), ctrlcon);
+ main_broadcast_command(new ACGetStats(ctrlcon), ctrlcon);
return 0;
}
// FIXIT-L This should track the owner so it can dump stats to the
// shell instead of the logs when initiated by a shell command
- DropStats();
- LogMessage("==================================================\n"); // Marking End of stats
+ DropStats(ctrlcon);
+ LogRespond(ctrlcon, "==================================================\n"); // Marking End of stats
+
ModuleManager::clear_global_active_counters();
}
class ACGetStats : public snort::AnalyzerCommand
{
public:
+ ACGetStats(ControlConn* conn) : ctrlcon(conn) {}
bool execute(Analyzer&, void**) override;
const char* stringify() override { return "GET_STATS"; }
~ACGetStats() override;
+private:
+ ControlConn* ctrlcon;
};
typedef enum clear_counter_type
LogLabel("Appid Statistics");
LogLabel("detected apps and services");
- LogMessage("%25.25s: %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n",
+ char buff[120];
+ snprintf(buff, sizeof(buff), "%25.25s: %-10s %-10s %-10s %-10s %-10s %-10s %-10s",
"Application", "Flows", "Clients", "Users", "Payloads", "Misc", "Incompat.", "Failed");
+ LogText(buff);
for (unsigned i = 0; i < app_num; i++)
{
continue;
std::string app_name = AppIdPegCounts::appid_detectors_info[i];
- LogMessage("%25.25s:", app_name.c_str());
- pegs->print();
+ pegs->print(app_name.c_str(), buff, sizeof(buff));
+ LogText(buff);
}
if (!unknown_pegs->all_zeros())
{
- LogMessage("%25.25s:", "unknown");
- unknown_pegs->print();
+ unknown_pegs->print("unknown", buff, sizeof(buff));
+ LogText(buff);
}
}
-
return !memcmp(stats, &zeroed_peg, sizeof(stats));
}
- void print()
+ void print(const char* app, char* buf, int buf_size)
{
- snort::LogMessage(" " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10")
- " " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10")"\n",
+ snprintf(buf, buf_size, "%25.25s: " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10")
+ " " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10"), app,
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6]);
}
};
void LogMessage(const char*,...) {}
void ErrorMessage(const char*,...) {}
void LogLabel(const char*, FILE*) {}
+void LogText(const char*, FILE*) {}
+
// Stubs for utils
char* snort_strdup(const char* str)
void ErrorMessage(const char*,...) { }
void WarningMessage(const char*,...) { }
void LogMessage(const char*,...) { }
+void LogText(const char*, FILE*) {}
+
void ParseWarning(WarningGroup, const char*, ...) { }
void LogLabel(const char*, FILE*) {}
}
void ErrorMessage(const char*,...) {}
void LogLabel(const char*, FILE*) {}
+void LogText(const char* s, FILE*) { LogMessage("%s\n", s); }
+
// Stubs for utils
char* snort_strdup(const char* str)
return 0;
}
-static int show_flow_ip_profiling(lua_State*)
+static int show_flow_ip_profiling(lua_State* L)
{
bool status = false;
+ ControlConn* ctrlcon = ControlConn::query_from_lua(L);
PerfMonitor* perf_monitor = (PerfMonitor*)InspectorManager::get_inspector(PERF_NAME, true);
if (perf_monitor)
status = perf_monitor->is_flow_ip_enabled();
else
- LogMessage("perf_monitor is not configured\n");
+ LogRespond(ctrlcon, "perf_monitor is not configured\n");
- LogMessage("Snort flow ip profiling is %s\n", status ? "enabled" : "disabled");
+ LogRespond(ctrlcon, "Snort flow ip profiling is %s\n", status ? "enabled" : "disabled");
return 0;
}
#include <cassert>
+#include "control/control.h"
#include "detection/detection_engine.h"
#include "file_api/file_stats.h"
#include "filters/sfthreshold.h"
{
THREAD_LOCAL PacketCount pc;
+static THREAD_LOCAL ControlConn* s_ctrlcon = nullptr;
//-------------------------------------------------------------------------
static inline void LogSeparator(FILE* fh = stdout)
{
- LogMessage(fh, "%s\n", STATS_SEPARATOR);
+ LogfRespond(s_ctrlcon, fh, "%s\n", STATS_SEPARATOR);
+}
+
+void LogText(const char* s, FILE* fh)
+{
+ LogfRespond(s_ctrlcon, fh, "%s\n", s);
}
void LogLabel(const char* s, FILE* fh)
{
if ( *s == ' ' )
{
- LogMessage(fh, "%s\n", s);
+ LogfRespond(s_ctrlcon, fh, "%s\n", s);
}
else
{
LogSeparator(fh);
- LogMessage(fh, "%s\n", s);
+ LogfRespond(s_ctrlcon, fh, "%s\n", s);
}
}
void LogValue(const char* s, const char* v, FILE* fh)
{
- LogMessage(fh, "%25.25s: %s\n", s, v);
+ LogfRespond(s_ctrlcon, fh, "%25.25s: %s\n", s, v);
}
void LogCount(const char* s, uint64_t c, FILE* fh)
{
if ( c )
- LogMessage(fh, "%25.25s: " STDu64 "\n", s, c);
+ {
+ LogfRespond(s_ctrlcon, fh, "%25.25s: " STDu64 "\n", s, c);
+ }
}
void LogStat(const char* s, uint64_t n, uint64_t tot, FILE* fh)
{
if ( n )
- LogMessage(fh, "%25.25s: " FMTu64("-12") "\t(%7.3f%%)\n", s, n, CalcPct(n, tot));
+ {
+ LogfRespond(s_ctrlcon, fh, "%25.25s: " FMTu64("-12") "\t(%7.3f%%)\n", s, n, CalcPct(n, tot));
+ }
}
void LogStat(const char* s, double d, FILE* fh)
{
if ( d )
- LogMessage(fh, "%25.25s: %g\n", s, d);
+ {
+ LogfRespond(s_ctrlcon, fh, "%25.25s: %g\n", s, d);
+ }
}
}
//-------------------------------------------------------------------------
-void DropStats()
+void DropStats(ControlConn* ctrlcon)
{
+ s_ctrlcon = ctrlcon;
LogLabel("Packet Statistics");
ModuleManager::get_module("daq")->show_stats();
LogLabel("Summary Statistics");
show_stats((PegCount*)&proc_stats, proc_names, array_size(proc_names)-1, "process");
+ s_ctrlcon = nullptr;
}
//-------------------------------------------------------------------------
using IndexVec = std::vector<unsigned>;
+class ControlConn;
+
// FIXIT-L split this out into appropriate modules
struct PacketCount
{
SO_PUBLIC inline PegCount get_packet_number() { return pc.analyzed_pkts; }
SO_PUBLIC void LogLabel(const char*, FILE* = stdout);
+SO_PUBLIC void LogText(const char*, FILE* = stdout);
SO_PUBLIC void LogValue(const char*, const char*, FILE* = stdout);
SO_PUBLIC void LogCount(const char*, uint64_t, FILE* = stdout);
void show_stats(SimpleStats*, const char* module_name);
double CalcPct(uint64_t, uint64_t);
-void DropStats();
+void DropStats(ControlConn* ctrlcon = nullptr);
void PrintStatistics();
void TimeStart();
void TimeStop();