Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 160: regression on sensu-handler.rb, introduced with Ruby 1.9.0 compatibility fix in 1.4.3 #161

Closed
wants to merge 2 commits into from

Conversation

raffraffraff
Copy link

Fixes a regression in the sensu-handler.rb, which breaks calls to the sensu API in version 1.4.3.

Description

The regression was caused by a previous commit which fixed a bug in Ruby 1.9 [sensu-handler.rb, line 136: changed 'uri' to 'uri.to_s']. This fix commit simply wraps the uri = in an if RUBY_VERSION > 1.9 check before deciding which method to use.

Motivation and Context

sensu-plugins 1.4.3 is currently broken on newer Ruby versions.

The issue this fixes is: #160

How Has This Been Tested?

I am running this fork in a test datacenter on 3x sensu servers, and it fixes the regression.
I have not tested this on any older Ruby versions, but it's a simple 'if' statement.

Versions used in test:
Ruby: 2.3.0
Sensu: 0.26.5
sensu-plugin: 1.4.3 (with this patch)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have updated the Changelog following the conventions laid out on Keep A Changelog

Known Caveats

Paul Rafferty added 2 commits October 17, 2016 12:04
… previous commit which fixed a bug in Ruby 1.9 [changed uri to uri.to_s]. This commit simply checks the Ruby version before setting the uri variable.
@cwjohnston
Copy link
Contributor

cwjohnston commented Oct 18, 2016

@raffraffraff @paulrqualtrics I've looked into this a little bit more and I think my alleged fix for 1.9 is broken for the same reason.

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.

cwjohnston added a commit that referenced this pull request Dec 5, 2016
Comparing the arguments for `Net::HTTPGenericRequest` on
[1.9.1](https://ruby-doc.org/stdlib-1.9.1/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html)
vs
[2.3.0](https://ruby-doc.org/stdlib-2.3.0/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html),
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 sensu-plugins/sensu-plugins-sensu#18
Closes #160
Closes #161
cwjohnston added a commit that referenced this pull request Dec 5, 2016
Comparing the arguments for `Net::HTTPGenericRequest` on
[1.9.1](https://ruby-doc.org/stdlib-1.9.1/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html)
vs
[2.3.0](https://ruby-doc.org/stdlib-2.3.0/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html),
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 sensu-plugins/sensu-plugins-sensu#18
Closes #160
Closes #161
@cwjohnston cwjohnston self-assigned this Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants