Skip to content

Commit

Permalink
Add basic support for rubies pre-1.9.1 (fixes #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfens committed Apr 7, 2016
1 parent ba57e14 commit ebc6a36
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog

- Add the `close_older` parameter to support the option of the same name in filebeat 1.2.0
- Add support for the `publish_async` parameter.
- Added limited, but improved support for Ruby versions pre-1.9.1 by fixing the hash sort issue
[\#20](https://github.com/pcfens/puppet-filebeat/issues/20)

## [v0.5.8](https://github.com/pcfens/puppet-filebeat/tree/v0.5.8)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v0.5.7...v0.5.8)
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Private Classes](#private-classes)
- [Public Defines](#public-defines)
5. [Limitations - OS compatibility, etc.](#limitations)
- [Pre-1.9.1 Ruby](#pre-1.9.1-ruby)
6. [Development - Guide for contributing to the module](#development)

## Description
Expand Down Expand Up @@ -223,13 +224,26 @@ to fully understand what these parameters do.


## Limitations

This module doesn't load the [elasticsearch index template](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-getting-started.html#filebeat-template) into elasticsearch (required when shipping
directly to elasticsearch).

Only filebeat versions after 1.0.0-rc1 are supported. 1.0.0-rc1 and older don't
support YAML like the ruby template can easily generate.

### Pre-1.9.1 Ruby
If you're on a system running a Ruby pre-1.9.1, hashes aren't sorted consistently, causing puppet runs to
not be idempotent. To fix this, a limited template is used if the rubyversion is pre-1.9.1.
The limited template only supports elasticsearch, logstash, file, and console outputs, and not all options
may be supported (there is no warning when an option is omitted). Unlike with newer rubies, as new versions
of filebeat are released, this template may not work until it's updated, even if you're using an updated
configuration hash.

If you don't care about keeping puppet idempotent, this can be overridden by setting the `conf_template`
parameter to 'filebeat/filebeat.yml.erb'.

See [templates/filebeat.yml.ruby18.erb](https://github.com/pcfens/puppet-filebeat/blob/master/templates/filebeat.yml.ruby18.erb)
for the all of the details.

## Development

Pull requests and bug reports are welcome. If you're sending a pull request, please consider
Expand Down
7 changes: 6 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
$shipper = {}
$logging = {}
$run_options = {}
$conf_template = "${module_name}/filebeat.yml.erb"

if versioncmp('1.9.1', $::rubyversion) > 0 {
$conf_template = "${module_name}/filebeat.yml.ruby18.erb"
} else {
$conf_template = "${module_name}/filebeat.yml.erb"
}

case $::kernel {
'Linux' : {
Expand Down
3 changes: 3 additions & 0 deletions spec/classes/filebeat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:kernel => 'Linux',
:osfamily => 'Debian',
:lsbdistid => 'Ubuntu',
:rubyversion => '1.9.3',
}
end

Expand Down Expand Up @@ -42,6 +43,7 @@
{
:kernel => 'Linux',
:osfamily => 'RedHat',
:rubyversion => '1.8.7',
}
end

Expand All @@ -62,6 +64,7 @@
let :facts do
{
:kernel => 'Windows',
:rubyversion => '1.9.3',
}
end

Expand Down
2 changes: 2 additions & 0 deletions spec/defines/prospector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
let :facts do {
:kernel => 'Linux',
:osfamily => 'Linux',
:rubyversion => '1.9.3',
}
end

Expand Down Expand Up @@ -124,6 +125,7 @@
context 'On Windows' do
let :facts do {
:kernel => 'Windows',
:rubyversion => '1.9.3',
}
end

Expand Down
257 changes: 257 additions & 0 deletions templates/filebeat.yml.ruby18.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
### Filebeat configuration managed by Puppet (Ruby 1.8 version) ###
---
filebeat:
spool_size: <%= @filebeat_config['filebeat']['spool_size'] %>
publish_async: <%= @filebeat_config['filebeat']['publish_async'] %>
idle_timeout: <%= @filebeat_config['filebeat']['idle_timeout'] %>
registry_file: <%= @filebeat_config['filebeat']['registry_file'] %>
config_dir: <%= @filebeat_config['filebeat']['config_dir'] %>

output:
<%- if @filebeat_config['output']['elasticsearch'] != nil -%>
elasticsearch:
hosts:
<%- @filebeat_config['output']['elasticsearch']['hosts'].each do |host| -%>
- <%= host %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['protocol'] != nil -%>
protocol: "<%= @filebeat_config['output']['elasticsearch']['protocol'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['username'] != nil -%>
username: "<%= @filebeat_config['output']['elasticsearch']['username'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['password'] != nil -%>
password: "<%= @filebeat_config['output']['elasticsearch']['password'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['worker'] != nil -%>
worker: <%= @filebeat_config['output']['elasticsearch']['worker'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['index'] != nil -%>
index: "<%= @filebeat_config['output']['elasticsearch']['index'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['path'] != nil -%>
path: "<%= @filebeat_config['output']['elasticsearch']['path'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['proxy_url'] != nil -%>
proxy_url: "<%= @filebeat_config['output']['elasticsearch']['proxy_url'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['max_retries'] != nil -%>
max_retries: <%= @filebeat_config['output']['elasticsearch']['max_retries'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['bulk_max_size'] != nil -%>
bulk_max_size: <%= @filebeat_config['output']['elasticsearch']['bulk_max_size'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['timeout'] != nil -%>
timeout: <%= @filebeat_config['output']['elasticsearch']['timeout'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['flush_interval'] != nil -%>
flush_interval: <%= @filebeat_config['output']['elasticsearch']['flush_interval'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['save_topology'] != nil -%>
save_topology: <%= @filebeat_config['output']['elasticsearch']['save_topology'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['topology_expire'] != nil -%>
topology_expire: <%= @filebeat_config['output']['elasticsearch']['topology_expire'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['template'] != nil -%>
template:
<%- if @filebeat_config['output']['elasticsearch']['template']['name'] != nil -%>
name: "<%= @filebeat_config['output']['elasticsearch']['name'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['template']['path'] != nil -%>
path: "<%= @filebeat_config['output']['elasticsearch']['path'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['template']['overwrite'] != nil -%>
overwrite: <%= @filebeat_config['output']['elasticsearch']['name'] %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls'] != nil -%>
tls:
<%- if @filebeat_config['output']['elasticsearch']['tls']['certificate_authorities'] != nil -%>
certificate_authorities:
<%- @filebeat_config['output']['elasticsearch']['tls']['certificate_authorities'].each do |ca| -%>
- <%= ca %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls']['certificate'] != nil -%>
certificate: "<%= @filebeat_config['output']['elasticsearch']['tls']['certificate'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls']['certifcate_key'] != nil -%>
certificate_key: "<%= @filebeat_config['output']['elasticsearch']['tls']['certificate_key'] %>"
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls']['insecure'] != nil -%>
insecure: <%= @filebeat_config['output']['elasticsearch']['tls']['insecure'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls']['cipher_suites'] != nil -%>
cipher_suites:
<%- @filebeat_config['output']['elasticsearch']['tls']['cipher_suites'].each do |cipher_suite| -%>
- <%= cipher_suite %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls']['curve_types'] != nil -%>
curve_types:
<%- @filebeat_config['output']['elasticsearch']['tls']['curve_types'].each do |curve_type| -%>
- <%= curve_type %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls']['min_version'] != nil -%>
min_version: <%= @filebeat_config['output']['elasticsearch']['tls']['min_version'] %>
<%- end -%>
<%- if @filebeat_config['output']['elasticsearch']['tls']['max_version'] != nil -%>
max_version: <%= @filebeat_config['output']['elasticsearch']['tls']['max_version'] %>
<%- end -%>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['logstash'] != nil -%>
logstash:
hosts:
<%- @filebeat_config['output']['logstash']['hosts'].each do |host| -%>
- <%= host %>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['worker'] != nil -%>
worker: <%= @filebeat_config['output']['logstash']['worker'] %>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['compression_level'] != nil -%>
compression_level: <%= @filebeat_config['output']['logstash']['compression_level'] %>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['loadbalance'] != nil -%>
loadbalance: <%= @filebeat_config['output']['logstash']['loadbalance'] %>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['index'] != nil -%>
index: <%= @filebeat_config['output']['logstash']['index'] %>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['tls'] != nil -%>
tls:
<%- if @filebeat_config['output']['logstash']['tls']['certificate_authorities'] != nil -%>
certificate_authorities:
<%- @filebeat_config['output']['logstash']['tls']['certificate_authorities'].each do |ca| -%>
- <%= ca %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['tls']['certificate'] != nil -%>
certificate: "<%= @filebeat_config['output']['logstash']['tls']['certificate'] %>"
<%- end -%>
<%- if @filebeat_config['output']['logstash']['tls']['certifcate_key'] != nil -%>
certificate_key: "<%= @filebeat_config['output']['logstash']['tls']['certificate_key'] %>"
<%- end -%>
<%- if @filebeat_config['output']['logstash']['tls']['insecure'] != nil -%>
insecure: <%= @filebeat_config['output']['logstash']['tls']['insecure'] %>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['tls']['cipher_suites'] != nil -%>
cipher_suites:
<%- @filebeat_config['output']['logstash']['tls']['cipher_suites'].each do |cipher_suite| -%>
- <%= cipher_suite %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['logstash']['tls']['curve_types'] != nil -%>
curve_types:
<%- @filebeat_config['output']['logstash']['tls']['curve_types'].each do |curve_type| -%>
- <%= curve_type %>
<%- end -%>
<%- end -%>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['file'] != nil -%>
file:
<%- if @filebeat_config['output']['file']['path'] != nil -%>
path: "<%= @filebeat_config['output']['file']['path'] %>"
<%- end -%>
<%- if @filebeat_config['output']['file']['filename'] != nil -%>
filename: <%= @filebeat_config['output']['file']['filename'] %>
<%- end -%>
<%- if @filebeat_config['output']['file']['rotate_every_kb'] != nil -%>
rotate_every_kb: <%= @filebeat_config['output']['file']['rotate_every_kb'] %>
<%- end -%>
<%- if @filebeat_config['output']['file']['number_of_files'] != nil -%>
number_of_files: <%= @filebeat_config['output']['file']['number_of_files'] %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['output']['console'] != nil -%>
console:
<%- if @filebeat_config['output']['console']['pretty'] != nil -%>
pretty: <%= @filebeat_config['output']['console']['pretty'] %>
<%- end -%>
<%- end -%>
<%- unless @filebeat_config['shipper'].empty? -%>
shipper:
<%- if @filebeat_config['shipper']['name'] != nil -%>
name: <%= @filebeat_config['shipper']['name'] %>
<%- end -%>
<%- if @filebeat_config['shipper']['tags'] != nil -%>
tags:
<%- @filebeat_config['shipper']['tags'].each do |tag| -%>
- <%= tag %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['shipper']['ignore_outgoing'] != nil -%>
ignore_outgoing: <%= @filebeat_config['shipper']['ignore_outgoing'] %>
<%- end -%>
<%- if @filebeat_config['shipper']['refresh_topology_freq'] != nil -%>
refresh_topology_freq: <%= @filebeat_config['shipper']['refresh_topology_freq'] %>
<%- end -%>
<%- if @filebeat_config['shipper']['topology_expire'] != nil -%>
topology_expire: <%= @filebeat_config['shipper']['topology_expire'] %>
<%- end -%>
<%- if @filebeat_config['shipper']['queue_size'] != nil -%>
queue_size: <%= @filebeat_config['shipper']['queue_size'] %>
<%- end -%>
<%- if @filebeat_config['shipper']['geoip']['paths'] != nil -%>
geoip:
paths:
<%- @filebeat_config['shipper']['geoip']['paths'].each do |path| -%>
- <%= path %>
<%- end -%>
<%- end -%>
<%- end -%>
<%- unless @filebeat_config['logging'].empty? -%>
logging:
<%- if @filebeat_config['logging']['to_syslog'] != nil -%>
to_syslog: <%= @filebeat_config['logging']['to_syslog'] %>
<%- end -%>
<%- if @filebeat_config['logging']['to_files'] != nil -%>
to_files: <%= @filebeat_config['logging']['to_files'] %>
<%- end -%>
<%- if @filebeat_config['logging']['files'] != nil -%>
files:
<%- if @filebeat_config['logging']['files']['path'] != nil -%>
path: <%= @filebeat_config['logging']['files']['path'] %>
<%- end -%>
<%- if @filebeat_config['logging']['files']['name'] != nil -%>
name: <%= @filebeat_config['logging']['files']['name'] %>
<%- end -%>
<%- if @filebeat_config['logging']['files']['rotateeverybytes'] != nil -%>
rotateeverybytes: <%= @filebeat_config['logging']['files']['rotateeverybytes'] %>
<%- end -%>
<%- if @filebeat_config['logging']['files']['keepfiles'] != nil -%>
keepfiles: <%= @filebeat_config['logging']['files']['keepfiles'] %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['logging']['selectors'] != nil -%>
selectors:
<%- @filebeat_config['logging']['selectors'].each do |selector| -%>
- <%= selector %>
<%- end -%>
<%- end -%>
<%- if @filebeat_config['logging']['level'] != nil -%>
level: <%= @filebeat_config['logging']['level'] %>
<%- end -%>
<%- end -%>
<%- unless @filebeat_config['runoptions'].empty? -%>
runoptions:
<%- if @filebeat_config['runoptions']['uid'] != nil -%>
uid=<%= @filebeat_config['runoptions']['uid'] %>
<%- end -%>
<%- if @filebeat_config['runoptions']['gid'] != nil -%>
gid=<%= @filebeat_config['runoptions']['gid'] %>
<%- end -%>
<%- end -%>

0 comments on commit ebc6a36

Please sign in to comment.