sensu-plugins / sensu-plugins-http

This plugin provides native HTTP instrumentation for monitoring and metrics collection, including: response code, JSON response, HTTP last modified, SSL expiry, and metrics via `curl`.
http://sensu-plugins.io
MIT License
30 stars 97 forks source link

metrics-http-json.rb HTTP basic auth #148

Open noahbailey opened 5 years ago

noahbailey commented 5 years ago

Extracting metrics from an api endpoint that requires authentication fails in a strange way. When the --url parameter is formatted like "user:pass@localhost:8080" the check fails with this output:

Check failed to run: Failed to open TCP connection to http:80 (getaddrinfo: Name or service not known), ["/usr/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'", "/usr/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'", "/usr/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'", "/usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'", "/usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'", "/usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'", "/usr/lib/ruby/2.3.0/net/http.rb:852:in `start'", "/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:in `transmit'", "/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in `execute'", "/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:in `execute'", "/var/lib/gems/2.3.0/gems/sensu-plugins-http-5.1.1/bin/metrics-http-json.rb:91:in `run'", "/var/lib/gems/2.3.0/gems/sensu-plugin-4.0.0/lib/sensu-plugin/cli.rb:59:in `block in <class:CLI>'"]

Of course, the request is not for port 80, making this failure perplexing.

jspaleta commented 5 years ago

let me take a look at this and see if I can figure it out. Ping here again on Monday if you haven't seen a response from me.

noahbailey commented 5 years ago

I suppose another way to go about it would be to add the --username and --password flags from the check-http-json.rb script.

noahbailey commented 5 years ago

Hey, @jspaleta any updates on this? If it helps at all, I'll be using this plugin to grab metrics from the CouchDB api, so it does need to have HTTP basic auth on a high port (5984/5986) Let me know if you need more info, cheers!

jspaleta commented 4 years ago

Yeah let's implement the username and password flags. I'll prioritize this right now and see if I can get this implemented.