diff --git a/.delivery/project.toml b/.delivery/project.toml new file mode 100644 index 0000000..6d5e361 --- /dev/null +++ b/.delivery/project.toml @@ -0,0 +1 @@ +remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml" diff --git a/.kitchen.dokken.yml b/.kitchen.dokken.yml deleted file mode 100644 index b4d4e3a..0000000 --- a/.kitchen.dokken.yml +++ /dev/null @@ -1,124 +0,0 @@ ---- -driver: - name: dokken - privileged: true - -transport: - name: dokken - -verifier: - name: inspec - -provisioner: - name: dokken - attributes: - apt: - confd: - install_recommends: false - -platforms: - - name: ubuntu14 - driver: - image: ubuntu:14.04 - pid_one_command: /sbin/init - intermediate_instructions: - - RUN /usr/bin/apt-get update -qq - - RUN /usr/bin/apt-get install -y net-tools apt-transport-https initscripts procps lsb-release curl gnupg - - - name: ubuntu16 - driver: - image: ubuntu:16.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update -qq - - RUN /usr/bin/apt-get install -y net-tools apt-transport-https initscripts procps lsb-release curl gnupg - - - name: debian8 - driver: - image: dokken/debian-8 - pid_one_command: /sbin/init - intermediate_instructions: - - RUN /usr/bin/apt-get update -qq - - RUN /usr/bin/apt-get install -y net-tools apt-transport-https initscripts procps lsb-release curl gnupg - - - name: debian9 - driver: - image: dokken/debian-9 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update -qq - - RUN /usr/bin/apt-get install -y net-tools apt-transport-https initscripts procps lsb-release curl gnupg - - - name: centos6 - driver: - image: centos:6.9 - pid_one_command: /sbin/init - platform: rhel - intermediate_instructions: - - RUN yum install -y net-tools initscripts which curl - - - name: centos7 - driver: - image: centos:7 - pid_one_command: /usr/lib/systemd/systemd - platform: rhel - intermediate_instructions: - - RUN yum install -y net-tools initscripts systemd-sysv which lsof curl - - - name: fedora26 - driver: - image: fedora:26 - pid_one_command: /usr/lib/systemd/systemd - platform: rhel - intermediate_instructions: - - RUN yum install -y net-tools initscripts systemd-sysv which lsof curl - - - name: amazon - driver: - image: amazonlinux:2017.03 - pid_one_command: /sbin/init - platform: amazon - intermediate_instructions: - - RUN yum install -y net-tools initscripts which - - - name: amazon2 - driver: - image: amazonlinux:2 - pid_one_command: /usr/lib/systemd/systemd - platform: amazon - intermediate_instructions: - - RUN yum install -y net-tools initscripts - -suites: - - name: chef13 - driver: - chef_version: 13.11.3 - verifier: - inspec_tests: - - test/smoke/v6 - run_list: - - recipe[filebeat_test::defaultv6] - - - name: chef14 - driver: - chef_version: 14.5.33 - verifier: - inspec_tests: - - test/smoke/v6 - run_list: - - recipe[filebeat_test::defaultv6] - - - name: chef14runit - driver: - chef_version: 14.5.33 - verifier: - inspec_tests: - - test/smoke/v6runit - run_list: - - recipe[filebeat_test::defaultv6runit] - - - name: chef14preview - driver: - chef_version: 14.5.33 - run_list: - - recipe[filebeat_test::defaultv6preview] diff --git a/.rubocop.yml b/.rubocop.yml index e9f9945..441c998 100755 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ AllCops: + # TargetRubyVersion: 2.3 Exclude: - Rakefile - Berksfile @@ -39,3 +40,5 @@ AbcSize: Enabled: false Style/BlockComments: Enabled: false +ChefModernize/WindowsZipfileUsage: + Enabled: false diff --git a/.travis.yml b/.travis.yml index 7146e63..24eaf12 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,10 @@ -sudo: required -dist: trusty - addons: apt: sources: - - chef-stable-trusty + - chef-stable-xenial packages: - - chefdk + - chef-workstation -# Don't run bundle install install: echo "skip bundle install" branches: @@ -20,28 +16,47 @@ services: docker env: matrix: - - INSTANCE=chef13-centos6 - - INSTANCE=chef13-centos7 - - INSTANCE=chef13-fedora26 - - INSTANCE=chef13-ubuntu14 - - INSTANCE=chef13-ubuntu16 - - INSTANCE=chef13-amazon - - INSTANCE=chef13-amazon2 - -script: - - KITCHEN_LOCAL_YAML=.kitchen.dokken.yml /opt/chefdk/embedded/bin/kitchen verify ${INSTANCE} - - cat .kitchen/logs/kitchen.log + - INSTANCE=current-ver-amazonlinux + - INSTANCE=current-ver-amazonlinux-2 + - INSTANCE=current-ver-debian-9 + - INSTANCE=current-ver-debian-10 + - INSTANCE=current-ver-centos-7 + - INSTANCE=current-ver-centos-8 + - INSTANCE=current-ver-oraclelinux-7 + - INSTANCE=current-ver-oraclelinux-8 + - INSTANCE=current-ver-fedora-latest + - INSTANCE=current-ver-ubuntu-1804 + - INSTANCE=current-ver-ubuntu-2004 + - INSTANCE=previous-ver-amazonlinux + - INSTANCE=previous-ver-amazonlinux-2 + - INSTANCE=previous-ver-debian-9 + - INSTANCE=previous-ver-debian-10 + - INSTANCE=previous-ver-centos-7 + - INSTANCE=previous-ver-centos-8 + - INSTANCE=previous-ver-oraclelinux-7 + - INSTANCE=previous-ver-oraclelinux-8 + - INSTANCE=previous-ver-fedora-latest + - INSTANCE=previous-ver-ubuntu-1804 + - INSTANCE=previous-ver-ubuntu-2004 before_script: - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) - - eval "$(/opt/chefdk/bin/chef shell-init bash)" - - /opt/chefdk/embedded/bin/chef --version - - /opt/chefdk/embedded/bin/cookstyle --version - - /opt/chefdk/embedded/bin/foodcritic --version + - eval "$(chef shell-init bash)" + - chef --version +script: CHEF_LICENSE=accept KITCHEN_LOCAL_YAML=kitchen.dokken.yml kitchen verify ${INSTANCE} matrix: + allow_failures: + - env: INSTANCE=previous-ver-oraclelinux-7 + - env: INSTANCE=previous-ver-oraclelinux-8 + - env: INSTANCE=current-ver-oraclelinux-7 + - env: INSTANCE=current-ver-oraclelinux-8 + - env: INSTANCE=previous-ver-fedora-latest + - env: INSTANCE=current-ver-fedora-latest include: - script: - - /opt/chefdk/bin/chef exec rake - env: UNIT_AND_LINT=1 + - delivery local all + env: + - UNIT_AND_LINT=1 + - CHEF_LICENSE=accept diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c95d6..77c9c4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,32 @@ filebeat CHANGELOG ================== -2.3.0 +2.4.0 ----- - Piotr Kantyka - Added property for prefix in prospector yaml filename +- Oskar Bedychaj - Added filebeat_install no resource handle + +- Neil Duff-Howie - Fixed runit service when a service name is supplied + +- Doug Luxem - Fixes Windows issue where filebeats service is reinstalled on each run + +- Chris Minton - Update the config and prospector resources to handle version dependency + +- Chris Minton - Update the integration tests for configs + +- Chris Minton - Update the README to give the correct configuration for different versions + +- Virender Khatri - Updated Kitchen Tests + +- Virender Khatri - Update filebeat version to the latest + +- Virender Khatri - Fix issue #159 - Filebeat 7.x replaces filebeat.registry_file with filebeat.registry.path + +- Virender Khatri - Update dependency cookbook versions + + 2.2.0 ----- diff --git a/README.md b/README.md index f817321..e99793d 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ This is a [Chef] cookbook to manage [Filebeat]. ## Most Recent Release ```ruby -cookbook 'filebeat', '~> 2.2.0' +cookbook 'filebeat', '~> 2.4.0' ``` ## From Git ```ruby -cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.2.0' +cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.4.0' ``` ## Repository @@ -39,14 +39,12 @@ Also works on Solaris zones given a physical Solaris 11.2 server. For that, use ## Supported Chef -- Chef 12 (last tested on 12.21.4) - -- Chef 13 (last tested on 13.3.42) +This cookbook is tested against current Chef version. But, the cookbook is known to work with Chef Client version >=12.14. ## Supported Filebeat -- 5.x - 6.x +- 7.x ## Cookbook Dependency diff --git a/kitchen.dokken.yml b/kitchen.dokken.yml new file mode 100644 index 0000000..ed9b0ed --- /dev/null +++ b/kitchen.dokken.yml @@ -0,0 +1,105 @@ +--- +driver: + name: dokken + privileged: true + chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> + chef_license: accept-no-persist + +transport: + name: dokken + +provisioner: + name: dokken + attributes: + apt: + confd: + install_recommends: false + +verifier: + name: inspec + +platforms: +- name: amazonlinux + driver: + image: dokken/amazonlinux + pid_one_command: /sbin/init + +- name: amazonlinux-2 + driver: + image: dokken/amazonlinux-2 + pid_one_command: /usr/lib/systemd/systemd + +- name: debian-9 + driver: + image: dokken/debian-9 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + +- name: debian-10 + driver: + image: dokken/debian-10 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + +- name: centos-7 + driver: + image: dokken/centos-7 + pid_one_command: /usr/lib/systemd/systemd + +- name: centos-8 + driver: + image: dokken/centos-8 + pid_one_command: /usr/lib/systemd/systemd + +- name: oraclelinux-7 + driver: + image: dokken/oraclelinux-7 + pid_one_command: /usr/lib/systemd/systemd + +- name: oraclelinux-8 + driver: + image: dokken/oraclelinux-8 + pid_one_command: /usr/lib/systemd/systemd + +- name: fedora-latest + driver: + image: dokken/fedora-latest + pid_one_command: /usr/lib/systemd/systemd + +- name: ubuntu-18.04 + driver: + image: dokken/ubuntu-18.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + +- name: ubuntu-20.04 + driver: + image: dokken/ubuntu-20.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + +suites: + - name: current-ver + verifier: + inspec_tests: + - test/smoke/current-ver + run_list: + - recipe[filebeat_test::current-ver] + + - name: previous-ver + verifier: + inspec_tests: + - test/smoke/previous-ver + run_list: + - recipe[filebeat_test::previous-ver] + + - name: runit + verifier: + inspec_tests: + - test/smoke/runit + run_list: + - recipe[filebeat_test::runit] diff --git a/.kitchen.yml b/kitchen.yml similarity index 96% rename from .kitchen.yml rename to kitchen.yml index 2805296..6030543 100644 --- a/.kitchen.yml +++ b/kitchen.yml @@ -18,13 +18,13 @@ provisioner: install_recommends: false platforms: - - name: ubuntu-14.04 + - name: ubuntu-18.04 run_list: - recipe[apt] - - name: centos-6.8 + - name: centos-7.6 run_list: - recipe[yum] - - name: centos-7.2 + - name: centos-8.0 run_list: - recipe[yum] - name: windows-2012R2 diff --git a/.kitchen.zone.yml b/kitchen.zone.yml similarity index 100% rename from .kitchen.zone.yml rename to kitchen.zone.yml diff --git a/libraries/matchers.rb b/libraries/matchers.rb index 4a911e4..8b13789 100644 --- a/libraries/matchers.rb +++ b/libraries/matchers.rb @@ -1,47 +1 @@ -if defined?(ChefSpec) - ChefSpec.define_matcher(:filebeat_install) - ChefSpec.define_matcher(:filebeat_install_preview) - ChefSpec.define_matcher(:filebeat_config) - ChefSpec.define_matcher(:filebeat_prospector) - ChefSpec.define_matcher(:filebeat_service) - def create_filebeat_install_preview(install) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_install_preview, :create, install) - end - - def delete_filebeat_install_preview(install) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_install_preview, :delete, install) - end - - def create_filebeat_install(install) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_install, :create, install) - end - - def delete_filebeat_install(install) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_install, :delete, install) - end - - def create_filebeat_service(service) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_service, :create, service) - end - - def delete_filebeat_service(service) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_service, :delete, service) - end - - def create_filebeat_config(config) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_config, :create, config) - end - - def delete_filebeat_config(config) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_config, :delete, config) - end - - def create_filebeat_prospector(prospector) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_prospector, :create, prospector) - end - - def delete_filebeat_prospector(prospector) - ChefSpec::Matchers::ResourceMatcher.new(:filebeat_prospector, :delete, prospector) - end -end diff --git a/metadata.rb b/metadata.rb index baacbc0..d8b1bf1 100644 --- a/metadata.rb +++ b/metadata.rb @@ -3,18 +3,17 @@ maintainer_email 'vir.khatri@gmail.com' license 'Apache-2.0' description 'Installs/Configures Elastic Filebeat' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '2.3.1' -source_url 'https://github.com/vkhatri/chef-filebeat' if respond_to?(:source_url) -issues_url 'https://github.com/vkhatri/chef-filebeat/issues' if respond_to?(:issues_url) -chef_version '>= 12.14' if respond_to?(:chef_version) +version '2.4.0' +source_url 'https://github.com/vkhatri/chef-filebeat' +issues_url 'https://github.com/vkhatri/chef-filebeat/issues' +chef_version '>= 12.14' depends 'homebrew', '~> 4.2' -depends 'elastic_repo', '>= 1.1.1' -depends 'yum-plugin-versionlock', '>= 0.1.2' +depends 'elastic_repo', '>= 1.2.0' +depends 'yum-plugin-versionlock', '>= 0.2.1' depends 'runit' depends 'windows' -%w[windows debian ubuntu centos amazon redhat fedora].each do |os| +%w(windows debian ubuntu centos amazon redhat fedora).each do |os| supports os end diff --git a/resources/config.rb b/resources/config.rb index 7e3efe2..28530d8 100755 --- a/resources/config.rb +++ b/resources/config.rb @@ -1,5 +1,5 @@ # -# Cookbook Name:: filebeat +# Cookbook:: filebeat # Resource:: filebeat_config # @@ -10,10 +10,10 @@ property :service_name, String, default: 'filebeat' property :filebeat_install_resource_name, String, default: 'default' property :config, Hash, default: default_config -property :conf_file, [String, NilClass], default: nil -property :disable_service, [TrueClass, FalseClass], default: false -property :notify_restart, [TrueClass, FalseClass], default: true -property :config_sensitive, [TrueClass, FalseClass], default: false +property :conf_file, [String, NilClass] +property :disable_service, [true, false], default: false +property :notify_restart, [true, false], default: true +property :config_sensitive, [true, false], default: false default_action :create @@ -26,14 +26,20 @@ new_resource.conf_file = new_resource.conf_file || default_conf_file(filebeat_install_resource.conf_dir) config = new_resource.config.dup - logging_files_path = node['platform'] == 'windows' ? "#{filebeat_install_resource.conf_dir}/logs" : filebeat_install_resource.log_dir + logging_files_path = platform?('windows') ? "#{filebeat_install_resource.conf_dir}/logs" : filebeat_install_resource.log_dir - config['filebeat.registry_file'] = node['platform'] == 'windows' ? "#{filebeat_install_resource.conf_dir}/registry" : '/var/lib/filebeat/registry' config['logging.files']['path'] ||= logging_files_path + + if filebeat_install_resource.version.to_f >= 7.0 + config['filebeat.registry.path'] = platform?('windows') ? "#{filebeat_install_resource.conf_dir}/registry" : '/var/lib/filebeat/registry' + else + config['filebeat.registry_file'] = platform?('windows') ? "#{filebeat_install_resource.conf_dir}/registry" : '/var/lib/filebeat/registry' + end + if filebeat_install_resource.version.to_f >= 6.0 config['filebeat.config.inputs'] ||= { 'enabled' => true, - 'path' => "#{filebeat_install_resource.prospectors_dir}/*.yml", + 'path' => "#{filebeat_install_resource.prospectors_dir}/*.yml", } else config['filebeat.config_dir'] = filebeat_install_resource.prospectors_dir @@ -48,7 +54,7 @@ file new_resource.conf_file do content JSON.parse(config.to_json).to_yaml.lines.to_a[1..-1].join notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service - mode 0o600 + mode '600' sensitive new_resource.config_sensitive end diff --git a/resources/install.rb b/resources/install.rb index 69a522e..5d8eef2 100755 --- a/resources/install.rb +++ b/resources/install.rb @@ -1,21 +1,21 @@ # -# Cookbook Name:: filebeat +# Cookbook:: filebeat # Resource:: filebeat_install # resource_name :filebeat_install -property :version, String, default: '6.4.2' +property :version, String, default: '7.6.2' property :release, String, default: '1' -property :setup_repo, [TrueClass, FalseClass], default: true -property :ignore_package_version, [TrueClass, FalseClass], default: false +property :setup_repo, [true, false], default: true +property :ignore_package_version, [true, false], default: false property :service_name, String, default: 'filebeat' -property :notify_restart, [TrueClass, FalseClass], default: true -property :disable_service, [TrueClass, FalseClass], default: false -property :delete_prospectors_dir, [TrueClass, FalseClass], default: false -property :conf_dir, [String, NilClass], default: nil -property :prospectors_dir, [String, NilClass], default: nil -property :log_dir, [String, NilClass], default: nil +property :notify_restart, [true, false], default: true +property :disable_service, [true, false], default: false +property :delete_prospectors_dir, [true, false], default: false +property :conf_dir, [String, NilClass] +property :prospectors_dir, [String, NilClass] +property :log_dir, [String, NilClass] property :windows_package_url, String, default: 'auto' property :windows_base_dir, String, default: 'C:/opt/filebeat' property :apt_options, String, default: "-o Dpkg::Options::='--force-confnew' --force-yes" @@ -27,7 +27,7 @@ new_resource.conf_dir = new_resource.conf_dir || default_config_dir(new_resource.version, new_resource.windows_base_dir) new_resource.prospectors_dir = new_resource.prospectors_dir || default_prospectors_dir(new_resource.conf_dir) new_resource.log_dir = new_resource.log_dir || default_log_dir(new_resource.conf_dir) - version_string = %w[fedora rhel amazon].include?(node['platform_family']) ? "#{new_resource.version}-#{new_resource.release}" : new_resource.version + version_string = platform_family?('fedora', 'rhel', 'amazon') ? "#{new_resource.version}-#{new_resource.release}" : new_resource.version with_run_context(:root) do edit_resource(:service, new_resource.service_name) do @@ -36,13 +36,13 @@ end ## install filebeat MacOS - if node['platform'] == 'mac_os_x' + if platform?('mac_os_x') include_recipe 'homebrew' # The brew package does not create the 'filebeat' directory in '/etc'. directory '/etc/filebeat' do action :create - mode 0o0755 + mode '755' owner 'root' group 'wheel' end @@ -60,7 +60,7 @@ end ## install filebeat windows - if node['platform'] == 'windows' + if platform?('windows') package_url = win_package_url(new_resource.version, new_resource.windows_package_url) package_file = ::File.join(Chef::Config[:file_cache_path], ::File.basename(package_url)) @@ -89,7 +89,7 @@ end ## install filebeat yum/apt - if %w[fedora rhel amazon debian].include?(node['platform_family']) + if platform_family?('fedora', 'rhel', 'amazon', 'debian') # setup yum/apt repository elastic_repo_opts = new_resource.elastic_repo_options.dup elastic_repo_opts['version'] = new_resource.version @@ -123,9 +123,9 @@ package 'filebeat' do # ~FC009 version version_string unless new_resource.ignore_package_version - options new_resource.apt_options if new_resource.apt_options && node['platform_family'] == 'debian' + options new_resource.apt_options if new_resource.apt_options && platform_family?('debian') notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service - if %w[rhel amazon].include?(node['platform_family']) + if platform_family?('rhel', 'amazon') flush_cache(:before => true) allow_downgrade true end @@ -133,10 +133,10 @@ end directory new_resource.log_dir do - mode 0o755 + mode '755' end - prospectors_dir_action = new_resource.delete_prospectors_dir ? %i[delete create] : %i[create] + prospectors_dir_action = new_resource.delete_prospectors_dir ? %i(delete create) : %i(create) directory new_resource.prospectors_dir do recursive true diff --git a/resources/install_preview.rb b/resources/install_preview.rb index 14ef89b..98c78f3 100755 --- a/resources/install_preview.rb +++ b/resources/install_preview.rb @@ -1,5 +1,5 @@ # -# Cookbook Name:: filebeat +# Cookbook:: filebeat # Resource:: filebeat_install_preview # @@ -7,18 +7,18 @@ property :version, String, default: '6.0.0-rc2' property :service_name, String, default: 'filebeat' -property :notify_restart, [TrueClass, FalseClass], default: true -property :disable_service, [TrueClass, FalseClass], default: false -property :delete_prospectors_dir, [TrueClass, FalseClass], default: false +property :notify_restart, [true, false], default: true +property :disable_service, [true, false], default: false +property :delete_prospectors_dir, [true, false], default: false property :package_url, String, default: 'auto' -property :conf_dir, [String, NilClass], default: nil -property :prospectors_dir, [String, NilClass], default: nil -property :log_dir, [String, NilClass], default: nil +property :conf_dir, [String, NilClass] +property :prospectors_dir, [String, NilClass] +property :log_dir, [String, NilClass] property :windows_base_dir, String, default: 'C:/opt/filebeat' -property :apt_install_options, [String, NilClass], default: nil +property :apt_install_options, [String, NilClass] default_action :create @@ -33,10 +33,10 @@ end end - if %w[fedora rhel amazon].include?(node['platform_family']) + if platform_family?('fedora', 'rhel', 'amazon') package_arch = node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'i686' package_family = 'rpm' - elsif node['platform_family'] == 'debian' + elsif platform_family?('debian') package_arch = node['kernel']['machine'] =~ /x86_64/ ? 'amd64' : 'i386' package_family = 'deb' else @@ -54,14 +54,14 @@ package 'filebeat' do # ~FC109 source package_file - provider Chef::Provider::Package::Dpkg if node['platform_family'] == 'debian' + provider Chef::Provider::Package::Dpkg if platform_family?('debian') end directory new_resource.log_dir do - mode 0o755 + mode '755' end - prospectors_dir_action = new_resource.delete_prospectors_dir ? %i[delete create] : %i[create] + prospectors_dir_action = new_resource.delete_prospectors_dir ? %i(delete create) : %i(create) directory new_resource.prospectors_dir do recursive true diff --git a/resources/prospector.rb b/resources/prospector.rb index 913b58c..01f62fc 100755 --- a/resources/prospector.rb +++ b/resources/prospector.rb @@ -1,5 +1,5 @@ # -# Cookbook Name:: filebeat +# Cookbook:: filebeat # Resource:: filebeat_prospector # @@ -9,11 +9,11 @@ property :filebeat_install_resource_name, String, default: 'default' property :prefix, String, default: 'lwrp-prospector-' property :config, [Array, Hash], default: {} -property :cookbook_file_name, [String, NilClass], default: nil -property :cookbook_file_name_cookbook, [String, NilClass], default: nil -property :disable_service, [TrueClass, FalseClass], default: false -property :notify_restart, [TrueClass, FalseClass], default: true -property :config_sensitive, [TrueClass, FalseClass], default: false +property :cookbook_file_name, [String, NilClass] +property :cookbook_file_name_cookbook, [String, NilClass] +property :disable_service, [true, false], default: false +property :notify_restart, [true, false], default: true +property :config_sensitive, [true, false], default: false default_action :create @@ -43,30 +43,33 @@ # ...and put this back the way we found them. YAML::ENGINE.yamler = defaultengine if Psych::VERSION.start_with?('1') + prospector_file_name = "#{new_resource.prefix}#{new_resource.name}.yml" + if new_resource.cookbook_file_name && new_resource.cookbook_file_name_cookbook cookbook_file "prospector_#{new_resource.name}" do - path ::File.join(filebeat_install_resource.prospectors_dir, "#{new_resource.prefix}#{new_resource.name}.yml") + path ::File.join(filebeat_install_resource.prospectors_dir, prospector_file_name) source new_resource.cookbook_file_name cookbook new_resource.cookbook_file_name_cookbook notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service - mode 0o600 + mode '600' sensitive new_resource.config_sensitive end else file "prospector_#{new_resource.name}" do - path ::File.join(filebeat_install_resource.prospectors_dir, "#{new_resource.prefix}#{new_resource.name}.yml") + path ::File.join(filebeat_install_resource.prospectors_dir, prospector_file_name) content file_content notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service - mode 0o600 + mode '600' sensitive new_resource.config_sensitive end end end action :delete do + prospector_file_name = "#{new_resource.prefix}#{new_resource.name}.yml" filebeat_install_resource = find_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name) file "prospector_#{new_resource.name}" do - path ::File.join(filebeat_install_resource.prospectors_dir, "#{new_resource.prefix}#{new_resource.name}.yml") + path ::File.join(filebeat_install_resource.prospectors_dir, prospector_file_name) action :delete end end diff --git a/resources/runit_service.rb b/resources/runit_service.rb index cd95c9e..f674070 100755 --- a/resources/runit_service.rb +++ b/resources/runit_service.rb @@ -1,5 +1,5 @@ # -# Cookbook Name:: filebeat +# Cookbook:: filebeat # Resource:: filebeat_runit_service # @@ -7,10 +7,10 @@ property :service_name, String, default: 'filebeat' property :filebeat_install_resource_name, String, default: 'default' -property :disable_service, [TrueClass, FalseClass], default: false -property :purge_prospectors_dir, [TrueClass, FalseClass], default: false +property :disable_service, [true, false], default: false +property :purge_prospectors_dir, [true, false], default: false property :runit_filebeat_cmd_options, String, default: '' -property :service_ignore_failure, [TrueClass, FalseClass], default: false +property :service_ignore_failure, [true, false], default: false default_action :create @@ -45,7 +45,7 @@ include_recipe 'runit::default' - service_action = new_resource.disable_service ? %i[disable stop] : %i[enable nothing] + service_action = new_resource.disable_service ? %i(disable stop) : %i(enable nothing) runit_cmd = "/usr/share/filebeat/bin/filebeat -c #{conf_file} -path.home /usr/share/filebeat -path.config #{filebeat_install_resource.conf_dir} -path.data /var/lib/filebeat -path.logs #{filebeat_install_resource.log_dir} #{new_resource.runit_filebeat_cmd_options}" runit_service new_resource.service_name do diff --git a/resources/service.rb b/resources/service.rb index 20b1056..e4ab1a9 100755 --- a/resources/service.rb +++ b/resources/service.rb @@ -1,5 +1,5 @@ # -# Cookbook Name:: filebeat +# Cookbook:: filebeat # Resource:: filebeat_service # @@ -7,10 +7,10 @@ property :service_name, String, default: 'filebeat' property :filebeat_install_resource_name, String, default: 'default' -property :disable_service, [TrueClass, FalseClass], default: false -property :purge_prospectors_dir, [TrueClass, FalseClass], default: false +property :disable_service, [true, false], default: false +property :purge_prospectors_dir, [true, false], default: false -property :service_ignore_failure, [TrueClass, FalseClass], default: false +property :service_ignore_failure, [true, false], default: false property :service_retries, Integer, default: 2 property :service_retry_delay, Integer, default: 0 @@ -45,10 +45,10 @@ not_if { new_resource.disable_service } end - service_action = new_resource.disable_service ? %i[disable stop] : %i[enable] + service_action = new_resource.disable_service ? %i(disable stop) : %i(enable) service new_resource.service_name do - provider Chef::Provider::Service::Solaris if node['platform_family'] == 'solaris2' + provider Chef::Provider::Service::Solaris if platform_family?('solaris2') retries new_resource.service_retries retry_delay new_resource.service_retry_delay supports :status => true, :restart => true diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d4cb24d..6cd424c 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,5 +13,3 @@ c.syntax = :expect end end - -at_exit { ChefSpec::Coverage.report! } diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index db9510e..d9d7f3b 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -26,7 +26,7 @@ context 'rhel-install' do let(:chef_run) do - ChefSpec::SoloRunner.new(step_into: ['filebeat_install'], platform: 'centos', version: '6.8') do |node| + ChefSpec::SoloRunner.new(step_into: ['filebeat_install'], platform: 'centos', version: '7.6') do |node| node.automatic['platform_family'] = 'rhel' end.converge(described_recipe) end @@ -50,7 +50,7 @@ context 'ubuntu-install' do let(:chef_run) do - ChefSpec::SoloRunner.new(step_into: ['filebeat_install'], platform: 'ubuntu', version: '14.04') do |node| + ChefSpec::SoloRunner.new(step_into: ['filebeat_install'], platform: 'ubuntu', version: '18.04') do |node| node.automatic['platform_family'] = 'debian' end.converge(described_recipe) end @@ -78,12 +78,12 @@ let(:node) { chef_run.node } - it 'create prospector directory C:/opt/filebeat/filebeat-6.4.2-windows-x86_64/conf.d' do - expect(chef_run).to create_directory('C:/opt/filebeat/filebeat-6.4.2-windows-x86_64/conf.d') + it 'create prospector directory C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/conf.d' do + expect(chef_run).to create_directory('C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/conf.d') end - it 'create prospector directory C:/opt/filebeat/filebeat-6.4.2-windows-x86_64/logs' do - expect(chef_run).to create_directory('C:/opt/filebeat/filebeat-6.4.2-windows-x86_64/logs') + it 'create prospector directory C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/logs' do + expect(chef_run).to create_directory('C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/logs') end it 'download filebeat package file' do @@ -129,7 +129,7 @@ context 'rhel-service' do let(:chef_run) do - ChefSpec::SoloRunner.new(step_into: ['filebeat_service'], platform: 'centos', version: '6.8') do |node| + ChefSpec::SoloRunner.new(step_into: ['filebeat_service'], platform: 'centos', version: '7.6') do |node| node.automatic['platform_family'] = 'rhel' end.converge(described_recipe) end @@ -141,7 +141,7 @@ context 'ubuntu-service' do let(:chef_run) do - ChefSpec::SoloRunner.new(step_into: ['filebeat_service'], platform: 'ubuntu', version: '14.04') do |node| + ChefSpec::SoloRunner.new(step_into: ['filebeat_service'], platform: 'ubuntu', version: '18.04') do |node| node.automatic['platform_family'] = 'debian' end.converge(described_recipe) end @@ -169,7 +169,7 @@ ############ # context 'rhel-config' do # let(:chef_run) do - # ChefSpec::SoloRunner.new(step_into: ['filebeat_config'], platform: 'centos', version: '6.8') do |node| + # ChefSpec::SoloRunner.new(step_into: ['filebeat_config'], platform: 'centos', version: '7.6') do |node| # node.automatic['platform_family'] = 'rhel' # end.converge(described_recipe) # end @@ -183,7 +183,7 @@ # # context 'ubuntu-config' do # let(:chef_run) do - # ChefSpec::SoloRunner.new(step_into: ['filebeat_config'], platform: 'ubuntu', version: '14.04') do |node| + # ChefSpec::SoloRunner.new(step_into: ['filebeat_config'], platform: 'ubuntu', version: '18.04') do |node| # node.automatic['platform_family'] = 'debian' # end.converge(described_recipe) # end @@ -205,8 +205,8 @@ # # let(:node) { chef_run.node } # - # it 'configure C:/opt/filebeat/filebeat-6.4.2-windows-x86_64/filebeat.yml' do - # expect(chef_run).to create_file('C:/opt/filebeat/filebeat-6.4.2-windows-x86_64/filebeat.yml') + # it 'configure C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/filebeat.yml' do + # expect(chef_run).to create_file('C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/filebeat.yml') # end # end end diff --git a/test/cookbooks/filebeat_test/attributes/default.rb b/test/cookbooks/filebeat_test/attributes/default.rb index 614b79f..1af4665 100644 --- a/test/cookbooks/filebeat_test/attributes/default.rb +++ b/test/cookbooks/filebeat_test/attributes/default.rb @@ -5,7 +5,7 @@ t['fields'] = { 'type' => 'test1_logs', 'engine' => 'kitchen' } t['type'] = 'log' t['input_type'] = 'log' - t['paths'] = %w[/var/log/test1.log] + t['paths'] = %w(/var/log/test1.log) t['recursive_glob_enabled'] = false t['encoding'] = 'utf-8' t['exclude_lines'] = ['^DBG'] @@ -82,15 +82,15 @@ 'paths' => ['/var/log/*.logy'], 'type' => 'log', 'fields' => { 'type' => 'extra_log_y' }, - 'exclude_files' => ['/var/log/messages', '/var/log/syslog', '/var/log/secure'] + 'exclude_files' => ['/var/log/messages', '/var/log/syslog', '/var/log/secure'], }, { 'enabled' => true, 'paths' => ['/var/log/*.logx'], 'type' => 'log', 'fields' => { 'type' => 'extra_log_x' }, - 'exclude_files' => ['/var/log/messages', '/var/log/syslog', '/var/log/secure'] - } + 'exclude_files' => ['/var/log/messages', '/var/log/syslog', '/var/log/secure'], + }, ] default['filebeat_test']['filebeat_config'].tap do |c| diff --git a/test/cookbooks/filebeat_test/metadata.rb b/test/cookbooks/filebeat_test/metadata.rb index 883ba1a..c867ea1 100644 --- a/test/cookbooks/filebeat_test/metadata.rb +++ b/test/cookbooks/filebeat_test/metadata.rb @@ -1,9 +1,11 @@ name 'filebeat_test' maintainer 'Virender Khatri' maintainer_email 'vir.khatri@gmail.com' -license 'Apache 2.0' +license 'Apache-2.0' description 'Installs/Configures Filebeat Test Cookbook Resources' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) - version '0.0.1' +source_url 'https://github.com/vkhatri/chef-filebeat' +issues_url 'https://github.com/vkhatri/chef-filebeat/issues' +chef_version '>= 12.14' + depends 'filebeat' diff --git a/test/cookbooks/filebeat_test/recipes/defaultv6.rb b/test/cookbooks/filebeat_test/recipes/current-ver.rb similarity index 68% rename from test/cookbooks/filebeat_test/recipes/defaultv6.rb rename to test/cookbooks/filebeat_test/recipes/current-ver.rb index c3e9545..27b9e1a 100644 --- a/test/cookbooks/filebeat_test/recipes/defaultv6.rb +++ b/test/cookbooks/filebeat_test/recipes/current-ver.rb @@ -2,17 +2,14 @@ filebeat_config 'default' do config node['filebeat_test']['filebeat_config'] - # filebeat_install_resource_name 'default' end node['filebeat_test']['prospectors'].each do |p_name, p_config| filebeat_prospector p_name do config p_config - # filebeat_install_resource_name 'default' end end filebeat_service 'default' do - # filebeat_install_resource_name 'default' purge_prospectors_dir true end diff --git a/test/cookbooks/filebeat_test/recipes/defaultv6preview.rb b/test/cookbooks/filebeat_test/recipes/preview.rb similarity index 100% rename from test/cookbooks/filebeat_test/recipes/defaultv6preview.rb rename to test/cookbooks/filebeat_test/recipes/preview.rb diff --git a/test/cookbooks/filebeat_test/recipes/previous-ver.rb b/test/cookbooks/filebeat_test/recipes/previous-ver.rb new file mode 100644 index 0000000..ba2eee1 --- /dev/null +++ b/test/cookbooks/filebeat_test/recipes/previous-ver.rb @@ -0,0 +1,17 @@ +filebeat_install 'default' do + version '6.8.8' +end + +filebeat_config 'default' do + config node['filebeat_test']['filebeat_config'] +end + +node['filebeat_test']['prospectors'].each do |p_name, p_config| + filebeat_prospector p_name do + config p_config + end +end + +filebeat_service 'default' do + purge_prospectors_dir true +end diff --git a/test/cookbooks/filebeat_test/recipes/defaultv6runit.rb b/test/cookbooks/filebeat_test/recipes/runit.rb similarity index 100% rename from test/cookbooks/filebeat_test/recipes/defaultv6runit.rb rename to test/cookbooks/filebeat_test/recipes/runit.rb diff --git a/test/smoke/current-ver/default.rb b/test/smoke/current-ver/default.rb new file mode 100644 index 0000000..2cef714 --- /dev/null +++ b/test/smoke/current-ver/default.rb @@ -0,0 +1,45 @@ +# # encoding: utf-8 + +# Inspec test for recipe filebeat::v6 + +# The Inspec reference, with examples and extensive documentation, can be +# found at http://inspec.io/docs/reference/resources/ + +if %w(redhat fedora amazon).include?(os[:family]) + describe file('/etc/yum.repos.d/elastic7.repo') do + its('content') { should match %r{https://artifacts.elastic.co/packages/7.x/yum} } + end +else + describe file('/etc/apt/sources.list.d/elastic7.list') do + its('content') { should match %r{https://artifacts.elastic.co/packages/7.x/apt} } + end +end + +describe file('/etc/filebeat/filebeat.yml') do + it { should exist } + # its('content') { should match 'filebeat.config.inputs' } +end + +describe command('filebeat test config') do + its('exit_status') { should eq 0 } + its('stdout') { should match 'Config OK' } +end + +describe package('filebeat') do + it { should be_installed } + its('version') { should match '7.6.2' } +end + +if %w(18.04 20.04 2 7 8).include?(os[:release]) + describe systemd_service('filebeat') do + it { should be_installed } + it { should be_enabled } + it { should be_running } + end +else + describe service('filebeat') do + it { should be_installed } + it { should be_enabled } + it { should be_running } + end +end diff --git a/test/smoke/v6/default.rb b/test/smoke/previous-ver/default.rb similarity index 82% rename from test/smoke/v6/default.rb rename to test/smoke/previous-ver/default.rb index 026e364..cf6f613 100644 --- a/test/smoke/v6/default.rb +++ b/test/smoke/previous-ver/default.rb @@ -5,7 +5,7 @@ # The Inspec reference, with examples and extensive documentation, can be # found at http://inspec.io/docs/reference/resources/ -if %w[redhat fedora amazon].include?(os[:family]) +if %w(redhat fedora amazon).include?(os[:family]) describe file('/etc/yum.repos.d/elastic6.repo') do its('content') { should match %r{https://artifacts.elastic.co/packages/6.x/yum} } end @@ -16,7 +16,8 @@ end describe file('/etc/filebeat/filebeat.yml') do - its('content') { should match 'filebeat.config.inputs' } + it { should exist } + # its('content') { should match 'filebeat.config.inputs' } end describe command('filebeat test config') do @@ -26,10 +27,10 @@ describe package('filebeat') do it { should be_installed } - its('version') { should match '6.4.2' } + its('version') { should match '6.8.8' } end -if %w[16.04 2 7].include?(os[:release]) +if %w(16.04 2 7).include?(os[:release]) describe systemd_service('filebeat') do it { should be_installed } it { should be_enabled } diff --git a/test/smoke/v6runit/default.rb b/test/smoke/runit/default.rb similarity index 100% rename from test/smoke/v6runit/default.rb rename to test/smoke/runit/default.rb