diff --git a/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/provider/plugin_zabbix.rb b/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/provider/plugin_zabbix.rb index ae369e9..c579348 100644 --- a/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/provider/plugin_zabbix.rb +++ b/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/provider/plugin_zabbix.rb @@ -55,8 +55,7 @@ class Puppet::Provider::Plugin_zabbix < Puppet::Provider result end - def self.api_request(api, body) - retries = 10 + def self.api_request(api, body, retries=10) cooldown = 1 Puppet.info("Trying to make a request to zabbix server, will try #{retries} times with #{cooldown} seconds between tries") retries.times do |r| @@ -71,8 +70,8 @@ class Puppet::Provider::Plugin_zabbix < Puppet::Provider return result["result"] rescue => e - if r == retries - Puppet.error("Out of retries to make a request to zabbix server (#{retries})") + if r == retries - 1 + Puppet.warning("Out of retries to make a request to zabbix server (#{retries})") raise e else Puppet.warning("Could not make request to zabbix: #{e}, sleeping #{cooldown*r} (retry (##{r}/#{retries}))") diff --git a/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/type/plugin_zabbix_host.rb b/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/type/plugin_zabbix_host.rb index a5f85bc..eb0a083 100644 --- a/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/type/plugin_zabbix_host.rb +++ b/deployment_scripts/puppet/modules/plugin_zabbix/lib/puppet/type/plugin_zabbix_host.rb @@ -66,6 +66,9 @@ Puppet::Type.newtype(:plugin_zabbix_host) do validate do |value| fail("groups is not an array") unless value.kind_of?(Array) or value.kind_of?(String) fail("groups array is empty") if value.empty? + if value.kind_of?(String) then + value = [value] + end value.each do |item| fail("group name is not a string") unless item.kind_of?(String) fail("group name is empty") unless item =~ /.+/ @@ -75,6 +78,10 @@ Puppet::Type.newtype(:plugin_zabbix_host) do newparam(:hostname) do desc 'Visible name of the host.' + + validate do |value| + raise(Puppet::Error, 'Invalid value') unless value.kind_of?(String) + end newvalues(/.+/) end diff --git a/deployment_scripts/puppet/modules/plugin_zabbix/spec/unit/provider/plugin_zabbix_spec.rb b/deployment_scripts/puppet/modules/plugin_zabbix/spec/unit/provider/plugin_zabbix_spec.rb index 5810f68..eecb8cb 100644 --- a/deployment_scripts/puppet/modules/plugin_zabbix/spec/unit/provider/plugin_zabbix_spec.rb +++ b/deployment_scripts/puppet/modules/plugin_zabbix/spec/unit/provider/plugin_zabbix_spec.rb @@ -27,12 +27,12 @@ describe Puppet::Provider::Plugin_zabbix do mock = {'error' => {'code' => 0, 'message' => 'test error', 'data' => 'not a real error'}} - Puppet::Provider::Plugin_zabbix.expects(:make_request).returns(mock) + Puppet::Provider::Plugin_zabbix.expects(:make_request).at_least(2).returns(mock) fake_api = {'endpoint' => 'http://localhost', 'username' => 'Admin', 'password' => 'zabbix'} expect { - cls.api_request(fake_api, {}) + cls.api_request(fake_api, {}, 2) }.to raise_error(Puppet::Error, /Zabbix API returned/) end