commit 2e6a452: Add new exporter to push JSON to a raw TCP socket; for example to Graylog.
Jason Lingohr
jason at lucid.net.au
Tue Aug 15 14:56:03 UTC 2023
Author: Jason Lingohr
Date: 2023-08-14 16:43:14 +1000
URL: https://github.com/rspamd/rspamd/commit/2e6a452f603cb190f12cd57573f929af2b402a52
Add new exporter to push JSON to a raw TCP socket; for example to Graylog.
---
src/plugins/lua/metadata_exporter.lua | 37 +++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/src/plugins/lua/metadata_exporter.lua b/src/plugins/lua/metadata_exporter.lua
index 9d0826735..eafb9c85c 100644
--- a/src/plugins/lua/metadata_exporter.lua
+++ b/src/plugins/lua/metadata_exporter.lua
@@ -26,6 +26,7 @@ local lua_util = require "lua_util"
local rspamd_http = require "rspamd_http"
local rspamd_util = require "rspamd_util"
local rspamd_logger = require "rspamd_logger"
+local rspamd_tcp = require "rspamd_tcp"
local ucl = require "ucl"
local E = {}
local N = 'metadata_exporter'
@@ -356,6 +357,23 @@ local pushers = {
timeout = rule.timeout or settings.timeout,
}, formatted, sendmail_cb)
end,
+ json_raw = function(task, formatted, rule)
+ local function json_raw_callback(err, code)
+ if err then
+ rspamd_logger.errx(task, 'got error %s in json_raw callback', err)
+ return maybe_defer(task, rule)
+ end
+ return true
+ end
+ rspamd_tcp.request({
+ task=task,
+ host=rule.host,
+ port=rule.port,
+ data=formatted,
+ callback=json_raw_callback,
+ read=false,
+ })
+ end,
}
local opts = rspamd_config:get_all_opt(N)
@@ -534,6 +552,21 @@ if type(settings.rules) ~= 'table' then
settings.rules[r.backend:upper()] = r
end
end
+ if settings.pusher_enabled.json_raw then
+ if not (settings.host and settings.port) then
+ rspamd_logger.errx(rspamd_config, 'No host and/or port is specified')
+ settings.pusher_enabled.json_raw = nil
+ else
+ local r = {}
+ r.backend = 'json_raw'
+ r.host = settings.host
+ r.port = settings.port
+ r.defer = settings.defer
+ r.selector = settings.pusher_select.json_raw
+ r.formatter = settings.pusher_format.json_raw
+ settings.rules[r.backend:upper()] = r
+ end
+ end
if not next(settings.pusher_enabled) then
rspamd_logger.errx(rspamd_config, 'No push backend enabled')
return
@@ -557,6 +590,10 @@ local backend_required_elements = {
redis_pubsub = {
'channel',
},
+ json_raw = {
+ 'host',
+ 'port',
+ },
}
local check_element = {
selector = function(k, v)
More information about the Commits
mailing list