Skip to content

Commit

Permalink
Merge pull request #390 from splunk/feature/udp-multi-listener
Browse files Browse the repository at this point in the history
Support a dynamic number of listeners for udp
  • Loading branch information
Ryan Faircloth authored and GitHub committed Apr 1, 2020
2 parents 9078ca9 + ef47e25 commit 593865a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions package/etc/go_templates/source_network.t
Original file line number Diff line number Diff line change
@@ -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"}})
Expand All @@ -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_SOCKETS" "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 (
Expand All @@ -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")) }}
Expand All @@ -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")
Expand Down Expand Up @@ -197,4 +206,4 @@ source s_{{ .port_id }} {
{{- end -}}
{{- if or (or (or (getenv (print "SC4S_LISTEN_" .port_id "_TCP_PORT")) (getenv (print "SC4S_LISTEN_" .port_id "_UDP_PORT"))) (getenv (print "SC4S_LISTEN_" .port_id "_TLS_PORT"))) (eq .port_id "DEFAULT") -}}
{{- template "T1" (.) -}}
{{- end -}}
{{- end -}}

0 comments on commit 593865a

Please sign in to comment.