From a7e8eeb4aab1cb363c0293ed87655f3314a47d30 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Fri, 16 Nov 2018 12:01:22 +0100 Subject: [PATCH 01/13] Implementing PDK --- .gitignore | 26 ++++++++- .gitlab-ci.yml | 41 ++++++++++++++ .pdkignore | 24 ++++++++ .rspec | 5 +- .rubocop.yml | 122 +++++++++++++++++++++++++++++++++++++++++ .travis.yml | 70 +++++++++++++++-------- .yardopts | 1 + Gemfile | 93 +++++++++++++++++++++++-------- Rakefile | 82 ++++++++++++++++++++++++--- appveyor.yml | 60 ++++++++++++++++++++ metadata.json | 103 +++++++++++++++++++--------------- spec/default_facts.yml | 8 +++ spec/spec_helper.rb | 45 ++++++++++++++- 13 files changed, 577 insertions(+), 103 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 .pdkignore create mode 100644 .rubocop.yml create mode 100644 .yardopts create mode 100644 appveyor.yml create mode 100644 spec/default_facts.yml diff --git a/.gitignore b/.gitignore index 6ee20c2..888e0bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,24 @@ -pkg/ -*.swp +.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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..6349814 --- /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 + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +parallel_spec-Ruby 2.1.9-Puppet ~> 4.0: + stage: unit + image: ruby:2.1.9 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 4.0' + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.4.4-Puppet ~> 5.5: + stage: syntax + image: ruby:2.4.4 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 5.5' + +parallel_spec-Ruby 2.4.4-Puppet ~> 5.5: + stage: unit + image: ruby:2.4.4 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5.5' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..888e0bf --- /dev/null +++ b/.pdkignore @@ -0,0 +1,24 @@ +.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 diff --git a/.rspec b/.rspec index 0357065..624a7f7 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ ---color ---format documentation -progress +--color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..617d14b --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,122 @@ +--- +require: rubocop-rspec +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.1' + Include: + - "./**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Metrics/LineLength: + 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: + 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/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 +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 +RSpec/DescribeClass: + Enabled: false +RSpec/ExampleLength: + Enabled: false +RSpec/MessageExpectation: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false +RSpec/NestedGroups: + Enabled: false +Style/AsciiComments: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/SymbolProc: + Enabled: false diff --git a/.travis.yml b/.travis.yml index 4aa34de..8f5472c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,47 @@ -sudo: false -cache: bundler -language: ruby -bundler_args: "--without development acceptance" -script: bundle exec rake validate lint -matrix: - fast_finish: true - include: - - rvm: 2.2.5 - env: PUPPET_GEM_VERSION="~> 5.0" STRICT_VARIABLES="yes" DEPLOY_TO_FORGE="yes" - - rvm: 2.2.5 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" - - rvm: 2.1.6 - env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" -deploy: - provider: puppetforge - user: gnubilafrance - password: - secure: Jr2gk1aVstZ6RusmWChZFYfthV3wrl8FTPVuR09lrDVh3eyNJicOCS+FwCu2kXzFNFSzXGQpDWoLDNjqO7Tq/m75962wJkQdtDsivUnYKvmNWMvjI5cgDydqEcgDKxV3XtphMzpAILkr5IdfNGEV9AMXcsc/kp8UUInCaOgBDL0= - on: - tags: true - all_branches: true - condition: "$DEPLOY_TO_FORGE = yes" +--- +sudo: false +dist: trusty +language: ruby +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - gem update --system + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.5.0 +env: + global: + - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" +matrix: + fast_finish: true + include: + - + env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" + - + env: CHECK=parallel_spec + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.4 + - + env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec + rvm: 2.1.9 +branches: + only: + - master + - /^v\d/ +notifications: + email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "" + on: + tags: true + all_branches: true + condition: "$DEPLOY_TO_FORGE = yes" diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..9c0d33f --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +--markup markdown diff --git a/Gemfile b/Gemfile index 40339a9..ef41ab2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,23 +1,70 @@ -source ENV['GEM_SOURCE'] || "https://rubygems.org" - -group :development, :unit_tests do - gem 'rake', :require => false - gem 'rspec-puppet', :require => false - gem 'puppetlabs_spec_helper', :require => false - gem 'puppet-lint', :require => false - gem 'metadata-json-lint', :require => false -end - -if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false -else - gem 'puppet', :require => false -end - -if rspecpuppetversion = ENV['RSPEC_GEM_VERSION'] - gem 'rspec', rspecpuppetversion, :require => false -else - gem 'rspec', :require => false -end - -# vim:ft=ruby +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +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 "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::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4') + 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 + +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +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 + +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 aa2d928..1ea31b2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,75 @@ -require 'rubygems' -require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' - -PuppetLint.configuration.fail_on_warnings -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] +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? + +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 + +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['name'] + raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal +end + +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = 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 + +PuppetLint.configuration.send('disable_relative') + +if Bundler.rubygems.find_name('github_changelog_generator').any? + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + 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; GO LABEL THEM" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["feature", "enhancement"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise <= Gem::Version.new('2.2.2')" +EOM + end +end + diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..81be36b --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,60 @@ +--- +version: 1.1.x.{build} +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: ~> 4.0 + RUBY_VERSION: 21 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 4.0 + RUBY_VERSION: 21-x64 + CHECK: parallel_spec + - + 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/metadata.json b/metadata.json index 301d7c7..f6c91fa 100644 --- a/metadata.json +++ b/metadata.json @@ -1,44 +1,59 @@ -{ - "name": "gnubilafrance-check_mk", - "version": "0.7.2", - "author": "Baptiste Grenier ", - "license": "Apache-2.0", - "summary": "Check_MK installation and configuration", - - "source": "https://github.com/gnubila-france/puppet-check_mk", - "project_page": "https://github.com/gnubila-france/puppet-check_mk", - "issues_url": "https://github.com/gnubila-france/puppet-check_mk/issues", - - "tags": [ "check_mk", "monitoring", "nagios" ], - - "operatingsystem_support": [ - { - "operatingsystem": "RedHat", - "operatingsystemrelease": [ - "5", - "6", - "7" - ] - }, - { - "operatingsystem": "CentOS", - "operatingsystemrelease": [ - "5", - "6", - "7" - ] - }, - { - "operatingsystem": "Debian", - "operatingsystemrelease": [ - "6", - "7" - ] - } - ], - - "dependencies": [ - { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 <5.0.0" }, - { "name": "puppetlabs/stdlib", "version_requirement": ">= 2.3.0 <5.0.0" } - ] -} +{ + "name": "gnubilafrance-check_mk", + "version": "0.7.2", + "author": "Baptiste Grenier ", + "summary": "Check_MK installation and configuration", + "license": "Apache-2.0", + "source": "https://github.com/gnubila-france/puppet-check_mk", + "project_page": "https://github.com/gnubila-france/puppet-check_mk", + "issues_url": "https://github.com/gnubila-france/puppet-check_mk/issues", + "dependencies": [ + { + "name": "puppetlabs/concat", + "version_requirement": ">= 1.0.0 <5.0.0" + }, + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 2.3.0 <5.0.0" + } + ], + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.7.0 < 7.0.0" + } + ], + "tags": [ + "check_mk", + "monitoring", + "nagios" + ], + "pdk-version": "1.7.1", + "template-url": "file://C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/pdk-templates.git", + "template-ref": "1.7.1-0-g810b982" +} diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..9553ec1 --- /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. +--- +concat_basedir: "" +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..b6e69b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,44 @@ -require 'puppetlabs_spec_helper/module_spec_helper' +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' + +begin + require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) +rescue LoadError => loaderror + warn "Could not require spec_helper_local: #{loaderror.message}" +end + +include RspecPuppetFacts + +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')) +default_module_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')) + +if File.exist?(default_facts_path) && File.readable?(default_facts_path) + default_facts.merge!(YAML.safe_load(File.read(default_facts_path))) +end + +if File.exist?(default_module_facts_path) && File.readable?(default_module_facts_path) + default_facts.merge!(YAML.safe_load(File.read(default_module_facts_path))) +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 + 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) + last_module.const_get(next_module) + end +end + +# 'spec_overrides' from sync.yml will appear below this line From fa7073645c6d64960bd6a04e2f7b3d3d31bda430 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Fri, 16 Nov 2018 14:10:48 +0100 Subject: [PATCH 02/13] Fixing style errors This commit was used to remove all style errors. Removed non standard files Removed all unit test because they contained too much style errors, will be added in later commits. --- .fixtures.yml | 1 + .gitignore | 1 + TODO | 2 - example.yaml | 71 ---------- manifests/agent.pp | 3 + manifests/agent/install.pp | 3 + manifests/agent/service.pp | 2 + manifests/config.pp | 4 +- manifests/host.pp | 3 + manifests/hostgroup.pp | 3 + manifests/init.pp | 3 + manifests/install.pp | 3 + manifests/install_tarball.pp | 5 +- manifests/params.pp | 2 + manifests/service.pp | 3 + metadata.json | 15 +-- spec/classes/check_mk_agent_config_spec.rb | 70 ---------- spec/classes/check_mk_agent_install_spec.rb | 119 ----------------- spec/classes/check_mk_agent_service_spec.rb | 29 ---- spec/classes/check_mk_agent_spec.rb | 43 ------ spec/classes/check_mk_config_spec.rb | 124 ------------------ spec/classes/check_mk_install_spec.rb | 20 --- spec/classes/check_mk_install_tarball_spec.rb | 102 -------------- spec/classes/check_mk_service_spec.rb | 16 --- spec/classes/check_mk_spec.rb | 41 ++++-- spec/classes/coverage_spec.rb | 1 - spec/defines/check_mk_agent_mrpe_spec.rb | 35 ----- spec/defines/check_mk_host_spec.rb | 33 ----- spec/defines/check_mk_hostgroup_spec.rb | 83 ------------ 29 files changed, 68 insertions(+), 772 deletions(-) delete mode 100644 TODO delete mode 100644 example.yaml delete mode 100644 spec/classes/check_mk_agent_config_spec.rb delete mode 100644 spec/classes/check_mk_agent_install_spec.rb delete mode 100644 spec/classes/check_mk_agent_service_spec.rb delete mode 100644 spec/classes/check_mk_agent_spec.rb delete mode 100644 spec/classes/check_mk_config_spec.rb delete mode 100644 spec/classes/check_mk_install_spec.rb delete mode 100644 spec/classes/check_mk_install_tarball_spec.rb delete mode 100644 spec/classes/check_mk_service_spec.rb delete mode 100644 spec/classes/coverage_spec.rb delete mode 100644 spec/defines/check_mk_agent_mrpe_spec.rb delete mode 100644 spec/defines/check_mk_host_spec.rb delete mode 100644 spec/defines/check_mk_hostgroup_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml index 76f4e25..97f036d 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,5 +2,6 @@ fixtures: repositories: stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" concat: "https://github.com/puppetlabs/puppetlabs-concat.git" + cron: "https://github.com/puppetlabs/puppetlabs-cron_core.git" symlinks: check_mk: "#{source_dir}" diff --git a/.gitignore b/.gitignore index 888e0bf..128e306 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ /convert_report.txt /update_report.txt .DS_Store +*.to_clean \ No newline at end of file diff --git a/TODO b/TODO deleted file mode 100644 index 1e0a106..0000000 --- a/TODO +++ /dev/null @@ -1,2 +0,0 @@ -Use nagios_hostgroup type rather than clumsily creating our own. -Add support for ignored_services to eliminate false alerts. diff --git a/example.yaml b/example.yaml deleted file mode 100644 index b7280d0..0000000 --- a/example.yaml +++ /dev/null @@ -1,71 +0,0 @@ -# Monitoring Server -check_mk::filestore: 'puppet:///files/check_mk' -check_mk::package: 'omd-0.56-rh60-29.x86_64.rpm' - -#check_parameters = [ -# ( (95, 99), ALL_HOSTS, [ "fs_/boot" ]), -# ( (3192, 3584), ALL_HOSTS, [ "JVM PODDSv3 Memory" ]), -# ( (150, 200), ALL_HOSTS, [ "JVM PODDSv3 Threads" ]), -# ( (4000, 6000), [ 'coherence' ], ALL_HOSTS, [ "Number of threads" ]), -#] -# Defaults: -# hosts: ALL_HOSTS -# tags: undef -check_mk::check_parameters: - 'fs_/boot': - warning: '95' - critical: '99' - 'JVM MyApp Memory': - warning: '3192' - critical: '3584' - 'JVM MyApp Threads': - warning: '150' - critical: '200' - 'Number of threads': - tags: [ 'coherence' ] - warning: '4000' - critical: '6000' - 'fs_/': - hosts: [ 'myhost1.domain.com', 'myhost2.domain.com' ] - warning: '60' - critical: '70' - -check_mk::host_groups: - 'Puppet_Masters': - host_tags: - - 'puppet-master' - - 'My_App': - description: 'My Application' - host_tags: - - 'my-app' - - 'My_DB': - description: 'My Database' - host_tags: - - 'my-db' - -#ignored_services = [ -# ( [ "windows" ], ALL_HOSTS, [ "LOG Security" ] ), -# ( ALL_HOSTS, [ "NFS mount /home/" ] ) -#] - -check_mk::ignored_services: - 'LOG security': - tags: - 'windows' - 'NFS mount /home/': - hosts: - - 'lnxuser1.domain.com' - - 'lnxuser2.domain.com' - -# Monitoring Agent -check_mk::agent::filestore: 'puppet:///files/check_mk' -check_mk::agent::version: '1.2.0p3-1' - -# Set host tags based on built-in and custom facts -check_mk::agent::host_tags: - - '%{envtype}' - - '%{kernel}' - - '%{role}' - - '%{location}' diff --git a/manifests/agent.pp b/manifests/agent.pp index 2a0ae78..715abe9 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -1,3 +1,6 @@ +# == Class: check_mk::agent +# +# Configures and install the check_mk agent. class check_mk::agent ( $filestore = undef, $host_tags = undef, diff --git a/manifests/agent/install.pp b/manifests/agent/install.pp index a377e56..cc632d5 100644 --- a/manifests/agent/install.pp +++ b/manifests/agent/install.pp @@ -1,3 +1,6 @@ +# == Class: check_mk::agent::install +# +# Install check_mk agent. class check_mk::agent::install ( $version = $check_mk::agent::version, $filestore = undef, diff --git a/manifests/agent/service.pp b/manifests/agent/service.pp index 0d3ff04..a0fe537 100644 --- a/manifests/agent/service.pp +++ b/manifests/agent/service.pp @@ -1,3 +1,5 @@ +# == Class: check_mk::agent::service +# class check_mk::agent::service { if ! defined(Service['xinetd']) { if $::operatingsystem == 'Debian' and diff --git a/manifests/config.pp b/manifests/config.pp index 328f3d9..2176a3a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,4 +1,6 @@ - +# == Class: check_mk::config +# +# Configures checkmk class check_mk::config ( $site, $host_groups = undef, diff --git a/manifests/host.pp b/manifests/host.pp index a584e71..cc3df00 100644 --- a/manifests/host.pp +++ b/manifests/host.pp @@ -1,3 +1,6 @@ +# == Class: check_mk::host +# +# Resource to create a check_mk host define check_mk::host ( $target = undef, $host_tags = [], diff --git a/manifests/hostgroup.pp b/manifests/hostgroup.pp index baec45f..6c44d8f 100644 --- a/manifests/hostgroup.pp +++ b/manifests/hostgroup.pp @@ -1,3 +1,6 @@ +# == Class: check_mk::hostgroup +# +# Resource to create a hostgroup define check_mk::hostgroup ( $dir, $hostgroups, diff --git a/manifests/init.pp b/manifests/init.pp index 3f1b6c7..5d8d8d0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,3 +1,6 @@ +# == Class: check_mk +# +# Main check_mk class class check_mk ( $checkmk_service = $check_mk::params::checkmk_service, $filestore = $check_mk::params::filestore, diff --git a/manifests/install.pp b/manifests/install.pp index 009918d..ba37ba3 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,3 +1,6 @@ +# == Class: check_mk::install +# +# Installs check_mk through a deb or rpm file class check_mk::install ( $site, $workspace, diff --git a/manifests/install_tarball.pp b/manifests/install_tarball.pp index f09e770..5c52616 100644 --- a/manifests/install_tarball.pp +++ b/manifests/install_tarball.pp @@ -1,3 +1,6 @@ +# == Class: check_mk::install_tarball +# +# Install check_mk through a tarball class check_mk::install_tarball ( $filestore, $version, @@ -45,7 +48,7 @@ require => File["${workspace}/check_mk-${version}.tar.gz"], } exec { 'change-setup-config-location': - command => "/usr/bin/perl -pi -e 's#^SETUPCONF=.*?$#SETUPCONF=${workspace}/check_mk_setup.conf#' ${workspace}/check_mk-${version}/setup.sh", + command => "/usr/bin/perl -pi -e 's#^SETUPCONF=.*?$#SETUPCONF=${workspace}/check_mk_setup.conf#' ${workspace}/check_mk-${version}/setup.sh", # lint:ignore:140chars unless => "/bin/egrep '^SETUPCONF=${workspace}/check_mk_setup.conf$' ${workspace}/check_mk-${version}/setup.sh", require => Exec['unpack-check_mk-tarball'], } diff --git a/manifests/params.pp b/manifests/params.pp index 80abc9b..2c5e039 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,3 +1,5 @@ +# == Class: check_mk::params +# class check_mk::params { # common variables diff --git a/manifests/service.pp b/manifests/service.pp index 5494eee..7ad470f 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,3 +1,6 @@ +# == Class: check_mk::service +# +# Configures the check mk service class check_mk::service ( $checkmk_service, $httpd_service, diff --git a/metadata.json b/metadata.json index f6c91fa..9731a32 100644 --- a/metadata.json +++ b/metadata.json @@ -10,18 +10,17 @@ "dependencies": [ { "name": "puppetlabs/concat", - "version_requirement": ">= 1.0.0 <5.0.0" + "version_requirement": ">= 4.0.0 <6.0.0" }, { "name": "puppetlabs/stdlib", - "version_requirement": ">= 2.3.0 <5.0.0" + "version_requirement": ">= 4.0.0 <6.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ - "5", "6", "7" ] @@ -29,7 +28,6 @@ { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "5", "6", "7" ] @@ -37,21 +35,22 @@ { "operatingsystem": "Debian", "operatingsystemrelease": [ - "6", - "7" + "8", + "9" ] } ], "requirements": [ { "name": "puppet", - "version_requirement": ">= 4.7.0 < 7.0.0" + "version_requirement": ">= 5.0.0 < 7.0.0" } ], "tags": [ "check_mk", "monitoring", - "nagios" + "nagios", + "omd" ], "pdk-version": "1.7.1", "template-url": "file://C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/pdk-templates.git", diff --git a/spec/classes/check_mk_agent_config_spec.rb b/spec/classes/check_mk_agent_config_spec.rb deleted file mode 100644 index 68fd2aa..0000000 --- a/spec/classes/check_mk_agent_config_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require 'spec_helper' -describe 'check_mk::agent::config', :type => :class do - - context 'Redhat Linux' do - let :facts do - { - :osfamily => 'RedHat', - } - end - context 'with defaults for all parameters' do - it { should contain_class('check_mk::agent::config') } - it { should contain_file('/etc/xinetd.d/check-mk-agent'). - with_content(/^\tport\s+ = 6556$/). - with_content(/^\tuser\s+ = root$/). - with_content(/^\tserver\s+ = \/usr\/bin\/check_mk_agent$/). - without_content(/only_from/). - with_notify('Class[Check_mk::Agent::Service]') - } - it { should contain_file('/etc/xinetd.d/check_mk').with_ensure('absent') } - end - context 'with use_cache' do - let :params do - { - :use_cache => true, - } - end - it { should contain_file('/etc/xinetd.d/check-mk-agent'). - with_content(/^\tserver\s+ = \/usr\/bin\/check_mk_caching_agent$/) - } - end - context 'with ip_whitelist' do - let :params do - { - :ip_whitelist => [ - '1.2.3.4', - '5.6.7.8', - ], - } - end - it { should contain_file('/etc/xinetd.d/check-mk-agent'). - with_content(/^\tonly_from\s+= 127.0.0.1 1.2.3.4 5.6.7.8$/) - } - end - context 'with custom user' do - let :params do - { - :user => 'custom', - } - end - it { should contain_file('/etc/xinetd.d/check-mk-agent'). - with_content(/^\tuser\s+ = custom$/) - } - end - end - - context 'Other OS' do - context 'with defaults for all parameters' do - it { should contain_file('/etc/xinetd.d/check_mk'). - with_content(/^\tport\s+ = 6556$/). - with_content(/^\tuser\s+ = root$/). - with_content(/^\tserver\s+ = \/usr\/bin\/check_mk_agent$/). - without_content(/only_from/). - with_notify('Class[Check_mk::Agent::Service]') - } - it { should_not contain_file('/etc/xinetd.d/check_mk').with_ensure('absent') } - end - end -end - - diff --git a/spec/classes/check_mk_agent_install_spec.rb b/spec/classes/check_mk_agent_install_spec.rb deleted file mode 100644 index dce3bd2..0000000 --- a/spec/classes/check_mk_agent_install_spec.rb +++ /dev/null @@ -1,119 +0,0 @@ -require 'spec_helper' -describe 'check_mk::agent::install', :type => :class do - - context 'RedHat Linux' do - let :facts do - { - :osfamily => 'Redhat', - } - end - - context 'with default parameters' do - it { should contain_class('check_mk::agent::install').with( - { - :version => nil, - :filestore => nil, - :workspace => '/root/check_mk', - :package => nil, - } - ) - } - it { should contain_package('xinetd') } - it { should contain_package('check_mk-agent').with_name('check-mk-agent') } - end - - context 'with custom package' do - let :params do - { - :package => 'custom-package', - } - end - it { should contain_class('check_mk::agent::install') } - it { should contain_package('xinetd') } - it { should contain_package('check_mk-agent').with_name('custom-package') } - end - - context 'with filestore' do - context 'without version' do - let :params do - { - :filestore => '/filestore', - } - end - it 'should fail' do - expect { catalogue }.to raise_error(Puppet::Error, /version must be specified/) - end - end - context 'with custom parameters' do - let :params do - { - :version => '1.2.3', - :filestore => '/filestore', - :workspace => '/workspace', - } - end - it { should contain_class('check_mk::agent::install') } - it { should contain_package('xinetd') } - it { should contain_file('/workspace').with_ensure('directory') } - it { should contain_File('/workspace/check_mk-agent-1.2.3.noarch.rpm').with( - { - :ensure => 'present', - :source => '/filestore/check_mk-agent-1.2.3.noarch.rpm', - :require => 'Package[xinetd]', - } - ).that_comes_before('Package[check_mk-agent]') - } - it { should contain_package('check_mk-agent').with( - { - :provider => 'rpm', - :source => '/workspace/check_mk-agent-1.2.3.noarch.rpm', - } - ) - } - end - end - end - - context 'Debian Linux' do - let :facts do - { - :osfamily => 'Debian', - } - end - - context 'with default parameters' do - it { should contain_class('check_mk::agent::install') } - it { should contain_package('xinetd') } - it { should contain_package('check_mk-agent').with_name('check-mk-agent') } - end - - context 'with custom package' do - let :params do - { - :package => 'custom-package', - } - end - it { should contain_class('check_mk::agent::install') } - it { should contain_package('xinetd') } - it { should contain_package('check_mk-agent').with_name('custom-package') } - end - end - - context 'Unknown OS' do - context 'with default parameters' do - it { should contain_class('check_mk::agent::install') } - it { should contain_package('xinetd') } - it { should contain_package('check_mk-agent').with_name('check_mk-agent') } - end - context 'with custom package' do - let :params do - { - :package => 'custom-package', - } - end - it { should contain_class('check_mk::agent::install') } - it { should contain_package('xinetd') } - it { should contain_package('check_mk-agent').with_name('custom-package') } - end - end -end diff --git a/spec/classes/check_mk_agent_service_spec.rb b/spec/classes/check_mk_agent_service_spec.rb deleted file mode 100644 index a85b3e9..0000000 --- a/spec/classes/check_mk_agent_service_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'spec_helper' -describe 'check_mk::agent::service', :type => :class do - - context 'all' do - it { should contain_class('check_mk::agent::service') } - it { should contain_service('xinetd').with({ - :ensure => 'running', - :enable => true, - }) - } - end - - context 'Debian 7' do - let :facts do - { - :operatingsystem => 'Debian', - :operatingsystemmajrelease => '7', - } - end - it { should contain_class('check_mk::agent::service') } - it { should contain_service('xinetd').with({ - :ensure => 'running', - :enable => true, - :hasstatus => false, - }) - } - end - -end diff --git a/spec/classes/check_mk_agent_spec.rb b/spec/classes/check_mk_agent_spec.rb deleted file mode 100644 index 6d08a4d..0000000 --- a/spec/classes/check_mk_agent_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'spec_helper' -describe 'check_mk::agent', :type => :class do - context 'Redhat Linux' do - let :facts do - { - :kernel => 'Linux', - :operatingsystem => 'Redhat', - :osfamily => 'Redhat', - } - end - context 'with defaults for all parameters' do - it { should contain_class('check_mk::agent') } - it { should contain_class('check_mk::agent::install').that_comes_before('Class[check_mk::agent::config]') } - it { should contain_class('check_mk::agent::config') } - it { should contain_class('check_mk::agent::service') } - end - context 'with mrpe_checks' do - context 'not a hash' do - let :params do - { - :mrpe_checks => 'not_a_hash', - } - end - it 'should fail' do - expect { catalogue }.to raise_error(Puppet::Error, /\"not_a_hash\" is not a Hash./) - end - end - context 'defined correctly' do - let :params do - { - :mrpe_checks => { - 'check1' => {'command' => 'command1'}, - 'check2' => {'command' => 'command2'}, - } - } - end - it { should contain_class('check_mk::agent') } - it { should contain_check_mk__agent__mrpe('check1').with_command('command1') } - it { should contain_check_mk__agent__mrpe('check2').with_command('command2') } - end - end - end -end diff --git a/spec/classes/check_mk_config_spec.rb b/spec/classes/check_mk_config_spec.rb deleted file mode 100644 index 9de298b..0000000 --- a/spec/classes/check_mk_config_spec.rb +++ /dev/null @@ -1,124 +0,0 @@ -require 'spec_helper' -describe 'check_mk::config', :type => :class do - context 'with site set' do - let :params do - { - :site => 'TEST_SITE' - } - end - it { should contain_class('check_mk::config') } - it { should contain_file('/omd/sites/TEST_SITE/etc/nagios/local').with_ensure_directory. - that_comes_before('File_line[nagios-add-check_mk-cfg_dir]') - } - it { should contain_file_line('nagios-add-check_mk-cfg_dir').with({ - :ensure => 'present', - :line => 'cfg_dir=/omd/sites/TEST_SITE/etc/nagios/local', - :path => '/omd/sites/TEST_SITE/etc/nagios/nagios.cfg', - :notify => 'Class[Check_mk::Service]', - }) - } - it { should contain_file_line('add-guest-users').with({ - :ensure => 'present', - :line => 'guest_users = [ "guest" ]', - :path => '/omd/sites/TEST_SITE/etc/check_mk/multisite.mk', - }) - } - it { should contain_file('/omd/sites/TEST_SITE/etc/check_mk/all_hosts_static').with({ - :ensure => 'file', - :content => '', - }) - } - it { should contain_concat('/omd/sites/TEST_SITE/etc/check_mk/main.mk').with({ - :owner => 'root', - :group => 'root', - :mode => '0644', - :notify => 'Exec[check_mk-refresh]', - }) - } - it { should contain_concat__fragment('all_hosts-header').with({ - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :content => /all_hosts = \[\n/, - :order => 10, - }) - } - it { should contain_concat__fragment('all_hosts-footer').with({ - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :content => /\]\n/, - :order => 19, - }) - } - it { should contain_concat__fragment('all-hosts-static').with({ - :ensure => '/omd/sites/TEST_SITE/etc/check_mk/all_hosts_static', - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :order => 18, - }) - } - it { should_not contain_file('/omd/sites/TEST_SITE/etc/nagios/local/hostgroups') } - it { should_not contain_concat__fragment('host_groups-header') } - it { should_not contain_concat__fragment('host_groups-footer') } - it { should_not contain_check_mk__hostgroup } - it { should contain_concat__fragment('check_mk-local-config').with({ - :ensure => '/omd/sites/TEST_SITE/etc/check_mk/main.mk.local', - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :order => 99, - }) - } - it { should contain_exec('check_mk-refresh').with({ - :command => /\/bin\/su -l -c '\/omd\/sites\/TEST_SITE\/bin\/check_mk -I' TEST_SITE/, - :refreshonly => true, - }) - } - it { should contain_exec('check_mk-reload').with({ - :command => /\/bin\/su -l -c '\/omd\/sites\/TEST_SITE\/bin\/check_mk -O' TEST_SITE/, - :refreshonly => true, - }) - } - it { should contain_cron('check_mk-refresh-inventory-daily').with({ - :user => 'root', - :command => /su -l -c '\/omd\/sites\/TEST_SITE\/bin\/check_mk -O' TEST_SITE/, - :minute => 0, - :hour => 0, - }) - } - end - context 'with host_groups' do - host_groups = { - 'group1' => {'host_tags' => []}, - 'group2' => {'host_tags' => []}, - } - let :params do - { - :site => 'TEST_SITE', - :host_groups => host_groups, - } - end - it { should contain_class('check_mk::config') } - it { should contain_file('/omd/sites/TEST_SITE/etc/nagios/local/hostgroups').with_ensure_directory } - it { should contain_concat__fragment('host_groups-header').with({ - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :content => /host_groups = \[\n/, - :order => 20, - }) - } - it { should contain_concat__fragment('host_groups-footer').with({ - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :content => /\]\n/, - :order => 29, - }) - } - it { should contain_check_mk__hostgroup('group1').with({ - :dir => '/omd/sites/TEST_SITE/etc/nagios/local/hostgroups', - :hostgroups => host_groups, - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :notify => 'Exec[check_mk-refresh]', - }) - } - it { should contain_check_mk__hostgroup('group2').with({ - :dir => '/omd/sites/TEST_SITE/etc/nagios/local/hostgroups', - :hostgroups => host_groups, - :target => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', - :notify => 'Exec[check_mk-refresh]', - }) - } - end -end diff --git a/spec/classes/check_mk_install_spec.rb b/spec/classes/check_mk_install_spec.rb deleted file mode 100644 index 9cf0b09..0000000 --- a/spec/classes/check_mk_install_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper' -describe 'check_mk::install', :type => :class do - context 'with necessary parameters set' do - let :params do - { - :filestore => false, - :package => 'package', - :site => 'site', - :workspace => 'workspace', - } - end - it { should contain_class('check_mk::install') } - it { should contain_package('package').with_ensure('installed').that_comes_before('Exec[omd-create-site]') } - it { should contain_exec('omd-create-site').with({ - :command => '/usr/bin/omd create site', - :creates => '/omd/sites/site/etc', - }) - } - end -end diff --git a/spec/classes/check_mk_install_tarball_spec.rb b/spec/classes/check_mk_install_tarball_spec.rb deleted file mode 100644 index 7537d85..0000000 --- a/spec/classes/check_mk_install_tarball_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -require 'spec_helper' -describe 'check_mk::install_tarball', :type => :class do - context 'with necessary parameters set' do - let :params do - { - :filestore => '/filestore', - :version => '1.2.3', - :workspace => '/workspace', - } - end - it { should contain_class('check_mk::install_tarball') } - it { should contain_package('nagios').with_ensure('present').that_comes_before('Package[nagios-plugins-all]') } - installed_packages = [ - 'xinetd', - 'mod_python', - 'make', - 'gcc-c++', - 'tar', - 'gzip' - ] - installed_packages.each do |package| - it { should contain_package(package).with_ensure('present') } - end - it { should contain_file('/etc/nagios/passwd').with({ - :ensure => 'present', - :owner => 'root', - :group => 'apache', - :mode => '0640', - }) - } - it { should contain_exec('set-nagiosadmin-password').with({ - :refreshonly => true, - :require => 'File[/etc/nagios/passwd]', - }) - } - it { should contain_exec('set-guest-password').with({ - :refreshonly => true, - :require => 'File[/etc/nagios/passwd]', - }) - } - it { should contain_exec('add-apache-to-nagios-group').with({ - :refreshonly => true, - }) - } - it { should contain_package('nagios-plugins-all').with({ - :ensure => 'present', - :require => 'Package[nagios]', - }) - } - it { should contain_exec('unpack-check_mk-tarball').with({ - :command => '/bin/tar -zxf /workspace/check_mk-1.2.3.tar.gz', - :cwd => '/workspace', - :creates => '/workspace/check_mk-1.2.3', - :require => 'File[/workspace/check_mk-1.2.3.tar.gz]', - }) - } - it { should contain_exec('change-setup-config-location').with({ - :command => "/usr/bin/perl -pi -e 's#^SETUPCONF=.*?$#SETUPCONF=/workspace/check_mk_setup.conf#' /workspace/check_mk-1.2.3/setup.sh", - :unless => "/bin/egrep '^SETUPCONF=/workspace/check_mk_setup.conf$' /workspace/check_mk-1.2.3/setup.sh", - :require => 'Exec[unpack-check_mk-tarball]', - }) - } - it { should contain_exec('remove-setup-header').with({ - :command => "/usr/bin/perl -pi -e 's#^DIRINFO=.*?$#DIRINFO=#' /workspace/check_mk-1.2.3/setup.sh", - :unless => "/bin/egrep '^DIRINFO=$' /workspace/check_mk-1.2.3/setup.sh", - :require => 'Exec[unpack-check_mk-tarball]', - }) - } - it { should contain_file('/workspace/check_mk_setup.conf').that_notifies('Exec[check_mk-setup]') } - it { should contain_file('/etc/nagios/check_mk').with({ - :ensure => 'directory', - :owner => 'nagios', - :group => 'nagios', - :recurse => true, - :require => 'Package[nagios]', - }) - } - it { should contain_file('/etc/nagios/check_mk/hostgroups').with({ - :ensure => 'directory', - :owner => 'nagios', - :group => 'nagios', - :require => 'File[/etc/nagios/check_mk]', - }) - } - it { should contain_exec('check_mk-setup').with({ - :command => '/workspace/check_mk-1.2.3/setup.sh --yes', - :cwd => '/workspace/check_mk-1.2.3', - :refreshonly => true, - :require => [ - 'Exec[change-setup-config-location]', - 'Exec[remove-setup-header]', - 'Exec[unpack-check_mk-tarball]', - 'File[/workspace/check_mk_setup.conf]', - 'File[/etc/nagios/check_mk]', - 'Package[nagios]', - ], - :notify => 'Class[Check_mk::Service]', - }) - } - - end -end diff --git a/spec/classes/check_mk_service_spec.rb b/spec/classes/check_mk_service_spec.rb deleted file mode 100644 index bb05c3d..0000000 --- a/spec/classes/check_mk_service_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' -describe 'check_mk::service', :type => :class do - context 'with defaults for all parameters' do - it { should contain_class('check_mk::service') } - it { should contain_service('httpd').with({ - :ensure => 'running', - :enable => 'true', - }) - } - it { should contain_service('omd').with({ - :ensure => 'running', - :enable => 'true', - }) - } - end -end diff --git a/spec/classes/check_mk_spec.rb b/spec/classes/check_mk_spec.rb index 169438f..5a61d9b 100644 --- a/spec/classes/check_mk_spec.rb +++ b/spec/classes/check_mk_spec.rb @@ -1,18 +1,31 @@ require 'spec_helper' -describe 'check_mk', :type => :class do - context 'with defaults for all parameters' do - it { should contain_class('check_mk') } - it { should contain_class('check_mk::install').with({ - :filestore => nil, - :package => 'omd-0.56', - :site => 'monitoring', - :workspace => '/root/check_mk', - }).that_comes_before('Class[check_mk::config]') } - it { should contain_class('check_mk::config').with({ - :host_groups => nil, - :site => 'monitoring', - }).that_comes_before('Class[check_mk::service]') } - it { should contain_class('check_mk::service') } +describe 'check_mk' do + on_supported_os.each do |os, os_facts| + context "with defaults for all parameters on #{os}" do + let(:facts) { os_facts } + + it { + is_expected.to compile + + is_expected.to contain_class('check_mk') + + is_expected.to contain_class('check_mk::instal').with( + 'filestore' => nil, + 'package' => 'omd-0.56', + 'site' => 'monitoring', + 'workspace' => '/root/check_mk', + 'before' => 'Class[Check_mk::Config]', + ) + + is_expected.to contain_class('check_mk::config').with( + 'host_groups' => nil, + 'site' => 'monitoring', + 'before' => 'Class[Check_mk::Service]', + ) + + is_expected.to contain_class('check_mk::service') + } + end end end diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb deleted file mode 100644 index 12513b8..0000000 --- a/spec/classes/coverage_spec.rb +++ /dev/null @@ -1 +0,0 @@ -at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/defines/check_mk_agent_mrpe_spec.rb b/spec/defines/check_mk_agent_mrpe_spec.rb deleted file mode 100644 index b911d0a..0000000 --- a/spec/defines/check_mk_agent_mrpe_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper' -describe 'check_mk::agent::mrpe', :type => :define do - let :title do - 'checkname' - end - context 'Unsupported OS' do - context 'with mandatory command' do - let :params do - {:command => 'command'} - end - it 'should fail' do - expect { catalogue }.to raise_error(Puppet::Error, /Creating mrpe.cfg is unsupported for operatingsystem/) - end - end - end - context 'RedHat Linux' do - let :facts do - { - :operatingsystem => 'redhat', - } - end - context 'with mandatory command' do - let :params do - {:command => 'command'} - end - it { should contain_check_mk__agent__mrpe('checkname') } - it { should contain_concat('/etc/check-mk-agent/mrpe.cfg').with_ensure('present') } - it { should contain_concat__fragment('checkname-mrpe-check').with({ - :target => '/etc/check-mk-agent/mrpe.cfg', - :content => /^checkname command\n$/, - }) - } - end - end -end diff --git a/spec/defines/check_mk_host_spec.rb b/spec/defines/check_mk_host_spec.rb deleted file mode 100644 index 0a60870..0000000 --- a/spec/defines/check_mk_host_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper' -describe 'check_mk::host', :type => :define do - let :title do - 'host' - end - context 'with empty host_tags array' do - let :params do - {:target => 'target'} - end - it { should contain_check_mk__host('host') } - it { should contain_concat__fragment('check_mk-host').with({ - :target => 'target', - :content => /^ 'host',\n$/, - :order => 11, - }) - } - end - context 'with custom host_tags' do - let :params do - { - :target => 'target', - :host_tags => ['tag1', 'tag2'], - } - end - it { should contain_check_mk__host('host') } - it { should contain_concat__fragment('check_mk-host').with({ - :target => 'target', - :content => /^ 'host|tag1|tag2',\n$/, - :order => 11, - }) - } - end -end diff --git a/spec/defines/check_mk_hostgroup_spec.rb b/spec/defines/check_mk_hostgroup_spec.rb deleted file mode 100644 index d2ba88e..0000000 --- a/spec/defines/check_mk_hostgroup_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'spec_helper' -describe 'check_mk::hostgroup', :type => :define do - - context 'with hostgroups, host_tags and description' do - let :title do - 'TEST_HOSTGROUP' - end - hostgroups = { - 'TEST_HOSTGROUP' => { - 'host_tags' => [ - 'tag1', - 'tag2', - ], - 'description' => 'TEST_DESCRIPTION', - }, - } - let :params do - { - :dir => '/dir', - :hostgroups => hostgroups, - :target => 'target' - } - end - it { should contain_check_mk__hostgroup('TEST_HOSTGROUP') } - it { should contain_concat__fragment('check_mk-hostgroup-TEST_HOSTGROUP').with({ - :target => 'target', - :content => /^ \( 'TEST_HOSTGROUP', \[ 'tag1', 'tag2' \], ALL_HOSTS \),\n$/, - :order => 21, - }) - } - expected_file_content = < 'present', - :content => expected_file_content, - }) - } - end - - context 'with hostgroups without description' do - let :title do - 'TEST_HOUSTGROUP_WITH_UNDERSCORES' - end - hostgroups = { - 'TEST_HOUSTGROUP_WITH_UNDERSCORES' => { - 'host_tags' => [ - 'tag1', - 'tag2', - ], - }, - } - let :params do - { - :dir => '/dir', - :hostgroups => hostgroups, - :target => '/target' - } - end - it { should contain_check_mk__hostgroup('TEST_HOUSTGROUP_WITH_UNDERSCORES') } - it { should contain_concat__fragment('check_mk-hostgroup-TEST_HOUSTGROUP_WITH_UNDERSCORES').with({ - :target => '/target', - :content => /^ \( 'TEST_HOUSTGROUP_WITH_UNDERSCORES', \[ 'tag1', 'tag2' \], ALL_HOSTS \),\n$/, - :order => 21, - }) - } - expected_file_content = < 'present', - :content => expected_file_content, - }) - } - end - -end From 9f18e2c6bc5b2cbda1328c0ebb9b2e8bb2bc6180 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Fri, 16 Nov 2018 14:25:20 +0100 Subject: [PATCH 03/13] Fixing unit test typo --- spec/classes/check_mk_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/classes/check_mk_spec.rb b/spec/classes/check_mk_spec.rb index 5a61d9b..2713638 100644 --- a/spec/classes/check_mk_spec.rb +++ b/spec/classes/check_mk_spec.rb @@ -10,7 +10,7 @@ is_expected.to contain_class('check_mk') - is_expected.to contain_class('check_mk::instal').with( + is_expected.to contain_class('check_mk::install').with( 'filestore' => nil, 'package' => 'omd-0.56', 'site' => 'monitoring', From 74590af95f076341014222df629f704dc36b85b9 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Fri, 16 Nov 2018 14:31:48 +0100 Subject: [PATCH 04/13] Changing before to require in unit test --- spec/classes/check_mk_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/classes/check_mk_spec.rb b/spec/classes/check_mk_spec.rb index 2713638..dbaf1c5 100644 --- a/spec/classes/check_mk_spec.rb +++ b/spec/classes/check_mk_spec.rb @@ -15,16 +15,17 @@ 'package' => 'omd-0.56', 'site' => 'monitoring', 'workspace' => '/root/check_mk', - 'before' => 'Class[Check_mk::Config]', ) is_expected.to contain_class('check_mk::config').with( 'host_groups' => nil, 'site' => 'monitoring', - 'before' => 'Class[Check_mk::Service]', + 'require' => 'Class[Check_mk::Install]', ) - is_expected.to contain_class('check_mk::service') + is_expected.to contain_class('check_mk::service').with( + 'require' => 'Class[Check_mk::Config]', + ) } end end From ad9037b743d4bffd668c7ed1a12316a59f0fa94f Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Fri, 16 Nov 2018 16:19:08 +0100 Subject: [PATCH 05/13] Fixing installation module for new version of check_mk --- manifests/install.pp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index ba37ba3..98a2c23 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -2,10 +2,10 @@ # # Installs check_mk through a deb or rpm file class check_mk::install ( - $site, - $workspace, - $filestore = undef, - $package = undef, + String $site, + Stdlib::Absolutepath $workspace, + Optional[Stdlib::Filesource] $filestore = undef, + String $package = undef, ) { if $filestore { if ! defined(File[$workspace]) { @@ -18,16 +18,28 @@ source => "${filestore}/${package}", require => File[$workspace], } - # omd-0.56-rh60-29.x86_64.rpm - if $package =~ /^(omd-\d+\.\d+)-(.*?)\.(rpm|deb)$/ { - $package_name = $1 - $type = $3 + + # check-mk-raw-1.5.0p7_0.stretch_amd64.deb + if $package =~ /^(check-mk-(\w*))-(\d*\.\d*\.\d*p\d*).+\.(deb)$/ { + case $4 { + 'deb': { + $type = 'apt' + $package_name = "${workspace}/${package}" + } + 'default': { + $type = $4 + $package_name = $1 + } + } + package { $package_name: ensure => installed, provider => $type, source => "${workspace}/${package}", require => File["${workspace}/${package}"], } + } else { + fail('Package does not match format check-mk-raw-1.5.0p7_0.stretch_amd64.deb') } } else { From 6448ede2190f025ed29b2c4e91d30dcc14e13758 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Tue, 20 Nov 2018 15:33:43 +0100 Subject: [PATCH 06/13] Fixing config class for new release of check_mk This is a breaking change Some configuration has been removed, because it is not recommended Also rewrote spec test for changed classes --- manifests/config.pp | 82 +++++++++---------- manifests/init.pp | 2 +- manifests/install.pp | 38 +++++---- manifests/service.pp | 9 ++- spec/classes/check_mk_config_spec.rb | 111 ++++++++++++++++++++++++++ spec/classes/check_mk_install_spec.rb | 64 +++++++++++++++ spec/classes/check_mk_service_spec.rb | 36 +++++++++ spec/classes/check_mk_spec.rb | 14 +++- 8 files changed, 289 insertions(+), 67 deletions(-) create mode 100644 spec/classes/check_mk_config_spec.rb create mode 100644 spec/classes/check_mk_install_spec.rb create mode 100644 spec/classes/check_mk_service_spec.rb diff --git a/manifests/config.pp b/manifests/config.pp index 2176a3a..ddbba76 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -2,59 +2,62 @@ # # Configures checkmk class check_mk::config ( - $site, - $host_groups = undef, + String $site, + Optional[Hash] $host_groups = undef, + Optional[Array] $all_hosts_static = undef, ) { $etc_dir = "/omd/sites/${site}/etc" $bin_dir = "/omd/sites/${site}/bin" file { "${etc_dir}/nagios/local": ensure => directory, + owner => $site, + group => $site, } + file_line { 'nagios-add-check_mk-cfg_dir': ensure => present, line => "cfg_dir=${etc_dir}/nagios/local", path => "${etc_dir}/nagios/nagios.cfg", require => File["${etc_dir}/nagios/local"], - notify => Class['check_mk::service'], - } - file_line { 'add-guest-users': - ensure => present, - line => 'guest_users = [ "guest" ]', - path => "${etc_dir}/check_mk/multisite.mk", - notify => Class['check_mk::service'], - } - file { "${etc_dir}/check_mk/all_hosts_static": - ensure => file, - content => template('check_mk/all_hosts_static.erb'), } + concat { "${etc_dir}/check_mk/main.mk": - owner => 'root', - group => 'root', - mode => 'u=rw,go=r', - notify => Exec['check_mk-refresh'], + owner => $site, + group => $site, + mode => '0644', } - # all_hosts + + # # all_hosts concat::fragment { 'all_hosts-header': target => "${etc_dir}/check_mk/main.mk", content => "all_hosts = [\n", order => 10, } + + file { "${etc_dir}/check_mk/all_hosts_static": + ensure => file, + content => template('check_mk/all_hosts_static.erb'), + } + + # # local list of hosts is in /omd/sites/${site}/etc/check_mk/all_hosts_static and is appended + concat::fragment { 'all-hosts-static': + source => "${etc_dir}/check_mk/all_hosts_static", + target => "${etc_dir}/check_mk/main.mk", + order => 18, + } + concat::fragment { 'all_hosts-footer': target => "${etc_dir}/check_mk/main.mk", content => "]\n", order => 19, } + + #TODO: Check if nodes are added automatically because we removed the exec Check_mk::Host <<| |>> { target => "${etc_dir}/check_mk/main.mk", - notify => Exec['check_mk-refresh'] - } - # local list of hosts is in /omd/sites/${site}/etc/check_mk/all_hosts_static and is appended - concat::fragment { 'all-hosts-static': - source => "${etc_dir}/check_mk/all_hosts_static", - target => "${etc_dir}/check_mk/main.mk", - order => 18, } - # host_groups + + # # host_groups if $host_groups { file { "${etc_dir}/nagios/local/hostgroups": ensure => directory, @@ -74,36 +77,25 @@ dir => "${etc_dir}/nagios/local/hostgroups", hostgroups => $host_groups, target => "${etc_dir}/check_mk/main.mk", - notify => Exec['check_mk-refresh'] } } - # local config is in /omd/sites/${site}/etc/check_mk/main.mk.local and is appended + + # # local config is in /omd/sites/${site}/etc/check_mk/main.mk.local and is appended file { "${etc_dir}/check_mk/main.mk.local": ensure => file, owner => 'root', group => 'root', mode => 'u=rw,go=r', } + concat::fragment { 'check_mk-local-config': source => "${etc_dir}/check_mk/main.mk.local", target => "${etc_dir}/check_mk/main.mk", order => 99, } - # re-read config if it changes - exec { 'check_mk-refresh': - command => "/bin/su -l -c '${bin_dir}/check_mk -I' ${site}", - refreshonly => true, - notify => Exec['check_mk-reload'], - } - exec { 'check_mk-reload': - command => "/bin/su -l -c '${bin_dir}/check_mk -O' ${site}", - refreshonly => true, - } - # re-read inventory daily - cron { 'check_mk-refresh-inventory-daily': - user => 'root', - command => "su -l -c '${bin_dir}/check_mk -O' ${site}", - minute => 0, - hour => 0, - } + + # In the original code 3 execs would be here, but is is not recommended + # to do a reindex, see https://mathias-kettner.de/checkmk_inventory.html + # This breaks large installs. The services class is subscribed to the + # config class so new changes should be noticed automatically. } diff --git a/manifests/init.pp b/manifests/init.pp index 5d8d8d0..b7f91ea 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -25,6 +25,6 @@ class { 'check_mk::service': checkmk_service => $checkmk_service, httpd_service => $httpd_service, - require => Class['check_mk::config'], + subscribe => Class['check_mk::config'], } } diff --git a/manifests/install.pp b/manifests/install.pp index 98a2c23..f54ae5d 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -20,23 +20,29 @@ } # check-mk-raw-1.5.0p7_0.stretch_amd64.deb - if $package =~ /^(check-mk-(\w*))-(\d*\.\d*\.\d*p\d*).+\.(deb)$/ { - case $4 { - 'deb': { - $type = 'apt' - $package_name = "${workspace}/${package}" - } - 'default': { - $type = $4 - $package_name = $1 + if $package =~ /^(check-mk-(\w*))-(\d*\.\d*\.\d*p\d*).+\.(\w+)$/ { + $type = $4 + $package_name = $1 + + if $type == 'deb' { + package {'gdebi': + ensure => present } - } - package { $package_name: - ensure => installed, - provider => $type, - source => "${workspace}/${package}", - require => File["${workspace}/${package}"], + exec {'install-check-mk': + command => "/usr/bin/gdebi --non-interactive ${workspace}/${package}", + unless => "/usr/bin/dpkg-query -W --showformat '\${Status} \${Package}\\n' | grep ${package_name} | grep -q 'install ok installed'", # lint:ignore:140chars + require => Package['gdebi'], + before => Exec['omd-create-site'], + } + } else { + package { $package_name: + ensure => installed, + provider => $type, + source => "${workspace}/${package}", + require => File["${workspace}/${package}"], + before => Exec['omd-create-site'], + } } } else { fail('Package does not match format check-mk-raw-1.5.0p7_0.stretch_amd64.deb') @@ -46,12 +52,12 @@ $package_name = $package package { $package_name: ensure => installed, + before => Exec['omd-create-site'], } } $etc_dir = "/omd/sites/${site}/etc" exec { 'omd-create-site': command => "/usr/bin/omd create ${site}", creates => $etc_dir, - require => Package[$package_name], } } diff --git a/manifests/service.pp b/manifests/service.pp index 7ad470f..ae55023 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -2,8 +2,8 @@ # # Configures the check mk service class check_mk::service ( - $checkmk_service, - $httpd_service, + String $checkmk_service, + String $httpd_service, ) { if ! defined(Service[$httpd_service]) { service { $httpd_service: @@ -18,7 +18,8 @@ } } service { $checkmk_service: - ensure => 'running', - enable => true, + ensure => 'running', + enable => true, + hasrestart => true, } } diff --git a/spec/classes/check_mk_config_spec.rb b/spec/classes/check_mk_config_spec.rb new file mode 100644 index 0000000..1b79590 --- /dev/null +++ b/spec/classes/check_mk_config_spec.rb @@ -0,0 +1,111 @@ +require 'spec_helper' + +describe 'check_mk::config' do + on_supported_os.each do |os, os_facts| + context "with site set on #{os}" do + let(:facts) { os_facts } + let(:params) { { site: 'TEST_SITE' } } + + it { + is_expected.to compile + + is_expected.to contain_class('check_mk::config') + + is_expected.to contain_file('/omd/sites/TEST_SITE/etc/nagios/local').with( + 'ensure' => 'directory', + 'owner' => 'TEST_SITE', + 'group' => 'TEST_SITE', + ) + + is_expected.to contain_file_line('nagios-add-check_mk-cfg_dir').with( + 'ensure' => 'present', + 'line' => 'cfg_dir=/omd/sites/TEST_SITE/etc/nagios/local', + 'path' => '/omd/sites/TEST_SITE/etc/nagios/nagios.cfg', + ).that_requires('File[/omd/sites/TEST_SITE/etc/nagios/local]') + + is_expected.to contain_file('/omd/sites/TEST_SITE/etc/check_mk/all_hosts_static').with( + 'ensure' => 'file', + 'content' => '', + ) + + is_expected.to contain_concat('/omd/sites/TEST_SITE/etc/check_mk/main.mk').with( + 'owner' => 'TEST_SITE', + 'group' => 'TEST_SITE', + 'mode' => '0644', + ) + + is_expected.to contain_concat__fragment('all_hosts-header').with( + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + 'content' => %r{all_hosts = \[\n}, + 'order' => 10, + ) + + is_expected.to contain_concat__fragment('all_hosts-footer').with( + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + 'content' => %r{\]\n}, + 'order' => 19, + ) + + is_expected.to contain_concat__fragment('all-hosts-static').with( + 'source' => '/omd/sites/TEST_SITE/etc/check_mk/all_hosts_static', + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + 'order' => 18, + ) + + is_expected.to contain_concat__fragment('check_mk-local-config').with( + 'source' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk.local', + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + 'order' => 99, + ) + + is_expected.not_to contain_file('/omd/sites/TEST_SITE/etc/nagios/local/hostgroups') + is_expected.not_to contain_concat__fragment('host_groups-header') + is_expected.not_to contain_concat__fragment('host_groups-footer') + } + end + context "with site set on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + site: 'TEST_SITE', + host_groups: { + group1: { + host_tags: [], + }, + group2: { + host_tags: [], + }, + }, + } + end + + it { + is_expected.to compile + is_expected.to contain_class('check_mk::config') + is_expected.to contain_file('/omd/sites/TEST_SITE/etc/nagios/local/hostgroups').with( + 'ensure' => 'directory', + ) + is_expected.to contain_concat__fragment('host_groups-header').with( + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + 'content' => %r{host_groups = \[\n}, + 'order' => 20, + ) + is_expected.to contain_concat__fragment('host_groups-footer').with( + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + 'content' => %r{\]\n}, + 'order' => 29, + ) + is_expected.to contain_check_mk__hostgroup('group1').with( + 'dir' => '/omd/sites/TEST_SITE/etc/nagios/local/hostgroups', + 'host_groups' => params['host_groups'], + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + ) + is_expected.to contain_check_mk__hostgroup('group2').with( + 'dir' => '/omd/sites/TEST_SITE/etc/nagios/local/hostgroups', + 'host_groups' => params['host_groups'], + 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', + ) + } + end + end +end diff --git a/spec/classes/check_mk_install_spec.rb b/spec/classes/check_mk_install_spec.rb new file mode 100644 index 0000000..6f727f7 --- /dev/null +++ b/spec/classes/check_mk_install_spec.rb @@ -0,0 +1,64 @@ +require 'spec_helper' + +describe 'check_mk::install' do + on_supported_os.each do |os, os_facts| + context "with necessary parameters set on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + filestore: '/filestore/', + package: 'check-mk-raw-1.5.0p7_0.stretch_amd64.deb', + site: 'site', + workspace: '/workspace', + } + end + + it { + is_expected.to compile + + is_expected.to contain_class('check_mk::install') + + is_expected.to contain_exec('omd-create-site').with( + 'command' => '/usr/bin/omd create site', + 'creates' => '/omd/sites/site/etc', + ).that_requires('Exec[install-check-mk]') + + is_expected.to contain_package('gdebi').with( + 'ensure' => 'present', + ) + + is_expected.to contain_exec('install-check-mk').with( + 'command' => '/usr/bin/gdebi --non-interactive /workspace/check-mk-raw-1.5.0p7_0.stretch_amd64.deb', + 'unless' => '/usr/bin/dpkg-query -W --showformat \'${Status} ${Package}\n\' | grep check-mk-raw | grep -q \'install ok installed\'', + ).that_requires('Package[gdebi]') + } + end + + context "with rpm file set on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + filestore: '/filestore/', + package: 'check-mk-raw-1.5.0p7-el7-38.x86_64.rpm', + site: 'site', + workspace: '/workspace', + } + end + + it { + is_expected.to compile + + is_expected.to contain_exec('omd-create-site').with( + 'command' => '/usr/bin/omd create site', + 'creates' => '/omd/sites/site/etc', + ).that_requires('Package[check-mk-raw]') + + is_expected.to contain_package('check-mk-raw').with( + 'ensure' => 'installed', + 'provider' => 'rpm', + 'source' => '/workspace/check-mk-raw-1.5.0p7-el7-38.x86_64.rpm', + ).that_requires('File[/workspace/check-mk-raw-1.5.0p7-el7-38.x86_64.rpm]') + } + end + end +end diff --git a/spec/classes/check_mk_service_spec.rb b/spec/classes/check_mk_service_spec.rb new file mode 100644 index 0000000..4641803 --- /dev/null +++ b/spec/classes/check_mk_service_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe 'check_mk::service' do + on_supported_os.each do |os, os_facts| + context "with required parameters set on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + checkmk_service: 'omd', + httpd_service: 'httpd', + } + end + + it { + is_expected.to compile + + is_expected.to contain_class('check_mk::service') + is_expected.to contain_service('httpd').with( + 'ensure' => 'running', + 'enable' => 'true', + ) + + is_expected.to contain_service('xinetd').with( + 'ensure' => 'running', + 'enable' => 'true', + ) + + is_expected.to contain_service('omd').with( + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + ) + } + end + end +end diff --git a/spec/classes/check_mk_spec.rb b/spec/classes/check_mk_spec.rb index dbaf1c5..9b100f4 100644 --- a/spec/classes/check_mk_spec.rb +++ b/spec/classes/check_mk_spec.rb @@ -24,8 +24,20 @@ ) is_expected.to contain_class('check_mk::service').with( - 'require' => 'Class[Check_mk::Config]', + 'subscribe' => 'Class[Check_mk::Config]', ) + case facts[:osfamily] + when 'RedHat' + is_expected.to contain_service('httpd').with( + 'ensure' => 'running', + 'enable' => 'true', + ) + when 'Debian' + is_expected.to contain_service('apache2').with( + 'ensure' => 'running', + 'enable' => 'true', + ) + end } end end From bc79a6d5420921bf655aa826bb12fba65d17bd62 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Tue, 20 Nov 2018 22:53:09 +0100 Subject: [PATCH 07/13] Adding new agent classes Breaking change! With check_mk and other OSses switching to systemd inetx is not being used anymore --- manifests/agent.pp | 24 ++++---- manifests/agent/config.pp | 64 +++----------------- manifests/agent/install.pp | 65 ++++++++++----------- manifests/agent/mrpe.pp | 33 ++++------- manifests/agent/params.pp | 15 +++++ manifests/agent/service.pp | 19 ------ manifests/install.pp | 6 +- spec/classes/check_mk_agent_config_spec.rb | 39 +++++++++++++ spec/classes/check_mk_agent_install_spec.rb | 61 +++++++++++++++++++ spec/classes/check_mk_agent_spec.rb | 38 ++++++++++++ spec/defines/check_mk_agent_mrpe_spec.rb | 43 ++++++++++++++ templates/agent/check_mk.erb | 39 ------------- templates/agent/encryption.cfg.erb | 2 + 13 files changed, 261 insertions(+), 187 deletions(-) create mode 100644 manifests/agent/params.pp delete mode 100644 manifests/agent/service.pp create mode 100644 spec/classes/check_mk_agent_config_spec.rb create mode 100644 spec/classes/check_mk_agent_install_spec.rb create mode 100644 spec/classes/check_mk_agent_spec.rb create mode 100644 spec/defines/check_mk_agent_mrpe_spec.rb delete mode 100644 templates/agent/check_mk.erb create mode 100644 templates/agent/encryption.cfg.erb diff --git a/manifests/agent.pp b/manifests/agent.pp index 715abe9..4375790 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -2,25 +2,21 @@ # # Configures and install the check_mk agent. class check_mk::agent ( - $filestore = undef, - $host_tags = undef, - $ip_whitelist = undef, - $port = '6556', - $server_dir = '/usr/bin', - $use_cache = false, - $user = 'root', - $version = undef, - $workspace = '/root/check_mk', - $package = undef, - $mrpe_checks = {}, -) { - validate_hash($mrpe_checks) + Optional[Stdlib::Filesource] $filestore = undef, + Optional[Array] $host_tags = undef, + Stdlib::Absolutepath $workspace = '/root/check_mk', + Optional[String] $package = undef, + Hash $mrpe_checks = {}, + Optional[String] $encryption_secret = undef, + Stdlib::Absolutepath $config_dir = $check_mk::agent::params::config_dir, +) inherits check_mk::agent::params { include check_mk::agent::install include check_mk::agent::config - include check_mk::agent::service Class['check_mk::agent::install'] -> Class['check_mk::agent::config'] + @@check_mk::host { $::fqdn: host_tags => $host_tags, } + create_resources('check_mk::agent::mrpe', $mrpe_checks) } diff --git a/manifests/agent/config.pp b/manifests/agent/config.pp index dbf7b42..2ca2675 100644 --- a/manifests/agent/config.pp +++ b/manifests/agent/config.pp @@ -4,66 +4,16 @@ # # === Parameters # -# [*ip_whitelist*] -# Array of IP allowed to access the check_mk agent. -# Default: undef -# -# [*port*] -# Check_mk port -# Default: undef -# -# [*server_dir*] -# Check_mk server directory. -# Default: undef -# -# [*use_cache*] -# Enable cache. -# Default: undef -# -# [*user*] -# Check_mk user. -# Default: undef # class check_mk::agent::config ( - $ip_whitelist = $check_mk::agent::ip_whitelist, - $port = $check_mk::agent::port, - $server_dir = $check_mk::agent::server_dir, - $use_cache = $check_mk::agent::use_cache, - $user = $check_mk::agent::user, + Optional[String] $encryption_secret = $check_mk::agent::encryption_secret, + Stdlib::Absolutepath $config_dir = $check_mk::agent::config_dir, ) inherits check_mk::agent { - if $use_cache { - $server = "${server_dir}/check_mk_caching_agent" - } else { - $server = "${server_dir}/check_mk_agent" - } - - if $ip_whitelist { - $only_from = join($ip_whitelist, ' ') - } else { - $only_from = undef - } - - $xinetd_file = $::osfamily ? { - 'RedHat' => '/etc/xinetd.d/check-mk-agent', - default => '/etc/xinetd.d/check_mk', - } - - file { $xinetd_file: - ensure => 'file', - owner => 'root', - group => 'root', - mode => '0444', - content => template('check_mk/agent/check_mk.erb'), - require => Package['check_mk-agent'], - notify => Class['check_mk::agent::service'], - } - - # Delete file from older check_mk package version - if $::osfamily == 'RedHat' { - file { '/etc/xinetd.d/check_mk': - ensure => 'absent', + if $encryption_secret { + file {'encryption_config': + ensure => file, + path => "${config_dir}/encryption.cfg", + content => template('check_mk/agent/encryption.cfg.erb'), } } } - -# vim: set et sta sw=2 ts=2 sts=2 noci noai:a diff --git a/manifests/agent/install.pp b/manifests/agent/install.pp index cc632d5..ff5d9f4 100644 --- a/manifests/agent/install.pp +++ b/manifests/agent/install.pp @@ -2,51 +2,48 @@ # # Install check_mk agent. class check_mk::agent::install ( - $version = $check_mk::agent::version, $filestore = undef, $workspace = $check_mk::agent::workspace, - $package = undef, + $package = 'check-mk-agent', ) inherits check_mk::agent { - if ! defined(Package['xinetd']) { - package { 'xinetd': - ensure => present, - } - } if $filestore { - if ! $version { - fail('version must be specified.') - } - if ! defined(File[$workspace]) { file { $workspace: ensure => directory, } } - file { "${workspace}/check_mk-agent-${version}.noarch.rpm": - ensure => present, - source => "${filestore}/check_mk-agent-${version}.noarch.rpm", - require => Package['xinetd'], - } - package { 'check_mk-agent': - ensure => present, - provider => 'rpm', - source => "${workspace}/check_mk-agent-${version}.noarch.rpm", - require => File["${workspace}/check_mk-agent-${version}.noarch.rpm"], - } - } - else { - $check_mk_agent = $package ? { - undef => $::osfamily ? { - 'Debian' => 'check-mk-agent', - 'RedHat' => 'check-mk-agent', - default => 'check_mk-agent', - }, - default => $package, + + # check-mk-agent_1.5.0p7-1_all.deb + if $package =~ /^(check-mk-(\w*))(-|_)(\d*\.\d*\.\d*p\d*).+\.(\w+)$/ { + case $5 { + 'deb': { + $type = 'dpkg' + } + default: { + $type = $5 + } + } + $package_name = $1 + + file { "${workspace}/${package}": + ensure => present, + source => "${filestore}/${package}", + } + + package { 'check_mk-agent': + ensure => present, + name => $package_name, + provider => $type, + source => "${workspace}/${package}", + require => File["${workspace}/${package}"], + } + } else { + fail('Package does not match format like check-mk-agent_1.5.0p7-1_all.deb') } + } else { package { 'check_mk-agent': - ensure => present, - name => $check_mk_agent, - require => Package['xinetd'], + ensure => present, + name => $package, } } } diff --git a/manifests/agent/mrpe.pp b/manifests/agent/mrpe.pp index eb0c80f..89e3718 100644 --- a/manifests/agent/mrpe.pp +++ b/manifests/agent/mrpe.pp @@ -15,30 +15,21 @@ # } # ``` # -## Authors -# -# * Bas Grolleman -# + define check_mk::agent::mrpe ( - $command, + String $command, + Stdlib::Absolutepath $config_dir = $check_mk::agent::config_dir, ) { - $mrpe_config_file = $::operatingsystem ? { - centos => '/etc/check-mk-agent/mrpe.cfg', - redhat => '/etc/check-mk-agent/mrpe.cfg', - default => undef, - } + $mrpe_config_file = "${config_dir}/mrpe.cfg" - if ( $mrpe_config_file ) { - if ! defined(Concat[$mrpe_config_file]) { - concat { $mrpe_config_file: - ensure => 'present', - } + if ! defined(Concat[$mrpe_config_file]) { + concat { $mrpe_config_file: + ensure => 'present', } - concat::fragment { "${name}-mrpe-check": - target => $mrpe_config_file, - content => "${name} ${command}\n", - } - } else { - fail("Creating mrpe.cfg is unsupported for operatingsystem ${::operatingsystem}") + } + + concat::fragment { "${name}-mrpe-check": + target => $mrpe_config_file, + content => "${name} ${command}\n", } } diff --git a/manifests/agent/params.pp b/manifests/agent/params.pp new file mode 100644 index 0000000..8304e4c --- /dev/null +++ b/manifests/agent/params.pp @@ -0,0 +1,15 @@ +# == Class: check_mk::agent::params +# +class check_mk::agent::params { + case $::osfamily { + 'RedHat': { + $config_dir = '/etc/check-mk-agent' + } + 'Debian': { + $config_dir = '/etc/check_mk' + } + default: { + fail("OS familly ${::osfamily} is not managed!") + } + } +} diff --git a/manifests/agent/service.pp b/manifests/agent/service.pp deleted file mode 100644 index a0fe537..0000000 --- a/manifests/agent/service.pp +++ /dev/null @@ -1,19 +0,0 @@ -# == Class: check_mk::agent::service -# -class check_mk::agent::service { - if ! defined(Service['xinetd']) { - if $::operatingsystem == 'Debian' and - versioncmp($::operatingsystemmajrelease, '7') == 0 { - service { 'xinetd': - ensure => 'running', - enable => true, - hasstatus => false, - } - } else { - service { 'xinetd': - ensure => 'running', - enable => true, - } - } - } -} diff --git a/manifests/install.pp b/manifests/install.pp index f54ae5d..9bd5fbd 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -20,8 +20,8 @@ } # check-mk-raw-1.5.0p7_0.stretch_amd64.deb - if $package =~ /^(check-mk-(\w*))-(\d*\.\d*\.\d*p\d*).+\.(\w+)$/ { - $type = $4 + if $package =~ /^(check-mk-(\w*))(-|_)(\d*\.\d*\.\d*p\d*).+\.(\w+)$/ { + $type = $5 $package_name = $1 if $type == 'deb' { @@ -45,7 +45,7 @@ } } } else { - fail('Package does not match format check-mk-raw-1.5.0p7_0.stretch_amd64.deb') + fail('Package does not match format like check-mk-raw-1.5.0p7_0.stretch_amd64.deb') } } else { diff --git a/spec/classes/check_mk_agent_config_spec.rb b/spec/classes/check_mk_agent_config_spec.rb new file mode 100644 index 0000000..038e927 --- /dev/null +++ b/spec/classes/check_mk_agent_config_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe 'check_mk::agent::config' do + on_supported_os.each do |os, os_facts| + context "with default parameters set on #{os}" do + let(:facts) { os_facts } + + it { + is_expected.to compile + } + end + context "with default parameters set on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + encryption_secret: 'SECRET', + } + end + + it { + is_expected.to compile + case facts[:osfamily] + when 'RedHat' + is_expected.to contain_file('encryption_config').with( + 'ensure' => 'file', + 'path' => '/etc/check-mk-agent/encryption.cfg', + 'content' => %r{PASSPHRASE=SECRET}, + ) + when 'Debian' + is_expected.to contain_file('encryption_config').with( + 'ensure' => 'file', + 'path' => '/etc/check_mk/encryption.cfg', + 'content' => %r{PASSPHRASE=SECRET}, + ) + end + } + end + end +end diff --git a/spec/classes/check_mk_agent_install_spec.rb b/spec/classes/check_mk_agent_install_spec.rb new file mode 100644 index 0000000..96ca2d6 --- /dev/null +++ b/spec/classes/check_mk_agent_install_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe 'check_mk::agent::install' do + on_supported_os.each do |os, os_facts| + context "with default parameters set on #{os}" do + let(:facts) { os_facts } + + it { + is_expected.to compile + is_expected.to contain_package('check_mk-agent').with( + 'ensure' => 'present', + 'name' => 'check-mk-agent', + ) + is_expected.to contain_class('check_mk::agent::install') + } + end + + context "with custom package on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + package: 'custom-package', + } + end + + it { + is_expected.to compile + is_expected.to contain_class('check_mk::agent::install') + is_expected.to contain_package('check_mk-agent').with( + 'name' => 'custom-package', + ) + } + end + + context "with filestore on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + filestore: '/filestore', + package: 'check-mk-agent_1.5.0p7-1_all.deb', + workspace: '/workspace', + } + end + + it { + is_expected.to compile + is_expected.to contain_class('check_mk::agent::install') + is_expected.to contain_file('/workspace/check-mk-agent_1.5.0p7-1_all.deb').with( + 'ensure' => 'present', + 'source' => '/filestore/check-mk-agent_1.5.0p7-1_all.deb', + ) + is_expected.to contain_package('check_mk-agent').with( + 'ensure' => 'present', + 'name' => 'check-mk-agent', + 'provider' => 'dpkg', + 'source' => '/workspace/check-mk-agent_1.5.0p7-1_all.deb', + ).that_requires('File[/workspace/check-mk-agent_1.5.0p7-1_all.deb]') + } + end + end +end diff --git a/spec/classes/check_mk_agent_spec.rb b/spec/classes/check_mk_agent_spec.rb new file mode 100644 index 0000000..0903235 --- /dev/null +++ b/spec/classes/check_mk_agent_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'check_mk::agent' do + on_supported_os.each do |os, os_facts| + context "with default parameters set on #{os}" do + let(:facts) { os_facts } + + it { + is_expected.to compile + is_expected.to contain_class('check_mk::agent') + is_expected.to contain_class('check_mk::agent::install') + is_expected.to contain_class('check_mk::agent::config').that_requires('Class[check_mk::agent::install]') + } + end + context "with mrpe_checks on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + mrpe_checks: { + check1: { + command: 'command1', + }, + check2: { + command: 'command2', + }, + }, + } + end + + it { + is_expected.to compile + is_expected.to contain_class('check_mk::agent') + is_expected.to contain_class('check_mk::agent::install') + is_expected.to contain_class('check_mk::agent::config').that_requires('Class[check_mk::agent::install]') + } + end + end +end diff --git a/spec/defines/check_mk_agent_mrpe_spec.rb b/spec/defines/check_mk_agent_mrpe_spec.rb new file mode 100644 index 0000000..587afa6 --- /dev/null +++ b/spec/defines/check_mk_agent_mrpe_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe 'check_mk::agent::mrpe' do + let(:pre_condition) do + "class { 'check_mk::agent': }" + end + let(:title) { 'check1' } + let(:params) do + { + command: 'command1', + } + end + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { + is_expected.to compile + case facts[:osfamily] + when 'RedHat' + is_expected.to contain_concat('/etc/check-mk-agent/mrpe.cfg').with( + 'ensure' => 'present', + ) + + is_expected.to contain_concat__fragment('check1-mrpe-check').with( + 'target' => '/etc/check-mk-agent/mrpe.cfg', + 'content' => %r{check1 command1\n}, + ) + when 'Debian' + is_expected.to contain_concat('/etc/check_mk/mrpe.cfg').with( + 'ensure' => 'present', + ) + + is_expected.to contain_concat__fragment('check1-mrpe-check').with( + 'target' => '/etc/check_mk/mrpe.cfg', + 'content' => %r{check1 command1\n}, + ) + end + } + end + end +end diff --git a/templates/agent/check_mk.erb b/templates/agent/check_mk.erb deleted file mode 100644 index 47824a9..0000000 --- a/templates/agent/check_mk.erb +++ /dev/null @@ -1,39 +0,0 @@ -# +------------------------------------------------------------------+ -# | ____ _ _ __ __ _ __ | -# | / ___| |__ ___ ___| | __ | \/ | |/ / | -# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | -# | | |___| | | | __/ (__| < | | | | . \ | -# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | -# | | -# | Copyright Mathias Kettner 2012 mk@mathias-kettner.de | -# +------------------------------------------------------------------+ -# -# This file is part of Check_MK. -# The official homepage is at http://mathias-kettner.de/check_mk. -# -# check_mk is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation in version 2. check_mk is distributed -# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- -# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more de- -# ails. You should have received a copy of the GNU General Public -# License along with GNU Make; see the file COPYING. If not, write -# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -# Boston, MA 02110-1301 USA. - -service check_mk -{ - type = UNLISTED - port = <%= @port %> - socket_type = stream - protocol = tcp - wait = no - user = <%= @user %> - server = <%= @server %> -<% if @only_from -%> - only_from = 127.0.0.1 <%= @only_from %> -<% end -%> - log_on_success = - disable = no -} diff --git a/templates/agent/encryption.cfg.erb b/templates/agent/encryption.cfg.erb new file mode 100644 index 0000000..7b47b0a --- /dev/null +++ b/templates/agent/encryption.cfg.erb @@ -0,0 +1,2 @@ +ENCRYPTED=yes +PASSPHRASE=<%= @encryption_secret %> \ No newline at end of file From fa2b14fd2a6c9234625d293b88a26a908fe6a239 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Thu, 22 Nov 2018 08:41:43 +0100 Subject: [PATCH 08/13] Fixing parameter bug --- manifests/agent.pp | 2 +- manifests/agent/install.pp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/agent.pp b/manifests/agent.pp index 4375790..57a2b87 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -5,7 +5,7 @@ Optional[Stdlib::Filesource] $filestore = undef, Optional[Array] $host_tags = undef, Stdlib::Absolutepath $workspace = '/root/check_mk', - Optional[String] $package = undef, + Optional[String] $package = 'check-mk-agent', Hash $mrpe_checks = {}, Optional[String] $encryption_secret = undef, Stdlib::Absolutepath $config_dir = $check_mk::agent::params::config_dir, diff --git a/manifests/agent/install.pp b/manifests/agent/install.pp index ff5d9f4..e38b263 100644 --- a/manifests/agent/install.pp +++ b/manifests/agent/install.pp @@ -2,9 +2,9 @@ # # Install check_mk agent. class check_mk::agent::install ( - $filestore = undef, + $filestore = $check_mk::agent::filestore, $workspace = $check_mk::agent::workspace, - $package = 'check-mk-agent', + $package = $check_mk::agent::package, ) inherits check_mk::agent { if $filestore { if ! defined(File[$workspace]) { From a96a7ecdab143147ef630dafdf45ea646acafb27 Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Thu, 22 Nov 2018 09:13:18 +0100 Subject: [PATCH 09/13] Changing datatype to String because modules is require in puppet path --- manifests/agent.pp | 2 +- manifests/install.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/agent.pp b/manifests/agent.pp index 57a2b87..0857bda 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -2,7 +2,7 @@ # # Configures and install the check_mk agent. class check_mk::agent ( - Optional[Stdlib::Filesource] $filestore = undef, + Optional[String] $filestore = undef, Optional[Array] $host_tags = undef, Stdlib::Absolutepath $workspace = '/root/check_mk', Optional[String] $package = 'check-mk-agent', diff --git a/manifests/install.pp b/manifests/install.pp index 9bd5fbd..384f613 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -4,7 +4,7 @@ class check_mk::install ( String $site, Stdlib::Absolutepath $workspace, - Optional[Stdlib::Filesource] $filestore = undef, + Optional[String] $filestore = undef, String $package = undef, ) { if $filestore { From da036b220a0a5fe435ab452b545515dc6d4469ba Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Wed, 28 Nov 2018 11:25:32 +0100 Subject: [PATCH 10/13] Fixing template mistake --- manifests/agent/config.pp | 1 + spec/classes/check_mk_agent_config_spec.rb | 6 ++++-- templates/agent/encryption.cfg.erb | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/manifests/agent/config.pp b/manifests/agent/config.pp index 2ca2675..a9c9cb6 100644 --- a/manifests/agent/config.pp +++ b/manifests/agent/config.pp @@ -12,6 +12,7 @@ if $encryption_secret { file {'encryption_config': ensure => file, + mode => '0600', path => "${config_dir}/encryption.cfg", content => template('check_mk/agent/encryption.cfg.erb'), } diff --git a/spec/classes/check_mk_agent_config_spec.rb b/spec/classes/check_mk_agent_config_spec.rb index 038e927..7b33839 100644 --- a/spec/classes/check_mk_agent_config_spec.rb +++ b/spec/classes/check_mk_agent_config_spec.rb @@ -23,14 +23,16 @@ when 'RedHat' is_expected.to contain_file('encryption_config').with( 'ensure' => 'file', + 'mode' => '0600', 'path' => '/etc/check-mk-agent/encryption.cfg', - 'content' => %r{PASSPHRASE=SECRET}, + 'content' => %r{PASSPHRASE=SECRET\n}, ) when 'Debian' is_expected.to contain_file('encryption_config').with( 'ensure' => 'file', + 'mode' => '0600', 'path' => '/etc/check_mk/encryption.cfg', - 'content' => %r{PASSPHRASE=SECRET}, + 'content' => %r{PASSPHRASE=SECRET\n}, ) end } diff --git a/templates/agent/encryption.cfg.erb b/templates/agent/encryption.cfg.erb index 7b47b0a..8660136 100644 --- a/templates/agent/encryption.cfg.erb +++ b/templates/agent/encryption.cfg.erb @@ -1,2 +1,2 @@ -ENCRYPTED=yes -PASSPHRASE=<%= @encryption_secret %> \ No newline at end of file +ENCRYPTED=yes +PASSPHRASE=<%= @encryption_secret %> From 29e9c10f4fecc60ae911e0cd8d1c0fc9cba3af3f Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Mon, 15 Apr 2019 11:49:01 +0200 Subject: [PATCH 11/13] Bumping PDK template --- .gitattributes | 5 ++ .gitignore | 52 ++++++------- .gitlab-ci.yml | 82 ++++++++++----------- .pdkignore | 66 +++++++++++------ .puppet-lint.rc | 1 + .travis.yml | 101 +++++++++++++------------ Gemfile | 141 +++++++++++++++++------------------ Rakefile | 151 +++++++++++++++++++------------------- appveyor.yml | 115 ++++++++++++++--------------- manifests/agent/params.pp | 30 ++++---- metadata.json | 116 ++++++++++++++--------------- spec/default_facts.yml | 15 ++-- spec/spec_helper.rb | 91 ++++++++++++----------- 13 files changed, 499 insertions(+), 467 deletions(-) create mode 100644 .gitattributes create mode 100644 .puppet-lint.rc 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 128e306..2767022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,27 @@ -.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 -*.to_clean \ No newline at end of file +.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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6349814..81e6d76 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,41 +1,41 @@ ---- -stages: - - syntax - - unit - -cache: - paths: - - vendor/bundle - -before_script: - - bundle -v - - rm Gemfile.lock || true - - gem update --system - - gem --version - - bundle -v - - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) - -parallel_spec-Ruby 2.1.9-Puppet ~> 4.0: - stage: unit - image: ruby:2.1.9 - script: - - bundle exec rake parallel_spec - variables: - PUPPET_GEM_VERSION: '~> 4.0' - -syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.4.4-Puppet ~> 5.5: - stage: syntax - image: ruby:2.4.4 - script: - - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - variables: - PUPPET_GEM_VERSION: '~> 5.5' - -parallel_spec-Ruby 2.4.4-Puppet ~> 5.5: - stage: unit - image: ruby:2.4.4 - script: - - bundle exec rake parallel_spec - variables: - PUPPET_GEM_VERSION: '~> 5.5' - +--- +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 index 888e0bf..e6215cd 100644 --- a/.pdkignore +++ b/.pdkignore @@ -1,24 +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 +.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/.travis.yml b/.travis.yml index 8f5472c..074a10f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,47 +1,54 @@ ---- -sudo: false -dist: trusty -language: ruby -cache: bundler -before_install: - - bundle -v - - rm -f Gemfile.lock - - gem update --system - - gem --version - - bundle -v -script: - - 'bundle exec rake $CHECK' -bundler_args: --without system_tests -rvm: - - 2.5.0 -env: - global: - - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" -matrix: - fast_finish: true - include: - - - env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" - - - env: CHECK=parallel_spec - - - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.4 - - - env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec - rvm: 2.1.9 -branches: - only: - - master - - /^v\d/ -notifications: - email: false -deploy: - provider: puppetforge - user: puppet - password: - secure: "" - on: - tags: true - all_branches: true - condition: "$DEPLOY_TO_FORGE = yes" +--- +dist: trusty +language: ruby +cache: bundler +before_install: + - 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: + - + 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/ +notifications: + email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "" + on: + tags: true + all_branches: true + condition: "$DEPLOY_TO_FORGE = yes" diff --git a/Gemfile b/Gemfile index ef41ab2..cf2c387 100644 --- a/Gemfile +++ b/Gemfile @@ -1,70 +1,71 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' - -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 "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::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4') - 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 - -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - -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 - -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 +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +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 "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 + +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +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 + +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 1ea31b2..750ef46 100644 --- a/Rakefile +++ b/Rakefile @@ -1,75 +1,76 @@ -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? - -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 - -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['name'] - raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal -end - -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = 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 - -PuppetLint.configuration.send('disable_relative') - -if Bundler.rubygems.find_name('github_changelog_generator').any? - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - 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; GO LABEL THEM" - config.configure_sections = { - "Changed" => { - "prefix" => "### Changed", - "labels" => ["backwards-incompatible"], - }, - "Added" => { - "prefix" => "### Added", - "labels" => ["feature", "enhancement"], - }, - "Fixed" => { - "prefix" => "### Fixed", - "labels" => ["bugfix"], - }, - } - end -else - desc 'Generate a Changelog from GitHub' - task :changelog do - raise <= Gem::Version.new('2.2.2')" -EOM - end -end - +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? + +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 + +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['name'] + raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal +end + +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 + +PuppetLint.configuration.send('disable_relative') + +if Bundler.rubygems.find_name('github_changelog_generator').any? + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + 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; GO LABEL THEM" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["feature", "enhancement"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise <= Gem::Version.new('2.2.2')" +EOM + end +end + diff --git a/appveyor.yml b/appveyor.yml index 81be36b..e10ba3b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,60 +1,55 @@ ---- -version: 1.1.x.{build} -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: ~> 4.0 - RUBY_VERSION: 21 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 4.0 - RUBY_VERSION: 21-x64 - CHECK: parallel_spec - - - 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 +--- +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/manifests/agent/params.pp b/manifests/agent/params.pp index 8304e4c..ff54dc0 100644 --- a/manifests/agent/params.pp +++ b/manifests/agent/params.pp @@ -1,15 +1,15 @@ -# == Class: check_mk::agent::params -# -class check_mk::agent::params { - case $::osfamily { - 'RedHat': { - $config_dir = '/etc/check-mk-agent' - } - 'Debian': { - $config_dir = '/etc/check_mk' - } - default: { - fail("OS familly ${::osfamily} is not managed!") - } - } -} +# == Class: check_mk::agent::params +# +class check_mk::agent::params { + case $::osfamily { + 'RedHat': { + $config_dir = '/etc/check-mk-agent' + } + 'Debian': { + $config_dir = '/etc/check_mk' + } + default: { + fail("OS familly ${::osfamily} is not managed!") + } + } +} diff --git a/metadata.json b/metadata.json index 9731a32..8517838 100644 --- a/metadata.json +++ b/metadata.json @@ -1,58 +1,58 @@ -{ - "name": "gnubilafrance-check_mk", - "version": "0.7.2", - "author": "Baptiste Grenier ", - "summary": "Check_MK installation and configuration", - "license": "Apache-2.0", - "source": "https://github.com/gnubila-france/puppet-check_mk", - "project_page": "https://github.com/gnubila-france/puppet-check_mk", - "issues_url": "https://github.com/gnubila-france/puppet-check_mk/issues", - "dependencies": [ - { - "name": "puppetlabs/concat", - "version_requirement": ">= 4.0.0 <6.0.0" - }, - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.0.0 <6.0.0" - } - ], - "operatingsystem_support": [ - { - "operatingsystem": "RedHat", - "operatingsystemrelease": [ - "6", - "7" - ] - }, - { - "operatingsystem": "CentOS", - "operatingsystemrelease": [ - "6", - "7" - ] - }, - { - "operatingsystem": "Debian", - "operatingsystemrelease": [ - "8", - "9" - ] - } - ], - "requirements": [ - { - "name": "puppet", - "version_requirement": ">= 5.0.0 < 7.0.0" - } - ], - "tags": [ - "check_mk", - "monitoring", - "nagios", - "omd" - ], - "pdk-version": "1.7.1", - "template-url": "file://C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/pdk-templates.git", - "template-ref": "1.7.1-0-g810b982" -} +{ + "name": "gnubilafrance-check_mk", + "version": "0.7.2", + "author": "Baptiste Grenier ", + "summary": "Check_MK installation and configuration", + "license": "Apache-2.0", + "source": "https://github.com/gnubila-france/puppet-check_mk", + "project_page": "https://github.com/gnubila-france/puppet-check_mk", + "issues_url": "https://github.com/gnubila-france/puppet-check_mk/issues", + "dependencies": [ + { + "name": "puppetlabs/concat", + "version_requirement": ">= 4.0.0 <6.0.0" + }, + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.0.0 <6.0.0" + } + ], + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "8", + "9" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 5.0.0 < 7.0.0" + } + ], + "tags": [ + "check_mk", + "monitoring", + "nagios", + "omd" + ], + "pdk-version": "1.10.0", + "template-url": "C:\\Program Files\\Puppet Labs\\DevelopmentKit\\share\\cache\\pdk-templates.git#1.10.0", + "template-ref": "1.10.0-0-gbba9ac3" +} diff --git a/spec/default_facts.yml b/spec/default_facts.yml index 9553ec1..ea1e480 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -1,8 +1,7 @@ -# Use default_module_facts.yml for module specific facts. -# -# Facts specified here will override the values provided by rspec-puppet-facts. ---- -concat_basedir: "" -ipaddress: "172.16.254.254" -is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" +# 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" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b6e69b6..93b25ec 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,44 +1,47 @@ -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' - -begin - require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) -rescue LoadError => loaderror - warn "Could not require spec_helper_local: #{loaderror.message}" -end - -include RspecPuppetFacts - -default_facts = { - puppetversion: Puppet.version, - facterversion: Facter.version, -} - -default_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')) -default_module_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')) - -if File.exist?(default_facts_path) && File.readable?(default_facts_path) - default_facts.merge!(YAML.safe_load(File.read(default_facts_path))) -end - -if File.exist?(default_module_facts_path) && File.readable?(default_module_facts_path) - default_facts.merge!(YAML.safe_load(File.read(default_module_facts_path))) -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 - 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) - last_module.const_get(next_module) - end -end - -# 'spec_overrides' from sync.yml will appear below this line +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 + +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 + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + 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 From 4029af3ebfc7e708ab697b49da354aceda0b0c4f Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Mon, 15 Apr 2019 15:48:21 +0200 Subject: [PATCH 12/13] Fix for the export host resource together with the unittests --- manifests/config.pp | 14 ++++++--- manifests/host.pp | 4 +-- spec/classes/check_mk_config_spec.rb | 7 ++++- spec/defines/check_mk_host_spec.rb | 44 ++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 spec/defines/check_mk_host_spec.rb diff --git a/manifests/config.pp b/manifests/config.pp index ddbba76..1586d04 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -22,9 +22,10 @@ } concat { "${etc_dir}/check_mk/main.mk": - owner => $site, - group => $site, - mode => '0644', + owner => $site, + group => $site, + mode => '0644', + notify => Exec['check_mk-reload'], } # # all_hosts @@ -94,7 +95,12 @@ order => 99, } - # In the original code 3 execs would be here, but is is not recommended + exec { 'check_mk-reload': + command => "/bin/su -l -c '${bin_dir}/check_mk --reload' ${site}", + refreshonly => true, + } + + # In the original code 2 execs would be here, but is is not recommended # to do a reindex, see https://mathias-kettner.de/checkmk_inventory.html # This breaks large installs. The services class is subscribed to the # config class so new changes should be noticed automatically. diff --git a/manifests/host.pp b/manifests/host.pp index cc3df00..cb43f0f 100644 --- a/manifests/host.pp +++ b/manifests/host.pp @@ -2,8 +2,8 @@ # # Resource to create a check_mk host define check_mk::host ( - $target = undef, - $host_tags = [], + Optional[String] $target = undef, + Optional[Array] $host_tags = [], ) { $host = $title if size($host_tags) > 0 { diff --git a/spec/classes/check_mk_config_spec.rb b/spec/classes/check_mk_config_spec.rb index 1b79590..2927070 100644 --- a/spec/classes/check_mk_config_spec.rb +++ b/spec/classes/check_mk_config_spec.rb @@ -32,7 +32,7 @@ 'owner' => 'TEST_SITE', 'group' => 'TEST_SITE', 'mode' => '0644', - ) + ).that_notifies('Exec[check_mk-reload]') is_expected.to contain_concat__fragment('all_hosts-header').with( 'target' => '/omd/sites/TEST_SITE/etc/check_mk/main.mk', @@ -58,6 +58,11 @@ 'order' => 99, ) + is_expected.to contain_exec('check_mk-reload').with( + 'command' => '/bin/su -l -c \'/omd/sites/TEST_SITE/bin/check_mk --reload\' TEST_SITE', + 'refreshonly' => true, + ) + is_expected.not_to contain_file('/omd/sites/TEST_SITE/etc/nagios/local/hostgroups') is_expected.not_to contain_concat__fragment('host_groups-header') is_expected.not_to contain_concat__fragment('host_groups-footer') diff --git a/spec/defines/check_mk_host_spec.rb b/spec/defines/check_mk_host_spec.rb new file mode 100644 index 0000000..7f1d0bc --- /dev/null +++ b/spec/defines/check_mk_host_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' + +describe 'check_mk::host' do + let(:title) { 'host1' } + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + let(:params) do + { + target: 'target', + } + end + + it { + is_expected.to contain_check_mk__host('host1') + is_expected.to contain_concat__fragment('check_mk-host1').with( + 'target' => 'target', + 'content' => %r{^ 'host1',\n$}, + 'order' => 11, + ) + } + end + + context "on #{os} with host_tags" do + let(:facts) { os_facts } + let(:params) do + { + target: 'target', + host_tags: ['tag1', 'tag2'], + } + end + + it { + is_expected.to contain_check_mk__host('host1') + is_expected.to contain_concat__fragment('check_mk-host1').with( + 'target' => 'target', + 'content' => %r{^ 'host1|tag1|tag2',\n$}, + 'order' => 11, + ) + } + end + end +end From 4b431b6ea356d765a6162e39ef1793b78228995e Mon Sep 17 00:00:00 2001 From: Romke van Dijk Date: Mon, 15 Apr 2019 16:31:36 +0200 Subject: [PATCH 13/13] Removing tarball installer, because check_mk does not support this anymore --- manifests/install_tarball.pp | 94 ------------------------------------ 1 file changed, 94 deletions(-) delete mode 100644 manifests/install_tarball.pp diff --git a/manifests/install_tarball.pp b/manifests/install_tarball.pp deleted file mode 100644 index 5c52616..0000000 --- a/manifests/install_tarball.pp +++ /dev/null @@ -1,94 +0,0 @@ -# == Class: check_mk::install_tarball -# -# Install check_mk through a tarball -class check_mk::install_tarball ( - $filestore, - $version, - $workspace, -) { - package { 'nagios': - ensure => present, - notify => Exec['set-nagiosadmin-password', 'set-guest-password', 'add-apache-to-nagios-group'], - } - file { '/etc/nagios/passwd': - ensure => present, - owner => 'root', - group => 'apache', - mode => '0640', - } - exec { 'set-nagiosadmin-password': - command => '/usr/bin/htpasswd -b /etc/nagios/passwd nagiosadmin letmein', - refreshonly => true, - require => File['/etc/nagios/passwd'], - } - exec { 'set-guest-password': - command => '/usr/bin/htpasswd -b /etc/nagios/passwd guest guest', - refreshonly => true, - require => File['/etc/nagios/passwd'], - } - exec { 'add-apache-to-nagios-group': - command => '/usr/sbin/usermod -a -G nagios apache', - refreshonly => true, - } - package { 'nagios-plugins-all': - ensure => present, - require => Package['nagios'], - } - package { [ 'xinetd', 'mod_python', 'make', 'gcc-c++', 'tar', 'gzip' ]: - ensure => present, - } - file { "${workspace}/check_mk-${version}.tar.gz": - ensure => present, - source => "${filestore}/check_mk-${version}.tar.gz", - } - exec { 'unpack-check_mk-tarball': - command => "/bin/tar -zxf ${workspace}/check_mk-${version}.tar.gz", - cwd => $workspace, - creates => "${workspace}/check_mk-${version}", - require => File["${workspace}/check_mk-${version}.tar.gz"], - } - exec { 'change-setup-config-location': - command => "/usr/bin/perl -pi -e 's#^SETUPCONF=.*?$#SETUPCONF=${workspace}/check_mk_setup.conf#' ${workspace}/check_mk-${version}/setup.sh", # lint:ignore:140chars - unless => "/bin/egrep '^SETUPCONF=${workspace}/check_mk_setup.conf$' ${workspace}/check_mk-${version}/setup.sh", - require => Exec['unpack-check_mk-tarball'], - } - # Avoid header like 'Written by setup of check_mk 1.2.0p3 at Thu Feb 7 12:26:17 GMT 2013' - # that changes every time the setup script is run - exec { 'remove-setup-header': - command => "/usr/bin/perl -pi -e 's#^DIRINFO=.*?$#DIRINFO=#' ${workspace}/check_mk-${version}/setup.sh", - unless => "/bin/egrep '^DIRINFO=$' ${workspace}/check_mk-${version}/setup.sh", - require => Exec['unpack-check_mk-tarball'], - } - file { "${workspace}/check_mk_setup.conf": - ensure => present, - content => template('check_mk/setup.conf.erb'), - notify => Exec['check_mk-setup'], - } - file { '/etc/nagios/check_mk': - ensure => directory, - owner => 'nagios', - group => 'nagios', - recurse => true, - require => Package['nagios'], - } - file { '/etc/nagios/check_mk/hostgroups': - ensure => directory, - owner => 'nagios', - group => 'nagios', - require => File['/etc/nagios/check_mk'], - } - exec { 'check_mk-setup': - command => "${workspace}/check_mk-${version}/setup.sh --yes", - cwd => "${workspace}/check_mk-${version}", - refreshonly => true, - require => [ - Exec['change-setup-config-location'], - Exec['remove-setup-header'], - Exec['unpack-check_mk-tarball'], - File["${workspace}/check_mk_setup.conf"], - File['/etc/nagios/check_mk'], - Package['nagios'], - ], - notify => Class['check_mk::service'], - } -}