mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-12 14:08:27 +00:00
Remove dep on nixio by adding simple syslog lua function
This commit is contained in:
parent
cddc56d179
commit
f7ba825023
@ -7,7 +7,7 @@ include_directories("${PROJECT_BINARY_DIR}/userspace/digwatch")
|
||||
include_directories("${CURL_INCLUDE_DIR}")
|
||||
include_directories("${LPEG_SRC}")
|
||||
|
||||
add_executable(digwatch formats.cpp fields.cpp rules.cpp digwatch.cpp)
|
||||
add_executable(digwatch formats.cpp fields.cpp rules.cpp syslog.cpp digwatch.cpp)
|
||||
|
||||
target_link_libraries(digwatch sinsp)
|
||||
target_link_libraries(digwatch "${LPEG_SRC}/lpeg.a")
|
||||
|
@ -22,6 +22,7 @@ extern "C" {
|
||||
#include "rules.h"
|
||||
#include "formats.h"
|
||||
#include "fields.h"
|
||||
#include "syslog.h"
|
||||
#include "utils.h"
|
||||
|
||||
static bool g_terminate = false;
|
||||
@ -288,7 +289,7 @@ int digwatch_init(int argc, char **argv)
|
||||
digwatch_formats::init(inspector, ls);
|
||||
digwatch_fields::init(inspector, ls);
|
||||
|
||||
digwatch_fields::init(inspector, ls);
|
||||
digwatch_syslog::init(ls);
|
||||
|
||||
rules->load_rules(rules_file);
|
||||
inspector->set_filter(rules->get_filter());
|
||||
|
@ -10,13 +10,10 @@ function mod.stdout(evt, level, format)
|
||||
end
|
||||
|
||||
function mod.syslog(evt, level, format)
|
||||
-- https://neopallium.github.io/nixio/modules/nixio.html#nixio.syslog
|
||||
levels = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"}
|
||||
|
||||
nixio = require("nixio")
|
||||
formatter = digwatch.formatter(format)
|
||||
msg = digwatch.format_event(evt, formatter)
|
||||
nixio.syslog(levels[level+1], msg)
|
||||
digwatch.syslog(level, msg)
|
||||
end
|
||||
|
||||
return mod
|
||||
|
32
userspace/digwatch/syslog.cpp
Normal file
32
userspace/digwatch/syslog.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "syslog.h"
|
||||
#include "chisel_api.h"
|
||||
#include "filterchecks.h"
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
|
||||
const static struct luaL_reg ll_digwatch [] =
|
||||
{
|
||||
{"syslog", &digwatch_syslog::syslog},
|
||||
{NULL,NULL}
|
||||
};
|
||||
|
||||
|
||||
void digwatch_syslog::init(lua_State *ls)
|
||||
{
|
||||
luaL_openlib(ls, "digwatch", ll_digwatch, 0);
|
||||
}
|
||||
|
||||
int digwatch_syslog::syslog(lua_State *ls) {
|
||||
int priority = luaL_checknumber(ls, 1);
|
||||
|
||||
if (priority > LOG_DEBUG) {
|
||||
return luaL_argerror(ls, 1, "digwatch.syslog: priority must be a number between 0 and 7");
|
||||
}
|
||||
|
||||
const char *msg = luaL_checkstring(ls, 2);
|
||||
::syslog(priority, "%s", msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
18
userspace/digwatch/syslog.h
Normal file
18
userspace/digwatch/syslog.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "sinsp.h"
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
}
|
||||
|
||||
class digwatch_syslog
|
||||
{
|
||||
public:
|
||||
static void init(lua_State *ls);
|
||||
|
||||
// value = digwatch.syslog(level, message)
|
||||
static int syslog(lua_State *ls);
|
||||
};
|
Loading…
Reference in New Issue
Block a user