2021-05-09 14:39:21 +02:00
|
|
|
# vim: set noet sw=2 ts=2 sts=2:
|
2018-12-14 14:58:11 +01:00
|
|
|
require 'rack'
|
2021-05-09 14:39:21 +02:00
|
|
|
require_relative 'dnsbl_exporter'
|
2018-12-14 14:58:11 +01:00
|
|
|
|
2021-05-09 14:39:21 +02:00
|
|
|
DnsblCollector.load_config './config.yml'
|
2018-12-14 14:58:11 +01:00
|
|
|
|
|
|
|
run lambda {|env|
|
|
|
|
begin
|
|
|
|
req = Rack::Request.new env
|
|
|
|
case req.path
|
|
|
|
when '/metrics'
|
|
|
|
collector = DnsblCollector.new
|
|
|
|
target =
|
|
|
|
begin
|
|
|
|
target = IPAddr.new req.params['target']
|
|
|
|
rescue IPAddr::AddressFamilyError
|
|
|
|
return [400, {"Content-Type" => "text/plain"}, ["Valid target-IP-Address expected.\n"]]
|
|
|
|
end
|
|
|
|
collector.collect target
|
|
|
|
[200, {"Content-Type" => "text/plain"}, [
|
2021-05-09 14:39:21 +02:00
|
|
|
Prometheus::Client::Formats::Text.marshal( collector.registry),
|
|
|
|
Prometheus::Client::Formats::Text.marshal( DnsblCollector.registry),
|
2018-12-14 14:58:11 +01:00
|
|
|
]]
|
|
|
|
else
|
|
|
|
[404, {"Content-Type" => "text/plain"}, ["Not found.\nYou want to try /metrics?\n"]]
|
|
|
|
end
|
|
|
|
rescue
|
2021-05-09 20:38:37 +02:00
|
|
|
STDERR.puts "#$! (#{$!.class})", *$!.backtrace
|
2018-12-14 14:58:11 +01:00
|
|
|
[500, {"Content-Type" => "text/plain"}, ["Server-error.\n"]]
|
|
|
|
end
|
|
|
|
}
|