From 1988aa01466ec3ee845fd8b8eab4e9c9db0d3c40 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 12:30:41 +0000 Subject: [PATCH 01/41] Update to pdk, rewrite code to new Puppet syntaxe and add support to winlogbeat 6 and 7 --- .gitattributes | 5 + .gitignore | 45 +- .gitlab-ci.yml | 41 ++ .pdkignore | 42 ++ .puppet-lint.rc | 1 + .rspec | 2 +- .rubocop.yml | 635 +++------------- .travis.yml | 57 +- .yardopts | 1 - Gemfile | 119 ++- Rakefile | 84 +-- appveyor.yml | 55 ++ data/common.yaml | 51 ++ hiera.yaml | 13 + lib/facter/winlogbeat_version.rb | 2 +- manifests/config.pp | 111 ++- manifests/init.pp | 181 +++-- manifests/install.pp | 21 +- manifests/params.pp | 43 -- manifests/service.pp | 5 + metadata.json | 35 +- spec/acceptance/001_basic_spec.rb | 7 + .../nodesets/ec2/image_templates_sihm.yaml | 14 + .../ec2/windows-2016-base-x64-sihm.yml | 27 + .../nodesets/ec2/windows-2016-base-x64.yml | 55 +- spec/default_facts.yml | 8 + spec/spec_helper.rb | 65 +- spec/spec_helper_acceptance.rb | 52 ++ templates/pure_hash.yml.epp | 2 + templates/winlogbeat1.yml.erb | 52 -- templates/winlogbeat1.yml.ruby18.erb | 288 -------- templates/winlogbeat5.yml.erb | 697 ------------------ 32 files changed, 818 insertions(+), 1998 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitlab-ci.yml create mode 100644 .pdkignore create mode 100644 .puppet-lint.rc create mode 100644 appveyor.yml create mode 100644 data/common.yaml create mode 100644 hiera.yaml delete mode 100644 manifests/params.pp create mode 100644 spec/acceptance/001_basic_spec.rb create mode 100644 spec/acceptance/nodesets/ec2/image_templates_sihm.yaml create mode 100644 spec/acceptance/nodesets/ec2/windows-2016-base-x64-sihm.yml create mode 100644 spec/default_facts.yml create mode 100644 spec/spec_helper_acceptance.rb create mode 100644 templates/pure_hash.yml.epp delete mode 100644 templates/winlogbeat1.yml.erb delete mode 100644 templates/winlogbeat1.yml.ruby18.erb delete mode 100644 templates/winlogbeat5.yml.erb diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore index e9b3cf4..2767022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,27 @@ -pkg/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.librarian/ -Puppetfile.lock +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns *.iml -.*.sw? -.yardoc/ -Guardfile +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..81e6d76 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,41 @@ +--- +stages: + - syntax + - unit + +cache: + paths: + - vendor/bundle + +before_script: + - bundle -v + - rm Gemfile.lock || true + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.3-Puppet ~> 6: + stage: syntax + image: ruby:2.5.3 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.5.3-Puppet ~> 6: + stage: unit + image: ruby:2.5.3 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.4.5-Puppet ~> 5: + stage: unit + image: ruby:2.4.5 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..e6215cd --- /dev/null +++ b/.pdkignore @@ -0,0 +1,42 @@ +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml +/appveyor.yml +/.fixtures.yml +/Gemfile +/.gitattributes +/.gitignore +/.gitlab-ci.yml +/.pdkignore +/Rakefile +/rakelib/ +/.rspec +/.rubocop.yml +/.travis.yml +/.yardopts +/spec/ +/.vscode/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..cc96ece --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--relative diff --git a/.rspec b/.rspec index 8c18f1a..16f9cdb 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ ---format documentation --color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml index 099a11c..f5a6c2a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,545 +1,122 @@ +--- require: rubocop-rspec AllCops: - TargetRubyVersion: 1.9 + DisplayCopNames: true + TargetRubyVersion: '2.1' Include: - - ./**/*.rb + - "./**/*.rb" Exclude: - - files/**/* - - vendor/**/* - - .vendor/**/* - - pkg/**/* - - spec/fixtures/**/* - - Gemfile - - Rakefile - - Guardfile - - Vagrantfile -Lint/ConditionPosition: - Enabled: True - -Lint/ElseLayout: - Enabled: True - -Lint/UnreachableCode: - Enabled: True - -Lint/UselessComparison: - Enabled: True - -Lint/EnsureReturn: - Enabled: True - -Lint/HandleExceptions: - Enabled: True - -Lint/LiteralInCondition: - Enabled: True - -Lint/ShadowingOuterLocalVariable: - Enabled: True - -Lint/LiteralInInterpolation: - Enabled: True - -Style/HashSyntax: - Enabled: True - -Style/RedundantReturn: - Enabled: True - -Layout/EndOfLine: - Enabled: False - -Lint/AmbiguousOperator: - Enabled: True - -Lint/AssignmentInCondition: - Enabled: True - -Layout/SpaceBeforeComment: - Enabled: True - -Style/AndOr: - Enabled: True - -Style/RedundantSelf: - Enabled: True - -Metrics/BlockLength: - Enabled: False - -# Method length is not necessarily an indicator of code quality -Metrics/MethodLength: - Enabled: False - -# Module length is not necessarily an indicator of code quality -Metrics/ModuleLength: - Enabled: False - -Style/WhileUntilModifier: - Enabled: True - -Lint/AmbiguousRegexpLiteral: - Enabled: True - -Security/Eval: - Enabled: True - -Lint/BlockAlignment: - Enabled: True - -Lint/DefEndAlignment: - Enabled: True - -Lint/EndAlignment: - Enabled: True - -Lint/DeprecatedClassMethods: - Enabled: True - -Lint/Loop: - Enabled: True - -Lint/ParenthesesAsGroupedExpression: - Enabled: True - -Lint/RescueException: - Enabled: True - -Lint/StringConversionInInterpolation: - Enabled: True - -Lint/UnusedBlockArgument: - Enabled: True - -Lint/UnusedMethodArgument: - Enabled: True - -Lint/UselessAccessModifier: - Enabled: True - -Lint/UselessAssignment: - Enabled: True - -Lint/Void: - Enabled: True - -Layout/AccessModifierIndentation: - Enabled: True - -Style/AccessorMethodName: - Enabled: True - -Style/Alias: - Enabled: True - -Layout/AlignArray: - Enabled: True - -Layout/AlignHash: - Enabled: True - -Layout/AlignParameters: - Enabled: True - -Metrics/BlockNesting: - Enabled: True - -Style/AsciiComments: - Enabled: True - -Style/Attr: - Enabled: True - -Style/BracesAroundHashParameters: - Enabled: True - -Style/CaseEquality: - Enabled: True - -Layout/CaseIndentation: - Enabled: True - -Style/CharacterLiteral: - Enabled: True - -Style/ClassAndModuleCamelCase: - Enabled: True - -Style/ClassAndModuleChildren: - Enabled: False - -Style/ClassCheck: - Enabled: True - -# Class length is not necessarily an indicator of code quality -Metrics/ClassLength: - Enabled: False - -Style/ClassMethods: - Enabled: True - -Style/ClassVars: - Enabled: True - -Style/WhenThen: - Enabled: True - -Style/WordArray: - Enabled: True - -Style/UnneededPercentQ: - Enabled: True - -Layout/Tab: - Enabled: True - -Layout/SpaceBeforeSemicolon: - Enabled: True - -Layout/TrailingBlankLines: - Enabled: True - -Layout/SpaceInsideBlockBraces: - Enabled: True - -Layout/SpaceInsideBrackets: - Enabled: True - -Layout/SpaceInsideHashLiteralBraces: - Enabled: True - -Layout/SpaceInsideParens: - Enabled: True - -Layout/LeadingCommentSpace: - Enabled: True - -Layout/SpaceBeforeFirstArg: - Enabled: True - -Layout/SpaceAfterColon: - Enabled: True - -Layout/SpaceAfterComma: - Enabled: True - -Layout/SpaceAfterMethodName: - Enabled: True - -Layout/SpaceAfterNot: - Enabled: True - -Layout/SpaceAfterSemicolon: - Enabled: True - -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: True - -Layout/SpaceAroundOperators: - Enabled: True - -Layout/SpaceBeforeBlockBraces: - Enabled: True - -Layout/SpaceBeforeComma: - Enabled: True - -Style/CollectionMethods: - Enabled: True - -Layout/CommentIndentation: - Enabled: True - -Style/ColonMethodCall: - Enabled: True - -Style/CommentAnnotation: - Enabled: True - -# 'Complexity' is very relative -Metrics/CyclomaticComplexity: - Enabled: False - -Style/ConstantName: - Enabled: True - -Style/Documentation: - Enabled: False - -Style/DefWithParentheses: - Enabled: True - -Style/PreferredHashMethods: - Enabled: True - -Layout/DotPosition: - EnforcedStyle: trailing - -Style/DoubleNegation: - Enabled: True - -Style/EachWithObject: - Enabled: True - -Layout/EmptyLineBetweenDefs: - Enabled: True - -Layout/IndentArray: - Enabled: True - -Layout/IndentHash: - Enabled: True - -Layout/IndentationConsistency: - Enabled: True - -Layout/IndentationWidth: - Enabled: True - -Layout/EmptyLines: - Enabled: True - -Layout/EmptyLinesAroundAccessModifier: - Enabled: True - -Style/EmptyLiteral: - Enabled: True - -# Configuration parameters: AllowURI, URISchemes. + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" Metrics/LineLength: - Enabled: False - -Style/MethodCallWithoutArgsParentheses: - Enabled: True - -Style/MethodDefParentheses: - Enabled: True - -Style/LineEndConcatenation: - Enabled: True - -Layout/TrailingWhitespace: - Enabled: True - -Style/StringLiterals: - Enabled: True - -Style/TrailingCommaInArguments: - Enabled: True - -Style/TrailingCommaInLiteral: - Enabled: True - -Style/GlobalVars: - Enabled: True - -Style/GuardClause: - Enabled: True - -Style/IfUnlessModifier: - Enabled: True - -Style/MultilineIfThen: - Enabled: True - -Style/NegatedIf: - Enabled: True - -Style/NegatedWhile: - Enabled: True - -Style/Next: - Enabled: True - -Style/SingleLineBlockParams: - Enabled: True - -Style/SingleLineMethods: - Enabled: True - -Style/SpecialGlobalVars: - Enabled: True - -Style/TrivialAccessors: - Enabled: True - -Style/UnlessElse: - Enabled: True - -Style/VariableInterpolation: - Enabled: True - -Style/VariableName: - Enabled: True - -Style/WhileUntilDo: - Enabled: True - -Style/EvenOdd: - Enabled: True - -Style/FileName: - Enabled: True - -Style/For: - Enabled: True - -Style/Lambda: - Enabled: True - -Style/MethodName: - Enabled: True - -Style/MultilineTernaryOperator: - Enabled: True - -Style/NestedTernaryOperator: - Enabled: True - -Style/NilComparison: - Enabled: True - + Description: People have wide screens, use them. + Max: 200 +GetText/DecorateString: + Description: We don't want to decorate test output. + Exclude: + - spec/* +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty Style/FormatString: - Enabled: True - -Style/MultilineBlockChain: - Enabled: True - -Style/Semicolon: - Enabled: True - -Style/SignalException: - Enabled: True - -Style/NonNilCheck: - Enabled: True - -Style/Not: - Enabled: True - -Style/NumericLiterals: - Enabled: True - -Style/OneLineConditional: - Enabled: True - -Style/OpMethod: - Enabled: True - -Style/ParenthesesAroundCondition: - Enabled: True - -Style/PercentLiteralDelimiters: - Enabled: True - -Style/PerlBackrefs: - Enabled: True - -Style/PredicateName: - Enabled: True - -Style/RedundantException: - Enabled: True - -Style/SelfAssignment: - Enabled: True - -Style/Proc: - Enabled: True - -Style/RaiseArgs: - Enabled: True - -Style/RedundantBegin: - Enabled: True - -Style/RescueModifier: - Enabled: True - -# based on https://github.com/voxpupuli/modulesync_config/issues/168 + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 EnforcedStyle: percent_r - Enabled: True - -Lint/UnderscorePrefixedVariableName: - Enabled: True - -Metrics/ParameterLists: - Enabled: False - -Lint/RequireParentheses: - Enabled: True - -Style/ModuleFunction: - Enabled: True - -Lint/Debugger: - Enabled: True - -Style/IfWithSemicolon: - Enabled: True - -Style/Encoding: - Enabled: True - -Style/BlockDelimiters: - Enabled: True - -Layout/MultilineBlockLayout: - Enabled: True - -# 'Complexity' is very relative +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +Layout/EndOfLine: + Enabled: false +Layout/IndentHeredoc: + Enabled: false Metrics/AbcSize: - Enabled: False - -# 'Complexity' is very relative + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false Metrics/PerceivedComplexity: - Enabled: False - -Lint/UselessAssignment: - Enabled: True - -Layout/ClosingParenthesisIndentation: - Enabled: True - -# RSpec - -RSpec/BeforeAfterAll: - Exclude: - - spec/acceptance/**/* - -# We don't use rspec in this way + Enabled: false RSpec/DescribeClass: - Enabled: False - -# Example length is not necessarily an indicator of code quality + Enabled: false RSpec/ExampleLength: - Enabled: False - -RSpec/NamedSubject: - Enabled: False - -# disabled for now since they cause a lot of issues -# these issues aren't easy to fix -RSpec/RepeatedDescription: - Enabled: False - + Enabled: false +RSpec/MessageExpectation: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false RSpec/NestedGroups: - Enabled: False - -# this is broken on ruby1.9 -Layout/IndentHeredoc: - Enabled: False - -# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs -Security/YAMLLoad: Enabled: false - -# This affects hiera interpolation, as well as some configs that we push. -Style/FormatStringToken: +Style/AsciiComments: + Enabled: false +Style/IfUnlessModifier: Enabled: false - -# This is useful, but sometimes a little too picky about where unit tests files -# are located. -RSpec/FilePath: +Style/SymbolProc: Enabled: false diff --git a/.travis.yml b/.travis.yml index 63091e6..ee67078 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,48 @@ --- -dist: xenial +dist: trusty language: ruby cache: bundler before_install: - - gem update --system - - gem update bundler - - bundle --version + - bundle -v + - rm -f Gemfile.lock + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v script: - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.5.3 +stages: + - static + - spec + - acceptance + - + if: tag =~ ^v\d + name: deploy matrix: fast_finish: true include: - - rvm: 2.4.4 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 5.0" CHECK=test - - rvm: 2.5.3 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls - - rvm: 2.5.3 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 6.0" CHECK=rubocop - - rvm: 2.4.4 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes + - + env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" + stage: static + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.5 + stage: spec + - + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.3 + stage: spec + - + env: DEPLOY_TO_FORGE=yes + stage: deploy branches: only: - - master - - /^v\d/ + - master + - /^v\d/ notifications: email: false - irc: - on_success: always - on_failure: always - channels: - - "chat.freenode.org#voxpupuli-notifications" deploy: provider: puppetforge user: puppet @@ -41,7 +50,5 @@ deploy: secure: "cw/RZwWlB1XyxCt+GnS9xgVA+v3qF9Yhps5HTV3dY3cZXBSYlZtPpNrk/2vmZ7SHAQF5zJv0WLUYs6Y8vtwGc3HegS/hXDKlclqGqvGjGtYOEihNZs2AKnXzNOJghFbyCnmEWHnBAPns03/qCh5cpEAQ7IrdkIz7Y6ahVwWC3XGM8Wg3fMYIoN/JY+Gpu9/biJzA23wXQU62ii4KSx6gM9nG/WofQrgKlK/35RxP8o00NHatXAV/cIfN4bM+7tMCjDL51tANrsPBaQGJZp1JX4sSuHLR0/krEoB8vGKqmvk5jN/Tp4GM0EfYHVhFn59HIA8ufPNNVVnU/1yMvic+cYE7hNrDwGmK0QxZMWLYS7/au0gzvVGBzN96LCA2tA9CjsZ379o7SqJb7Y0+ycEgxVSeJX8yZSumIkfCTYlHkHDtJdbY4jrfl8h3pCNUK2CJ0e2jtNqILYQswudtQa+Xqrz2KV1t6HQgjNtfTmG4M/V1ronDfDbQPaUxZQlOyglOGFv7zpqjt7Ybgz+h2auE3iz2u9z9edQS/8aKyBIutOMfYrVeTvxMlriLZnmTmv9QAQ9YtPLTDRvRu0cc8EytcqMwV7fatZ2dnoy3qv2UCAB5zAq/m/TMJZ4FemOijrz9JYvUh5kU67gBHDFm4FTvHUOG8LnGmOMwDtNdRHHCQHw=" on: tags: true - # all_branches is required to use tags all_branches: true - # Only publish the build marked with "DEPLOY_TO_FORGE" condition: "$DEPLOY_TO_FORGE = yes" diff --git a/.yardopts b/.yardopts index 3687f51..29c933b 100644 --- a/.yardopts +++ b/.yardopts @@ -1,2 +1 @@ --markup markdown ---output-dir docs/ diff --git a/Gemfile b/Gemfile index 24dbb7f..cf2c387 100644 --- a/Gemfile +++ b/Gemfile @@ -1,82 +1,71 @@ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' -def location_for(place, fake_version = nil) - if place =~ /^(git[:@][^#]*)#(.*)/ - [fake_version, { :git => $1, :branch => $2, :require => false }].compact - elsif place =~ /^file:\/\/(.*)/ - ['>= 0', { :path => File.expand_path($1), :require => false }] +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] else - [place, { :require => false }] + [place_or_version, { require: false }] end end -group :test do - gem 'puppetlabs_spec_helper', '>= 2.14.0', :require => false - gem 'rspec-puppet-facts', '>= 1.8.0', :require => false - gem 'rspec-puppet-utils', :require => false - gem 'puppet-lint-leading_zero-check', :require => false - gem 'puppet-lint-trailing_comma-check', :require => false - gem 'puppet-lint-version_comparison-check', :require => false - gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false - gem 'puppet-lint-unquoted_string-check', :require => false - gem 'puppet-lint-variable_contains_upcase', :require => false - gem 'puppet-lint-absolute_classname-check', :require => false - gem 'metadata-json-lint', :require => false - gem 'redcarpet', :require => false - gem 'rubocop', '~> 0.49.1', :require => false - gem 'rubocop-rspec', '~> 1.15.0', :require => false - gem 'mocha', '~> 1.4.0', :require => false - gem 'coveralls', :require => false - gem 'simplecov-console', :require => false - gem 'parallel_tests', :require => false -end +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') group :development do - gem 'travis', :require => false - gem 'travis-lint', :require => false - gem 'guard-rake', :require => false - gem 'overcommit', '>= 0.39.1', :require => false + gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') + gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') + gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') + gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] end -group :system_tests do - gem 'winrm', :require => false - if beaker_version = ENV['BEAKER_VERSION'] - gem 'beaker', *location_for(beaker_version) - else - gem 'beaker', '>= 4.2.0', :require => false - end - if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] - gem 'beaker-rspec', *location_for(beaker_rspec_version) - else - gem 'beaker-rspec', :require => false - end - gem 'serverspec', :require => false - gem 'beaker-hostgenerator', '>= 1.1.22', :require => false - gem 'beaker-docker', :require => false - gem 'beaker-puppet', :require => false - gem 'beaker-puppet_install_helper', :require => false - gem 'beaker-module_install_helper', :require => false - gem 'rbnacl', '>= 4', :require => false - gem 'rbnacl-libsodium', :require => false - gem 'bcrypt_pbkdf', :require => false -end +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] -group :release do - gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator' - gem 'puppet-blacksmith', :require => false - gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem' - gem 'puppet-strings', '>= 2.2', :require => false -end +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version +if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} + # If we're using a Puppet gem on Windows which handles its own win32-xxx gem + # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). + gems['win32-dir'] = ['<= 0.4.9', require: false] + gems['win32-eventlog'] = ['<= 0.6.5', require: false] + gems['win32-process'] = ['<= 0.7.5', require: false] + gems['win32-security'] = ['<= 0.2.5', require: false] + gems['win32-service'] = ['0.8.8', require: false] +end -if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', facterversion.to_s, :require => false, :groups => [:test] -else - gem 'facter', :require => false, :groups => [:test] +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params end -ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 6.0' : puppetversion = ENV['PUPPET_VERSION'].to_s -gem 'puppet', puppetversion, :require => false, :groups => [:test] +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end +end # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 09701d0..ff244fb 100644 --- a/Rakefile +++ b/Rakefile @@ -1,82 +1,4 @@ +require 'rake' require 'puppetlabs_spec_helper/rake_tasks' - -# load optional tasks for releases -# only available if gem group releases is installed -begin - require 'voxpupuli/release/rake_tasks' -rescue LoadError -end - -PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' -PuppetLint.configuration.absolute_classname_reverse = true - -exclude_paths = %w( - pkg/**/* - vendor/**/* - .vendor/**/* - spec/**/* -) -PuppetLint.configuration.ignore_paths = exclude_paths -PuppetSyntax.exclude_paths = exclude_paths - -desc 'Auto-correct puppet-lint offenses' -task 'lint:auto_correct' do - Rake::Task[:lint_fix].invoke -end - -desc 'Run acceptance tests' -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' -end - -desc 'Run tests' -task test: [:release_checks] - -namespace :check do - desc 'Check for trailing whitespace' - task :trailing_whitespace do - Dir.glob('**/*.md', File::FNM_DOTMATCH).sort.each do |filename| - next if filename =~ %r{^((modules|acceptance|\.?vendor|spec/fixtures|pkg)/|REFERENCE.md)} - File.foreach(filename).each_with_index do |line, index| - if line =~ %r{\s\n$} - puts "#{filename} has trailing whitespace on line #{index + 1}" - exit 1 - end - end - end - end -end -Rake::Task[:release_checks].enhance ['check:trailing_whitespace'] - -desc "Run main 'test' task and report merged results to coveralls" -task test_with_coveralls: [:test] do - if Dir.exist?(File.expand_path('../lib', __FILE__)) - require 'coveralls/rake/task' - Coveralls::RakeTask.new - Rake::Task['coveralls:push'].invoke - else - puts 'Skipping reporting to coveralls. Module has no lib dir' - end -end - -desc 'Generate REFERENCE.md' -task :reference, [:debug, :backtrace] do |t, args| - patterns = '' - Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) -end - -begin - require 'github_changelog_generator/task' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - version = (Blacksmith::Modulefile.new).version - config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/ - config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} - config.user = 'voxpupuli' - metadata_json = File.join(File.dirname(__FILE__), 'metadata.json') - metadata = JSON.load(File.read(metadata_json)) - config.project = metadata['name'] - end -rescue LoadError -end -# vim: syntax=ruby +require 'puppet-syntax/tasks/puppet-syntax' +require 'fileutils' \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..e10ba3b --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,55 @@ +--- +version: 1.1.x.{build} +branches: + only: + - master +skip_commits: + message: /^\(?doc\)?.*/ +clone_depth: 10 +init: + - SET + - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' +environment: + matrix: + - + RUBY_VERSION: 24-x64 + CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24-x64 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25-x64 + CHECK: parallel_spec +matrix: + fast_finish: true +install: + - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% + - bundle install --jobs 4 --retry 2 --without system_tests + - type Gemfile.lock +build: off +test_script: + - bundle exec puppet -V + - ruby -v + - gem -v + - bundle -v + - bundle exec rake %CHECK% +notifications: + - provider: Email + to: + - nobody@nowhere.com + on_build_success: false + on_build_failure: false + on_build_status_changed: false diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..18cdca2 --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,51 @@ +--- +# User settings +winlogbeat::service_ensure: 'running' +winlogbeat::service_enable: true +winlogbeat::spool_size: 2048 +winlogbeat::idle_timeout: '5s' +winlogbeat::publish_async: false +winlogbeat::shutdown_timeout: '0' +winlogbeat::beat_name: "%{lookup($::fqdn)}" +winlogbeat::tags: [] +winlogbeat::queue_size: 1000 +winlogbeat::fields: {} +winlogbeat::fields_under_root: false +winlogbeat::outputs: {} +winlogbeat::logging: {} +winlogbeat::run_options: {} +winlogbeat::disable_config_test: false +winlogbeat::package_ensure: '6.7.2' +winlogbeat::event_logs: [] +winlogbeat::setup: {} +winlogbeat::queue: {} +winlogbeat::processors: {} +winlogbeat::registry_flush: null +winlogbeat::manage_download_file: true +winlogbeat::download_url: null +winlogbeat::winlogbeat_zip_path: null +winlogbeat::proxy_address: null +winlogbeat::xpack: null +winlogbeat::max_procs: null + +# Internal module +winlogbeat::service_provider: null +winlogbeat::config_file_mode: '0644' +winlogbeat::config_dir_mode: '0755' +winlogbeat::kernel_fail_message: "%{lookup($::kernel)} is not supported by winlogbeat." +winlogbeat::conf_template: 'winlogbeat/pure_hash.yml.epp' +winlogbeat::config_file_owner: 'Administrator' +winlogbeat::config_file_group: null +winlogbeat::config_dir_owner: 'Administrator' +winlogbeat::config_dir_group: null +winlogbeat::config_file: "C:/Program Files/%{lookup($winlogbeat::folder_name)}/winlogbeat.yml" +winlogbeat::registry_file: 'C:/ProgramData/%{lookup($winlogbeat::folder_name)}/registry' +winlogbeat::install_dir: 'C:/Program Files' +winlogbeat::tmp_dir: 'C:/Windows/Temp' +winlogbeat::folder_name: 'Winlogbeat' + +lookup_options: + winlogbeat::event_logs: + merge: + strategy: 'deep' + merge_hash_arrays: true \ No newline at end of file diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..f4d9032 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,13 @@ +--- +version: 5 +defaults: + data_hash: yaml_data + +# The default values can be merged if you want to extend with additional packages +# If not, use 'default_hierarchy' instead of 'hierarchy' +# +hierarchy: +- name: 'Per Operating System' + path: "os/%{os.name}.yaml" +- name: 'Common' + path: 'common.yaml' \ No newline at end of file diff --git a/lib/facter/winlogbeat_version.rb b/lib/facter/winlogbeat_version.rb index a9ba238..280ef01 100644 --- a/lib/facter/winlogbeat_version.rb +++ b/lib/facter/winlogbeat_version.rb @@ -1,6 +1,6 @@ require 'facter' Facter.add('winlogbeat_version') do - confine :kernel => %w[Windows] # rubocop:disable Style/HashSyntax + confine :kernel => ['Windows'] # rubocop:disable Style/HashSyntax if File.exist?('c:\Program Files\Winlogbeat\winlogbeat.exe') winlogbeat_version = Facter::Util::Resolution.exec('"c:\Program Files\Winlogbeat\winlogbeat.exe" --version') end diff --git a/manifests/config.pp b/manifests/config.pp index 70a3ff8..c875c74 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,37 +1,86 @@ +# winlogbeat::config +# +# Manage the configuration of winlogbeat +# +# @summary A private class to manage the winglobeat config file + class winlogbeat::config { - $winlogbeat_config = delete_undef_values({ - 'beat_name' => $winlogbeat::beat_name, - 'tags' => $winlogbeat::tags, - 'queue_size' => $winlogbeat::queue_size, - 'max_procs' => $winlogbeat::max_procs, - 'fields' => $winlogbeat::fields, - 'fields_under_root' => $winlogbeat::fields_under_root, - 'winlogbeat' => { - 'registry_file' => $winlogbeat::registry_file, - 'metrics' => $winlogbeat::metrics, - 'event_logs' => $winlogbeat::event_logs_final, - }, - 'output' => $winlogbeat::outputs, - 'shipper' => $winlogbeat::shipper, - 'logging' => $winlogbeat::logging, - 'runoptions' => $winlogbeat::run_options, - }) + $major_version = regsubst($winlogbeat::package_ensure, '^(\d)\..*', '\1') - case $::kernel { - 'Windows' : { - $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') - $winlogbeat_path = join([$cmd_install_dir, 'Winlogbeat', 'winlogbeat.exe'], '\\') - file {'winlogbeat.yml': - ensure => file, - path => $winlogbeat::config_file, - content => template($winlogbeat::real_conf_template), - validate_cmd => "\"${winlogbeat_path}\" -N -configtest -c \"%\"", - notify => Service['winlogbeat'], - } - } # end Windows + if versioncmp($major_version, '6') >= 0 { + $winlogbeat_config_temp = delete_undef_values({ + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'name' => $winlogbeat::beat_name, + 'tags' => $winlogbeat::tags, + 'max_procs' => $winlogbeat::max_procs, + 'fields' => $winlogbeat::fields, + 'fields_under_root' => $winlogbeat::fields_under_root, + 'winlogbeat' => { + 'registry_file' => $winlogbeat::registry_file, + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'event_logs' => $winlogbeat::event_logs, + }, + 'output' => $winlogbeat::outputs, + 'logging' => $winlogbeat::logging, + 'runoptions' => $winlogbeat::run_options, + 'processors' => $winlogbeat::processors, + 'setup' => $winlogbeat::setup, + 'queue' => $winlogbeat::queue, + }) + # Add the 'xpack' section if supported (version >= 6.1.0) and not undef + if $winlogbeat::xpack and versioncmp($winlogbeat::package_ensure, '6.1.0') >= 0 { + $winlogbeat_config = deep_merge($winlogbeat_config_temp, {'xpack' => $winlogbeat::xpack}) + } + else { + $winlogbeat_config = $winlogbeat_config_temp + } + } else { + $winlogbeat_config = delete_undef_values({ + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'name' => $winlogbeat::beat_name, + 'tags' => $winlogbeat::tags, + 'queue_size' => $winlogbeat::queue_size, + 'max_procs' => $winlogbeat::max_procs, + 'fields' => $winlogbeat::fields, + 'fields_under_root' => $winlogbeat::fields_under_root, + 'winlogbeat' => { + 'spool_size' => $winlogbeat::spool_size, + 'idle_timeout' => $winlogbeat::idle_timeout, + 'registry_file' => $winlogbeat::registry_file, + 'publish_async' => $winlogbeat::publish_async, + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'event_logs' => $winlogbeat::event_logs, + }, + 'output' => $winlogbeat::outputs, + 'logging' => $winlogbeat::logging, + 'runoptions' => $winlogbeat::run_options, + 'processors' => $winlogbeat::processors, + }) + } - default : { - fail($winlogbeat::kernel_fail_message) + if ($facts['winlogbeat_version']) { + $skip_validation = versioncmp($facts['winlogbeat_version'], $major_version) ? { + -1 => true, + default => false, } + } else { + $skip_validation = false + } + + $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') + $winlogbeat_path = join([$cmd_install_dir, 'winlogbeat', 'winlogbeat.exe'], '\\') + + $validate_cmd = ($winlogbeat::disable_config_test or $skip_validation) ? { + true => undef, + default => "\"${winlogbeat_path}\" -N -configtest -c \"%\"", } + + file {'winlogbeat.yml': + ensure => $winlogbeat::file_ensure, + path => $winlogbeat::config_file, + content => template($winlogbeat::conf_template), + validate_cmd => $validate_cmd, + notify => Service['winlogbeat'], + } + } diff --git a/manifests/init.pp b/manifests/init.pp index 373b7aa..b8bd205 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -12,104 +12,125 @@ # }, # } # -# @param package_ensure [String] The version parameter for the winlogbeat package +# @param package_ensure [String] The ensure parameter for the winlogbeat package (default: present) # @param service_ensure [String] The ensure parameter on the winlogbeat service (default: running) # @param service_enable [String] The enable parameter on the winlogbeat service (default: true) -# @param registry_file [String] The registry file used to store positions, absolute or relative to working directory (default .winlogbeat.yml) -# @param outputs [Hash] Will be converted to YAML for the required outputs section of the winlogbeat config -# @param shipper [Hash] Will be converted to YAML to create the optional shipper section of the winlogbeat config -# @param logging [Hash] Will be converted to YAML to create the optional logging section of the winlogbeat config +# @param spool_size [Integer] How large the spool should grow before being flushed to the network (default: 2048) +# @param idle_timeout [String] How often the spooler should be flushed even if spool size isn't reached (default: 5s) +# @param publish_async [Boolean] If set to true winlogbeat will publish while preparing the next batch of lines to send (defualt: false) +# @param registry_file [String] The registry file used to store positions, absolute or relative to working directory (default .winlogbeat) +# @param registry_flush [String] The timeout value that controls when registry entries are written to disk (default: 0s) +# @param config_dir [String] The directory where prospectors should be defined (default: /etc/winlogbeat/conf.d) +# @param config_dir_mode [String] The unix permissions mode set on the configuration directory (default: 0755) +# @param config_file_mode [String] The unix permissions mode set on configuration files (default: 0644) +# @param purge_conf_dir [Boolean] Should files in the prospector configuration directory not managed by puppet be automatically purged +# @param outputs [Hash] Will be converted to YAML for the required outputs section of the configuration (see documentation, and above) +# @param logging [Hash] Will be converted to YAML to create the optional logging section of the winlogbeat config (see documentation) # @param conf_template [String] The configuration template to use to generate the main winlogbeat.yml config file -# @param download_url [String] The URL of the zip file that should be downloaded to install winlogbeat -# @param install_dir [String] Where winlogbeat should be installed -# @param tmp_dir [String] Where winlogbeat should be temporarily downloaded to so it can be installed -# @param event_logs [Hash] Event_logs that will be forwarded. -# @param event_logs_merge [Boolean] Whether $event_logs should merge all hiera sources, or use simple automatic parameter lookup - +# @param download_url [String] The URL of the zip file that should be downloaded to install winlogbeat (windows only) +# @param install_dir [String] Where winlogbeat should be installed (windows only) +# @param tmp_dir [String] Where winlogbeat should be temporarily downloaded to so it can be installed (windows only) +# @param shutdown_timeout [String] How long winlogbeat waits on shutdown for the publisher to finish sending events +# @param beat_name [String] The name of the beat shipper (default: hostname) +# @param tags [Array] A list of tags that will be included with each published transaction +# @param queue_size [String] The internal queue size for events in the pipeline +# @param max_procs [Integer] The maximum number of CPUs that can be simultaneously used +# @param fields [Hash] Optional fields that should be added to each event output +# @param fields_under_root [Boolean] If set to true, custom fields are stored in the top level instead of under fields +# @param processors [Array] Processors that will be added. Commonly used to create processors using hiera. +# @param setup [Hash] setup that will be created. Commonly used to create setup using hiera +# proxy_address [String] Proxy server to use for downloading files +# @param xpack [Hash] Configuration items to export internal stats to a monitoring Elasticsearch cluster class winlogbeat ( - $major_version = undef, - $package_ensure = $winlogbeat::params::package_ensure, - $service_ensure = $winlogbeat::params::service_ensure, - $service_enable = $winlogbeat::params::service_enable, - $service_provider = $winlogbeat::params::service_provider, - $registry_file = $winlogbeat::params::registry_file, - $config_file = $winlogbeat::params::config_file, - $outputs = $winlogbeat::params::outputs, - $shipper = $winlogbeat::params::shipper, - $logging = $winlogbeat::params::logging, - $run_options = $winlogbeat::params::run_options, - $conf_template = undef, - $download_url = undef, - $install_dir = $winlogbeat::params::install_dir, - $tmp_dir = $winlogbeat::params::tmp_dir, - #### v5 only #### - $use_generic_template = $winlogbeat::params::use_generic_template, - $beat_name = $winlogbeat::params::beat_name, - $tags = $winlogbeat::params::tags, - $queue_size = $winlogbeat::params::queue_size, - $max_procs = $winlogbeat::params::max_procs, - $fields = $winlogbeat::params::fields, - $fields_under_root = $winlogbeat::params::fields_under_root, - $metrics = undef, - #### End v5 only #### - $event_logs = {}, - $event_logs_merge = false, - $proxy_address = undef, -) inherits winlogbeat::params { + String $package_ensure, + Variant[Boolean, Enum['stopped', 'running']] $service_ensure, + Boolean $service_enable, + Optional[String] $service_provider, + Integer $spool_size, + String $idle_timeout, + Boolean $publish_async, + String $registry_file, + Optional[String] $registry_flush, + String $config_file, + Optional[String] $config_file_owner, + Optional[String] $config_file_group, + String[4,4] $config_dir_mode, + String[4,4] $config_file_mode, + Optional[String] $config_dir_owner, + Optional[String] $config_dir_group, + Hash $outputs, + Hash $logging, + Hash $run_options, + String $conf_template, + Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $download_url, + Boolean $manage_download_file, + Optional[String] $winlogbeat_zip_path, + Optional[String] $install_dir, + String $folder_name, + String $tmp_dir, + String $shutdown_timeout, + String $beat_name, + Array $tags, + Integer $queue_size, + Optional[Integer] $max_procs, + Hash $fields, + Boolean $fields_under_root, + Boolean $disable_config_test, + Hash $setup, + Hash $queue, + Hash $processors, + Array[Hash] $event_logs, + Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $proxy_address, # lint:ignore:140chars + Optional[Hash] $xpack, + String $kernel_fail_message, +) { - validate_bool($event_logs_merge) + include ::stdlib - if $major_version == undef and getvar('::winlogbeat_version') == undef { - $real_version = '5' - } elsif $major_version == undef and versioncmp($::winlogbeat_version, '5.0.0') >= 0 { - $real_version = '5' - } elsif $major_version == undef and versioncmp($::winlogbeat_version, '5.0.0') < 0 { - $real_version = '1' - } else { - $real_version = $major_version + if ($::kernel != 'Windows') { + fail($kernel_fail_message) } - if $conf_template != undef { - $real_conf_template = $conf_template - } elsif $real_version == '1' { - if versioncmp('1.9.1', $::rubyversion) > 0 { - $real_conf_template = "${module_name}/winlogbeat1.yml.ruby18.erb" - } else { - $real_conf_template = "${module_name}/winlogbeat1.yml.erb" - } - } elsif $real_version == '5' { - if $use_generic_template { - $real_conf_template = "${module_name}/winlogbeat1.yml.erb" - } else { - $real_conf_template = "${module_name}/winlogbeat5.yml.erb" - } + $url_arch = $::architecture ? { + 'x86' => 'x86', + 'x64' => 'x86_64', + default => fail("${::architecture} is not supported by filebeat."), } $real_download_url = $download_url ? { - undef => "https://artifacts.elastic.co/downloads/beats/winlogbeat/winlogbeat-${package_ensure}-windows-${winlogbeat::params::url_arch}.zip", + undef => "https://artifacts.elastic.co/downloads/beats/winlogbeat/winlogbeat-${package_ensure}-windows-${url_arch}.zip", default => $download_url, } - if $event_logs_merge { - $event_logs_final = hiera_hash('winlogbeat::event_logs', $event_logs) - } else { - $event_logs_final = $event_logs + if $config_file != 'C:/Program Files/Winlogbeat/winlogbeat.yml' { + warning('You\'ve specified a non-standard config_file location - winlogbeat may fail to start unless you\'re doing something to fix this') # lint:ignore:140chars } - if $config_file != $winlogbeat::params::config_file { - warning('You\'ve specified a non-standard config_file location - winlogbeat may fail to start unless you\'re doing something to fix this') + if $package_ensure == 'absent' { + $alternate_ensure = 'absent' + $real_service_ensure = 'stopped' + $file_ensure = 'absent' + $directory_ensure = 'absent' + } else { + $alternate_ensure = 'present' + $file_ensure = 'file' + $directory_ensure = 'directory' + $real_service_ensure = $service_ensure } - validate_hash($outputs, $logging, $event_logs_final) - validate_string($registry_file, $package_ensure) + # If we're removing winlogbeat, do things in a different order to make sure + # we remove as much as possible + contain ::winlogbeat::install + contain ::winlogbeat::config + contain ::winlogbeat::service - if(!empty($proxy_address)){ - validate_re($proxy_address, ['^(http(?:s)?\:\/\/[a-zA-Z0-9]+(?:(?:\.|\-)[a-zA-Z0-9]+)+(?:\:\d+)?(?:\/[\w\-]+)*(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$'], 'ERROR: You must enter a proxy url in a valid format i.e. http://proxy.net:3128') + if $package_ensure == 'absent' { + Class['::winlogbeat::config'] + -> Class['::winlogbeat::install'] + -> Class['::winlogbeat::service'] + } else { + Class['::winlogbeat::install'] + -> Class['::winlogbeat::config'] + -> Class['::winlogbeat::service'] } - - anchor { 'winlogbeat::begin': } - -> class { 'winlogbeat::install': } - -> class { 'winlogbeat::config': } - -> class { 'winlogbeat::service': } - -> anchor { 'winlogbeat::end': } } diff --git a/manifests/install.pp b/manifests/install.pp index fc92b02..92334f8 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,13 +1,12 @@ +# winlogbeat::install +# +# Manage the installation of Winlogbeat +# +# @summary A private class to manage the installation of Winlogbeat class winlogbeat::install { - # I'd like to use chocolatey to do this install, but the package for chocolatey is - # failing for updates and seems rather unpredictable at the moment. We may revisit - # that in the future as it would greatly simplify this code and basically reduce it to - # one package resource with type => chocolatey.... - - $filename = regsubst($winlogbeat::real_download_url, '^https.*\/([^\/]+)\.[^.].*', '\1') - $foldername = 'Winlogbeat' + $filename = regsubst($winlogbeat::real_download_url, '.*\/([^\/]+)\.zip$', '\1') $zip_file = join([$winlogbeat::tmp_dir, "${filename}.zip"], '/') - $install_folder = join([$winlogbeat::install_dir, $foldername], '/') + $install_folder = join([$winlogbeat::install_dir, $winlogbeat::folder_name], '/') $version_file = join([$install_folder, $filename], '/') Exec { @@ -31,8 +30,9 @@ proxy_server => $winlogbeat::proxy_address, } + exec { "unzip ${filename}": - command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", + command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars creates => $version_file, require => [ File[$winlogbeat::install_dir], @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", + command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } @@ -72,5 +72,6 @@ command => './install-service-winlogbeat.ps1', refreshonly => true, subscribe => Exec["mark ${filename}"], + notify => Class['winlogbeat::service'], } } diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index d981fdc..0000000 --- a/manifests/params.pp +++ /dev/null @@ -1,43 +0,0 @@ -class winlogbeat::params { - $service_ensure = running - $service_enable = true - $beat_name = $::fqdn - $tags = [] - $queue_size = 1000 - $max_procs = undef - $fields = {} - $fields_under_root = false - $outputs = {} - $shipper = {} - $logging = {} - $run_options = {} - $use_generic_template = false - $kernel_fail_message = "${::kernel} is not supported by winlogbeat." - - # These are irrelevant as long as the template is set based on the major_version parameter - # if versioncmp('1.9.1', $::rubyversion) > 0 { - # $conf_template = "${module_name}/winlogbeat.yml.ruby18.erb" - # } else { - # $conf_template = "${module_name}/winlogbeat.yml.erb" - # } - - case $::kernel { - 'Windows' : { - $package_ensure = '5.4.3' - $config_file = 'C:/Program Files/Winlogbeat/winlogbeat.yml' - $registry_file = 'C:/ProgramData/winlogbeat/.winlogbeat.yml' - $install_dir = 'C:/Program Files' - $tmp_dir = 'C:/Windows/Temp' - $service_provider = undef - $url_arch = $::architecture ? { - 'x86' => 'x86', - 'x64' => 'x86_64', - default => fail("${::architecture} is not supported by winlogbeat."), - } - } - - default : { - fail($kernel_fail_message) - } - } -} diff --git a/manifests/service.pp b/manifests/service.pp index a5503ae..84ffb27 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,3 +1,8 @@ +# winlogbeat::service +# +# Manage the winlogbeat service +# +# @summary A private class to manage the winlogbeat service class winlogbeat::service { service { 'winlogbeat': ensure => $winlogbeat::service_ensure, diff --git a/metadata.json b/metadata.json index 1212d20..0e6addc 100644 --- a/metadata.json +++ b/metadata.json @@ -7,21 +7,6 @@ "source": "https://github.com/voxpupuli/puppet-winlogbeat", "project_page": "https://github.com/voxpupuli/puppet-winlogbeat", "issues_url": "https://github.com/voxpupuli/puppet-winlogbeat/issues", - "tags": [ - "winlogbeat", - "logstash", - "elasticsearch", - "elastic" - ], - "operatingsystem_support": [ - { - "operatingsystem": "Windows", - "operatingsystemrelease": [ - "Server 2012", - "Server 2012 R2" - ] - } - ], "dependencies": [ { "name": "puppetlabs-powershell", @@ -36,10 +21,28 @@ "version_requirement": ">= 0.5.0 < 4.0.0" } ], + "operatingsystem_support": [ + { + "operatingsystem": "Windows", + "operatingsystemrelease": [ + "Server 2012", + "Server 2012 R2" + ] + } + ], "requirements": [ { "name": "puppet", "version_requirement": ">= 5.5.8 < 7.0.0" } - ] + ], + "tags": [ + "winlogbeat", + "logstash", + "elasticsearch", + "elastic" + ], + "pdk-version": "1.10.0", + "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git#1.10.0", + "template-ref": "1.10.0-0-gbba9ac3" } diff --git a/spec/acceptance/001_basic_spec.rb b/spec/acceptance/001_basic_spec.rb new file mode 100644 index 0000000..027f0ce --- /dev/null +++ b/spec/acceptance/001_basic_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper_acceptance' + +describe 'basic tests:' do + it 'make sure we have copied the module across' do + shell("ls #{default['distmoduledir']}/winlogbeat/Rakefile", acceptable_exit_codes: 0) + end +end diff --git a/spec/acceptance/nodesets/ec2/image_templates_sihm.yaml b/spec/acceptance/nodesets/ec2/image_templates_sihm.yaml new file mode 100644 index 0000000..d3af23e --- /dev/null +++ b/spec/acceptance/nodesets/ec2/image_templates_sihm.yaml @@ -0,0 +1,14 @@ +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# see also: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +# Hint: image IDs (ami-*) for the same image are different per location. +# +AMI: + # Microsoft Windows Server 2016 Base + windows-2016-base-eu-west-1: + :image: + :aio: ami-08a92ed64caa44b84 + :region: eu-west-1 diff --git a/spec/acceptance/nodesets/ec2/windows-2016-base-x64-sihm.yml b/spec/acceptance/nodesets/ec2/windows-2016-base-x64-sihm.yml new file mode 100644 index 0000000..4b5c6e0 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/windows-2016-base-x64-sihm.yml @@ -0,0 +1,27 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + windows-2016-base-x64: + platform: windows-2016-64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: windows-2016-base-eu-west-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user + subnet_id: subnet-098d092357089e460 + vpc_id: vpc-0bf7145b4474b5335 +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates_sihm.yaml \ No newline at end of file diff --git a/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml b/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml index 0932e29..7ddaab7 100644 --- a/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml +++ b/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml @@ -1,29 +1,26 @@ ---- -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -# -# Additional ~/.fog config file with AWS EC2 credentials -# required. -# -# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md -# -HOSTS: - windows-2016-base-x64: - roles: - - master - platform: windows-2016-64 - hypervisor: ec2 - # refers to image_tempaltes.yaml AMI[vmname] entry: - vmname: windows-2016-base-eu-central-1 - # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: - snapshot: aio - # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): - amisize: t2.micro - # required so that beaker sanitizes sshd_config and root authorized_keys: - user: ec2-user -CONFIG: - type: aio - :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml -... -# vim: syntax=yaml +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + windows-2008R2-serverstandard-x64: + platform: windows-server-amd64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: windows-2016-base-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml + diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..6e41e04 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,8 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" +winlogbeat_version: undef diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c53e703..93b25ec 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,42 +1,47 @@ -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -RSpec.configure do |c| - c.mock_with :rspec -end - require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' + +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + include RspecPuppetFacts -if File.exist?(File.join(__dir__, 'default_module_facts.yml')) - facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end - end -end +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} -if Dir.exist?(File.expand_path('../../lib', __FILE__)) - require 'coveralls' - require 'simplecov' - require 'simplecov-console' - SimpleCov.formatters = [ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console - ] - SimpleCov.start do - track_files 'lib/**/*.rb' - add_filter '/spec' - add_filter '/vendor' - add_filter '/.vendor' +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) + + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end RSpec.configure do |c| - # Coverage generation + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do - RSpec::Puppet::Coverage.report! end end + +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end +end + +# 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..57c2db7 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,52 @@ +require 'beaker-rspec/spec_helper' +require 'beaker-rspec/helpers/serverspec' +require 'beaker/puppet_install_helper' +require 'beaker/module_install_helper' +require 'winrm' + +ENV['BEAKER_PUPPET_AGENT_VERSION'] = '5.3.7' +ENV['BEAKER_PUPPET_COLLECTION'] = 'puppet5' +ENV['AWS_REGION'] = 'eu-west-1' + +hosts.each do |host| + case host['platform'] + when %r{windows} + include Serverspec::Helper::Windows + include Serverspec::Helper::WinRM + + version = ENV['PUPPET_VERSION'] || '5.3.7' + + install_puppet(version: version) + + else + install_puppet + end +end + +# run_puppet_install_helper +install_module_on(hosts) +install_module_dependencies_on(hosts) + +UNSUPPORTED_PLATFORMS = ['aix', 'Solaris', 'BSD', 'linux'].freeze + +RSpec.configure do |c| + module_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module + puppet_module_install(source: module_root, module_name: 'winlogbeat') + end +end + +shared_examples 'an idempotent resource' do + it 'apply with no errors' do + apply_manifest(pp, catch_failures: true) + end + + it 'apply a second time without changes', :skip_pup_5016 do + apply_manifest(pp, catch_changes: true) + end +end diff --git a/templates/pure_hash.yml.epp b/templates/pure_hash.yml.epp new file mode 100644 index 0000000..caeca8f --- /dev/null +++ b/templates/pure_hash.yml.epp @@ -0,0 +1,2 @@ +### Winlogbeat configuration managed by Puppet ### +<%= $winlogbeat_config.to_yaml() %> \ No newline at end of file diff --git a/templates/winlogbeat1.yml.erb b/templates/winlogbeat1.yml.erb deleted file mode 100644 index c196795..0000000 --- a/templates/winlogbeat1.yml.erb +++ /dev/null @@ -1,52 +0,0 @@ -<%- if @winlogbeat_config['output']['file'] -%> -<%- if @winlogbeat_config['output']['file']['rotate_every_kb'] -%> -<%- @winlogbeat_config['output']['file']['rotate_every_kb'] = Integer(@winlogbeat_config['output']['file']['rotate_every_kb']) -%> -<%- end -%> -<%- if @winlogbeat_config['output']['file']['number_of_files'] -%> -<%- @winlogbeat_config['output']['file']['number_of_files'] = Integer(@winlogbeat_config['output']['file']['number_of_files']) -%> -<%- end -%> -<%- end -%> -<%- if @winlogbeat_config['output']['elasticsearch'] -%> -<%- if @winlogbeat_config['output']['elasticsearch']['port'] -%> -<%- @winlogbeat_config['output']['elasticsearch']['port'] = Integer(@winlogbeat_config['output']['elasticsearch']['port']) -%> -<%- end -%> -<%- end -%> -<%- if @winlogbeat_config['output']['logstash'] -%> -<%- if @winlogbeat_config['output']['logstash']['bulk_max_size'] -%> -<%- @winlogbeat_config['output']['logstash']['bulk_max_size'] = Integer(@winlogbeat_config['output']['logstash']['bulk_max_size']) -%> -<%- end -%> -<%- if @winlogbeat_config['output']['logstash']['port'] -%> -<%- @winlogbeat_config['output']['logstash']['port'] = Integer(@winlogbeat_config['output']['logstash']['port']) -%> -<%- end -%> -<%- end -%> -<%- if @winlogbeat_config['shipper'] -%> -<%- if @winlogbeat_config['shipper']['refresh_topology_freq'] -%> -<%- @winlogbeat_config['shipper']['refresh_topology_freq'] = Integer(@winlogbeat_config['shipper']['refresh_topology_freq']) -%> -<%- end -%> -<%- if @winlogbeat_config['shipper']['topology_expire'] -%> -<%- @winlogbeat_config['shipper']['topology_expire'] = Integer(@winlogbeat_config['shipper']['topology_expire']) -%> -<%- end -%> -<%- if @winlogbeat_config['shipper']['queue_size'] -%> -<%- @winlogbeat_config['shipper']['queue_size'] = Integer(@winlogbeat_config['shipper']['queue_size']) -%> -<%- end -%> -<%- end -%> -<%- if @winlogbeat_config['logging']['files'] -%> -<%- if @winlogbeat_config['logging']['files']['rotateeverybytes'] -%> -<%- @winlogbeat_config['logging']['files']['rotateeverybytes'] = Integer(@winlogbeat_config['logging']['files']['rotateeverybytes']) -%> -<%- end -%> -<%- if @winlogbeat_config['logging']['files']['keepfiles'] -%> -<%- @winlogbeat_config['logging']['files']['keepfiles'] = Integer(@winlogbeat_config['logging']['files']['keepfiles']) -%> -<%- end -%> -<%- end -%> -### Winlogbeat configuration managed by Puppet ### ---- -winlogbeat: - registry_file: <%= @winlogbeat_config['winlogbeat']['registry_file'] %> - <%- if @winlogbeat_config['winlogbeat']['event_logs'] != nil -%> - event_logs: - <%- @winlogbeat_config['winlogbeat']['event_logs'].each do |event_log,options| -%> - - name: <%= event_log %> - ignore_older: <%= options["ignore_older"] %> - <%- end -%> - <%- end -%> -<%= @winlogbeat_config.keep_if{|k,v| ['output','shipper','logging','runoptions'].include?(k)}.to_yaml.gsub("---\n", '') %> diff --git a/templates/winlogbeat1.yml.ruby18.erb b/templates/winlogbeat1.yml.ruby18.erb deleted file mode 100644 index 4184e16..0000000 --- a/templates/winlogbeat1.yml.ruby18.erb +++ /dev/null @@ -1,288 +0,0 @@ -### winlogbeat configuration managed by Puppet (Ruby 1.8 version) ### ---- -winlogbeat: - registry_file: <%= @winlogbeat_config['winlogbeat']['registry_file'] %> - <%- if @winlogbeat_config['winlogbeat']['event_logs'] != nil -%> - event_logs: - <%- @winlogbeat_config['winlogbeat']['event_logs'].each do |event_log,options| -%> - - name: <%= event_log %> - ignore_older: <%= options["ignore_older"] %> - <%- end -%> - <%- end -%> - - output: - <%- if @winlogbeat_config['output']['elasticsearch'] != nil -%> - elasticsearch: - hosts: - <%- @winlogbeat_config['output']['elasticsearch']['hosts'].each do |host| -%> - - <%= host %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['port'] != nil -%> - port: <%= @winlogbeat_config['output']['elasticsearch']['port'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['protocol'] != nil -%> - protocol: "<%= @winlogbeat_config['output']['elasticsearch']['protocol'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['username'] != nil -%> - username: "<%= @winlogbeat_config['output']['elasticsearch']['username'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['password'] != nil -%> - password: "<%= @winlogbeat_config['output']['elasticsearch']['password'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['worker'] != nil -%> - worker: <%= @winlogbeat_config['output']['elasticsearch']['worker'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['index'] != nil -%> - index: "<%= @winlogbeat_config['output']['elasticsearch']['index'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['path'] != nil -%> - path: "<%= @winlogbeat_config['output']['elasticsearch']['path'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['proxy_url'] != nil -%> - proxy_url: "<%= @winlogbeat_config['output']['elasticsearch']['proxy_url'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['max_retries'] != nil -%> - max_retries: <%= @winlogbeat_config['output']['elasticsearch']['max_retries'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['bulk_max_size'] != nil -%> - bulk_max_size: <%= @winlogbeat_config['output']['elasticsearch']['bulk_max_size'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['timeout'] != nil -%> - timeout: <%= @winlogbeat_config['output']['elasticsearch']['timeout'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['flush_interval'] != nil -%> - flush_interval: <%= @winlogbeat_config['output']['elasticsearch']['flush_interval'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['save_topology'] != nil -%> - save_topology: <%= @winlogbeat_config['output']['elasticsearch']['save_topology'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['topology_expire'] != nil -%> - topology_expire: <%= @winlogbeat_config['output']['elasticsearch']['topology_expire'] %> - <%- end -%> - - <%- if @winlogbeat_config['output']['elasticsearch']['template'] != nil -%> - template: - <%- if @winlogbeat_config['output']['elasticsearch']['template']['name'] != nil -%> - name: "<%= @winlogbeat_config['output']['elasticsearch']['name'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['path'] != nil -%> - path: "<%= @winlogbeat_config['output']['elasticsearch']['path'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['overwrite'] != nil -%> - overwrite: <%= @winlogbeat_config['output']['elasticsearch']['name'] %> - <%- end -%> - <%- end -%> - - <%- if @winlogbeat_config['output']['elasticsearch']['tls'] != nil -%> - tls: - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['certificate_authorities'] != nil -%> - certificate_authorities: - <%- @winlogbeat_config['output']['elasticsearch']['tls']['certificate_authorities'].each do |ca| -%> - - <%= ca %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['certificate'] != nil -%> - certificate: "<%= @winlogbeat_config['output']['elasticsearch']['tls']['certificate'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['certificate_key'] != nil -%> - certificate_key: "<%= @winlogbeat_config['output']['elasticsearch']['tls']['certificate_key'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['insecure'] != nil -%> - insecure: <%= @winlogbeat_config['output']['elasticsearch']['tls']['insecure'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['cipher_suites'] != nil -%> - cipher_suites: - <%- @winlogbeat_config['output']['elasticsearch']['tls']['cipher_suites'].each do |cipher_suite| -%> - - <%= cipher_suite %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['curve_types'] != nil -%> - curve_types: - <%- @winlogbeat_config['output']['elasticsearch']['tls']['curve_types'].each do |curve_type| -%> - - <%= curve_type %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['min_version'] != nil -%> - min_version: <%= @winlogbeat_config['output']['elasticsearch']['tls']['min_version'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['tls']['max_version'] != nil -%> - max_version: <%= @winlogbeat_config['output']['elasticsearch']['tls']['max_version'] %> - <%- end -%> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash'] != nil -%> - logstash: - hosts: - <%- @winlogbeat_config['output']['logstash']['hosts'].each do |host| -%> - - <%= host %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['port'] != nil -%> - port: <%= @winlogbeat_config['output']['logstash']['port'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['worker'] != nil -%> - worker: <%= @winlogbeat_config['output']['logstash']['worker'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['compression_level'] != nil -%> - compression_level: <%= @winlogbeat_config['output']['logstash']['compression_level'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['loadbalance'] != nil -%> - loadbalance: <%= @winlogbeat_config['output']['logstash']['loadbalance'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['index'] != nil -%> - index: <%= @winlogbeat_config['output']['logstash']['index'] %> - <%- end -%> - - <%- if @winlogbeat_config['output']['logstash']['tls'] != nil -%> - tls: - <%- if @winlogbeat_config['output']['logstash']['tls']['certificate_authorities'] != nil -%> - certificate_authorities: - <%- @winlogbeat_config['output']['logstash']['tls']['certificate_authorities'].each do |ca| -%> - - <%= ca %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['tls']['certificate'] != nil -%> - certificate: "<%= @winlogbeat_config['output']['logstash']['tls']['certificate'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['tls']['certificate_key'] != nil -%> - certificate_key: "<%= @winlogbeat_config['output']['logstash']['tls']['certificate_key'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['tls']['insecure'] != nil -%> - insecure: <%= @winlogbeat_config['output']['logstash']['tls']['insecure'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['tls']['cipher_suites'] != nil -%> - cipher_suites: - <%- @winlogbeat_config['output']['logstash']['tls']['cipher_suites'].each do |cipher_suite| -%> - - <%= cipher_suite %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['tls']['curve_types'] != nil -%> - curve_types: - <%- @winlogbeat_config['output']['logstash']['tls']['curve_types'].each do |curve_type| -%> - - <%= curve_type %> - <%- end -%> - <%- end -%> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['redis'] != nil -%> - redis: - <%- if @winlogbeat_config['output']['redis']['host'] != nil -%> - host: "<%= @winlogbeat_config['output']['redis']['host'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['port'] != nil -%> - port: <%= @winlogbeat_config['output']['redis']['port'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['save_topology'] != nil -%> - save_topology: <%= @winlogbeat_config['output']['redis']['save_topology'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['index'] != nil -%> - index: "<%= @winlogbeat_config['output']['redis']['index'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['db'] != nil -%> - db: <%= @winlogbeat_config['output']['redis']['db'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['db_topology'] != nil -%> - db_topology: <%= @winlogbeat_config['output']['redis']['db_topology'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['password'] != nil -%> - password: "<%= @winlogbeat_config['output']['redis']['password'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['timeout'] != nil -%> - timeout: <%= @winlogbeat_config['output']['redis']['timeout'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['reconnect_interval'] != nil -%> - reconnect_interval: <%= @winlogbeat_config['output']['redis']['reconnect_interval'] %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['file'] != nil -%> - file: - <%- if @winlogbeat_config['output']['file']['path'] != nil -%> - path: "<%= @winlogbeat_config['output']['file']['path'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['file']['filename'] != nil -%> - filename: <%= @winlogbeat_config['output']['file']['filename'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['file']['rotate_every_kb'] != nil -%> - rotate_every_kb: <%= @winlogbeat_config['output']['file']['rotate_every_kb'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['file']['number_of_files'] != nil -%> - number_of_files: <%= @winlogbeat_config['output']['file']['number_of_files'] %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['console'] != nil -%> - console: - <%- if @winlogbeat_config['output']['console']['pretty'] != nil -%> - pretty: <%= @winlogbeat_config['output']['console']['pretty'] %> - <%- end -%> - <%- end -%> - - <%- unless @winlogbeat_config['shipper'].empty? -%> - shipper: - <%- if @winlogbeat_config['shipper']['name'] != nil -%> - name: <%= @winlogbeat_config['shipper']['name'] %> - <%- end -%> - <%- if @winlogbeat_config['shipper']['tags'] != nil -%> - tags: - <%- @winlogbeat_config['shipper']['tags'].each do |tag| -%> - - <%= tag %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['shipper']['ignore_outgoing'] != nil -%> - ignore_outgoing: <%= @winlogbeat_config['shipper']['ignore_outgoing'] %> - <%- end -%> - <%- if @winlogbeat_config['shipper']['refresh_topology_freq'] != nil -%> - refresh_topology_freq: <%= @winlogbeat_config['shipper']['refresh_topology_freq'] %> - <%- end -%> - <%- if @winlogbeat_config['shipper']['topology_expire'] != nil -%> - topology_expire: <%= @winlogbeat_config['shipper']['topology_expire'] %> - <%- end -%> - <%- if @winlogbeat_config['shipper']['queue_size'] != nil -%> - queue_size: <%= @winlogbeat_config['shipper']['queue_size'] %> - <%- end -%> - <%- end -%> - - <%- unless @winlogbeat_config['logging'].empty? -%> - logging: - <%- if @winlogbeat_config['logging']['to_syslog'] != nil -%> - to_syslog: <%= @winlogbeat_config['logging']['to_syslog'] %> - <%- end -%> - <%- if @winlogbeat_config['logging']['to_files'] != nil -%> - to_files: <%= @winlogbeat_config['logging']['to_files'] %> - <%- end -%> - - <%- if @winlogbeat_config['logging']['files'] != nil -%> - files: - <%- if @winlogbeat_config['logging']['files']['path'] != nil -%> - path: <%= @winlogbeat_config['logging']['files']['path'] %> - <%- end -%> - <%- if @winlogbeat_config['logging']['files']['name'] != nil -%> - name: <%= @winlogbeat_config['logging']['files']['name'] %> - <%- end -%> - <%- if @winlogbeat_config['logging']['files']['rotateeverybytes'] != nil -%> - rotateeverybytes: <%= @winlogbeat_config['logging']['files']['rotateeverybytes'] %> - <%- end -%> - <%- if @winlogbeat_config['logging']['files']['keepfiles'] != nil -%> - keepfiles: <%= @winlogbeat_config['logging']['files']['keepfiles'] %> - <%- end -%> - <%- end -%> - - <%- if @winlogbeat_config['logging']['selectors'] != nil -%> - selectors: - <%- @winlogbeat_config['logging']['selectors'].each do |selector| -%> - - <%= selector %> - <%- end -%> - <%- end -%> - - <%- if @winlogbeat_config['logging']['level'] != nil -%> - level: <%= @winlogbeat_config['logging']['level'] %> - <%- end -%> - <%- end -%> - - <%- unless @winlogbeat_config['runoptions'].empty? -%> - runoptions: - <%- if @winlogbeat_config['runoptions']['uid'] != nil -%> - uid=<%= @winlogbeat_config['runoptions']['uid'] %> - <%- end -%> - <%- if @winlogbeat_config['runoptions']['gid'] != nil -%> - gid=<%= @winlogbeat_config['runoptions']['gid'] %> - <%- end -%> -<%- end -%> diff --git a/templates/winlogbeat5.yml.erb b/templates/winlogbeat5.yml.erb deleted file mode 100644 index 00e5920..0000000 --- a/templates/winlogbeat5.yml.erb +++ /dev/null @@ -1,697 +0,0 @@ -#======================= Winlogbeat specific options ========================== - -winlogbeat.registry_file: <%= @winlogbeat_config['winlogbeat']['registry_file'] %> - -<%- if @winlogbeat_config['winlogbeat']['metrics'] != nil && @winlogbeat_config['winlogbeat']['metrics']['bindaddress'] != nil -%> -winlogbeat.metrics: - bindaddress: <%= @winlogbeat_config['winlogbeat']['metrics']['bindaddress'] %> -<%- end -%> - -<%- if @winlogbeat_config['winlogbeat']['event_logs'].length > 0 -%> -winlogbeat.event_logs: - <%- @winlogbeat_config['winlogbeat']['event_logs'].each_pair do |name, options| -%> - - name: "<%= options['name'] || name %>" - <%- if options['ignore_older'] != nil -%> - ignore_older: <%= options['ignore_older'] %> - <%- end -%> - <%- if options['forwarded'] != nil -%> - forwarded: <%= options['forwarded'] %> - <%- end -%> - <%- if options['event_id'] != nil -%> - event_id: <%= options['event_id'] %> - <%- end -%> - <%- if options['level'] != nil -%> - level: <%= options['level'] %> - <%- end -%> - <%- if options['provider'] != nil -%> - provider: - <%- options['provider'].each do |p| -%> - - <%= p %> - <%- end -%> - <%- end -%> - <%- if options['include_xml'] != nil -%> - include_xml: <%= options['include_xml'] %> - <%- end -%> - <%- if options['tags'] != nil -%> - tags: - <%- options['tags'].each do |tag| -%> - - <%= tag %> - <%- end -%> - <%- end -%> - <%- if options['fields'] != nil -%> - fields: - <%- options['fields'].each_pair do |k, v| -%> - <%= k %>: <%= v %> - <%- end -%> - <%- end -%> - <%- if options['fields_under_root'] != nil -%> - fields_under_root: <%= options['fields_under_root'] %> - <%- end -%> - <%- end -%> -<%- end -%> - -#================================ General ====================================== - -name: <%= @winlogbeat_config['beat_name'] %> -<%- if @winlogbeat_config['tags'].length > 0 -%> -tags: -<%- @winlogbeat_config['tags'].each do |tag| -%> - - <%= tag %> -<%- end -%> -<%- end -%> - -<%- if @winlogbeat_config['fields'].length > 0 -%> -fields: - <%- @winlogbeat_config['fields'].each_pair do |k, v| -%> - <%= k %>: <%= v %> - <%- end -%> -<%- end -%> - -fields_under_root: <%= @winlogbeat_config['fields_under_root'] %> -queue_size: <%= @winlogbeat_config['queue_size'] %> - -# The internal queue size for bulk events in the processing pipeline. -# Do not modify this value. -#bulk_queue_size: 0 - -<%- if @winlogbeat_config['max_procs'] != nil -%> -max_procs: <%= @winlogbeat_config['max_procs'] %> -<%- end -%> - -#================================ Processors =================================== - -# Processors are used to reduce the number of fields in the exported event or to -# enhance the event with external metadata. This section defines a list of -# processors that are applied one by one and the first one receives the initial -# event: -# -# event -> filter1 -> event1 -> filter2 ->event2 ... -# -# The supported processors are drop_fields, drop_event, include_fields, and -# add_cloud_metadata. -# -# For example, you can use the following processors to keep the fields that -# contain CPU load percentages, but remove the fields that contain CPU ticks -# values: -# -#processors: -#- include_fields: -# fields: ["cpu"] -#- drop_fields: -# fields: ["cpu.user", "cpu.system"] -# -# The following example drops the events that have the HTTP response code 200: -# -#processors: -#- drop_event: -# when: -# equals: -# http.code: 200 -# -# The following example enriches each event with metadata from the cloud -# provider about the host machine. It works on EC2, GCE, and DigitalOcean. -# -#processors: -#- add_cloud_metadata: -# - -#================================ Outputs ====================================== - -<%- if @winlogbeat_config['output']['elasticsearch'] != nil -%> -#-------------------------- Elasticsearch output ------------------------------ -output.elasticsearch: - <%- if @winlogbeat_config['output']['elasticsearch']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['elasticsearch']['enabled'] %> - <%- end -%> - hosts: - <%- @winlogbeat_config['output']['elasticsearch']['hosts'].each do |host| -%> - - <%= host %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['compression_level'] != nil -%> - compression_level: <%= @winlogbeat_config['output']['elasticsearch']['compression_level'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['protocol'] != nil -%> - protocol: "<%= @winlogbeat_config['output']['elasticsearch']['protocol'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['username'] != nil -%> - username: "<%= @winlogbeat_config['output']['elasticsearch']['username'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['password'] != nil -%> - password: "<%= @winlogbeat_config['output']['elasticsearch']['password'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['parameters'] != nil && @winlogbeat_config['output']['elasticsearch']['parameters'].length > 0 -%> - parameters: - <%- @winlogbeat_config['output']['elasticsearch']['parameters'].each_pair do |k, v| -%> - <%= k %>: <%= v %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['worker'] != nil -%> - worker: <%= @winlogbeat_config['output']['elasticsearch']['worker'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['index'] != nil -%> - index: "<%= @winlogbeat_config['output']['elasticsearch']['index'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['pipeline'] != nil -%> - pipeline: "<%= @winlogbeat_config['output']['elasticsearch']['pipeline'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['pipelines'] != nil -%> - pipelines: - <%- @winlogbeat_config['output']['elasticsearch']['pipelines'].each do |pipeline| -%> - <%- if pipeline['name'] != nil -%> - - pipeline: "<%= pipeline['name'] %>" - when.equals: - <%= pipeline['filter'] %>: "<%= pipeline['pattern'] %>" - <%- end -%> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['indices'] != nil -%> - indices: - <%- @winlogbeat_config['output']['elasticsearch']['indices'].each do |indice| -%> - <%- if indice['name'] != nil -%> - - index: "<%= indice['name'] %>" - <%- if indice['pipeline'] != nil -%> - pipeline: "<%= indice['pipeline'] %>" - <%- end -%> - when.contains: - <%= indice['filter'] %>: "<%= indice['pattern'] %>" - <%- end -%> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['path'] != nil -%> - path: "<%= @winlogbeat_config['output']['elasticsearch']['path'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['proxy_url'] != nil -%> - proxy_url: "<%= @winlogbeat_config['output']['elasticsearch']['proxy_url'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['max_retries'] != nil -%> - max_retries: <%= @winlogbeat_config['output']['elasticsearch']['max_retries'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['bulk_max_size'] != nil -%> - bulk_max_size: <%= @winlogbeat_config['output']['elasticsearch']['bulk_max_size'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['timeout'] != nil -%> - timeout: <%= @winlogbeat_config['output']['elasticsearch']['timeout'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['flush_interval'] != nil -%> - flush_interval: <%= @winlogbeat_config['output']['elasticsearch']['flush_interval'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template'] != nil -%> - template: - <%- if @winlogbeat_config['output']['elasticsearch']['template']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['elasticsearch']['template']['enabled'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['name'] != nil -%> - name: "<%= @winlogbeat_config['output']['elasticsearch']['template']['name'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['path'] != nil -%> - path: "<%= @winlogbeat_config['output']['elasticsearch']['template']['path'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['overwrite'] != nil -%> - overwrite: <%= @winlogbeat_config['output']['elasticsearch']['template']['name'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['versions']['2.x'] != nil -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['versions']['2.x']['enabled'] != nil -%> - versions.2x.enabled: <%= @winlogbeat_config['output']['elasticsearch']['template']['versions']['2.x']['enabled'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['template']['versions']['2.x']['path'] != nil -%> - versions.2x.path: "<%= @winlogbeat_config['output']['elasticsearch']['template']['versions']['2.x']['path'] %>" - <%- end -%> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl'] != nil -%> - ssl: - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['elasticsearch']['ssl']['enabled'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['verification_mode'] != nil -%> - verification_mode: <%= @winlogbeat_config['output']['elasticsearch']['ssl']['verification_mode'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['supported_protocols'] != nil -%> - supported_protocols: - <%- @winlogbeat_config['output']['elasticsearch']['ssl']['supported_protocols'].each do |protocol| -%> - - <%= protocol %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['certificate_authorities'] != nil -%> - certificate_authorities: - <%- @winlogbeat_config['output']['elasticsearch']['ssl']['certificate_authorities'].each do |ca| -%> - - <%= ca %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['certificate'] != nil -%> - certificate: "<%= @winlogbeat_config['output']['elasticsearch']['ssl']['certificate'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['key'] != nil -%> - key: "<%= @winlogbeat_config['output']['elasticsearch']['ssl']['key'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['key_passphrase'] != nil -%> - key_passphrase: '<%= @winlogbeat_config['output']['elasticsearch']['ssl']['key_passphrase'] %>' - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['cipher_suites'] != nil -%> - cipher_suites: - <%- @winlogbeat_config['output']['elasticsearch']['ssl']['cipher_suites'].each do |cipher_suite| -%> - - <%= cipher_suite %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['elasticsearch']['ssl']['curve_types'] != nil -%> - curve_types: - <%- @winlogbeat_config['output']['elasticsearch']['ssl']['curve_types'].each do |curve_type| -%> - - <%= curve_type %> - <%- end -%> - <%- end -%> - <%- end -%> -<%- end -%> -<%- if @winlogbeat_config['output']['logstash'] != nil -%> -#----------------------------- Logstash output -------------------------------- -output.logstash: - <%- if @winlogbeat_config['output']['logstash']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['logstash']['enabled'] %> - <%- end -%> - hosts: - <%- @winlogbeat_config['output']['logstash']['hosts'].each do |host| -%> - - <%= host %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['worker'] != nil -%> - worker: <%= @winlogbeat_config['output']['logstash']['worker'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['compression_level'] != nil -%> - compression_level: <%= @winlogbeat_config['output']['logstash']['compression_level'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['loadbalance'] != nil -%> - loadbalance: <%= @winlogbeat_config['output']['logstash']['loadbalance'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['pipelining'] != nil -%> - pipelining: <%= @winlogbeat_config['output']['logstash']['pipelining'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['index'] != nil -%> - index: <%= @winlogbeat_config['output']['logstash']['index'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['proxy_url'] != nil -%> - proxy_url: <%= @winlogbeat_config['output']['logstash']['proxy_url'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['proxy_use_local_resolver'] != nil -%> - proxy_use_local_resolver: <%= @winlogbeat_config['output']['logstash']['proxy_use_local_resolver'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl'] != nil -%> - ssl: - <%- if @winlogbeat_config['output']['logstash']['ssl']['enabled'] == false -%> - enabled: false - <%- else -%> - enabled: true - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl']['verification_mode'] != nil -%> - verification_mode: <%= @winlogbeat_config['output']['logstash']['ssl']['verification_mode'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl']['certificate_authorities'] != nil -%> - certificate_authorities: - <%- @winlogbeat_config['output']['logstash']['ssl']['certificate_authorities'].each do |ca| -%> - - <%= ca %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl']['certificate'] != nil -%> - certificate: "<%= @winlogbeat_config['output']['logstash']['ssl']['certificate'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl']['key'] != nil -%> - key: "<%= @winlogbeat_config['output']['logstash']['ssl']['key'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl']['key_passphrase'] != nil -%> - key_passphrase: '<%= @winlogbeat_config['output']['logstash']['ssl']['key_passphrase'] %>' - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl']['cipher_suites'] != nil -%> - cipher_suites: - <%- @winlogbeat_config['output']['logstash']['ssl']['cipher_suites'].each do |cipher_suite| -%> - - <%= cipher_suite %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['logstash']['ssl']['curve_types'] != nil -%> - curve_types: - <%- @winlogbeat_config['output']['logstash']['ssl']['curve_types'].each do |curve_type| -%> - - <%= curve_type %> - <%- end -%> - <%- end -%> - <%- end -%> -<%- end -%> -<%- if @winlogbeat_config['output']['kafka'] != nil -%> -#------------------------------- Kafka output --------------------------------- -output.kafka: - <%- if @winlogbeat_config['output']['kafka']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['kafka']['enabled'] %> - <%- end -%> - hosts: - <%- @winlogbeat_config['output']['kafka']['hosts'].each do |host| -%> - - <%= host %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['topic'] != nil -%> - topic: <%= @winlogbeat_config['output']['kafka']['topic'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['round_robin'] != nil -%> - round_robin: - group_events: <%= @winlogbeat_config['output']['kafka']['round_robin']['group_events'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['key'] != nil -%> - key: '<%= @winlogbeat_config['output']['kafka']['key'] %>' - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['codec.format'] != nil -%> - codec.format: - <%- if @winlogbeat_config['output']['kafka']['codec.format']['string'] != nil -%> - string: <%= @winlogbeat_config['output']['kafka']['codec.format']['string'] %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['partition'] != nil and @winlogbeat_config['output']['kafka']['partition']['hash'] != nil -%> - partition.hash: - <%- if @winlogbeat_config['output']['kafka']['partition']['hash']['reachable_only'] != nil -%> - reachable_only: <%= @winlogbeat_config['output']['kafka']['partition']['hash']['reachable_only'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['partition']['hash']['hash'] != nil -%> - hash: - <%- @winlogbeat_config['output']['kafka']['partition']['hash']['hash'].each do |value| -%> - - <%= value %> - <%- end -%> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['username'] != nil -%> - username: '<%= @winlogbeat_config['output']['kafka']['username'] %>' - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['password'] != nil -%> - password: '<%= @winlogbeat_config['output']['kafka']['password'] %>' - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['version'] != nil -%> - version: <%= @winlogbeat_config['output']['kafka']['version'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['metadata'] != nil -%> - metadata: - <%- if @winlogbeat_config['output']['kafka']['retry']['max'] != nil -%> - retry.max: 3 - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['retry']['backoff'] != nil -%> - retry.backoff: 3 - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['retry']['frequency'] != nil -%> - retry.frequency: 3 - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['worker'] != nil -%> - worker: <%= @winlogbeat_config['output']['kafka']['worker'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['max_retries'] != nil -%> - max_retries: <%= @winlogbeat_config['output']['kafka']['max_retries'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['bulk_max_size'] != nil -%> - bulk_max_size: <%= @winlogbeat_config['output']['kafka']['bulk_max_size'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['timeout'] != nil -%> - timeout: <%= @winlogbeat_config['output']['kafka']['timeout'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['broker_timeout'] != nil -%> - broker_timeout: <%= @winlogbeat_config['output']['kafka']['broker_timeout'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['channel_buffer_size'] != nil -%> - channel_buffer_size: <%= @winlogbeat_config['output']['kafka']['channel_buffer_size'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['keep_alive'] != nil -%> - keep_alive: <%= @winlogbeat_config['output']['kafka']['keep_alive'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['compression'] != nil -%> - compression: <%= @winlogbeat_config['output']['kafka']['compression'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['max_message_bytes'] != nil -%> - max_message_bytes: <%= @winlogbeat_config['output']['kafka']['max_message_bytes'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['required_acks'] != nil -%> - required_acks: <%= @winlogbeat_config['output']['kafka']['required_acks'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['flush_interval'] != nil -%> - flush_interval: <%= @winlogbeat_config['output']['kafka']['flush_interval'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['client_id'] != nil -%> - client_id: <%= @winlogbeat_config['output']['kafka']['client_id'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl'] != nil -%> - ssl: - <%- if @winlogbeat_config['output']['kafka']['ssl']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['kafka']['ssl']['enabled'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['verification_mode'] != nil -%> - verification_mode: <%= @winlogbeat_config['output']['kafka']['ssl']['verification_mode'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['supported_protocols'] != nil -%> - supported_protocols: - <%- @winlogbeat_config['output']['kafka']['ssl']['supported_protocols'].each do |protocol| -%> - - <%= protocol %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['certificate_authorities'] != nil -%> - certificate_authorities: - <%- @winlogbeat_config['output']['kafka']['ssl']['certificate_authorities'].each do |ca| -%> - - <%= ca %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['certificate'] != nil -%> - certificate: "<%= @winlogbeat_config['output']['kafka']['ssl']['certificate'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['key'] != nil -%> - key: "<%= @winlogbeat_config['output']['kafka']['ssl']['key'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['key_passphrase'] != nil -%> - key_passphrase: '<%= @winlogbeat_config['output']['kafka']['ssl']['key_passphrase'] %>' - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['cipher_suites'] != nil -%> - cipher_suites: - <%- @winlogbeat_config['output']['kafka']['ssl']['cipher_suites'].each do |cipher_suite| -%> - - <%= cipher_suite %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['kafka']['ssl']['curve_types'] != nil -%> - curve_types: - <%- @winlogbeat_config['output']['kafka']['ssl']['curve_types'].each do |curve_type| -%> - - <%= curve_type %> - <%- end -%> - <%- end -%> - <%- end -%> -<%- end -%> -<%- if @winlogbeat_config['output']['redis'] != nil -%> -#------------------------------- Redis output --------------------------------- -output.redis: - <%- if @winlogbeat_config['output']['redis']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['redis']['enabled'] %> - <%- end -%> - hosts: - <%- @winlogbeat_config['output']['redis']['hosts'].each do |host| -%> - - <%= host %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['port'] != nil -%> - port: <%= @winlogbeat_config['output']['redis']['port'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['key'] != nil -%> - key: <%= @winlogbeat_config['output']['redis']['key'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['password'] != nil -%> - password: <%= @winlogbeat_config['output']['redis']['password'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['db'] != nil -%> - db: <%= @winlogbeat_config['output']['redis']['db'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['datetype'] != nil -%> - datetype: <%= @winlogbeat_config['output']['redis']['datetype'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['worker'] != nil -%> - worker: <%= @winlogbeat_config['output']['redis']['worker'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['loadbalance'] != nil -%> - loadbalance: <%= @winlogbeat_config['output']['redis']['loadbalance'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['timeout'] != nil -%> - timeout: <%= @winlogbeat_config['output']['redis']['timeout'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['max_retries'] != nil -%> - max_retries: <%= @winlogbeat_config['output']['redis']['max_retries'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['bulk_max_size'] != nil -%> - bulk_max_size: <%= @winlogbeat_config['output']['redis']['bulk_max_size'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['proxy_url'] != nil -%> - proxy_url: <%= @winlogbeat_config['output']['redis']['proxy_url'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['proxy_use_local_resolver'] != nil -%> - proxy_use_local_resolver: <%= @winlogbeat_config['output']['redis']['proxy_use_local_resolver'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl'] != nil -%> - ssl: - <%- if @winlogbeat_config['output']['redis']['ssl']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['logstash']['ssl']['enabled'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['verification_mode'] != nil -%> - verification_mode: <%= @winlogbeat_config['output']['redis']['ssl']['verification_mode'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['supported_protocols'] != nil -%> - supported_protocols: - <%- @winlogbeat_config['output']['redis']['ssl']['supported_protocols'].each do |protocol| -%> - - <%= protocol %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['certificate_authorities'] != nil -%> - certificate_authorities: - <%- @winlogbeat_config['output']['redis']['ssl']['certificate_authorities'].each do |ca| -%> - - <%= ca %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['certificate'] != nil -%> - certificate: "<%= @winlogbeat_config['output']['redis']['ssl']['certificate'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['key'] != nil -%> - key: "<%= @winlogbeat_config['output']['redis']['ssl']['key'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['key_passphrase'] != nil -%> - key_passphrase: '<%= @winlogbeat_config['output']['redis']['ssl']['key_passphrase'] %>' - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['cipher_suites'] != nil -%> - cipher_suites: - <%- @winlogbeat_config['output']['redis']['ssl']['cipher_suites'].each do |cipher_suite| -%> - - <%= cipher_suite %> - <%- end -%> - <%- end -%> - <%- if @winlogbeat_config['output']['redis']['ssl']['curve_types'] != nil -%> - curve_types: - <%- @winlogbeat_config['output']['redis']['ssl']['curve_types'].each do |curve_type| -%> - - <%= curve_type %> - <%- end -%> - <%- end -%> - <%- end -%> -<%- end -%> -<%- if @winlogbeat_config['output']['file'] != nil -%> -#------------------------------- File output ---------------------------------- -output.file: - <%- if @winlogbeat_config['output']['file']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['file']['enabled'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['file']['path'] != nil -%> - path: "<%= @winlogbeat_config['output']['file']['path'] %>" - <%- end -%> - <%- if @winlogbeat_config['output']['file']['filename'] != nil -%> - filename: <%= @winlogbeat_config['output']['file']['filename'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['file']['rotate_every_kb'] != nil -%> - rotate_every_kb: <%= @winlogbeat_config['output']['file']['rotate_every_kb'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['file']['number_of_files'] != nil -%> - number_of_files: <%= @winlogbeat_config['output']['file']['number_of_files'] %> - <%- end -%> -<%- end -%> -<%- if @winlogbeat_config['output']['console'] != nil -%> -#-------------------------- Console output ------------------------------------ -output.console: - <%- if @winlogbeat_config['output']['console']['enabled'] != nil -%> - enabled: <%= @winlogbeat_config['output']['console']['enabled'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['console']['pretty'] != nil -%> - pretty: <%= @winlogbeat_config['output']['console']['pretty'] %> - <%- end -%> - <%- if @winlogbeat_config['output']['console']['bulk_max_size'] != nil -%> - bulk_max_size: <%= @winlogbeat_config['output']['console']['bulk_max_size'] %> - <%- end -%> -<%- end -%> - -#================================= Paths ====================================== - -# The home path for the winlogbeat installation. This is the default base path -# for all other path settings and for miscellaneous files that come with the -# distribution (for example, the sample dashboards). -# If not set by a CLI flag or in the configuration file, the default for the -# home path is the location of the binary. -#path.home: - -# The configuration path for the winlogbeat installation. This is the default -# base path for configuration files, including the main YAML configuration file -# and the Elasticsearch template file. If not set by a CLI flag or in the -# configuration file, the default for the configuration path is the home path. -#path.config: ${path.home} - -# The data path for the winlogbeat installation. This is the default base path -# for all the files in which winlogbeat needs to store its data. If not set by a -# CLI flag or in the configuration file, the default for the data path is a data -# subdirectory inside the home path. -#path.data: ${path.home}/data - -# The logs path for a winlogbeat installation. This is the default location for -# the Beat's log files. If not set by a CLI flag or in the configuration file, -# the default for the logs path is a logs subdirectory inside the home path. -#path.logs: ${path.home}/logs - -#============================== Dashboards ===================================== -# These settings control loading the sample dashboards to the Kibana index. Loading -# the dashboards is disabled by default and can be enabled either by setting the -# options here, or by using the `-setup` CLI flag. -#dashboards.enabled: false - -# The URL from where to download the dashboards archive. By default this URL -# has a value which is computed based on the Beat name and version. For released -# versions, this URL points to the dashboard archive on the artifacts.elastic.co -# website. -#dashboards.url: - -# The directory from where to read the dashboards. It is used instead of the URL -# when it has a value. -#dashboards.directory: - -# The file archive (zip file) from where to read the dashboards. It is used instead -# of the URL when it has a value. -#dashboards.file: - -# If this option is enabled, the snapshot URL is used instead of the default URL. -#dashboards.snapshot: false - -# The URL from where to download the snapshot version of the dashboards. By default -# this has a value which is computed based on the Beat name and version. -#dashboards.snapshot_url - -# In case the archive contains the dashboards from multiple Beats, this lets you -# select which one to load. You can load all the dashboards in the archive by -# setting this to the empty string. -#dashboards.beat: winlogbeat - -# The name of the Kibana index to use for setting the configuration. Default is ".kibana" -#dashboards.kibana_index: .kibana - -# The Elasticsearch index name. This overwrites the index name defined in the -# dashboards and index pattern. Example: testbeat-* -#dashboards.index: - -#================================ Logging ====================================== -<%- if @winlogbeat_config['logging']['level'] != nil -%> -logging.level: <%= @winlogbeat_config['logging']['level'] %> -<%- end -%> -<%- if @winlogbeat_config['logging']['selectors'] != nil && @winlogbeat_config['logging']['selectors'].length > 0 -%> -logging.selectors: -<%- @winlogbeat_config['logging']['selectors'].each do |selector| -%> - - <%= selector %> -<%- end -%> -<%- end -%> -<%- if @winlogbeat_config['logging']['to_syslog'] != nil -%> -logging.to_syslog: <%= @winlogbeat_config['logging']['to_syslog'] %> -<%- end -%> -<%- if @winlogbeat_config['logging']['metrics'] != nil -%> -<%- if @winlogbeat_config['logging']['metrics']['enabled'] != nil -%> -logging.metrics.enabled: <%= @winlogbeat_config['logging']['metrics']['enabled'] %> -<%- end -%> -<%- if @winlogbeat_config['logging']['metrics']['period'] != nil -%> -logging.metrics.period: <%= @winlogbeat_config['logging']['metrics']['period'] %> -<%- end -%> -<%- end -%> -<%- if @winlogbeat_config['logging']['to_files'] != nil -%> -logging.to_files: <%= @winlogbeat_config['logging']['to_files'] %> -<%- end -%> -<%- if @winlogbeat_config['logging']['files'] != nil -%> -logging.files: - <%- if @winlogbeat_config['logging']['files']['path'] != nil -%> - path: <%= @winlogbeat_config['logging']['files']['path'] %> - <%- end -%> - <%- if @winlogbeat_config['logging']['files']['name'] != nil -%> - name: <%= @winlogbeat_config['logging']['files']['name'] %> - <%- end -%> - <%- if @winlogbeat_config['logging']['files']['rotateeverybytes'] != nil -%> - rotateeverybytes: <%= @winlogbeat_config['logging']['files']['rotateeverybytes'] %> - <%- end -%> - <%- if @winlogbeat_config['logging']['files']['keepfiles'] != nil -%> - keepfiles: <%= @winlogbeat_config['logging']['files']['keepfiles'] %> - <%- end -%> -<%- end -%> From 60220d41242db909b20cfaa70a71fbcc49eefa92 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 13:22:32 +0000 Subject: [PATCH 02/41] Fix type for download_url parameter --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index b8bd205..2b53417 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -62,7 +62,7 @@ Hash $logging, Hash $run_options, String $conf_template, - Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $download_url, + Optional[Stdlib::Filesource] $download_url, Boolean $manage_download_file, Optional[String] $winlogbeat_zip_path, Optional[String] $install_dir, From 5f1be7d02221fe54a7cbef339929f42ed708dc3a Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 13:57:13 +0000 Subject: [PATCH 03/41] Replace by string to test purpose --- manifests/init.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 2b53417..74ade4e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -43,7 +43,7 @@ # @param xpack [Hash] Configuration items to export internal stats to a monitoring Elasticsearch cluster class winlogbeat ( String $package_ensure, - Variant[Boolean, Enum['stopped', 'running']] $service_ensure, + Stdlib::Ensure::Service $service_ensure, Boolean $service_enable, Optional[String] $service_provider, Integer $spool_size, @@ -54,15 +54,15 @@ String $config_file, Optional[String] $config_file_owner, Optional[String] $config_file_group, - String[4,4] $config_dir_mode, - String[4,4] $config_file_mode, + Stdlib::Filemode $config_dir_mode, + Stdlib::Filemode $config_file_mode, Optional[String] $config_dir_owner, Optional[String] $config_dir_group, Hash $outputs, Hash $logging, Hash $run_options, String $conf_template, - Optional[Stdlib::Filesource] $download_url, + Optional[String] $download_url, Boolean $manage_download_file, Optional[String] $winlogbeat_zip_path, Optional[String] $install_dir, From 4b846254d464f3f0a260e64350f48ff577dbeb7c Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 14:19:59 +0000 Subject: [PATCH 04/41] Comment the delation of zip for test pupose --- manifests/init.pp | 2 +- manifests/install.pp | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 74ade4e..a604b87 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -62,7 +62,7 @@ Hash $logging, Hash $run_options, String $conf_template, - Optional[String] $download_url, + Optional[Stdlib::Filesource] $download_url, Boolean $manage_download_file, Optional[String] $winlogbeat_zip_path, Optional[String] $install_dir, diff --git a/manifests/install.pp b/manifests/install.pp index 92334f8..66409ab 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -39,13 +39,15 @@ Archive[$zip_file], ], } + + notify("\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)") # Clean up after ourselves - file { $zip_file: - ensure => absent, - backup => false, - require => Exec["unzip ${filename}"], - } + #file { $zip_file: + # ensure => absent, + # backup => false, + # require => Exec["unzip ${filename}"], + #} # You can't remove the old dir while the service has files locked... exec { "stop service ${filename}": @@ -60,6 +62,8 @@ creates => $version_file, require => Exec["stop service ${filename}"], } + + notify("Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'") exec { "mark ${filename}": command => "New-Item '${version_file}' -ItemType file", From 59b04c3da6b7f460512c526f5854f4a917efe0c7 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 14:22:40 +0000 Subject: [PATCH 05/41] Use string instead filesource because of the regex is break for puppet source. --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index a604b87..74ade4e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -62,7 +62,7 @@ Hash $logging, Hash $run_options, String $conf_template, - Optional[Stdlib::Filesource] $download_url, + Optional[String] $download_url, Boolean $manage_download_file, Optional[String] $winlogbeat_zip_path, Optional[String] $install_dir, From 48614d098bdfae8cb75a033f33dbadc94b7c1125 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 14:25:52 +0000 Subject: [PATCH 06/41] Fix syntaxe --- manifests/install.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 66409ab..7936d0c 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -40,7 +40,7 @@ ], } - notify("\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)") + notice("\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)") # Clean up after ourselves #file { $zip_file: @@ -63,7 +63,7 @@ require => Exec["stop service ${filename}"], } - notify("Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'") + notice("Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'") exec { "mark ${filename}": command => "New-Item '${version_file}' -ItemType file", From 3b6cb2fdee2bd5f0226fe3d93751666dac83936c Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 15:01:39 +0000 Subject: [PATCH 07/41] Use file instead archive when proxy is not set (bug when use puppet://) --- manifests/install.pp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 7936d0c..50aa28d 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -23,21 +23,27 @@ # However, this requires 7zip, which archive can install via chocolatey: # https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31 # I'm not choosing to impose those dependencies on anyone at this time... - archive { $zip_file: - source => $winlogbeat::real_download_url, - cleanup => false, - creates => $version_file, - proxy_server => $winlogbeat::proxy_address, + if ($winlogbeat::proxy_address) { + archive { $zip_file: + source => $winlogbeat::real_download_url, + cleanup => false, + creates => $version_file, + proxy_server => $winlogbeat::proxy_address, + before => Exec["unzip ${filename}"], + } + } else { + # Use file when source is puppet:/// because of archive break zip file + file { $zip_file: + source => $winlogbeat::real_download_url, + before => Exec["unzip ${filename}"], + } } exec { "unzip ${filename}": command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars creates => $version_file, - require => [ - File[$winlogbeat::install_dir], - Archive[$zip_file], - ], + require => File[$winlogbeat::install_dir], } notice("\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)") From 5983018552600d7db2a5ee9fac735699b89dfe7a Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 15:28:37 +0000 Subject: [PATCH 08/41] Fix test setting when winlogbeat >= 6 --- manifests/config.pp | 10 +++++++--- manifests/install.pp | 6 ------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index c875c74..22d5c99 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -30,10 +30,11 @@ # Add the 'xpack' section if supported (version >= 6.1.0) and not undef if $winlogbeat::xpack and versioncmp($winlogbeat::package_ensure, '6.1.0') >= 0 { $winlogbeat_config = deep_merge($winlogbeat_config_temp, {'xpack' => $winlogbeat::xpack}) - } - else { + } else { $winlogbeat_config = $winlogbeat_config_temp } + + $cmd_test_winlogbeat = "\"${winlogbeat_path}\" -N config test -c \"%\"" } else { $winlogbeat_config = delete_undef_values({ 'shutdown_timeout' => $winlogbeat::shutdown_timeout, @@ -56,6 +57,8 @@ 'runoptions' => $winlogbeat::run_options, 'processors' => $winlogbeat::processors, }) + + $cmd_test_winlogbeat = "\"${winlogbeat_path}\" -N -configtest -c \"%\"" } if ($facts['winlogbeat_version']) { @@ -70,9 +73,10 @@ $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') $winlogbeat_path = join([$cmd_install_dir, 'winlogbeat', 'winlogbeat.exe'], '\\') + $validate_cmd = ($winlogbeat::disable_config_test or $skip_validation) ? { true => undef, - default => "\"${winlogbeat_path}\" -N -configtest -c \"%\"", + default => $cmd_test_winlogbeat, } file {'winlogbeat.yml': diff --git a/manifests/install.pp b/manifests/install.pp index 50aa28d..ac9b3a7 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -48,12 +48,6 @@ notice("\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)") - # Clean up after ourselves - #file { $zip_file: - # ensure => absent, - # backup => false, - # require => Exec["unzip ${filename}"], - #} # You can't remove the old dir while the service has files locked... exec { "stop service ${filename}": From cd0c09ad95a5f4e5607f8e9b160afbffece97d3a Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 15:36:02 +0000 Subject: [PATCH 09/41] Fix common.yaml when lookup and get fact value --- data/common.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index 18cdca2..5286df8 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -6,7 +6,7 @@ winlogbeat::spool_size: 2048 winlogbeat::idle_timeout: '5s' winlogbeat::publish_async: false winlogbeat::shutdown_timeout: '0' -winlogbeat::beat_name: "%{lookup($::fqdn)}" +winlogbeat::beat_name: "%{facts.fqdn}" winlogbeat::tags: [] winlogbeat::queue_size: 1000 winlogbeat::fields: {} @@ -32,14 +32,14 @@ winlogbeat::max_procs: null winlogbeat::service_provider: null winlogbeat::config_file_mode: '0644' winlogbeat::config_dir_mode: '0755' -winlogbeat::kernel_fail_message: "%{lookup($::kernel)} is not supported by winlogbeat." +winlogbeat::kernel_fail_message: "%{facts.kernel} is not supported by winlogbeat." winlogbeat::conf_template: 'winlogbeat/pure_hash.yml.epp' winlogbeat::config_file_owner: 'Administrator' winlogbeat::config_file_group: null winlogbeat::config_dir_owner: 'Administrator' winlogbeat::config_dir_group: null -winlogbeat::config_file: "C:/Program Files/%{lookup($winlogbeat::folder_name)}/winlogbeat.yml" -winlogbeat::registry_file: 'C:/ProgramData/%{lookup($winlogbeat::folder_name)}/registry' +winlogbeat::config_file: "C:/Program Files/%{lookup('winlogbeat::folder_name')}/winlogbeat.yml" +winlogbeat::registry_file: 'C:/ProgramData/%{lookup('winlogbeat::folder_name')}/registry' winlogbeat::install_dir: 'C:/Program Files' winlogbeat::tmp_dir: 'C:/Windows/Temp' winlogbeat::folder_name: 'Winlogbeat' From abfbe59a4e1012a7ebe5513a4dc2fb3b1de5d440 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 15:39:20 +0000 Subject: [PATCH 10/41] Fix common.yaml typo --- data/common.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/common.yaml b/data/common.yaml index 5286df8..f1f94e8 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -39,7 +39,7 @@ winlogbeat::config_file_group: null winlogbeat::config_dir_owner: 'Administrator' winlogbeat::config_dir_group: null winlogbeat::config_file: "C:/Program Files/%{lookup('winlogbeat::folder_name')}/winlogbeat.yml" -winlogbeat::registry_file: 'C:/ProgramData/%{lookup('winlogbeat::folder_name')}/registry' +winlogbeat::registry_file: "C:/ProgramData/%{lookup('winlogbeat::folder_name')}/registry" winlogbeat::install_dir: 'C:/Program Files' winlogbeat::tmp_dir: 'C:/Windows/Temp' winlogbeat::folder_name: 'Winlogbeat' From d0abb75f38cffdd582590e0bf8569220fb1c8453 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 15:51:22 +0000 Subject: [PATCH 11/41] Try fix epp template --- manifests/config.pp | 6 +++--- templates/pure_hash.yml.epp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 22d5c99..56ef1ca 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -6,6 +6,8 @@ class winlogbeat::config { $major_version = regsubst($winlogbeat::package_ensure, '^(\d)\..*', '\1') + $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') + $winlogbeat_path = join([$cmd_install_dir, 'winlogbeat', 'winlogbeat.exe'], '\\') if versioncmp($major_version, '6') >= 0 { $winlogbeat_config_temp = delete_undef_values({ @@ -70,15 +72,13 @@ $skip_validation = false } - $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') - $winlogbeat_path = join([$cmd_install_dir, 'winlogbeat', 'winlogbeat.exe'], '\\') - $validate_cmd = ($winlogbeat::disable_config_test or $skip_validation) ? { true => undef, default => $cmd_test_winlogbeat, } + $winlogbeat_config_yaml= $winlogbeat_config.to_yaml() file {'winlogbeat.yml': ensure => $winlogbeat::file_ensure, path => $winlogbeat::config_file, diff --git a/templates/pure_hash.yml.epp b/templates/pure_hash.yml.epp index caeca8f..9577eac 100644 --- a/templates/pure_hash.yml.epp +++ b/templates/pure_hash.yml.epp @@ -1,2 +1,2 @@ ### Winlogbeat configuration managed by Puppet ### -<%= $winlogbeat_config.to_yaml() %> \ No newline at end of file +<%= $winlogbeat_config_yaml %> \ No newline at end of file From 2bac390aa72706be7fc6a88016151eac94a21654 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Wed, 15 May 2019 15:55:26 +0000 Subject: [PATCH 12/41] Fix command to test winlogbeat --- manifests/config.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 56ef1ca..8607a2f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -36,7 +36,7 @@ $winlogbeat_config = $winlogbeat_config_temp } - $cmd_test_winlogbeat = "\"${winlogbeat_path}\" -N config test -c \"%\"" + $cmd_test_winlogbeat = "\"${winlogbeat_path}\" test config -c \"%\"" } else { $winlogbeat_config = delete_undef_values({ 'shutdown_timeout' => $winlogbeat::shutdown_timeout, From dab35c759e9b98e9dcee46e100424eb5ebb004a6 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 17 May 2019 09:13:19 +0000 Subject: [PATCH 13/41] Remove default value for outputs --- data/common.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/data/common.yaml b/data/common.yaml index f1f94e8..12736a2 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -11,7 +11,6 @@ winlogbeat::tags: [] winlogbeat::queue_size: 1000 winlogbeat::fields: {} winlogbeat::fields_under_root: false -winlogbeat::outputs: {} winlogbeat::logging: {} winlogbeat::run_options: {} winlogbeat::disable_config_test: false From 09ee68f0081db4dda967076028126e7cb39c4402 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 17 May 2019 09:40:30 +0000 Subject: [PATCH 14/41] Fix epp template --- data/common.yaml | 1 + manifests/config.pp | 4 ++-- templates/pure_hash.yml.epp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index 12736a2..f1f94e8 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -11,6 +11,7 @@ winlogbeat::tags: [] winlogbeat::queue_size: 1000 winlogbeat::fields: {} winlogbeat::fields_under_root: false +winlogbeat::outputs: {} winlogbeat::logging: {} winlogbeat::run_options: {} winlogbeat::disable_config_test: false diff --git a/manifests/config.pp b/manifests/config.pp index 8607a2f..0fd75e2 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -78,11 +78,11 @@ default => $cmd_test_winlogbeat, } - $winlogbeat_config_yaml= $winlogbeat_config.to_yaml() + $winlogbeat_config_yaml = $winlogbeat_config.to_yaml() file {'winlogbeat.yml': ensure => $winlogbeat::file_ensure, path => $winlogbeat::config_file, - content => template($winlogbeat::conf_template), + content => epp($winlogbeat::conf_template), validate_cmd => $validate_cmd, notify => Service['winlogbeat'], } diff --git a/templates/pure_hash.yml.epp b/templates/pure_hash.yml.epp index 9577eac..0a07940 100644 --- a/templates/pure_hash.yml.epp +++ b/templates/pure_hash.yml.epp @@ -1,2 +1,2 @@ ### Winlogbeat configuration managed by Puppet ### -<%= $winlogbeat_config_yaml %> \ No newline at end of file +<%= $winlogbeat::config::winlogbeat_config_yaml %> \ No newline at end of file From 08bbcae03b35b1cdfc61525a817b6557498981e2 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 17 May 2019 11:31:20 +0000 Subject: [PATCH 15/41] Fix the doc --- manifests/init.pp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 74ade4e..c292d74 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -20,15 +20,19 @@ # @param publish_async [Boolean] If set to true winlogbeat will publish while preparing the next batch of lines to send (defualt: false) # @param registry_file [String] The registry file used to store positions, absolute or relative to working directory (default .winlogbeat) # @param registry_flush [String] The timeout value that controls when registry entries are written to disk (default: 0s) -# @param config_dir [String] The directory where prospectors should be defined (default: /etc/winlogbeat/conf.d) # @param config_dir_mode [String] The unix permissions mode set on the configuration directory (default: 0755) +# @param config_dir_owner [String] The owner set on the configuration directory (default: Administrator) +# @param config_dir_group [String] The group set on the configuration directory (default: Administrators) # @param config_file_mode [String] The unix permissions mode set on configuration files (default: 0644) -# @param purge_conf_dir [Boolean] Should files in the prospector configuration directory not managed by puppet be automatically purged +# @param config_file_owner [String] The owner set on configuration files (default: Administrator) +# @param config_file_group [String] The group set on configuration files (default: Administrators) # @param outputs [Hash] Will be converted to YAML for the required outputs section of the configuration (see documentation, and above) # @param logging [Hash] Will be converted to YAML to create the optional logging section of the winlogbeat config (see documentation) +# @param run_options [Hash] Will be converted to YAML to create optionnal run options section of the winlogbeat config # @param conf_template [String] The configuration template to use to generate the main winlogbeat.yml config file # @param download_url [String] The URL of the zip file that should be downloaded to install winlogbeat (windows only) # @param install_dir [String] Where winlogbeat should be installed (windows only) +# @param folder_name [String] The folder name to use to install winlogbeat (default: Winlogbeat) # @param tmp_dir [String] Where winlogbeat should be temporarily downloaded to so it can be installed (windows only) # @param shutdown_timeout [String] How long winlogbeat waits on shutdown for the publisher to finish sending events # @param beat_name [String] The name of the beat shipper (default: hostname) @@ -38,9 +42,12 @@ # @param fields [Hash] Optional fields that should be added to each event output # @param fields_under_root [Boolean] If set to true, custom fields are stored in the top level instead of under fields # @param processors [Array] Processors that will be added. Commonly used to create processors using hiera. +# @param disable_config_test [Boolean] Disable the configuration testing before to restart Winlogbeat servie (Default: false) # @param setup [Hash] setup that will be created. Commonly used to create setup using hiera -# proxy_address [String] Proxy server to use for downloading files +# @param proxy_address [String] Proxy server to use for downloading files # @param xpack [Hash] Configuration items to export internal stats to a monitoring Elasticsearch cluster +# @param queue [Hash] Will be converted to YAML to create the optional queue section of the winlogbeat config (see documentation) +# @param event_logs [Array[Hash]] Will be converted to Yaml to create the event_logs section of the winlogbeat class winlogbeat ( String $package_ensure, Stdlib::Ensure::Service $service_ensure, @@ -63,8 +70,6 @@ Hash $run_options, String $conf_template, Optional[String] $download_url, - Boolean $manage_download_file, - Optional[String] $winlogbeat_zip_path, Optional[String] $install_dir, String $folder_name, String $tmp_dir, From 7ce510ad1fb128fffa4fba32545258a2bc62f06b Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 17 May 2019 13:09:44 +0000 Subject: [PATCH 16/41] Fix lint issue and remove debug lines --- manifests/config.pp | 6 +++--- manifests/install.pp | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 0fd75e2..a5eb46c 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -35,7 +35,7 @@ } else { $winlogbeat_config = $winlogbeat_config_temp } - + $cmd_test_winlogbeat = "\"${winlogbeat_path}\" test config -c \"%\"" } else { $winlogbeat_config = delete_undef_values({ @@ -59,7 +59,7 @@ 'runoptions' => $winlogbeat::run_options, 'processors' => $winlogbeat::processors, }) - + $cmd_test_winlogbeat = "\"${winlogbeat_path}\" -N -configtest -c \"%\"" } @@ -72,7 +72,7 @@ $skip_validation = false } - + $validate_cmd = ($winlogbeat::disable_config_test or $skip_validation) ? { true => undef, default => $cmd_test_winlogbeat, diff --git a/manifests/install.pp b/manifests/install.pp index ac9b3a7..eba0ae7 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -34,8 +34,8 @@ } else { # Use file when source is puppet:/// because of archive break zip file file { $zip_file: - source => $winlogbeat::real_download_url, - before => Exec["unzip ${filename}"], + source => $winlogbeat::real_download_url, + before => Exec["unzip ${filename}"], } } @@ -45,8 +45,6 @@ creates => $version_file, require => File[$winlogbeat::install_dir], } - - notice("\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)") # You can't remove the old dir while the service has files locked... @@ -62,8 +60,7 @@ creates => $version_file, require => Exec["stop service ${filename}"], } - - notice("Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'") + exec { "mark ${filename}": command => "New-Item '${version_file}' -ItemType file", From 1483af3d2a25190efe31cad5aab6b13f53a1ac24 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Thu, 23 May 2019 14:48:10 +0000 Subject: [PATCH 17/41] Add dependency to wait unzip on target before lauch script sthat install service --- manifests/install.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/install.pp b/manifests/install.pp index eba0ae7..b1ec7ad 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -74,5 +74,6 @@ refreshonly => true, subscribe => Exec["mark ${filename}"], notify => Class['winlogbeat::service'], + require => Exec["unzip ${filename}"] } } From 67395d2ae36bdbe461754ec77bc4dd4dc4f7dcf1 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Thu, 23 May 2019 14:59:32 +0000 Subject: [PATCH 18/41] Remove the require, it not fix that. --- manifests/install.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index b1ec7ad..eba0ae7 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -74,6 +74,5 @@ refreshonly => true, subscribe => Exec["mark ${filename}"], notify => Class['winlogbeat::service'], - require => Exec["unzip ${filename}"] } } From fb07d11502d57353730908c7b98c0589c040300b Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Fri, 17 Jan 2020 09:43:45 +0000 Subject: [PATCH 19/41] Use version 6.8.5 as default --- data/common.yaml | 100 +++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index f1f94e8..9a7bae3 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,51 +1,51 @@ ---- -# User settings -winlogbeat::service_ensure: 'running' -winlogbeat::service_enable: true -winlogbeat::spool_size: 2048 -winlogbeat::idle_timeout: '5s' -winlogbeat::publish_async: false -winlogbeat::shutdown_timeout: '0' -winlogbeat::beat_name: "%{facts.fqdn}" -winlogbeat::tags: [] -winlogbeat::queue_size: 1000 -winlogbeat::fields: {} -winlogbeat::fields_under_root: false -winlogbeat::outputs: {} -winlogbeat::logging: {} -winlogbeat::run_options: {} -winlogbeat::disable_config_test: false -winlogbeat::package_ensure: '6.7.2' -winlogbeat::event_logs: [] -winlogbeat::setup: {} -winlogbeat::queue: {} -winlogbeat::processors: {} -winlogbeat::registry_flush: null -winlogbeat::manage_download_file: true -winlogbeat::download_url: null -winlogbeat::winlogbeat_zip_path: null -winlogbeat::proxy_address: null -winlogbeat::xpack: null -winlogbeat::max_procs: null - -# Internal module -winlogbeat::service_provider: null -winlogbeat::config_file_mode: '0644' -winlogbeat::config_dir_mode: '0755' -winlogbeat::kernel_fail_message: "%{facts.kernel} is not supported by winlogbeat." -winlogbeat::conf_template: 'winlogbeat/pure_hash.yml.epp' -winlogbeat::config_file_owner: 'Administrator' -winlogbeat::config_file_group: null -winlogbeat::config_dir_owner: 'Administrator' -winlogbeat::config_dir_group: null -winlogbeat::config_file: "C:/Program Files/%{lookup('winlogbeat::folder_name')}/winlogbeat.yml" -winlogbeat::registry_file: "C:/ProgramData/%{lookup('winlogbeat::folder_name')}/registry" -winlogbeat::install_dir: 'C:/Program Files' -winlogbeat::tmp_dir: 'C:/Windows/Temp' -winlogbeat::folder_name: 'Winlogbeat' - -lookup_options: - winlogbeat::event_logs: - merge: - strategy: 'deep' +--- +# User settings +winlogbeat::service_ensure: 'running' +winlogbeat::service_enable: true +winlogbeat::spool_size: 2048 +winlogbeat::idle_timeout: '5s' +winlogbeat::publish_async: false +winlogbeat::shutdown_timeout: '0' +winlogbeat::beat_name: "%{facts.fqdn}" +winlogbeat::tags: [] +winlogbeat::queue_size: 1000 +winlogbeat::fields: {} +winlogbeat::fields_under_root: false +winlogbeat::outputs: {} +winlogbeat::logging: {} +winlogbeat::run_options: {} +winlogbeat::disable_config_test: false +winlogbeat::package_ensure: '6.8.5' +winlogbeat::event_logs: [] +winlogbeat::setup: {} +winlogbeat::queue: {} +winlogbeat::processors: {} +winlogbeat::registry_flush: null +winlogbeat::manage_download_file: true +winlogbeat::download_url: null +winlogbeat::winlogbeat_zip_path: null +winlogbeat::proxy_address: null +winlogbeat::xpack: null +winlogbeat::max_procs: null + +# Internal module +winlogbeat::service_provider: null +winlogbeat::config_file_mode: '0644' +winlogbeat::config_dir_mode: '0755' +winlogbeat::kernel_fail_message: "%{facts.kernel} is not supported by winlogbeat." +winlogbeat::conf_template: 'winlogbeat/pure_hash.yml.epp' +winlogbeat::config_file_owner: 'Administrator' +winlogbeat::config_file_group: null +winlogbeat::config_dir_owner: 'Administrator' +winlogbeat::config_dir_group: null +winlogbeat::config_file: "C:/Program Files/%{lookup('winlogbeat::folder_name')}/winlogbeat.yml" +winlogbeat::registry_file: "C:/ProgramData/%{lookup('winlogbeat::folder_name')}/registry" +winlogbeat::install_dir: 'C:/Program Files' +winlogbeat::tmp_dir: 'C:/Windows/Temp' +winlogbeat::folder_name: 'Winlogbeat' + +lookup_options: + winlogbeat::event_logs: + merge: + strategy: 'deep' merge_hash_arrays: true \ No newline at end of file From 946c867720e33d2fbf37b62e276f4e8e1e451089 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 10:56:45 +0000 Subject: [PATCH 20/41] Add ability to remove winlogbeat --- manifests/install.pp | 128 ++++++++++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 50 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index eba0ae7..89243f0 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -13,66 +13,94 @@ provider => powershell, } - if ! defined(File[$winlogbeat::install_dir]) { - file { $winlogbeat::install_dir: - ensure => directory, - } - } + case $::winlogbeat::ensure { + 'present': { + if ! defined(File[$winlogbeat::install_dir]) { + file { $winlogbeat::install_dir: + ensure => directory, + } + } - # Note: We can use archive for unzip and cleanup, thus removing the following two resources. - # However, this requires 7zip, which archive can install via chocolatey: - # https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31 - # I'm not choosing to impose those dependencies on anyone at this time... - if ($winlogbeat::proxy_address) { - archive { $zip_file: - source => $winlogbeat::real_download_url, - cleanup => false, - creates => $version_file, - proxy_server => $winlogbeat::proxy_address, - before => Exec["unzip ${filename}"], + # Note: We can use archive for unzip and cleanup, thus removing the following two resources. + # However, this requires 7zip, which archive can install via chocolatey: + # https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31 + # I'm not choosing to impose those dependencies on anyone at this time... + if ($winlogbeat::proxy_address) { + archive { $zip_file: + source => $winlogbeat::real_download_url, + cleanup => false, + creates => $version_file, + proxy_server => $winlogbeat::proxy_address, + before => Exec["unzip ${filename}"], + } + } else { + # Use file when source is puppet:/// because of archive break zip file + file { $zip_file: + source => $winlogbeat::real_download_url, + before => Exec["unzip ${filename}"], + } } - } else { - # Use file when source is puppet:/// because of archive break zip file - file { $zip_file: - source => $winlogbeat::real_download_url, - before => Exec["unzip ${filename}"], + + + exec { "unzip ${filename}": + command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars + creates => $version_file, + require => File[$winlogbeat::install_dir], } - } - exec { "unzip ${filename}": - command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars - creates => $version_file, - require => File[$winlogbeat::install_dir], - } + # You can't remove the old dir while the service has files locked... + exec { "stop service ${filename}": + command => 'Set-Service -Name winlogbeat -Status Stopped', + creates => $version_file, + onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'winlogbeat\'") {exit 0} else {exit 1}', + require => Exec["unzip ${filename}"], + } + exec { "rename ${filename}": + command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + creates => $version_file, + require => Exec["stop service ${filename}"], + } - # You can't remove the old dir while the service has files locked... - exec { "stop service ${filename}": - command => 'Set-Service -Name winlogbeat -Status Stopped', - creates => $version_file, - onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'winlogbeat\'") {exit 0} else {exit 1}', - require => Exec["unzip ${filename}"], - } - exec { "rename ${filename}": - command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars - creates => $version_file, - require => Exec["stop service ${filename}"], - } + exec { "mark ${filename}": + command => "New-Item '${version_file}' -ItemType file", + creates => $version_file, + require => Exec["rename ${filename}"], + } + exec { "install ${filename}": + cwd => $install_folder, + command => './install-service-winlogbeat.ps1', + refreshonly => true, + subscribe => Exec["mark ${filename}"], + notify => Class['winlogbeat::service'], + } + } + 'absent': { - exec { "mark ${filename}": - command => "New-Item '${version_file}' -ItemType file", - creates => $version_file, - require => Exec["rename ${filename}"], - } + # Stop and remove service + exec { "stop service ${filename}": + command => 'Set-Service -Name winlogbeat -Status Stopped', + onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'winlogbeat\'") {exit 0} else {exit 1}', + } - exec { "install ${filename}": - cwd => $install_folder, - command => './install-service-winlogbeat.ps1', - refreshonly => true, - subscribe => Exec["mark ${filename}"], - notify => Class['winlogbeat::service'], + -> exec { "uninstall ${filename}": + cwd => $install_folder, + command => './uninstall-service-winlogbeat.ps1', + onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'winlogbeat\'") {exit 0} else {exit 1}', + } + + # Remove folders + -> file {$install_folder: + ensure => 'absent', + force => true, + } + + } + default: { + fail('ensure must be present or absent') + } } } From 02518287e2bf5b564b609f40d5e737dd9f2a26a9 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 11:01:35 +0000 Subject: [PATCH 21/41] Add ability to remove winlogbeat --- manifests/config.pp | 1 + manifests/init.pp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/manifests/config.pp b/manifests/config.pp index a5eb46c..ba033a9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -9,6 +9,7 @@ $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') $winlogbeat_path = join([$cmd_install_dir, 'winlogbeat', 'winlogbeat.exe'], '\\') + if versioncmp($major_version, '6') >= 0 { $winlogbeat_config_temp = delete_undef_values({ 'shutdown_timeout' => $winlogbeat::shutdown_timeout, diff --git a/manifests/init.pp b/manifests/init.pp index c292d74..881ef0f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -112,11 +112,13 @@ } if $package_ensure == 'absent' { + $ensure = 'absent' $alternate_ensure = 'absent' $real_service_ensure = 'stopped' $file_ensure = 'absent' $directory_ensure = 'absent' } else { + $ensure = 'present' $alternate_ensure = 'present' $file_ensure = 'file' $directory_ensure = 'directory' From 08401d2a3634cf777cd26e69a28fa3d88622c367 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 11:10:40 +0000 Subject: [PATCH 22/41] Add ability to remove winlogbeat --- manifests/config.pp | 150 +++++++++++++++++++++++--------------------- manifests/init.pp | 6 +- 2 files changed, 83 insertions(+), 73 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index ba033a9..d72dc23 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -9,83 +9,93 @@ $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') $winlogbeat_path = join([$cmd_install_dir, 'winlogbeat', 'winlogbeat.exe'], '\\') + case $::winlogbeat::ensure { + 'present': { + if versioncmp($major_version, '6') >= 0 { + $winlogbeat_config_temp = delete_undef_values({ + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'name' => $winlogbeat::beat_name, + 'tags' => $winlogbeat::tags, + 'max_procs' => $winlogbeat::max_procs, + 'fields' => $winlogbeat::fields, + 'fields_under_root' => $winlogbeat::fields_under_root, + 'winlogbeat' => { + 'registry_file' => $winlogbeat::registry_file, + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'event_logs' => $winlogbeat::event_logs, + }, + 'output' => $winlogbeat::outputs, + 'logging' => $winlogbeat::logging, + 'runoptions' => $winlogbeat::run_options, + 'processors' => $winlogbeat::processors, + 'setup' => $winlogbeat::setup, + 'queue' => $winlogbeat::queue, + }) + # Add the 'xpack' section if supported (version >= 6.1.0) and not undef + if $winlogbeat::xpack and versioncmp($winlogbeat::package_ensure, '6.1.0') >= 0 { + $winlogbeat_config = deep_merge($winlogbeat_config_temp, {'xpack' => $winlogbeat::xpack}) + } else { + $winlogbeat_config = $winlogbeat_config_temp + } - if versioncmp($major_version, '6') >= 0 { - $winlogbeat_config_temp = delete_undef_values({ - 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'name' => $winlogbeat::beat_name, - 'tags' => $winlogbeat::tags, - 'max_procs' => $winlogbeat::max_procs, - 'fields' => $winlogbeat::fields, - 'fields_under_root' => $winlogbeat::fields_under_root, - 'winlogbeat' => { - 'registry_file' => $winlogbeat::registry_file, - 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'event_logs' => $winlogbeat::event_logs, - }, - 'output' => $winlogbeat::outputs, - 'logging' => $winlogbeat::logging, - 'runoptions' => $winlogbeat::run_options, - 'processors' => $winlogbeat::processors, - 'setup' => $winlogbeat::setup, - 'queue' => $winlogbeat::queue, - }) - # Add the 'xpack' section if supported (version >= 6.1.0) and not undef - if $winlogbeat::xpack and versioncmp($winlogbeat::package_ensure, '6.1.0') >= 0 { - $winlogbeat_config = deep_merge($winlogbeat_config_temp, {'xpack' => $winlogbeat::xpack}) - } else { - $winlogbeat_config = $winlogbeat_config_temp - } + $cmd_test_winlogbeat = "\"${winlogbeat_path}\" test config -c \"%\"" + } else { + $winlogbeat_config = delete_undef_values({ + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'name' => $winlogbeat::beat_name, + 'tags' => $winlogbeat::tags, + 'queue_size' => $winlogbeat::queue_size, + 'max_procs' => $winlogbeat::max_procs, + 'fields' => $winlogbeat::fields, + 'fields_under_root' => $winlogbeat::fields_under_root, + 'winlogbeat' => { + 'spool_size' => $winlogbeat::spool_size, + 'idle_timeout' => $winlogbeat::idle_timeout, + 'registry_file' => $winlogbeat::registry_file, + 'publish_async' => $winlogbeat::publish_async, + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'event_logs' => $winlogbeat::event_logs, + }, + 'output' => $winlogbeat::outputs, + 'logging' => $winlogbeat::logging, + 'runoptions' => $winlogbeat::run_options, + 'processors' => $winlogbeat::processors, + }) - $cmd_test_winlogbeat = "\"${winlogbeat_path}\" test config -c \"%\"" - } else { - $winlogbeat_config = delete_undef_values({ - 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'name' => $winlogbeat::beat_name, - 'tags' => $winlogbeat::tags, - 'queue_size' => $winlogbeat::queue_size, - 'max_procs' => $winlogbeat::max_procs, - 'fields' => $winlogbeat::fields, - 'fields_under_root' => $winlogbeat::fields_under_root, - 'winlogbeat' => { - 'spool_size' => $winlogbeat::spool_size, - 'idle_timeout' => $winlogbeat::idle_timeout, - 'registry_file' => $winlogbeat::registry_file, - 'publish_async' => $winlogbeat::publish_async, - 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'event_logs' => $winlogbeat::event_logs, - }, - 'output' => $winlogbeat::outputs, - 'logging' => $winlogbeat::logging, - 'runoptions' => $winlogbeat::run_options, - 'processors' => $winlogbeat::processors, - }) + $cmd_test_winlogbeat = "\"${winlogbeat_path}\" -N -configtest -c \"%\"" + } - $cmd_test_winlogbeat = "\"${winlogbeat_path}\" -N -configtest -c \"%\"" - } + if ($facts['winlogbeat_version']) { + $skip_validation = versioncmp($facts['winlogbeat_version'], $major_version) ? { + -1 => true, + default => false, + } + } else { + $skip_validation = false + } - if ($facts['winlogbeat_version']) { - $skip_validation = versioncmp($facts['winlogbeat_version'], $major_version) ? { - -1 => true, - default => false, - } - } else { - $skip_validation = false - } + $validate_cmd = ($winlogbeat::disable_config_test or $skip_validation) ? { + true => undef, + default => $cmd_test_winlogbeat, + } - $validate_cmd = ($winlogbeat::disable_config_test or $skip_validation) ? { - true => undef, - default => $cmd_test_winlogbeat, - } + $winlogbeat_config_yaml = $winlogbeat_config.to_yaml() + file {'winlogbeat.yml': + ensure => $winlogbeat::file_ensure, + path => $winlogbeat::config_file, + content => epp($winlogbeat::conf_template), + validate_cmd => $validate_cmd, + notify => Service['winlogbeat'], + } - $winlogbeat_config_yaml = $winlogbeat_config.to_yaml() - file {'winlogbeat.yml': - ensure => $winlogbeat::file_ensure, - path => $winlogbeat::config_file, - content => epp($winlogbeat::conf_template), - validate_cmd => $validate_cmd, - notify => Service['winlogbeat'], + } + 'absent': { + # Nothink todo + } + default: { + fail('ensure must be absent or present') + } } } diff --git a/manifests/init.pp b/manifests/init.pp index 881ef0f..f916155 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -131,10 +131,10 @@ contain ::winlogbeat::config contain ::winlogbeat::service - if $package_ensure == 'absent' { - Class['::winlogbeat::config'] + if $ensure == 'absent' { + Class['::winlogbeat::service'] + -> Class['::winlogbeat::config'] -> Class['::winlogbeat::install'] - -> Class['::winlogbeat::service'] } else { Class['::winlogbeat::install'] -> Class['::winlogbeat::config'] From 878c6f4716eec98c79d5f244918b91cd77d063d7 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 11:16:23 +0000 Subject: [PATCH 23/41] Add ability to remove winlogbeat --- manifests/init.pp | 4 +++- manifests/service.pp | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index f916155..239b88d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -114,7 +114,8 @@ if $package_ensure == 'absent' { $ensure = 'absent' $alternate_ensure = 'absent' - $real_service_ensure = 'stopped' + $real_service_ensure = 'absent' + $real_service_enable = false $file_ensure = 'absent' $directory_ensure = 'absent' } else { @@ -123,6 +124,7 @@ $file_ensure = 'file' $directory_ensure = 'directory' $real_service_ensure = $service_ensure + $real_service_enable = $service_enable } # If we're removing winlogbeat, do things in a different order to make sure diff --git a/manifests/service.pp b/manifests/service.pp index 84ffb27..272c478 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -5,8 +5,8 @@ # @summary A private class to manage the winlogbeat service class winlogbeat::service { service { 'winlogbeat': - ensure => $winlogbeat::service_ensure, - enable => $winlogbeat::service_enable, - provider => $winlogbeat::service_provider, + ensure => $::winlogbeat::real_service_ensure, + enable => $::winlogbeat::real_service_enable, + provider => $::winlogbeat::service_provider, } } \ No newline at end of file From 205134358afef40a8afaca91c95cacf08c698c8c Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 11:18:50 +0000 Subject: [PATCH 24/41] Add ability to remove winlogbeat --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 239b88d..bd32f7d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -114,7 +114,7 @@ if $package_ensure == 'absent' { $ensure = 'absent' $alternate_ensure = 'absent' - $real_service_ensure = 'absent' + $real_service_ensure = 'stopped' $real_service_enable = false $file_ensure = 'absent' $directory_ensure = 'absent' From 88b71a6fea13d19e943b3aa0985dbd44cb1c34d7 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 11:56:00 +0000 Subject: [PATCH 25/41] Add ability to remove winlogbeat --- manifests/install.pp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 89243f0..877e9eb 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -87,8 +87,7 @@ } -> exec { "uninstall ${filename}": - cwd => $install_folder, - command => './uninstall-service-winlogbeat.ps1', + command => "${install_folder}/uninstall-service-winlogbeat.ps1", onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'winlogbeat\'") {exit 0} else {exit 1}', } From bbfbbcbd7113203b1d911873c898da332d188906 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 12:37:03 +0000 Subject: [PATCH 26/41] Try to fix factor --- lib/facter/winlogbeat_version.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/facter/winlogbeat_version.rb b/lib/facter/winlogbeat_version.rb index 280ef01..c0cbb8c 100644 --- a/lib/facter/winlogbeat_version.rb +++ b/lib/facter/winlogbeat_version.rb @@ -1,10 +1,13 @@ require 'facter' Facter.add('winlogbeat_version') do - confine :kernel => ['Windows'] # rubocop:disable Style/HashSyntax + confine 'kernel' => ['Windows'] if File.exist?('c:\Program Files\Winlogbeat\winlogbeat.exe') - winlogbeat_version = Facter::Util::Resolution.exec('"c:\Program Files\Winlogbeat\winlogbeat.exe" --version') + winlogbeat_version = Facter::Util::Resolution.exec('"c:\Program Files\Winlogbeat\winlogbeat.exe" version') + if winlogbeat_version.empty? + winlogbeat_version = Facter::Util::Resolution.exec('"c:\Program Files\Winlogbeat\winlogbeat.exe" --version') + end end setcode do - %r{^winlogbeat version ([^\s]+)?}.match(winlogbeat_version)[1] unless winlogbeat_version.nil? + winlogbeat_version.nil ? false : %r{^winlogbeat version ([^\s]+)?}.match(winlogbeat_version)[1] end end From 8f879cef3ef308168aad4647abc7fb8c2550cade Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 12:40:00 +0000 Subject: [PATCH 27/41] Try to fix factor --- lib/facter/winlogbeat_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/winlogbeat_version.rb b/lib/facter/winlogbeat_version.rb index c0cbb8c..0f570ce 100644 --- a/lib/facter/winlogbeat_version.rb +++ b/lib/facter/winlogbeat_version.rb @@ -8,6 +8,6 @@ end end setcode do - winlogbeat_version.nil ? false : %r{^winlogbeat version ([^\s]+)?}.match(winlogbeat_version)[1] + winlogbeat_version.nil? ? false : %r{^winlogbeat version ([^\s]+)?}.match(winlogbeat_version)[1] end end From 5f13dad95056ea0abdfa5b0a110ece741f11ea1a Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 13:13:23 +0000 Subject: [PATCH 28/41] Use winlogbeat 7.5.1 as default version --- data/common.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/common.yaml b/data/common.yaml index 9a7bae3..e591a0e 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -15,7 +15,7 @@ winlogbeat::outputs: {} winlogbeat::logging: {} winlogbeat::run_options: {} winlogbeat::disable_config_test: false -winlogbeat::package_ensure: '6.8.5' +winlogbeat::package_ensure: '7.5.1' winlogbeat::event_logs: [] winlogbeat::setup: {} winlogbeat::queue: {} From 24428f2f63efd8e3fc420c434635cc38caec7d59 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 23 Jan 2020 13:29:46 +0000 Subject: [PATCH 29/41] Fix version on metadata --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 0e6addc..3cdaf12 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppet-winlogbeat", - "version": "0.2.3-rc0", + "version": "7.5.1", "author": "Vox Pupuli", "summary": "A module to install and manage the winlogbeat log shipper", "license": "Apache-2.0", From baac9ea4f8500b61b333156534943b6ecac6d790 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Fri, 8 Jan 2021 15:04:55 +0000 Subject: [PATCH 30/41] Try to resolve conflict --- Gemfile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Gemfile b/Gemfile index f8a7931..9cac903 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,4 @@ gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] puppetversion = ENV['PUPPET_VERSION'] || '~> 6.0' gem 'puppet', puppetversion, :require => false, :groups => [:test] -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end -end # vim: syntax=ruby From 00bdfe54b2d8fe53ae3439f2b676e50918849893 Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Fri, 8 Jan 2021 15:51:18 +0000 Subject: [PATCH 31/41] Fix lint code wit pdk validate --- manifests/config.pp | 83 ++++++++++++++++------------------ manifests/init.pp | 25 +++++----- manifests/install.pp | 33 ++++++-------- manifests/service.pp | 6 +-- spec/spec_helper_acceptance.rb | 2 +- 5 files changed, 70 insertions(+), 79 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index d72dc23..2104df4 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -9,57 +9,57 @@ $cmd_install_dir = regsubst($winlogbeat::install_dir, '/', '\\', 'G') $winlogbeat_path = join([$cmd_install_dir, 'winlogbeat', 'winlogbeat.exe'], '\\') - case $::winlogbeat::ensure { + case $winlogbeat::ensure { 'present': { if versioncmp($major_version, '6') >= 0 { - $winlogbeat_config_temp = delete_undef_values({ - 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'name' => $winlogbeat::beat_name, - 'tags' => $winlogbeat::tags, - 'max_procs' => $winlogbeat::max_procs, - 'fields' => $winlogbeat::fields, - 'fields_under_root' => $winlogbeat::fields_under_root, - 'winlogbeat' => { - 'registry_file' => $winlogbeat::registry_file, + $winlogbeat_config_temp = delete_undef_values( { 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'event_logs' => $winlogbeat::event_logs, - }, - 'output' => $winlogbeat::outputs, - 'logging' => $winlogbeat::logging, - 'runoptions' => $winlogbeat::run_options, - 'processors' => $winlogbeat::processors, - 'setup' => $winlogbeat::setup, - 'queue' => $winlogbeat::queue, + 'name' => $winlogbeat::beat_name, + 'tags' => $winlogbeat::tags, + 'max_procs' => $winlogbeat::max_procs, + 'fields' => $winlogbeat::fields, + 'fields_under_root' => $winlogbeat::fields_under_root, + 'winlogbeat' => { + 'registry_file' => $winlogbeat::registry_file, + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'event_logs' => $winlogbeat::event_logs, + }, + 'output' => $winlogbeat::outputs, + 'logging' => $winlogbeat::logging, + 'runoptions' => $winlogbeat::run_options, + 'processors' => $winlogbeat::processors, + 'setup' => $winlogbeat::setup, + 'queue' => $winlogbeat::queue, }) # Add the 'xpack' section if supported (version >= 6.1.0) and not undef if $winlogbeat::xpack and versioncmp($winlogbeat::package_ensure, '6.1.0') >= 0 { - $winlogbeat_config = deep_merge($winlogbeat_config_temp, {'xpack' => $winlogbeat::xpack}) + $winlogbeat_config = deep_merge($winlogbeat_config_temp, { 'xpack' => $winlogbeat::xpack }) } else { $winlogbeat_config = $winlogbeat_config_temp } $cmd_test_winlogbeat = "\"${winlogbeat_path}\" test config -c \"%\"" } else { - $winlogbeat_config = delete_undef_values({ - 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'name' => $winlogbeat::beat_name, - 'tags' => $winlogbeat::tags, - 'queue_size' => $winlogbeat::queue_size, - 'max_procs' => $winlogbeat::max_procs, - 'fields' => $winlogbeat::fields, - 'fields_under_root' => $winlogbeat::fields_under_root, - 'winlogbeat' => { - 'spool_size' => $winlogbeat::spool_size, - 'idle_timeout' => $winlogbeat::idle_timeout, - 'registry_file' => $winlogbeat::registry_file, - 'publish_async' => $winlogbeat::publish_async, - 'shutdown_timeout' => $winlogbeat::shutdown_timeout, - 'event_logs' => $winlogbeat::event_logs, - }, - 'output' => $winlogbeat::outputs, - 'logging' => $winlogbeat::logging, - 'runoptions' => $winlogbeat::run_options, - 'processors' => $winlogbeat::processors, + $winlogbeat_config = delete_undef_values( { + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'name' => $winlogbeat::beat_name, + 'tags' => $winlogbeat::tags, + 'queue_size' => $winlogbeat::queue_size, + 'max_procs' => $winlogbeat::max_procs, + 'fields' => $winlogbeat::fields, + 'fields_under_root' => $winlogbeat::fields_under_root, + 'winlogbeat' => { + 'spool_size' => $winlogbeat::spool_size, + 'idle_timeout' => $winlogbeat::idle_timeout, + 'registry_file' => $winlogbeat::registry_file, + 'publish_async' => $winlogbeat::publish_async, + 'shutdown_timeout' => $winlogbeat::shutdown_timeout, + 'event_logs' => $winlogbeat::event_logs, + }, + 'output' => $winlogbeat::outputs, + 'logging' => $winlogbeat::logging, + 'runoptions' => $winlogbeat::run_options, + 'processors' => $winlogbeat::processors, }) $cmd_test_winlogbeat = "\"${winlogbeat_path}\" -N -configtest -c \"%\"" @@ -74,21 +74,19 @@ $skip_validation = false } - $validate_cmd = ($winlogbeat::disable_config_test or $skip_validation) ? { true => undef, default => $cmd_test_winlogbeat, } $winlogbeat_config_yaml = $winlogbeat_config.to_yaml() - file {'winlogbeat.yml': + file { 'winlogbeat.yml': ensure => $winlogbeat::file_ensure, path => $winlogbeat::config_file, content => epp($winlogbeat::conf_template), validate_cmd => $validate_cmd, notify => Service['winlogbeat'], } - } 'absent': { # Nothink todo @@ -97,5 +95,4 @@ fail('ensure must be absent or present') } } - } diff --git a/manifests/init.pp b/manifests/init.pp index 7b6645d..24138aa 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -89,17 +89,16 @@ Optional[Hash] $xpack, String $kernel_fail_message, ) { - - include ::stdlib + include stdlib if ($::kernel != 'Windows') { fail($kernel_fail_message) } - $url_arch = $::architecture ? { + $url_arch = $facts['os']['architecture'] ? { 'x86' => 'x86', 'x64' => 'x86_64', - default => fail("${::architecture} is not supported by winloagbeat."), + default => fail("${facts['os']['architecture']} is not supported by winloagbeat."), } $real_download_url = $download_url ? { @@ -129,17 +128,17 @@ # If we're removing winlogbeat, do things in a different order to make sure # we remove as much as possible - contain ::winlogbeat::install - contain ::winlogbeat::config - contain ::winlogbeat::service + contain winlogbeat::install + contain winlogbeat::config + contain winlogbeat::service if $ensure == 'absent' { - Class['::winlogbeat::service'] - -> Class['::winlogbeat::config'] - -> Class['::winlogbeat::install'] + Class['winlogbeat::service'] + -> Class['winlogbeat::config'] + -> Class['winlogbeat::install'] } else { - Class['::winlogbeat::install'] - -> Class['::winlogbeat::config'] - -> Class['::winlogbeat::service'] + Class['winlogbeat::install'] + -> Class['winlogbeat::config'] + -> Class['winlogbeat::service'] } } diff --git a/manifests/install.pp b/manifests/install.pp index 877e9eb..aa88bce 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -13,7 +13,7 @@ provider => powershell, } - case $::winlogbeat::ensure { + case $winlogbeat::ensure { 'present': { if ! defined(File[$winlogbeat::install_dir]) { file { $winlogbeat::install_dir: @@ -26,29 +26,27 @@ # https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31 # I'm not choosing to impose those dependencies on anyone at this time... if ($winlogbeat::proxy_address) { - archive { $zip_file: - source => $winlogbeat::real_download_url, - cleanup => false, - creates => $version_file, - proxy_server => $winlogbeat::proxy_address, - before => Exec["unzip ${filename}"], - } + archive { $zip_file: + source => $winlogbeat::real_download_url, + cleanup => false, + creates => $version_file, + proxy_server => $winlogbeat::proxy_address, + before => Exec["unzip ${filename}"], + } } else { - # Use file when source is puppet:/// because of archive break zip file - file { $zip_file: - source => $winlogbeat::real_download_url, - before => Exec["unzip ${filename}"], - } + # Use file when source is puppet:/// because of archive break zip file + file { $zip_file: + source => $winlogbeat::real_download_url, + before => Exec["unzip ${filename}"], + } } - exec { "unzip ${filename}": command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${winlogbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars creates => $version_file, require => File[$winlogbeat::install_dir], } - # You can't remove the old dir while the service has files locked... exec { "stop service ${filename}": command => 'Set-Service -Name winlogbeat -Status Stopped', @@ -63,7 +61,6 @@ require => Exec["stop service ${filename}"], } - exec { "mark ${filename}": command => "New-Item '${version_file}' -ItemType file", creates => $version_file, @@ -79,7 +76,6 @@ } } 'absent': { - # Stop and remove service exec { "stop service ${filename}": command => 'Set-Service -Name winlogbeat -Status Stopped', @@ -92,11 +88,10 @@ } # Remove folders - -> file {$install_folder: + -> file { $install_folder: ensure => 'absent', force => true, } - } default: { fail('ensure must be present or absent') diff --git a/manifests/service.pp b/manifests/service.pp index 97428e4..80fb47d 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -5,8 +5,8 @@ # @summary A private class to manage the winlogbeat service class winlogbeat::service { service { 'winlogbeat': - ensure => $::winlogbeat::real_service_ensure, - enable => $::winlogbeat::real_service_enable, - provider => $::winlogbeat::service_provider, + ensure => $winlogbeat::real_service_ensure, + enable => $winlogbeat::real_service_enable, + provider => $winlogbeat::service_provider, } } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 57c2db7..e1d14b9 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -27,7 +27,7 @@ install_module_on(hosts) install_module_dependencies_on(hosts) -UNSUPPORTED_PLATFORMS = ['aix', 'Solaris', 'BSD', 'linux'].freeze +UNSUPPORTED_PLATFORMS = %w[aix Solaris BSD linux].freeze RSpec.configure do |c| module_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) From 501c102f6e7ce3054104208d2c888234bfd34072 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 13:57:41 +0000 Subject: [PATCH 32/41] bump: update pdk version Signed-off-by: disaster37 --- .devcontainer/Dockerfile | 6 + .devcontainer/devcontainer.json | 23 ++ .gitignore | 1 + .gitlab-ci.yml | 48 +-- .pdkignore | 5 + .rubocop.yml | 520 +++++++++++++++++++++++++++++++- .travis.yml | 45 +++ .vscode/extensions.json | 6 + Gemfile | 69 +++-- Rakefile | 125 +++++--- appveyor.yml | 16 +- metadata.json | 6 +- spec/default_facts.yml | 2 +- spec/spec_helper.rb | 87 +++++- 14 files changed, 839 insertions(+), 120 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .travis.yml create mode 100644 .vscode/extensions.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..12ed4ff --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM puppet/pdk:latest + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f1a55dc --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pdk --version", +} diff --git a/.gitignore b/.gitignore index 2767022..988dcbb 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ .project .envrc /inventory.yaml +/spec/fixtures/litmus_inventory.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 81e6d76..6d5e786 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,39 +3,51 @@ stages: - syntax - unit -cache: - paths: - - vendor/bundle +default: + cache: + paths: + - vendor/bundle -before_script: - - bundle -v - - rm Gemfile.lock || true - - gem update --system $RUBYGEMS_VERSION - - gem --version - - bundle -v - - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + before_script: &before_script + - bundle -v + - rm Gemfile.lock || true + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# Set `rubygems_version` in the .sync.yml to set a value" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) -syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.3-Puppet ~> 6: +validate lint check rubocop-Ruby 2.5.7-Puppet ~> 6: stage: syntax - image: ruby:2.5.3 + image: ruby:2.5.7 script: - - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + - bundle exec rake validate lint check rubocop variables: PUPPET_GEM_VERSION: '~> 6' -parallel_spec-Ruby 2.5.3-Puppet ~> 6: +parallel_spec-Ruby 2.5.7-Puppet ~> 6: stage: unit - image: ruby:2.5.3 + image: ruby:2.5.7 script: - bundle exec rake parallel_spec variables: PUPPET_GEM_VERSION: '~> 6' -parallel_spec-Ruby 2.4.5-Puppet ~> 5: +validate lint check rubocop-Ruby 2.7.2-Puppet ~> 7: + stage: syntax + image: ruby:2.7.2 + script: + - bundle exec rake validate lint check rubocop + variables: + PUPPET_GEM_VERSION: '~> 7' + +parallel_spec-Ruby 2.7.2-Puppet ~> 7: stage: unit - image: ruby:2.4.5 + image: ruby:2.7.2 script: - bundle exec rake parallel_spec variables: - PUPPET_GEM_VERSION: '~> 5' + PUPPET_GEM_VERSION: '~> 7' diff --git a/.pdkignore b/.pdkignore index e6215cd..c538bea 100644 --- a/.pdkignore +++ b/.pdkignore @@ -25,13 +25,16 @@ .project .envrc /inventory.yaml +/spec/fixtures/litmus_inventory.yaml /appveyor.yml +/.editorconfig /.fixtures.yml /Gemfile /.gitattributes /.gitignore /.gitlab-ci.yml /.pdkignore +/.puppet-lint.rc /Rakefile /rakelib/ /.rspec @@ -40,3 +43,5 @@ /.yardopts /spec/ /.vscode/ +/.sync.yml +/.devcontainer/ diff --git a/.rubocop.yml b/.rubocop.yml index 198a359..8f782e7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,519 @@ --- -inherit_gem: - voxpupuli-test: rubocop.yml +require: +- rubocop-performance +- rubocop-rspec +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.4' + Include: + - "**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Layout/LineLength: + Description: People have wide screens, use them. + Max: 200 +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +RSpec/DescribeSymbol: + Exclude: + - spec/unit/facter/**/*.rb +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInArrayLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Performance/AncestorsInclude: + Enabled: true +Performance/BigDecimalWithNumericArgument: + Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true +Performance/CaseWhenSplat: + Enabled: true +Performance/ConstantRegexp: + Enabled: true +Performance/MethodObjectAsBlock: + Enabled: true +Performance/RedundantSortBlock: + Enabled: true +Performance/RedundantStringChars: + Enabled: true +Performance/ReverseFirst: + Enabled: true +Performance/SortReverse: + Enabled: true +Performance/Squeeze: + Enabled: true +Performance/StringInclude: + Enabled: true +Performance/Sum: + Enabled: true +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +Bundler/InsecureProtocolSource: + Enabled: false +Gemspec/DuplicatedAssignment: + Enabled: false +Gemspec/OrderedDependencies: + Enabled: false +Gemspec/RequiredRubyVersion: + Enabled: false +Gemspec/RubyVersionGlobalsUsage: + Enabled: false +Layout/ArgumentAlignment: + Enabled: false +Layout/BeginEndAlignment: + Enabled: false +Layout/ClosingHeredocIndentation: + Enabled: false +Layout/EmptyComment: + Enabled: false +Layout/EmptyLineAfterGuardClause: + Enabled: false +Layout/EmptyLinesAroundArguments: + Enabled: false +Layout/EmptyLinesAroundAttributeAccessor: + Enabled: false +Layout/EndOfLine: + Enabled: false +Layout/FirstArgumentIndentation: + Enabled: false +Layout/HashAlignment: + Enabled: false +Layout/HeredocIndentation: + Enabled: false +Layout/LeadingEmptyLines: + Enabled: false +Layout/SpaceAroundMethodCallOperator: + Enabled: false +Layout/SpaceInsideArrayLiteralBrackets: + Enabled: false +Layout/SpaceInsideReferenceBrackets: + Enabled: false +Lint/BigDecimalNew: + Enabled: false +Lint/BooleanSymbol: + Enabled: false +Lint/ConstantDefinitionInBlock: + Enabled: false +Lint/DeprecatedOpenSSLConstant: + Enabled: false +Lint/DisjunctiveAssignmentInConstructor: + Enabled: false +Lint/DuplicateElsifCondition: + Enabled: false +Lint/DuplicateRequire: + Enabled: false +Lint/DuplicateRescueException: + Enabled: false +Lint/EmptyConditionalBody: + Enabled: false +Lint/EmptyFile: + Enabled: false +Lint/ErbNewArguments: + Enabled: false +Lint/FloatComparison: + Enabled: false +Lint/HashCompareByIdentity: + Enabled: false +Lint/IdentityComparison: + Enabled: false +Lint/InterpolationCheck: + Enabled: false +Lint/MissingCopEnableDirective: + Enabled: false +Lint/MixedRegexpCaptureTypes: + Enabled: false +Lint/NestedPercentLiteral: + Enabled: false +Lint/NonDeterministicRequireOrder: + Enabled: false +Lint/OrderedMagicComments: + Enabled: false +Lint/OutOfRangeRegexpRef: + Enabled: false +Lint/RaiseException: + Enabled: false +Lint/RedundantCopEnableDirective: + Enabled: false +Lint/RedundantRequireStatement: + Enabled: false +Lint/RedundantSafeNavigation: + Enabled: false +Lint/RedundantWithIndex: + Enabled: false +Lint/RedundantWithObject: + Enabled: false +Lint/RegexpAsCondition: + Enabled: false +Lint/ReturnInVoidContext: + Enabled: false +Lint/SafeNavigationConsistency: + Enabled: false +Lint/SafeNavigationWithEmpty: + Enabled: false +Lint/SelfAssignment: + Enabled: false +Lint/SendWithMixinArgument: + Enabled: false +Lint/ShadowedArgument: + Enabled: false +Lint/StructNewOverride: + Enabled: false +Lint/ToJSON: + Enabled: false +Lint/TopLevelReturnWithArgument: + Enabled: false +Lint/TrailingCommaInAttributeDeclaration: + Enabled: false +Lint/UnreachableLoop: + Enabled: false +Lint/UriEscapeUnescape: + Enabled: false +Lint/UriRegexp: + Enabled: false +Lint/UselessMethodDefinition: + Enabled: false +Lint/UselessTimes: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/BlockNesting: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false +Metrics/PerceivedComplexity: + Enabled: false +Migration/DepartmentName: + Enabled: false +Naming/AccessorMethodName: + Enabled: false +Naming/BlockParameterName: + Enabled: false +Naming/HeredocDelimiterCase: + Enabled: false +Naming/HeredocDelimiterNaming: + Enabled: false +Naming/MemoizedInstanceVariableName: + Enabled: false +Naming/MethodParameterName: + Enabled: false +Naming/RescuedExceptionsVariableName: + Enabled: false +Naming/VariableNumber: + Enabled: false +Performance/BindCall: + Enabled: false +Performance/DeletePrefix: + Enabled: false +Performance/DeleteSuffix: + Enabled: false +Performance/InefficientHashSearch: + Enabled: false +Performance/UnfreezeString: + Enabled: false +Performance/UriDefaultParser: + Enabled: false +RSpec/Be: + Enabled: false +RSpec/Capybara/CurrentPathExpectation: + Enabled: false +RSpec/Capybara/FeatureMethods: + Enabled: false +RSpec/Capybara/VisibilityMatcher: + Enabled: false +RSpec/ContextMethod: + Enabled: false +RSpec/ContextWording: + Enabled: false +RSpec/DescribeClass: + Enabled: false +RSpec/EmptyHook: + Enabled: false +RSpec/EmptyLineAfterExample: + Enabled: false +RSpec/EmptyLineAfterExampleGroup: + Enabled: false +RSpec/EmptyLineAfterHook: + Enabled: false +RSpec/ExampleLength: + Enabled: false +RSpec/ExampleWithoutDescription: + Enabled: false +RSpec/ExpectChange: + Enabled: false +RSpec/ExpectInHook: + Enabled: false +RSpec/FactoryBot/AttributeDefinedStatically: + Enabled: false +RSpec/FactoryBot/CreateList: + Enabled: false +RSpec/FactoryBot/FactoryClassName: + Enabled: false +RSpec/HooksBeforeExamples: + Enabled: false +RSpec/ImplicitBlockExpectation: + Enabled: false +RSpec/ImplicitSubject: + Enabled: false +RSpec/LeakyConstantDeclaration: + Enabled: false +RSpec/LetBeforeExamples: + Enabled: false +RSpec/MissingExampleGroupArgument: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/MultipleSubjects: + Enabled: false +RSpec/NestedGroups: + Enabled: false +RSpec/PredicateMatcher: + Enabled: false +RSpec/ReceiveCounts: + Enabled: false +RSpec/ReceiveNever: + Enabled: false +RSpec/RepeatedExampleGroupBody: + Enabled: false +RSpec/RepeatedExampleGroupDescription: + Enabled: false +RSpec/RepeatedIncludeExample: + Enabled: false +RSpec/ReturnFromStub: + Enabled: false +RSpec/SharedExamples: + Enabled: false +RSpec/StubbedMock: + Enabled: false +RSpec/UnspecifiedException: + Enabled: false +RSpec/VariableDefinition: + Enabled: false +RSpec/VoidExpect: + Enabled: false +RSpec/Yield: + Enabled: false +Security/Open: + Enabled: false +Style/AccessModifierDeclarations: + Enabled: false +Style/AccessorGrouping: + Enabled: false +Style/AsciiComments: + Enabled: false +Style/BisectedAttrAccessor: + Enabled: false +Style/CaseLikeIf: + Enabled: false +Style/ClassEqualityComparison: + Enabled: false +Style/ColonMethodDefinition: + Enabled: false +Style/CombinableLoops: + Enabled: false +Style/CommentedKeyword: + Enabled: false +Style/Dir: + Enabled: false +Style/DoubleCopDisableDirective: + Enabled: false +Style/EmptyBlockParameter: + Enabled: false +Style/EmptyLambdaParameter: + Enabled: false +Style/Encoding: + Enabled: false +Style/EvalWithLocation: + Enabled: false +Style/ExpandPathArguments: + Enabled: false +Style/ExplicitBlockArgument: + Enabled: false +Style/ExponentialNotation: + Enabled: false +Style/FloatDivision: + Enabled: false +Style/FrozenStringLiteralComment: + Enabled: false +Style/GlobalStdStream: + Enabled: false +Style/HashAsLastArrayItem: + Enabled: false +Style/HashLikeCase: + Enabled: false +Style/HashTransformKeys: + Enabled: false +Style/HashTransformValues: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/KeywordParametersOrder: + Enabled: false +Style/MinMax: + Enabled: false +Style/MixinUsage: + Enabled: false +Style/MultilineWhenThen: + Enabled: false +Style/NegatedUnless: + Enabled: false +Style/NumericPredicate: + Enabled: false +Style/OptionalBooleanParameter: + Enabled: false +Style/OrAssignment: + Enabled: false +Style/RandomWithOffset: + Enabled: false +Style/RedundantAssignment: + Enabled: false +Style/RedundantCondition: + Enabled: false +Style/RedundantConditional: + Enabled: false +Style/RedundantFetchBlock: + Enabled: false +Style/RedundantFileExtensionInRequire: + Enabled: false +Style/RedundantRegexpCharacterClass: + Enabled: false +Style/RedundantRegexpEscape: + Enabled: false +Style/RedundantSelfAssignment: + Enabled: false +Style/RedundantSort: + Enabled: false +Style/RescueStandardError: + Enabled: false +Style/SingleArgumentDig: + Enabled: false +Style/SlicingWithRange: + Enabled: false +Style/SoleNestedConditional: + Enabled: false +Style/StderrPuts: + Enabled: false +Style/StringConcatenation: + Enabled: false +Style/Strip: + Enabled: false +Style/SymbolProc: + Enabled: false +Style/TrailingBodyOnClass: + Enabled: false +Style/TrailingBodyOnMethodDefinition: + Enabled: false +Style/TrailingBodyOnModule: + Enabled: false +Style/TrailingCommaInHashLiteral: + Enabled: false +Style/TrailingMethodEndStatement: + Enabled: false +Style/UnpackFirst: + Enabled: false +Lint/DuplicateBranch: + Enabled: false +Lint/DuplicateRegexpCharacterClassElement: + Enabled: false +Lint/EmptyBlock: + Enabled: false +Lint/EmptyClass: + Enabled: false +Lint/NoReturnInBeginEndBlocks: + Enabled: false +Lint/ToEnumArguments: + Enabled: false +Lint/UnexpectedBlockArity: + Enabled: false +Lint/UnmodifiedReduceAccumulator: + Enabled: false +Performance/CollectionLiteralInLoop: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false +Style/CollectionCompact: + Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false +Style/NegatedIfElseCondition: + Enabled: false +Style/NilLambda: + Enabled: false +Style/RedundantArgument: + Enabled: false +Style/SwapValues: + Enabled: false diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..444e17a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,45 @@ +--- +os: linux +dist: xenial +language: ruby +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.5.7 +stages: + - static + - spec + - acceptance + - + if: tag =~ ^v\d + name: deploy +jobs: + fast_finish: true + include: + - + env: CHECK="validate lint check rubocop" + stage: static + - + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.7 + stage: spec + - + env: DEPLOY_TO_FORGE=yes + stage: deploy +branches: + only: + - main + - /^v\d/ +notifications: + email: false diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2f1e4f7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/Gemfile b/Gemfile index 9cac903..a167b88 100644 --- a/Gemfile +++ b/Gemfile @@ -1,33 +1,62 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' -group :test do - gem 'voxpupuli-test', '~> 2.1', :require => false - gem 'coveralls', :require => false - gem 'simplecov-console', :require => false +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] + else + [place_or_version, { require: false }] + end end +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') + group :development do - gem 'guard-rake', :require => false - gem 'overcommit', '>= 0.39.1', :require => false + gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] end - group :system_tests do - gem 'puppet_metadata', '~> 0.3.0', :require => false - gem 'voxpupuli-acceptance', :require => false + gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] end -group :release do - gem 'github_changelog_generator', :require => false, :git => 'https://github.com/voxpupuli/github-changelog-generator', :branch => 'voxpupuli_essential_fixes' - gem 'puppet-blacksmith', :require => false - gem 'voxpupuli-release', :require => false - gem 'puppet-strings', '>= 2.2', :require => false -end +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} -gem 'puppetlabs_spec_helper', '~> 2.0', :require => false -gem 'rake', :require => false -gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] +gems['puppet'] = location_for(puppet_version) -puppetversion = ENV['PUPPET_VERSION'] || '~> 6.0' -gem 'puppet', puppetversion, :require => false, :groups => [:test] +# If facter or hiera versions have been specified via the environment +# variables +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version + +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params +end + +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] + +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end +end # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index d1bf749..2906c15 100644 --- a/Rakefile +++ b/Rakefile @@ -1,61 +1,88 @@ -# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), -# otherwise attempt to load it directly. -begin - require 'voxpupuli/test/rake' -rescue LoadError - require 'puppetlabs_spec_helper/rake_tasks' -end +# frozen_string_literal: true + +require 'bundler' +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? +require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? +require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? -# load optional tasks for releases -# only available if gem group releases is installed -begin - require 'voxpupuli/release/rake_tasks' -rescue LoadError +def changelog_user + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['author'] + raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator user:#{returnVal}" + returnVal end -desc "Run main 'test' task and report merged results to coveralls" -task test_with_coveralls: [:test] do - if Dir.exist?(File.expand_path('../lib', __FILE__)) - require 'coveralls/rake/task' - Coveralls::RakeTask.new - Rake::Task['coveralls:push'].invoke - else - puts 'Skipping reporting to coveralls. Module has no lib dir' +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + + returnVal = nil + returnVal ||= begin + metadata_source = JSON.load(File.read('metadata.json'))['source'] + metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) + + metadata_source_match && metadata_source_match[1] end + + raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? + + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal end -desc 'Generate REFERENCE.md' -task :reference, [:debug, :backtrace] do |t, args| - patterns = '' - Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] + raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator future_release:#{returnVal}" + returnVal end -begin - require 'github_changelog_generator/task' - require 'puppet_blacksmith' +PuppetLint.configuration.send('disable_relative') + +if Bundler.rubygems.find_name('github_changelog_generator').any? GitHubChangelogGenerator::RakeTask.new :changelog do |config| - version = (Blacksmith::Modulefile.new).version - config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/ - config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} - config.user = 'voxpupuli' - metadata_json = File.join(File.dirname(__FILE__), 'metadata.json') - metadata = JSON.load(File.read(metadata_json)) - config.project = metadata['name'] + raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? + config.user = "#{changelog_user}" + config.project = "#{changelog_project}" + config.future_release = "#{changelog_future_release}" + config.exclude_labels = ['maintenance'] + config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." + config.add_pr_wo_labels = true + config.issues = false + config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["enhancement", "feature"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bug", "documentation", "bugfix"], + }, + } end - - # Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715 - require 'rbconfig' - if RbConfig::CONFIG['host_os'] =~ /linux/ - task :changelog do - puts 'Fixing line endings...' - changelog_file = File.join(__dir__, 'CHANGELOG.md') - changelog_txt = File.read(changelog_file) - new_contents = changelog_txt.gsub(%r{\r\n}, "\n") - File.open(changelog_file, "w") {|file| file.puts new_contents } - end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise < 1.15' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" +EOM end - -rescue LoadError end -# vim: syntax=ruby + diff --git a/appveyor.yml b/appveyor.yml index e10ba3b..a70c01e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,8 +1,10 @@ --- version: 1.1.x.{build} +skip_branch_with_pr: true branches: only: - - master + - main + - release skip_commits: message: /^\(?doc\)?.*/ clone_depth: 10 @@ -15,16 +17,8 @@ init: environment: matrix: - - RUBY_VERSION: 24-x64 - CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24-x64 - CHECK: parallel_spec + RUBY_VERSION: 25-x64 + CHECK: validate lint check rubocop - PUPPET_GEM_VERSION: ~> 6.0 RUBY_VERSION: 25 diff --git a/metadata.json b/metadata.json index d95d3a2..f8643aa 100644 --- a/metadata.json +++ b/metadata.json @@ -42,7 +42,7 @@ "elasticsearch", "elastic" ], - "pdk-version": "1.10.0", - "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git#1.10.0", - "template-ref": "1.10.0-0-gbba9ac3" + "pdk-version": "2.2.0", + "template-url": "pdk-default#2.2.0", + "template-ref": "tags/2.2.0-0-g2381db6" } diff --git a/spec/default_facts.yml b/spec/default_facts.yml index 6e41e04..f777abf 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -3,6 +3,6 @@ # Facts specified here will override the values provided by rspec-puppet-facts. --- ipaddress: "172.16.254.254" +ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" is_pe: false macaddress: "AA:AA:AA:AA:AA:AA" -winlogbeat_version: undef diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d266f6b..9b1fa6f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,73 @@ -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config - -# puppetlabs_spec_helper will set up coverage if the env variable is set. -# We want to do this if lib exists and it hasn't been explicitly set. -ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) - -require 'voxpupuli/test/spec_helper' - -if File.exist?(File.join(__dir__, 'default_module_facts.yml')) - facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end +# frozen_string_literal: true + +RSpec.configure do |c| + c.mock_with :rspec +end + +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' + +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + +include RspecPuppetFacts + +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) + + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end + +# read default_facts and merge them over what is provided by facterdb +default_facts.each do |fact, value| + add_custom_fact fact, value +end + +RSpec.configure do |c| + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns end end + +# Ensures that a module is defined +# @param module_name Name of the module +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end +end + +# 'spec_overrides' from sync.yml will appear below this line From c433237843787be1433f7ee7fd7c17f68accaa60 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 14:05:45 +0000 Subject: [PATCH 33/41] fix: try to fix upgrade Signed-off-by: disaster37 --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index aa88bce..e43cbe7 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + command => "Start-Sleep -Seconds 10; Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } From 3b887529bb8a9b055ff2536a6e263cb8ef9a0770 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 14:12:24 +0000 Subject: [PATCH 34/41] fix: add sleep for troobleshotig purpose Signed-off-by: disaster37 --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index e43cbe7..ab55b81 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Start-Sleep -Seconds 10; Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error;Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error;Start-Sleep -Seconds 60; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } From c7b05bd64c679a05a6c0da836befa3215d76f3a7 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 14:22:01 +0000 Subject: [PATCH 35/41] fix: remove sleep during install Signed-off-by: disaster37 --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index ab55b81..d02a808 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error;Start-Sleep -Seconds 60; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } From 556916bc84912262c7c9298dba930d18edb212a4 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 14:31:19 +0000 Subject: [PATCH 36/41] fix: redo sleep Signed-off-by: disaster37 --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index d02a808..ab55b81 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error;Start-Sleep -Seconds 60; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } From b90ea749f443d5be088388e6002809d4af152bb0 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 14:41:05 +0000 Subject: [PATCH 37/41] fix: fix typo on powershell cmd Signed-off-by: disaster37 --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index ab55b81..4131224 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Error;Start-Sleep -Seconds 60; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Stop; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } From 98bdf2fdb66bc1dcec1f3bd25273fd9c71ead488 Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 14:44:49 +0000 Subject: [PATCH 38/41] fix: add sleep between stop service and remove folders Signed-off-by: disaster37 --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index 4131224..3076b46 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Stop; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + command => "Start-Sleep -Seconds 10;Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Stop; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } From 517945e4e715ccca3f2fd7c10e198b88c97a11cf Mon Sep 17 00:00:00 2001 From: disaster37 Date: Fri, 28 Jan 2022 14:47:33 +0000 Subject: [PATCH 39/41] bump: set default verison to 7.16.3 Signed-off-by: disaster37 --- data/common.yaml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index e591a0e..dd96ad9 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,11 +1,11 @@ --- # User settings -winlogbeat::service_ensure: 'running' +winlogbeat::service_ensure: "running" winlogbeat::service_enable: true winlogbeat::spool_size: 2048 -winlogbeat::idle_timeout: '5s' +winlogbeat::idle_timeout: "5s" winlogbeat::publish_async: false -winlogbeat::shutdown_timeout: '0' +winlogbeat::shutdown_timeout: "0" winlogbeat::beat_name: "%{facts.fqdn}" winlogbeat::tags: [] winlogbeat::queue_size: 1000 @@ -15,7 +15,7 @@ winlogbeat::outputs: {} winlogbeat::logging: {} winlogbeat::run_options: {} winlogbeat::disable_config_test: false -winlogbeat::package_ensure: '7.5.1' +winlogbeat::package_ensure: "7.16.3" winlogbeat::event_logs: [] winlogbeat::setup: {} winlogbeat::queue: {} @@ -30,22 +30,22 @@ winlogbeat::max_procs: null # Internal module winlogbeat::service_provider: null -winlogbeat::config_file_mode: '0644' -winlogbeat::config_dir_mode: '0755' +winlogbeat::config_file_mode: "0644" +winlogbeat::config_dir_mode: "0755" winlogbeat::kernel_fail_message: "%{facts.kernel} is not supported by winlogbeat." -winlogbeat::conf_template: 'winlogbeat/pure_hash.yml.epp' -winlogbeat::config_file_owner: 'Administrator' +winlogbeat::conf_template: "winlogbeat/pure_hash.yml.epp" +winlogbeat::config_file_owner: "Administrator" winlogbeat::config_file_group: null -winlogbeat::config_dir_owner: 'Administrator' +winlogbeat::config_dir_owner: "Administrator" winlogbeat::config_dir_group: null winlogbeat::config_file: "C:/Program Files/%{lookup('winlogbeat::folder_name')}/winlogbeat.yml" winlogbeat::registry_file: "C:/ProgramData/%{lookup('winlogbeat::folder_name')}/registry" -winlogbeat::install_dir: 'C:/Program Files' -winlogbeat::tmp_dir: 'C:/Windows/Temp' -winlogbeat::folder_name: 'Winlogbeat' +winlogbeat::install_dir: "C:/Program Files" +winlogbeat::tmp_dir: "C:/Windows/Temp" +winlogbeat::folder_name: "Winlogbeat" lookup_options: winlogbeat::event_logs: merge: - strategy: 'deep' - merge_hash_arrays: true \ No newline at end of file + strategy: "deep" + merge_hash_arrays: true From 2c9da336a8db4e326961aaf398aa4f93b870d95d Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Thu, 10 Mar 2022 10:20:40 +0000 Subject: [PATCH 40/41] fix: processor is array of hash and not hash --- data/common.yaml | 2 +- manifests/init.pp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index dd96ad9..675746d 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -19,7 +19,7 @@ winlogbeat::package_ensure: "7.16.3" winlogbeat::event_logs: [] winlogbeat::setup: {} winlogbeat::queue: {} -winlogbeat::processors: {} +winlogbeat::processors: [] winlogbeat::registry_flush: null winlogbeat::manage_download_file: true winlogbeat::download_url: null diff --git a/manifests/init.pp b/manifests/init.pp index 24138aa..e984b05 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -41,7 +41,7 @@ # @param max_procs [Integer] The maximum number of CPUs that can be simultaneously used # @param fields [Hash] Optional fields that should be added to each event output # @param fields_under_root [Boolean] If set to true, custom fields are stored in the top level instead of under fields -# @param processors [Array] Processors that will be added. Commonly used to create processors using hiera. +# @param processors [Array[Hash]] Processors that will be added. Commonly used to create processors using hiera. # @param disable_config_test [Boolean] Disable the configuration testing before to restart Winlogbeat servie (Default: false) # @param setup [Hash] setup that will be created. Commonly used to create setup using hiera # @param proxy_address [String] Proxy server to use for downloading files @@ -83,7 +83,7 @@ Boolean $disable_config_test, Hash $setup, Hash $queue, - Hash $processors, + Array[Hash] $processors, Array[Hash] $event_logs, Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $proxy_address, # lint:ignore:140chars Optional[Hash] $xpack, From 398e62ef0b9d18b37f3f2550c76c130a5406adca Mon Sep 17 00:00:00 2001 From: langoureaux-s Date: Mon, 14 Mar 2022 09:29:08 +0000 Subject: [PATCH 41/41] fix: ignore error when delete winlogbeat folder, because it can be the first install --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index 3076b46..86dff39 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,7 +56,7 @@ } exec { "rename ${filename}": - command => "Start-Sleep -Seconds 10;Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Stop; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars + command => "Start-Sleep -Seconds 10;Remove-Item '${install_folder}' -Recurse -Force -ErrorAction Ignore; Rename-Item '${winlogbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], }