From d6c83567fede8ea25b0741a12598d242c2163031 Mon Sep 17 00:00:00 2001 From: Joris van Lieshout Date: Thu, 11 Aug 2016 18:08:17 +0200 Subject: [PATCH 1/3] Define service here as well if it's not found Because chef 11 and older chef 12 clients honor use_inline_resources slightly different preventing the resource notification to be found. Defining it if not exists in current run_context. --- metadata.rb | 2 +- providers/check.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index c2c232e..279f014 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs and configures Nagios NRPE client' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.6.0' +version '1.6.1' issues_url 'https://github.com/schubergphilis/nrpe/issues' if respond_to?(:issues_url) source_url 'https://github.com/schubergphilis/nrpe' if respond_to?(:source_url) chef_version '>= 11.0' if respond_to?(:chef_version) diff --git a/providers/check.rb b/providers/check.rb index dc6d723..75483ca 100644 --- a/providers/check.rb +++ b/providers/check.rb @@ -28,6 +28,14 @@ def whyrun_supported? config_file = "#{node['nrpe']['conf_dir']}/nrpe.d/#{new_resource.command_name}.cfg" + begin + _r = run_context.resource_collection.find("service[#{node['nrpe']['service_name']}]") + rescue Chef::Exceptions::ResourceNotFound + service node['nrpe']['service_name'] do + action :nothing + end + end + if new_resource.template unless new_resource.command.nil? raise 'You cannot specify command and template!' @@ -58,6 +66,15 @@ def whyrun_supported? action :remove do config_file = "#{node['nrpe']['conf_dir']}/nrpe.d/#{new_resource.command_name}.cfg" + + begin + _r = run_context.resource_collection.find("service[#{node['nrpe']['service_name']}]") + rescue Chef::Exceptions::ResourceNotFound + service node['nrpe']['service_name'] do + action :nothing + end + end + if ::File.exist?(config_file) Chef::Log.info "Removing #{new_resource.command_name} from #{node['nrpe']['conf_dir']}/nrpe.d/" f = file config_file do From 50b331d90309df3cffe85c87ecc9a1bc20c86e7f Mon Sep 17 00:00:00 2001 From: Joris van Lieshout Date: Thu, 11 Aug 2016 18:08:31 +0200 Subject: [PATCH 2/3] rubocop file to cleanup some style things --- .rubocop.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..05427e4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,8 @@ +AllCops: + Include: + - Berksfile + - Gemfile + - Rakefile + +Metrics/LineLength: + Max: 120 From 818a39d96362dcb1fb6ef658f2f7f9c55093030c Mon Sep 17 00:00:00 2001 From: Joris van Lieshout Date: Thu, 11 Aug 2016 18:14:17 +0200 Subject: [PATCH 3/3] small line lenght style fixes --- recipes/_package_install.rb | 6 ++++-- recipes/configure.rb | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/recipes/_package_install.rb b/recipes/_package_install.rb index ac92d9d..ff709ef 100644 --- a/recipes/_package_install.rb +++ b/recipes/_package_install.rb @@ -30,7 +30,8 @@ # # For backward compatibility it can be defined as an array or as a Hash. # -# If it is defined as a hash, by default versions for each packages is nil. So it will install the latest one available in repositories. +# If it is defined as a hash, by default versions for each packages is nil. So it will install the +# latest one available in repositories. # # By default followings are defined and can be adjusted for your tate in your wrapper cookbook # default['nrpe']['packages'] = { @@ -39,7 +40,8 @@ # 'nagios-plugins-basic' => {'version' => nil}, # 'nagios-plugins-standard' => {'version' => nil} # } -# These version information can be overriden in your environment specific attributes so you can intall any version you prefer +# These version information can be overriden in your environment specific attributes so you can intall +# any version you prefer # # In case of defining as an array, it is as usual. It will install latest version found in repositories diff --git a/recipes/configure.rb b/recipes/configure.rb index f974e28..279a49e 100644 --- a/recipes/configure.rb +++ b/recipes/configure.rb @@ -89,7 +89,9 @@ # The updating of the list of checks. ruby_block 'updating of the list of checks' do block do - checks = run_context.resource_collection.select { |r| r.is_a?(Chef::Resource::NrpeCheck) && r.action == [:add] }.map(&:command_name) + checks = run_context.resource_collection.select do |r| + r.is_a?(Chef::Resource::NrpeCheck) && r.action == [:add] + end.map(&:command_name) node.default['nrpe']['checks'] = checks end end