The included apply-template.rb
provides a way generate Logstash config fragments from a shared template.
This can be useful for shared verbose configuration that is shared across multiple pipelines.
For example, if we are using multiple pipelines with pipelines.yml
- pipeline.id: one
path.config: "${LOGSTASH_HOME}/pipelines/one/*.conf"
- pipeline.id: two
path.config: "${LOGSTASH_HOME}/pipelines/two/*.conf"
- pipeline.id: three
path.config: "${LOGSTASH_HOME}/pipelines/three/*.conf"
And the following directory structure:
${LOGSTASH_HOME}/pipelines/
input-beats.erb
one/
input-beats-a.yml
input-beats-b.yml
filters.conf
outputs.conf
two/
input-beats.yml
inputs.conf
filters.conf
outputs.conf
three/
input-beats.yml
inputs.conf
filters.conf
outputs.conf
WHERE pipelines/input-beats.erb
contained:
input { beats { port => <%= port || 5044 %> ssl => true ssl_certificate => "/path/to/logstash.crt" ssl_key => "/path/to/logstash.crt" ssl_certificate_authorities => "/path/to/org.ca" ssl_verify_mode => force_peer tags => <%= Array(tags).inspect %> } }
AND pipelines/one/input-beats-a.yml
contained:
--- port: 5045 tags: source-a
AND pipelines/one/input-beats-b.yml
contained:
--- port: 5046 tags: source-b
AND pipelines/two/input-beats.yml
contained:
--- port: 5047 tags: two
AND pipelines/three/input-beats.yml
contained:
--- port: 5048 tags: - three - third
Then running the command:
./apply-template.rb pipelines/input-beats.erb pipelines/*/input-beats*.yml
Would produce four output files, resulting in a directory structure like:
${LOGSTASH_HOME}/pipelines/
input-beats.erb
one/
input-beats-a.conf
input-beats-a.yml
input-beats-b.conf
input-beats-b.yml
filters.conf
outputs.conf
two/
input-beats.conf
input-beats.yml
inputs.conf
filters.conf
outputs.conf
three/
input-beats.conf
inputs.conf
filters.conf
outputs.conf
WHERE pipelines/one/input-beats-a.conf
would contain:
## GENERATED: 2022-04-22T00:14:56+00:00 ## TEMPLATE: REDACTED/pipelines/input-beats.erb ## CONFIG: REDACTED/pipelines/one/input-beats-a.yml input { beats { port => 5045 ssl => true ssl_certificate => "/path/to/logstash.crt" ssl_key => "/path/to/logstash.crt" ssl_certificate_authorities => "/path/to/org.ca" ssl_verify_mode => force_peer tags => ["source-a"] } }
AND pipelines/one/input-beats-b.conf
would contain:
## GENERATED: 2022-04-22T00:14:56+00:00 ## TEMPLATE: REDACTED/pipelines/input-beats.erb ## CONFIG: REDACTED/pipelines/one/input-beats-b.yml input { beats { port => 5046 ssl => true ssl_certificate => "/path/to/logstash.crt" ssl_key => "/path/to/logstash.crt" ssl_certificate_authorities => "/path/to/org.ca" ssl_verify_mode => force_peer tags => ["source-b"] } }
AND pipelines/three/input-beats.conf
would contain:
## GENERATED: 2022-04-22T00:14:56+00:00 ## TEMPLATE: REDACTED/pipelines/input-beats.erb ## CONFIG: REDACTED/pipelines/three/input-beats.yml input { beats { port => 5048 ssl => true ssl_certificate => "/path/to/logstash.crt" ssl_key => "/path/to/logstash.crt" ssl_certificate_authorities => "/path/to/org.ca" ssl_verify_mode => force_peer tags => ["three", "third"] } }
AND pipelines/two/input-beats.conf
would contain:
## GENERATED: 2022-04-22T00:14:56+00:00 ## TEMPLATE: REDACTED/pipelines/input-beats.erb ## CONFIG: REDACTED/pipelines/two/input-beats.yml input { beats { port => 5047 ssl => true ssl_certificate => "/path/to/logstash.crt" ssl_key => "/path/to/logstash.crt" ssl_certificate_authorities => "/path/to/org.ca" ssl_verify_mode => force_peer tags => ["two"] } }