diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e8bbf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.sw[pomnqrst] +*.gem + +config.yml +Gemfile.lock diff --git a/config.ru b/config.ru index 13d7500..1b244c3 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,9 @@ +# vim: set noet sw=2 ts=2 sts=2: require 'rack' -require './dnsbl_exporter' +require_relative 'dnsbl_exporter' +require 'yaml' +DnsblCollector.load_config './config.yml' run lambda {|env| begin @@ -16,7 +19,8 @@ run lambda {|env| end collector.collect target [200, {"Content-Type" => "text/plain"}, [ - Prometheus::Client::Formats::Text.marshal( collector.prometheus) + Prometheus::Client::Formats::Text.marshal( collector.registry), + Prometheus::Client::Formats::Text.marshal( DnsblCollector.registry), ]] else [404, {"Content-Type" => "text/plain"}, ["Not found.\nYou want to try /metrics?\n"]] diff --git a/config.yml b/config.yml.example similarity index 96% rename from config.yml rename to config.yml.example index 6be99f2..0c7b31a 100644 --- a/config.yml +++ b/config.yml.example @@ -1,7 +1,7 @@ # vim: set et sw=2 ts=2 sts=2: --- resolver: - nameservers: 8.8.8.8 + nameservers: '::1' blacklists: - all.s5h.net - b.barracudacentral.org @@ -17,7 +17,6 @@ blacklists: - dnsbl-1.uceprotect.net - dnsbl-2.uceprotect.net - dnsbl-3.uceprotect.net -- dnsbl.anticaptcha.net - dnsbl.dronebl.org - dnsbl.inps.de - dnsbl.sorbs.net diff --git a/dnsbl_exporter.rb b/dnsbl_exporter.rb index fba6bf5..31a7cf8 100644 --- a/dnsbl_exporter.rb +++ b/dnsbl_exporter.rb @@ -1,52 +1,76 @@ +# vim: set noet sw=2 ts=2 sts=2: require 'prometheus/client' require 'prometheus/client/formats/text' require 'net/dns' -require 'yaml' +require 'ostruct' -class DnsblCollector - attr_reader :lists, :prometheus, :configfile, :resolver, :metrics +class DnsblCollector + class <