sensu-plugins / sensu-plugin

A framework for writing Sensu plugins & handlers with Ruby.
http://sensuapp.org
MIT License
126 stars 117 forks source link

Fix regression in Sensu::Handler api_request under Ruby >= 2.0 #162

Closed cwjohnston closed 7 years ago

cwjohnston commented 7 years ago

Description

In #155 we attempted to address incompatibility with Ruby 1.9.x and instead introduced a regression which broke api_request method under Ruby 2.x. This change is intended to correct a regression introduced in #155.

Motivation and Context

Comparing the arguments for Net::HTTPGenericRequest on 1.9.1 vs 2.3.0, I see that 1.9.1 expects argument path where as 2.3.0 takes uri_or_path argument. If the uri_or_path is not a URI object, it is treated as the path.

I believe we can unconditionally pass the value of uri.path to net_http_req_class(method).new on both ruby 1.9 and 2.x, as the hostname, port and scheme are explicitly set when calling Net::HTTP.start.

Closes https://github.com/sensu-plugins/sensu-plugins-sensu/issues/18 Closes https://github.com/sensu-plugins/sensu-plugin/issues/160 Closes https://github.com/sensu-plugins/sensu-plugin/issues/161

How Has This Been Tested?

In order to test this change I created an Ubuntu 16.04 VM and used the ruby-build and rbenv tools to configure two separate Ruby environments: 1.9.3-p551 and 2.3.3, respectively.

I configured a Sensu stack to process events submitted via the client's local socket and installed sensu-plugin 1.4.3 and a handler plugin in each of the aforementioned Ruby environments.

This enabled me to test this change with regard to handler accessing the API for check dependencies and silence stashes, both of which are working under both Rubies with this change.

Types of changes

Checklist:

Known Caveats

analytically commented 7 years ago

Thanks!!