sensu-plugins / sensu-plugins-docker

This plugin provides native Docker instrumentation for monitoring and metrics collection, including: container status, container number, and container metrics via `docker ps`.
http://sensu-plugins.io
MIT License
35 stars 57 forks source link

Prevent check-container-logs.rb failing on a nil string #66

Closed DrMurx closed 6 years ago

DrMurx commented 6 years ago

Pull Request Checklist

General

Purpose

When chopping the binary headers from docker log response, empty log lines lead to a nil.gsub due to how String::byteslice works. This PR filters that condition properly.

majormoses commented 6 years ago

Thanks for your contribution to Sensu plugins! Without people like you submitting PRs we couldn't run the project. I will review it shortly.

DrMurx commented 6 years ago

Providing testing artifacts isn't easy here as the causing condition can't be reproduced reliably.

This is the error I receive and which I tried to fix:

Check failed to run: undefined method `gsub' for nil:NilClass, [
"/usr/local/bundle/bin/check-container-logs.rb:143:in `block in remove_headers'", 
"/usr/local/bundle/bin/check-container-logs.rb:139:in `map!'", 
"/usr/local/bundle/bin/check-container-logs.rb:139:in `remove_headers'", 
"/usr/local/bundle/bin/check-container-logs.rb:134:in `process_docker_logs'", 
"/usr/local/bundle/bin/check-container-logs.rb:188:in `block in run'", 
"/usr/local/bundle/bin/check-container-logs.rb:187:in `each'", 
"/usr/local/bundle/bin/check-container-logs.rb:187:in `run'", 
"/usr/local/bundle/gems/sensu-plugin-2.5.0/lib/sensu-plugin/cli.rb:57:in `block in <class:CLI>'"
]

This is clearly because Ruby's string slice methods (in this case byteslice) return nil if the slice attempt is outside the string boundaries.

majormoses commented 6 years ago

released: https://rubygems.org/gems/sensu-plugins-docker/versions/3.1.1