File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed
Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 1919
2020include_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
3043end
3144
3245template "/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" ]
3851end
3952
4053prometheus_exporter "smokeping" do
Original file line number Diff line number Diff line change 22targets:
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
You can’t perform that action at this time.
0 commit comments