Skip to content

Commit 5b93145

Browse files
committed
Generate smokeping targets from all hosts known to DNS
1 parent 2a6d9b3 commit 5b93145

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

cookbooks/prometheus/recipes/smokeping.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,35 @@
1919

2020
include_recipe "prometheus"
2121

22-
ip4_hosts = []
23-
ip6_hosts = []
22+
hosts = {}
2423

25-
search(:node, "networking:interfaces") do |host|
26-
next if host.name == node.name
24+
%w[ipv4 ipv6].each do |protocol|
25+
json_file = "#{Chef::Config[:file_cache_path]}/#{protocol}.json"
2726

28-
ip4_hosts << host[:fqdn] unless host.ipaddresses(:role => :external, :family => :inet).empty?
29-
ip6_hosts << host[:fqdn] unless host.ipaddresses(:role => :external, :family => :inet6).empty?
27+
remote_file json_file do
28+
source "https://dns.openstreetmap.org/#{protocol}.json"
29+
owner "root"
30+
group "root"
31+
mode "644"
32+
backup false
33+
ignore_failure true
34+
end
35+
36+
hosts[protocol] = if File.exist?(json_file)
37+
JSON.parse(IO.read(json_file)).filter_map do |name, address|
38+
name unless address.start_with?("10.")
39+
end
40+
else
41+
[]
42+
end
3043
end
3144

3245
template "/etc/prometheus/exporters/smokeping.yml" do
3346
source "smokeping.yml.erb"
3447
owner "root"
3548
group "root"
3649
mode "644"
37-
variables :ip4_hosts => ip4_hosts, :ip6_hosts => ip6_hosts
50+
variables :ip4_hosts => hosts["ipv4"], :ip6_hosts => hosts["ipv6"]
3851
end
3952

4053
prometheus_exporter "smokeping" do

cookbooks/prometheus/templates/default/smokeping.yml.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
targets:
33
- hosts:
44
<% @ip4_hosts.sort.each do |host| -%>
5-
- <%= host %>
5+
- <%= host %>.openstreetmap.org
66
<% end -%>
77
interval: 5s
88
network: ip4
99
size: 24
1010
- hosts:
1111
<% @ip6_hosts.sort.each do |host| -%>
12-
- <%= host %>
12+
- <%= host %>.openstreetmap.org
1313
<% end -%>
1414
interval: 5s
1515
network: ip6

0 commit comments

Comments
 (0)