diff options
author | Andrew Lewis <nerf@judo.za.org> | 2016-11-10 10:00:09 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2016-11-10 10:00:09 +0200 |
commit | c1bd4e098a637c35edf494a0d15c98de1baae5f8 (patch) | |
tree | 00f09fc0b25549d183b6ed4b95c59ff6a8b2e246 | |
parent | 54ddf6b74babe0bdcf2e455ba287b4afeb94c872 (diff) | |
download | rspamd-c1bd4e098a637c35edf494a0d15c98de1baae5f8.tar.gz rspamd-c1bd4e098a637c35edf494a0d15c98de1baae5f8.zip |
[Feature] Add HTTP backend to metadata exporter
-rw-r--r-- | src/plugins/lua/metadata_exporter.lua | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/src/plugins/lua/metadata_exporter.lua b/src/plugins/lua/metadata_exporter.lua index eb463a2ca..62fdc0d64 100644 --- a/src/plugins/lua/metadata_exporter.lua +++ b/src/plugins/lua/metadata_exporter.lua @@ -17,25 +17,33 @@ limitations under the License. -- A plugin that pushes metadata (or whole messages) to external services +local rspamd_http local rspamd_logger = require "rspamd_logger" local settings = { format = function(task) return task:get_content() end, + mime_type = 'text/plain', } local opts = rspamd_config:get_all_opt('metadata_exporter') if not opts then return end -local redis_params = rspamd_parse_redis_server('metadata_exporter') -if not redis_params then - rspamd_logger.errx(rspamd_config, 'no servers are specified, disabling module') - return -end +local redis_params local channel = opts['channel'] -if not channel then - rspamd_logger.errx(rspamd_config, 'no channel is specified, disabling module') - return +local url = opts['url'] +if not (url or channel) then + rspamd_logger.errx('No backends configured') +end +if channel then + redis_params = rspamd_parse_redis_server('metadata_exporter') + if not redis_params then + rspamd_logger.errx(rspamd_config, 'No redis servers are specified') + return + end +end +if url then + rspamd_http = require "rspamd_http" end if opts['select'] then settings.select = assert(loadstring(opts['select']))() @@ -43,9 +51,20 @@ end if opts['format'] then settings.format = assert(loadstring(opts['format']))() end +if opts['mime_type'] then + settings['mime_type'] = opts['mime_type'] +end local function metadata_exporter(task) local ret,conn,upstream + local function http_callback(err, code, body, headers) + if err then + rspamd_logger.errx(task, 'got error %s in http callback', err) + end + if code ~= 200 then + rspamd_logger.errx(task, 'got unexpected http status: %s', code) + end + end local function redis_set_cb(err, data) if err then rspamd_logger.errx(task, 'got error %s when publishing record on server %s', @@ -64,14 +83,25 @@ local function metadata_exporter(task) rspamd_logger.debugx(task, 'Format returned non-truthy value: %1', data) return end - ret,conn,upstream = rspamd_redis_make_request(task, - redis_params, -- connect params - nil, -- hash key - true, -- is write - redis_set_cb, --callback - 'PUBLISH', -- command - {channel, data} -- arguments - ) + if channel then + ret,conn,upstream = rspamd_redis_make_request(task, + redis_params, -- connect params + nil, -- hash key + true, -- is write + redis_set_cb, --callback + 'PUBLISH', -- command + {channel, data} -- arguments + ) + end + if url then + rspamd_http.request({ + task=task, + url=url, + body=data, + callback=http_callback, + mime_type=settings['mime_type'], + }) + end end rspamd_config:register_symbol({ |