From 73871fe3c93292fe6674b08b6f99ec01687bdea4 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Wed, 1 Apr 2020 18:15:22 -0400 Subject: [PATCH] Support a dynamic number of listeners for udp --- package/etc/go_templates/source_network.t | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/package/etc/go_templates/source_network.t b/package/etc/go_templates/source_network.t index 47bfab1..b4e5353 100644 --- a/package/etc/go_templates/source_network.t +++ b/package/etc/go_templates/source_network.t @@ -1,13 +1,8 @@ -{{ define "T1" }} - -# The following is the source port declaration for {{ (print .port_id) }} - -source s_{{ .port_id }} { - channel { - source { -{{- if or (getenv (print "SC4S_LISTEN_" .port_id "_UDP_PORT")) (eq .port_id "DEFAULT") }} - syslog ( +{{ define "UDP" }} + syslog ( transport("udp") + so-reuseport(1) + persist-name("udp{{.instance}}") port({{ getenv (print "SC4S_LISTEN_" .port_id "_UDP_PORT") "514" }}) ip-protocol(4) so-rcvbuf({{getenv "SC4S_SOURCE_UDP_SO_RCVBUFF" "1703936"}}) @@ -17,7 +12,21 @@ source s_{{ .port_id }} { use-fqdn(no) chain-hostnames(off) flags(validate-utf8, no-parse {{- if (conv.ToBool (getenv "SC4S_SOURCE_STORE_RAWMSG" "no")) }} store-raw-message {{- end}}) - ); + ); +{{- end}} + +{{ define "T1" }} + +# The following is the source port declaration for {{ (print .port_id) }} + +source s_{{ .port_id }} { + channel { + source { +{{- if or (getenv (print "SC4S_LISTEN_" .port_id "_UDP_PORT")) (eq .port_id "DEFAULT") }} +{{- range (math.Seq (getenv "SC4S_SOURCE_LISTEN_UDP_INSTANCES" "5"))}} +{{- $context := dict "instance" . "port_id" "DEFAULT" }} +{{- template "UDP" $context }} +{{- end}} {{- end}} {{- if or (getenv (print "SC4S_LISTEN_" .port_id "_TCP_PORT")) (eq .port_id "DEFAULT") }} network ( @@ -32,7 +41,7 @@ source s_{{ .port_id }} { use-dns(no) use-fqdn(no) chain-hostnames(off) - flags(no-parse {{- if (conv.ToBool (getenv "SC4S_SOURCE_STORE_RAWMSG" "no")) }} store-raw-message {{- end}}) + flags(validate-utf8, no-parse {{- if (conv.ToBool (getenv "SC4S_SOURCE_STORE_RAWMSG" "no")) }} store-raw-message {{- end}}) ); {{- end}} {{- if (conv.ToBool (getenv "SC4S_SOURCE_TLS_ENABLE" "no")) }} @@ -48,7 +57,7 @@ source s_{{ .port_id }} { use-dns(no) use-fqdn(no) chain-hostnames(off) - flags(no-parse {{- if (conv.ToBool (getenv "SC4S_SOURCE_STORE_RAWMSG" "no")) }} store-raw-message {{- end}}) + flags(validate-utf8, no-parse {{- if (conv.ToBool (getenv "SC4S_SOURCE_STORE_RAWMSG" "no")) }} store-raw-message {{- end}}) tls(allow-compress(yes) key-file("/opt/syslog-ng/tls/server.key") cert-file("/opt/syslog-ng/tls/server.pem")