23 lines
631 B
Ruby
23 lines
631 B
Ruby
# vim: set noet sw=2 ts=2 sts=2:
|
|
require 'rack'
|
|
require_relative 'collector'
|
|
|
|
run lambda {|env|
|
|
begin
|
|
req = Rack::Request.new env
|
|
case req.path
|
|
when '/probe'
|
|
collector = BlackboxSshd::Collector.new
|
|
collector.collect req.params['target']
|
|
[200, {"Content-Type" => "text/plain"}, [
|
|
Prometheus::Client::Formats::Text.marshal( collector.registry),
|
|
]]
|
|
else
|
|
[404, {"Content-Type" => "text/plain"}, ["Not found.\nYou want to try /probe?\n"]]
|
|
end
|
|
rescue
|
|
STDERR.puts "#$! (#{$!.class})", *$!.backtrace
|
|
[500, {"Content-Type" => "text/plain"}, ["Server-error.\n"]]
|
|
end
|
|
}
|