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

Add new options to dump json on failure and enable formatting #86

Merged
merged 2 commits into from
Feb 18, 2018
Merged

Add new options to dump json on failure and enable formatting #86

merged 2 commits into from
Feb 18, 2018

Conversation

jplindquist
Copy link
Contributor

@jplindquist jplindquist commented Feb 8, 2018

Add 2 new options check-http-json.rb:

  • --dump-json, which defaults to false will dump the json response on failure
    and formatting

  • --pretty, which defaults to false will format the json output in a pretty format if --dump-json is enabled

Pull Request Checklist

Is this in reference to an existing issue? Possibly? Not sure if this relates to #85 or not honestly

General

  • Update Changelog following the conventions laid out on Keep A Changelog

  • Update README with any necessary configuration snippets

  • Binstubs are created if needed

  • RuboCop passes

  • Existing tests pass

New Plugins

  • Tests

  • Add the plugin to the README

  • Does it have a complete header as outlined here

Purpose

Allow users to include the json response in the result on failure, and format it if they so choose

Known Compatibility Issues

None, existing functionality remains exactly the same, just adding 2 new options

Copy link
Member

@majormoses majormoses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think it is a great idea, I do have some concerns that I'd like to address around potential credential leakage.

@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]
### Added - 2018-02-08
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally we date it after it has been accepted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, I got a little ahead of myself following the template. I can update that if you'd like if/when it gets accepted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem I will merge, fixup, and release this hopefully tonight.

end

ok message
rescue => e
critical "key check failed: #{e}"
if config[:dump_json]
json_response = config[:pretty] ? JSON.pretty_generate(json) : json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if someone is specifying authentication this is an opportunity for it to leak out. Can we add some redaction for basic auth headers if they exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only dump the parsed json from the body of the response after it's been validated, and we're trying to match a specific key/value (https://github.com/jplindquist/sensu-plugins-http/blob/fec20b0bac993a02fabdeedbce67fd70ed6d7bc4/bin/check-http-json.rb#L181-L183). It should not include any headers of the request or response at all as far as I know.

I'll be happy to update it if you want with additional checks if auth headers are set, but otherwise this is just a straight dump of the parsed json body after the request is made and we've received a valid json response

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are correct on closer inspection.

end

ok message
rescue => e
critical "key check failed: #{e}"
if config[:dump_json]
json_response = config[:pretty] ? JSON.pretty_generate(json) : json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are correct on closer inspection.

@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]
### Added - 2018-02-08
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem I will merge, fixup, and release this hopefully tonight.

@majormoses
Copy link
Member

I will fixup the dep issue on ruby 2.2 prior to merging.

@jplindquist
Copy link
Contributor Author

Awesome, thanks so much for the review @majormoses . Let me know if I can do anything else to help

@majormoses majormoses merged commit bc59e4e into sensu-plugins:master Feb 18, 2018
@majormoses
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants