Skip to content

Commit cc70dcc

Browse files
author
Richard Pijnenburg
committed
Initial commit for rewrite
- Deployed new base structure - added logstash codec function - added initial start of new config and conditional handling - new spec tests - new test tasks
1 parent c193b4c commit cc70dcc

25 files changed

+1272
-370
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
*.swp
12
spec/fixtures
2-

.travis.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@ language: ruby
22
rvm:
33
- 1.8.7
44
- 1.9.3
5-
- ruby-head
5+
- 2.0.0
66
script:
77
- "rake lint"
8+
- "rake parser_validate"
9+
- "rake template_verify"
810
- "rake spec SPEC_OPTS='--format documentation'"
911
env:
1012
- PUPPET_VERSION="~> 2.7.0"
1113
- PUPPET_VERSION="~> 3.0.0"
1214
- PUPPET_VERSION="~> 3.1.0"
1315
- PUPPET_VERSION="~> 3.2.0"
16+
- PUPPET_VERSION="~> 3.3.0"
1417
matrix:
1518
allow_failures:
16-
- rvm: ruby-head
17-
exclude:
18-
- rvm: 1.9.3
19-
env: PUPPET_GEM_VERSION="~> 2.7.0"
20-
- rvm: ruby-head
21-
env: PUPPET_GEM_VERSION="~> 2.7.0"
22-
gemfile: .gemfile
23-
notifications:
24-
email:
25-
19+
- rvm: 2.0.0
20+
gemfile: Gemfile

.gemfile renamed to Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source :rubygems
1+
source 'https://rubygems.org'
22

33
puppetversion = ENV['PUPPET_VERSION']
44
gem 'puppet', puppetversion, :require => false

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2012-2013 Richard Pijnenburg
1+
Copyright (c) 2012-2013 Elasticsearch <http://www.elasticsearch.org>
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

Modulefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name 'ispavailability-logstash'
22
version '0.3.4'
3-
source 'https://github.com/electrical/puppet-logstash'
3+
source 'https://github.com/logstash/puppet-logstash'
44
author 'ispavailability'
55
license 'Apache License, Version 2.0'
66
summary 'Module for managing and configuring Logstash'
77
description 'Module for managing and configuring Logstash'
8-
project_page 'https://github.com/electrical/puppet-logstash'
9-
dependency 'puppetlabs/stdlib', '>= 3.0.0'
8+
project_page 'https://github.com/logstash/puppet-logstash'
9+
dependency 'puppetlabs/stdlib', '>= 4.0.0'

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'rubygems'
22
require 'puppetlabs_spec_helper/rake_tasks'
33
require 'puppet-lint'
4+
require './spec/lib/template_check_task.rb'
5+
require './spec/lib/parser_validate_task.rb'
46
PuppetLint.configuration.send("disable_80chars")
57
PuppetLint.configuration.send("disable_class_inherits_from_params_class")

files/etc/sysconfig/logstash.defaults

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
module Puppet::Parser::Functions
2+
newfunction(:logstash_codec, :type => :rvalue, :doc => <<-EOS
3+
Logstash codec function
4+
EOS
5+
) do |arguments|
6+
7+
# We only expect maximum of 2 arguments.
8+
raise(Puppet::ParseError, "logstash_codec(): Wrong number of arguments given (#{arguments.size} given)") if arguments.size > 2
9+
10+
codec_name = arguments[0]
11+
codec_config = arguments[1]
12+
13+
# First argument is the codec name, this has to be a string
14+
unless codec_name.is_a?(String)
15+
raise(Puppet::ParseError, "logstash_codec(): Codec name requires to be a String")
16+
end
17+
18+
# Second argument is the coded config, this has to be a hash.
19+
unless codec_config.nil? and codec_config.is_a?(Hash)
20+
raise(Puppet::ParseError, "logstash_codec(): Codec config requires to be a Hash")
21+
end
22+
23+
case codec_name
24+
25+
when 'compress_spooler'
26+
# spool_size - number
27+
unless codec_config['spool_size'].nil? and codec_config['spool_size'].is_a?(Number)
28+
opt_spool_size = "\t spool_size => #{codec_config['spool_size']}\n"
29+
end
30+
31+
# compress_level - number
32+
unless codec_config['compress_level'].nil? and codec_config['compress_level'].is_a?(Number)
33+
opt_spool_size = "\t compress_level => #{codec_config['compress_level']}\n"
34+
end
35+
36+
37+
opts_codec = "#{opt_spool_size}"
38+
39+
when 'dots'
40+
# No config
41+
42+
when 'edn'
43+
# No config
44+
45+
when 'fluent'
46+
# No config
47+
48+
when 'graphite'
49+
# charset - String
50+
unless codec_config['charset'].nil? and codec_config['charset'].is_a?(String)
51+
if [ 'UTF-8', 'bla', 'bla2', 'bla3' ].include?(codec_config['charset'])
52+
opt_charset = "\t charset => #{codec_config['charset']}\n"
53+
end
54+
end
55+
56+
# metrics - hash
57+
unless codec_config['metrics'].nil? and codec_config['metrics'].is_a?(Hash)
58+
opt_metrics = "\t metrics => #{codec_config['metrics']}\n"
59+
end
60+
61+
# fields_are_metrics - bool
62+
unless codec_config['fields_are_metrics'].nil? and codec_config['fields_are_metrics'].is_a?(Bool)
63+
opt_fields_are_metrics = "\t fields_are_metrics => #{codec_config['fields_are_metrics']}\n"
64+
end
65+
66+
# include_metrics - array
67+
unless codec_config['include_metrics'].nil? and codec_config['include_metrics'].is_a?(Array)
68+
opt_include_metrics = "\t include_metrics => #{codec_config['include_metrics']}\n"
69+
end
70+
71+
# exclude_metrics - array
72+
unless codec_config['exclude_metrics'].nil? and codec_config['exclude_metrics'].is_a?(Array)
73+
opt_exclude_metrics = "\t exclude_metrics => #{codec_config['exclude_metrics']}\n"
74+
end
75+
76+
# metrics_format - string
77+
unless codec_config['metrics_format'].nil? and codec_config['metrics_format'].is_a?(String)
78+
opt_metrics_format = "\t metrics_format => #{codec_config['metrics_format']}\n"
79+
end
80+
81+
opt_codec = "#{opt_charset}#{opt_metrics}#{opt_fields_are_metrics}#{opt_include_metrics}#{opt_exclude_metrics}#{opt_metrics_format}"
82+
83+
when 'json'
84+
unless codec_config['charset'].nil? and codec_config['charset'].is_a?(String)
85+
if [ 'UTF-8', 'bla', 'bla2', 'bla3' ].include?(codec_config['charset'])
86+
opt_charset = "\t charset => #{codec_config['charset']}\n"
87+
end
88+
end
89+
90+
opt_codec = "#{opt_charset}"
91+
92+
when 'json_lines'
93+
unless codec_config['charset'].nil? and codec_config['charset'].is_a?(String)
94+
if [ 'UTF-8', 'bla', 'bla2', 'bla3' ].include?(codec_config['charset'])
95+
opt_charset = "\t charset => #{codec_config['charset']}\n"
96+
end
97+
end
98+
99+
opt_codec = "#{opt_charset}"
100+
101+
when 'json_spooler'
102+
103+
# spool_size - number
104+
unless codec_config['spool_size'].nil? and codec_config['spool_size'].is_a?(Number)
105+
opt_spool_size = "\t spool_size => #{codec_config['spool_size']}\n"
106+
end
107+
108+
opts_codec = "#{opt_spool_size}"
109+
110+
when 'line'
111+
112+
unless codec_config['format'].nil? and codec_config['format'].is_a?(String)
113+
opt_format = "\t format => #{codec_config['format']}\n"
114+
end
115+
116+
unless codec_config['charset'].nil? and codec_config['charset'].is_a?(String)
117+
if [ 'UTF-8', 'bla', 'bla2', 'bla3' ].include?(codec_config['charset'])
118+
opt_charset = "\t charset => #{codec_config['charset']}\n"
119+
end
120+
end
121+
122+
opt_codec = "#{opt_format}#{opt_charset}"
123+
124+
when 'msgpack'
125+
126+
# format - string
127+
unless codec_config['format'].nil? and codec_config['format'].is_a?(String)
128+
opt_format = "\t format => #{codec_config['format']}\n"
129+
end
130+
131+
opts_codec = "#{opt_format}"
132+
133+
when 'multiline'
134+
135+
# pattern - string
136+
unless codec_config['pattern'].nil? and codec_config['pattern'].is_a?(String)
137+
opt_pattern = "\t pattern => #{codec_config['pattern']}\n"
138+
end
139+
140+
# what - previous / next
141+
unless codec_config['what'].nil? and codec_config['what'].is_a?(String)
142+
if ['previous', 'next' ].include?(codec_config['what'])
143+
opt_what = "\t what => #{codec_config['what']}\n"
144+
end
145+
end
146+
147+
# negate - boolean
148+
unless codec_config['negate'].nil? and codec_config['negate'].is_a?(Bool)
149+
opt_negate = "\t negate => #{codec_config['negate']}\n"
150+
end
151+
152+
# patterns_dir - array
153+
unless codec_config['patterns_dir'].nil? and codec_config['patterns_dir'].is_a(Array)
154+
patterns_dir = codec_config['patterns_dir'].join("', '")
155+
opt_format = "\t patterns_dir => ['"+patterns_dir+"']\n"
156+
end
157+
158+
# charset - list
159+
unless codec_config['charset'].nil? and codec_config['charset'].is_a?(String)
160+
if [ 'UTF-8', 'bla', 'bla2', 'bla3' ].include?(codec_config['charset'])
161+
opt_charset = "\t charset => #{codec_config['charset']}\n"
162+
end
163+
end
164+
165+
# multiline_tag - string
166+
unless codec_config['multiline_tag'].nil? and codec_config['multiline_tag'].is_a?(String)
167+
opt_multiline_tag = "\t multiline_tag => #{codec_config['multiline_tag']}\n"
168+
end
169+
170+
opts_codec = "#{opt_pattern}#{opt_what}#{opt_negate}#{opt_format}#{opt_charset}#{opt_multiline_tag}"
171+
172+
when 'netflow'
173+
# cache_ttl - number
174+
unless codec_config['cache_ttl'].nil? and codec_config['cache_ttl'].is_a?(Number)
175+
opt_cache_ttl = "\t cache_ttl => #{codec_config['cache_ttl']}\n"
176+
end
177+
178+
# target - string
179+
unless codec_config['target'].nil? and codec_config['target'].is_a?(String)
180+
opt_target = "\t target => #{codec_config['target']}\n"
181+
end
182+
183+
# version - list
184+
unless codec_config['version'].nil? and codec_config['version'].is_a?(Number)
185+
if [ '5', '9' ].include?(codec_config['version'])
186+
opt_version = "\t version => #{codec_config['version']}\n"
187+
end
188+
end
189+
190+
opt_codec = "#{opt_cache_ttl}#{opt_target}#{opt_version}"
191+
192+
when 'noop'
193+
# No config
194+
195+
when 'oldlogstashjson'
196+
# No config
197+
198+
when 'plain'
199+
200+
unless codec_config['format'].nil?
201+
opt_format = "\t format => #{codec_config['format']}\n"
202+
end
203+
204+
unless codec_config['charset'].nil?
205+
if [ 'UTF-8', 'bla', 'bla2', 'bla3' ].include?(codec_config['charset'])
206+
opt_charset = "\t charset => #{codec_config['charset']}\n"
207+
end
208+
end
209+
210+
opts_codec = "#{opt_format}#{opt_charset}"
211+
212+
when 'rubydebug'
213+
# No config
214+
215+
when 'spool'
216+
# spool_size - number
217+
unless codec_config['spool_size'].nil? and codec_config['spool_size'].is_a?(Number)
218+
opt_spool_size = "\t spool_size => #{codec_config['spool_size']}\n"
219+
end
220+
221+
opts_codec = "#{opt_spool_size}"
222+
223+
else
224+
# We have an invalid codec name
225+
raise(Puppet::ParseError, "#{codec_name} is not a valid codec name")
226+
227+
end # case codec_name
228+
229+
opts = "\n#{opts_codec}\t" unless opts_codec.nil?
230+
result = "#{codec_name} {#{opts}}"
231+
return result
232+
233+
end # do |arguments|
234+
235+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Puppet::Type.type(:logstash_config).provide(:ruby, :parent => Puppet::Type.type(:file).provider(:posix)) do
2+
3+
def exists?
4+
resource.stat ? true : false
5+
end
6+
7+
def create
8+
# FIXME security issue because the file won't necessarily
9+
# be created with the specified mode/owner/group if they
10+
# are specified
11+
send("content=", resource.should_content)
12+
resource.property_fix
13+
end
14+
15+
def destroy
16+
File.unlink(resource[:path]) if exists?
17+
end
18+
19+
def content
20+
actual = File.read(resource[:path]) rescue nil
21+
(actual == resource.should_content) ? resource.no_content : actual
22+
end
23+
#
24+
def content=(value)
25+
File.open(resource[:path], 'w') do |fh|
26+
fh.print resource.should_content
27+
end
28+
end
29+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Puppet::Type.newtype(:logstash_condition) do
2+
3+
4+
@doc = ""
5+
6+
newparam(:name, :namevar => true) do
7+
desc "Unique name"
8+
end
9+
10+
newparam(:condition) do
11+
desc "Condition ( if, elsif, else )"
12+
end
13+
14+
newparam(:expression) do
15+
desc "Expression"
16+
end
17+
18+
newparam(:children) do
19+
desc "Children items"
20+
end
21+
22+
newparam(:require) do
23+
desc "Require which resource to be in front of this one"
24+
end
25+
26+
newparam(:tag) do
27+
desc "Tag"
28+
end
29+
30+
validate do
31+
# think up some validation
32+
end
33+
34+
end
35+

0 commit comments

Comments
 (0)