require 'rack' require './dnsbl_exporter' 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"}, [ Prometheus::Client::Formats::Text.marshal( collector.prometheus) ]] else [404, {"Content-Type" => "text/plain"}, ["Not found.\nYou want to try /metrics?\n"]] end rescue STDERR.puts "#$! (#{$!.class})", $!.backtrace [500, {"Content-Type" => "text/plain"}, ["Server-error.\n"]] end }