From 71007c4d765169a65f499e4ff34951b1c16b5b64 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 23 Aug 2025 15:11:20 +0100 Subject: [PATCH] Generate smokeping targets from all hosts known to DNS --- cookbooks/prometheus/recipes/smokeping.rb | 24 +++++++++++++------ .../templates/default/smokeping.yml.erb | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cookbooks/prometheus/recipes/smokeping.rb b/cookbooks/prometheus/recipes/smokeping.rb index c626eb37c..e72a73a42 100644 --- a/cookbooks/prometheus/recipes/smokeping.rb +++ b/cookbooks/prometheus/recipes/smokeping.rb @@ -19,14 +19,24 @@ include_recipe "prometheus" -ip4_hosts = [] -ip6_hosts = [] +hosts = {} -search(:node, "networking:interfaces") do |host| - next if host.name == node.name +%w[ipv4 ipv6].each do |protocol| + json_file = "#{Chef::Config[:file_cache_path]}/#{protocol}.json" - ip4_hosts << host[:fqdn] unless host.ipaddresses(:role => :external, :family => :inet).empty? - ip6_hosts << host[:fqdn] unless host.ipaddresses(:role => :external, :family => :inet6).empty? + remote_file json_file do + source "https://dns.openstreetmap.org/#{protocol}.json" + compile_time true + ignore_failure true + end + + hosts[protocol] = if File.exist?(json_file) + JSON.parse(IO.read(json_file)).filter_map do |name, address| + name unless address.start_with?("10.") + end + else + [] + end end template "/etc/prometheus/exporters/smokeping.yml" do @@ -34,7 +44,7 @@ template "/etc/prometheus/exporters/smokeping.yml" do owner "root" group "root" mode "644" - variables :ip4_hosts => ip4_hosts, :ip6_hosts => ip6_hosts + variables :ip4_hosts => hosts["ipv4"], :ip6_hosts => hosts["ipv6"] end prometheus_exporter "smokeping" do diff --git a/cookbooks/prometheus/templates/default/smokeping.yml.erb b/cookbooks/prometheus/templates/default/smokeping.yml.erb index 7618e64cf..b96bc1379 100644 --- a/cookbooks/prometheus/templates/default/smokeping.yml.erb +++ b/cookbooks/prometheus/templates/default/smokeping.yml.erb @@ -2,14 +2,14 @@ targets: - hosts: <% @ip4_hosts.sort.each do |host| -%> - - <%= host %> + - <%= host %>.openstreetmap.org <% end -%> interval: 5s network: ip4 size: 24 - hosts: <% @ip6_hosts.sort.each do |host| -%> - - <%= host %> + - <%= host %>.openstreetmap.org <% end -%> interval: 5s network: ip6 -- 2.39.5