WeAreFarmGeek / diplomat

A HTTP Ruby API for Consul
BSD 3-Clause "New" or "Revised" License
370 stars 116 forks source link

Support for Output in TTL checks #178

Closed kinnalru closed 5 years ago

kinnalru commented 5 years ago

Support for passing Output field in consul TTL checks as described here: https://www.consul.io/api/agent/check.html

kinnalru commented 5 years ago

Hi. @pierresouchay, when you plan to update version of a gem to make "Use correct verbs for Check methods" accessible?

pierresouchay commented 5 years ago

@kinnalru I'll produce a new version once we merge this PR, is that OK?

kinnalru commented 5 years ago

@kinnalru I'll produce a new version once we merge this PR, is that OK?

ok

pierresouchay commented 5 years ago

@kinnalru Actually, it seems to work with critical as well...

#!/usr/bin/env ruby
require 'diplomat'

Diplomat.configure do |config|
  config.url = ENV['CONSUL_HTTP_ADDR'] || "http://localhost:8500"
end
check_id = 'check_ttl'
ttl = Diplomat::Check.register_ttl(check_id, 'check_ttl', 'ttl_check to update', '5m')
puts Diplomat::Check.checks
sleep(3)
puts "Update TTL pass"
Diplomat::Check.pass(check_id, '{"canard": "PASS This is my long output"}')
puts Diplomat::Check.checks
sleep 5
puts "Update TTL warn"
Diplomat::Check.warn(check_id, '{"canard": "WARN This is my long output"}')
puts Diplomat::Check.checks
sleep 5

puts "Update TTL critical"
Diplomat::Check.fail(check_id, '{"canard": "CRITICAL This is my long output"}')
puts Diplomat::Check.checks
sleep 5

Outputs:

{"check_ttl"=>{"Node"=>"C02X72TUJGH5", "CheckID"=>"check_ttl", "Name"=>"check_ttl", "Status"=>"warning", "Notes"=>"ttl_check to update", "Output"=>"{\"canard\": \"WARN This is my long output\"}", "ServiceID"=>"", "ServiceName"=>"", "ServiceTags"=>[], "Definition"=>{"Interval"=>"", "Timeout"=>"", "DeregisterCriticalServiceAfter"=>""}, "CreateIndex"=>0, "ModifyIndex"=>0}}
Update TTL pass
{"check_ttl"=>{"Node"=>"C02X72TUJGH5", "CheckID"=>"check_ttl", "Name"=>"check_ttl", "Status"=>"passing", "Notes"=>"ttl_check to update", "Output"=>"{\"canard\": \"PASS This is my long output\"}", "ServiceID"=>"", "ServiceName"=>"", "ServiceTags"=>[], "Definition"=>{"Interval"=>"", "Timeout"=>"", "DeregisterCriticalServiceAfter"=>""}, "CreateIndex"=>0, "ModifyIndex"=>0}}
Update TTL warn
{"check_ttl"=>{"Node"=>"C02X72TUJGH5", "CheckID"=>"check_ttl", "Name"=>"check_ttl", "Status"=>"warning", "Notes"=>"ttl_check to update", "Output"=>"{\"canard\": \"WARN This is my long output\"}", "ServiceID"=>"", "ServiceName"=>"", "ServiceTags"=>[], "Definition"=>{"Interval"=>"", "Timeout"=>"", "DeregisterCriticalServiceAfter"=>""}, "CreateIndex"=>0, "ModifyIndex"=>0}}
Update TTL critical
{"check_ttl"=>{"Node"=>"C02X72TUJGH5", "CheckID"=>"check_ttl", "Name"=>"check_ttl", "Status"=>"critical", "Notes"=>"ttl_check to update", "Output"=>"{\"canard\": \"CRITICAL This is my long output\"}", "ServiceID"=>"", "ServiceName"=>"", "ServiceTags"=>[], "Definition"=>{"Interval"=>"", "Timeout"=>"", "DeregisterCriticalServiceAfter"=>""}, "CreateIndex"=>0, "ModifyIndex"=>0}}
kinnalru commented 5 years ago

@kinnalru Actually, it seems to work with critical as well...

It's good. So just consul UI not show "critical" output.

pierresouchay commented 5 years ago

@kinnalru You should try Consul-UI rich HTML UI for Consul https://github.com/criteo/consul-templaterb/ :-)

The UI source (customizable is here: https://github.com/criteo/consul-templaterb/tree/master/samples/consul-ui )