diff --git a/userspace/digwatch/CMakeLists.txt b/userspace/digwatch/CMakeLists.txt index 387bdad2..fd71d282 100644 --- a/userspace/digwatch/CMakeLists.txt +++ b/userspace/digwatch/CMakeLists.txt @@ -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") diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index a995a28d..1e863ee7 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -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()); diff --git a/userspace/digwatch/lua/output.lua b/userspace/digwatch/lua/output.lua index 26a39ac0..a15d89c2 100644 --- a/userspace/digwatch/lua/output.lua +++ b/userspace/digwatch/lua/output.lua @@ -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 diff --git a/userspace/digwatch/syslog.cpp b/userspace/digwatch/syslog.cpp new file mode 100644 index 00000000..8d811651 --- /dev/null +++ b/userspace/digwatch/syslog.cpp @@ -0,0 +1,32 @@ +#include "syslog.h" +#include "chisel_api.h" +#include "filterchecks.h" + +#include + + +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; +} + diff --git a/userspace/digwatch/syslog.h b/userspace/digwatch/syslog.h new file mode 100644 index 00000000..54dccc17 --- /dev/null +++ b/userspace/digwatch/syslog.h @@ -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); +};