Class: Puppet::Util::SensuAPIValidator
- Inherits:
-
Object
- Object
- Puppet::Util::SensuAPIValidator
- Defined in:
- lib/puppet/util/sensu_api_validator.rb
Overview
Validator class, for testing that SensuAPI is alive
Instance Attribute Summary collapse
-
#sensu_api_port ⇒ Object
readonly
Returns the value of attribute sensu_api_port.
-
#sensu_api_server ⇒ Object
readonly
Returns the value of attribute sensu_api_server.
-
#test_headers ⇒ Object
readonly
Returns the value of attribute test_headers.
-
#test_path ⇒ Object
readonly
Returns the value of attribute test_path.
-
#use_ssl ⇒ Object
readonly
Returns the value of attribute use_ssl.
Instance Method Summary collapse
-
#attempt_connection ⇒ Object
Utility method; attempts to make an http/https connection to the sensu_api server.
-
#initialize(sensu_api_server, sensu_api_port, use_ssl = false, test_path = "/version") ⇒ SensuAPIValidator
constructor
A new instance of SensuAPIValidator.
Constructor Details
#initialize(sensu_api_server, sensu_api_port, use_ssl = false, test_path = "/version") ⇒ SensuAPIValidator
Returns a new instance of SensuAPIValidator.
13 14 15 16 17 18 |
# File 'lib/puppet/util/sensu_api_validator.rb', line 13 def initialize(sensu_api_server, sensu_api_port, use_ssl=false, test_path = "/version") @sensu_api_server = sensu_api_server @sensu_api_port = sensu_api_port @use_ssl = use_ssl @test_path = test_path end |
Instance Attribute Details
#sensu_api_port ⇒ Object (readonly)
Returns the value of attribute sensu_api_port.
8 9 10 |
# File 'lib/puppet/util/sensu_api_validator.rb', line 8 def sensu_api_port @sensu_api_port end |
#sensu_api_server ⇒ Object (readonly)
Returns the value of attribute sensu_api_server.
7 8 9 |
# File 'lib/puppet/util/sensu_api_validator.rb', line 7 def sensu_api_server @sensu_api_server end |
#test_headers ⇒ Object (readonly)
Returns the value of attribute test_headers.
11 12 13 |
# File 'lib/puppet/util/sensu_api_validator.rb', line 11 def test_headers @test_headers end |
#test_path ⇒ Object (readonly)
Returns the value of attribute test_path.
10 11 12 |
# File 'lib/puppet/util/sensu_api_validator.rb', line 10 def test_path @test_path end |
#use_ssl ⇒ Object (readonly)
Returns the value of attribute use_ssl.
9 10 11 |
# File 'lib/puppet/util/sensu_api_validator.rb', line 9 def use_ssl @use_ssl end |
Instance Method Details
#attempt_connection ⇒ Object
Utility method; attempts to make an http/https connection to the sensu_api server. This is abstracted out into a method so that it can be called multiple times for retry attempts.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet/util/sensu_api_validator.rb', line 25 def attempt_connection # All that we care about is that we are able to connect successfully via # http(s), so here we're simpling hitting a somewhat arbitrary low-impact URL # on the sensu_api server. http = Net::HTTP.new(@sensu_api_server, @sensu_api_port) http.use_ssl = @use_ssl http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(@test_path) request.add_field("Accept", "application/json") response = http.request(request) unless response.kind_of?(Net::HTTPSuccess) || response.kind_of?(Net::HTTPUnauthorized) Puppet.notice "Unable to connect to sensu_api server (http#{use_ssl ? "s" : ""}://#{sensu_api_server}:#{sensu_api_port}): [#{response.code}] #{response.msg}" return false end return true rescue Exception => e Puppet.notice "Unable to connect to sensu_api server (http#{use_ssl ? "s" : ""}://#{sensu_api_server}:#{sensu_api_port}): #{e.}" return false end |