sensu / http-checks

HTTP checks for use with Sensu
MIT License
2 stars 5 forks source link

http-check is broken, cannot handle any errors #14

Closed FlorinAndrei closed 2 years ago

FlorinAndrei commented 3 years ago

It works fine if the port is up and running:

# ./http-check --url http://user.service.consul:80/metadata
http-check OK: HTTP Status 200 for http://user.service.consul:80/metadata

However, any error whatsoever (either timeout or connection refused) results in the Usage Help screen:

# ./http-check --url http://user.service.consul:81/metadata
Usage:
  http-check [flags]
  http-check [command]

Available Commands:
  help        Help about any command
  version     Print the version number of this plugin

Flags:
  -H, --header strings           Additional header(s) to send in check request
  -h, --help                     help for http-check
  -i, --insecure-skip-verify     Skip TLS certificate verification (not recommended!)
  -C, --mtls-cert-file string    Certificate file for mutual TLS auth in PEM format
  -K, --mtls-key-file string     Key file for mutual TLS auth in PEM format
  -r, --redirect-ok              Allow redirects
  -s, --search-string string     String to search for, if not provided do status check only
  -T, --timeout int              Request timeout in seconds (default 15)
  -t, --trusted-ca-file string   TLS CA certificate bundle in PEM format
  -u, --url string               URL to test (default "http://localhost:80/")

Use "http-check [command] --help" for more information about a command.

Error executing http-check: error executing check: Get http://user.service.consul:81/metadata: dial tcp 10.2.95.221:81: connect: connection refused

Instead, it should produce the standard service failure message.

This plugin is broken, it cannot be used as is.

sensu-discourse commented 3 years ago

This issue has been mentioned on Sensu Community. There might be relevant details there:

https://discourse.sensu.io/t/http-check-cannot-handle-connection-refused/2743/4

jspaleta commented 3 years ago

For clarity... when you say "should produce the standard service failure message" Do you mean the full output should be:

Error executing http-check: error executing check: Get http://user.service.consul:81/metadata: dial tcp 10.2.95.221:81: connect: connection refused
FlorinAndrei commented 3 years ago

It should not print out the usage blob.

Its output should conform to some standard format. I do not know what standard Sensu uses these days, but if you guys are still following the Nagios template, then it's this in terms of printed text and process exit code:

https://www.howtoforge.com/tutorial/write-a-custom-nagios-check-plugin/

Would be nice if that brief line of text could distinguish between connection refused and connection timed out.