diff --git a/.gitignore b/.gitignore index fa9c9ca..988dcbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,28 @@ -pkg/ -spec/fixtures/ +.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 -Gemfile.lock -.vagrant -log/ +.project +.envrc +/inventory.yaml +/spec/fixtures/litmus_inventory.yaml diff --git a/.rspec b/.rspec index 4e1e0d2..16f9cdb 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ --color +--format documentation diff --git a/.travis.yml b/.travis.yml index e36086e..444e17a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,45 @@ --- -sudo: false +os: linux +dist: xenial language: ruby -bundler_args: --without development system_tests -before_install: rm Gemfile.lock || true -rvm: - - 1.9.3 - - 2.0.0 - - 2.1.0 +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v script: - - bundle exec rake syntax - - bundle exec rake lint - - bundle exec rake spec -env: - - PUPPET_GEM_VERSION="~> 3.6.0" STRICT_VARIABLES=yes - - PUPPET_GEM_VERSION="~> 3.7.0" STRICT_VARIABLES=yes - - PUPPET_GEM_VERSION="~> 3.8.0" STRICT_VARIABLES=yes FUTURE_PARSER=yes - - PUPPET_GEM_VERSION="~> 4.1.0" - - PUPPET_GEM_VERSION="~> 4.2.0" + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.5.7 +stages: + - static + - spec + - acceptance + - + if: tag =~ ^v\d + name: deploy +jobs: + fast_finish: true + include: + - + env: CHECK="validate lint check rubocop" + stage: static + - + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.7 + stage: spec + - + env: DEPLOY_TO_FORGE=yes + stage: deploy +branches: + only: + - main + - /^v\d/ +notifications: + email: false diff --git a/Gemfile b/Gemfile index dbfe086..a167b88 100644 --- a/Gemfile +++ b/Gemfile @@ -1,39 +1,62 @@ -source ENV['GEM_SOURCE'] || "https://rubygems.org" - -group :test do - gem 'rake', '< 11.0' - gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 4.0.0' - gem "rspec", '< 3.2.0' - gem "rspec-puppet" - gem "puppetlabs_spec_helper" - gem "metadata-json-lint" - gem "rspec-puppet-facts" - gem 'rubocop', '0.33.0' - gem 'simplecov', '>= 0.11.0' - gem 'simplecov-console' - - gem "puppet-lint-absolute_classname-check" - gem "puppet-lint-leading_zero-check" - gem "puppet-lint-trailing_comma-check" - gem "puppet-lint-version_comparison-check" - gem "puppet-lint-classes_and_types_beginning_with_digits-check" - gem "puppet-lint-unquoted_string-check" - gem 'puppet-lint-resource_reference_syntax' +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 "travis" - gem "travis-lint" - gem "puppet-blacksmith" - gem "guard-rake" - gem 'json_pure', '<= 2.0.1', :require => false if RUBY_VERSION < '2.0.0' - gem 'safe_yaml', '~> 1.0.4' + gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] end - group :system_tests do - gem "beaker" - gem "beaker-rspec" - gem "beaker-puppet_install_helper" + gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] end -# vim:ft=ruby +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 + +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/README.md b/README.md index 2c040d1..bc03f71 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,11 @@ on Linux based systems. **NOTE: You must have a proper MTA installed and configured to send mail externally.** -### Stdlib +By default, logwatch will monitor all services it knows how to. -This module requires puppetlabs-stdlib >= 3.2.0 +### Concat + +This module requires puppetlabs-concat >= 2.2.1 ### What logwatch affects @@ -84,15 +86,16 @@ Add a regex to `ignore.conf` to suppress that output from the logwatch report ##### `logwatch` ``` -output -format -mail_to -mail_from -range -detail -service -package_ensure -package_name + $output - Acceptable values include unformatted, stdout - defaults to 'unformatted' + $format - Acceptable values include html or text - defaults to 'text' + $mail_to - Array of email addresses to send to + $mail_from - email address for logwatch 'from' emails + $range - Requires a regex op ^All$, ^Today$, or ^Yesterday$. + $detail - Requires a regex of ^Low$, ^Med$, or ^$High'. + $service - Array of services to watch, defaults to 'All' + $package_ensure - ensure the package is installed or latest or present + $package_name - the name of the pacakge to install, logwatch typically is sufficient + ``` ##### `logwatch::ignore` @@ -103,13 +106,13 @@ regex ## Limitations -This module has been built on and tested against Puppet 3. +This module has been built on and tested against Puppet 6. The module has been tested on: -* RedHat Enterprise Linux 6/7 -* CentOS 6/7 -* Ubuntu 12.04/14.04 +* RedHat Enterprise Linux 7/8 (including Rocky Linux) +* CentOS 7/8 +* Ubuntu 18.04/20.04 ## Development diff --git a/Rakefile b/Rakefile index c254254..0f8754e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,16 +1,89 @@ +# frozen_string_literal: true + +require 'bundler' +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' - -PuppetLint.configuration.fail_on_warnings -PuppetLint.configuration.send('relative') -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send('disable_class_parameter_defaults') -PuppetLint.configuration.send('disable_documentation') -PuppetLint.configuration.send('disable_single_quote_string_with_variables') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] - -desc "Run acceptance tests" -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' +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 + returnVal ||= begin + metadata_source = JSON.load(File.read('metadata.json'))['source'] + metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) + + metadata_source_match && metadata_source_match[1] + end + + raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? + + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal end + +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; LABEL THEM ON GITHUB" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["enhancement", "feature"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bug", "documentation", "bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise < 1.15' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" +EOM + end +end + diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..2fbf0ff --- /dev/null +++ b/data/common.yaml @@ -0,0 +1 @@ +--- {} diff --git a/manifests/init.pp b/manifests/init.pp index 51b0626..ee8c071 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,39 +3,31 @@ # This class configures Logwatch # # Parameters -# $output -# $format -# $mail_to -# $mail_from -# $range -# $detail -# $service -# $package_ensure -# $package_name +# $output - unformatted, stdout - defaults to 'unformatted' +# $format - html or text - defaults to 'text' +# $mail_to - Array of email addresses to send to +# $mail_from - email address for logwatch 'from' emails +# $range - Requires a regex op ^All$, ^Today$, or ^Yesterday$. +# $detail - Requires a regex of ^Low$, ^Med$, or ^$High'. +# $service - Array of services to watch, defaults to 'All' +# $package_ensure - ensure the package is installed or latest or present +# $package_name - the name of the pacakge to install, logwatch typically is sufficient # class logwatch ( - $output = $logwatch::params::output, - $format = $logwatch::params::format, - $mail_to = $logwatch::params::mail_to, - $mail_from = $logwatch::params::mail_from, - $range = $logwatch::params::range, - $detail = $logwatch::params::detail, - $service = $logwatch::params::service, - $package_ensure = $logwatch::params::package_ensure, - $package_name = $logwatch::params::package_name, - $ignore_conf = $logwatch::params::ignore_conf, + Array $service = $logwatch::params::service, + Array $mail_to = $logwatch::params::mail_to, + String $output = $logwatch::params::output, + String $format = $logwatch::params::format, + String $mail_from = $logwatch::params::mail_from, + String $package_ensure = $logwatch::params::package_ensure, + String $package_name = $logwatch::params::package_name, + Optional $ignore_conf = $logwatch::params::ignore_conf, + Variant[ String, Enum[ 'All', 'Today', 'Yesterday' ] ] + $range = $logwatch::params::range, + Variant[ String, Enum[ 'Low', 'Med', 'High' ] ] + $detail = $logwatch::params::detail, ) inherits logwatch::params { - validate_string($output) - validate_string($format) - validate_array($mail_to) - validate_string($mail_from) - validate_re($range, ['^All$', '^Today$', '^Yesterday$']) - validate_re($detail, ['^Low$', '^Med$', '^High$']) - validate_array($service) - validate_string($package_ensure) - validate_string($package_name) - anchor { 'logwatch::begin': } -> class { '::logwatch::install': } -> class { '::logwatch::config': } diff --git a/manifests/params.pp b/manifests/params.pp index c6a52c9..9f85b10 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -2,14 +2,8 @@ # class logwatch::params { - $output = $::osfamily ? { - 'RedHat' => 'unformatted', - default => 'stdout', - } - $format = $::osfamily ? { - 'RedHat' => 'text', - default => 'test', - } + $output = 'unformatted' + $format = 'text' $mail_to = [ 'root' ] $mail_from = 'Logwatch' $range = 'Yesterday' diff --git a/metadata.json b/metadata.json index 1c2b541..9d81dfd 100644 --- a/metadata.json +++ b/metadata.json @@ -7,10 +7,20 @@ "source": "https://github.com/jonmosco/puppet-logwatch", "project_page": "https://github.com/jonmosco/puppet-logwatch", "issues_url": "https://github.com/jonmosco/puppet-logwatch/issues", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.2.0 < 5.0.0" + }, + { + "name": "puppetlabs/concat", + "version_requirement": ">= 2.2.1 < 3.0.0" + } + ], "operatingsystem_support": [ { "operatingsystem": "RedHat", - "operatingsystemrelease": [ + "operatingsystemrelease": [ "5", "6", "7" @@ -18,7 +28,7 @@ }, { "operatingsystem": "CentOS", - "operatingsystemrelease": [ + "operatingsystemrelease": [ "5", "6", "7" @@ -50,14 +60,7 @@ "version_requirement": ">= 3.0.0 < 5.0.0" } ], - "dependencies": [ - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.2.0 < 5.0.0" - }, - { - "name": "puppetlabs/concat", - "version_requirement": ">= 2.2.1 < 3.0.0" - } - ] + "pdk-version": "2.3.0", + "template-url": "pdk-default#2.3.0", + "template-ref": "tags/2.3.0-0-g8aaceff" } diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..f777abf --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,8 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +ipaddress: "172.16.254.254" +ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..9b1fa6f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,73 @@ +# frozen_string_literal: true + +RSpec.configure do |c| + c.mock_with :rspec +end + require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' + +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + +include RspecPuppetFacts + +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) + + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end + +# read default_facts and merge them over what is provided by facterdb +default_facts.each do |fact, value| + add_custom_fact fact, value +end + +RSpec.configure do |c| + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end +end + +# Ensures that a module is defined +# @param module_name Name of the module +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end +end + +# 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 2b69740..5c42c54 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -17,7 +17,7 @@ # Install module puppet_module_install(:source => proj_root, :module_name => 'logwatch') hosts.each do |host| - on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module','install','puppetlabs-concat'), { :acceptable_exit_codes => [0,1] } end end end