]> git.openstreetmap.org Git - chef.git/blob - cookbooks/prometheus/recipes/smokeping.rb
Exclude OOB addresses from smokeping
[chef.git] / cookbooks / prometheus / recipes / smokeping.rb
1 #
2 # Cookbook:: prometheus
3 # Recipe:: smokeping
4 #
5 # Copyright:: 2023, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 include_recipe "prometheus"
21
22 hosts = {}
23
24 %w[ipv4 ipv6].each do |protocol|
25   json_file = "#{Chef::Config[:file_cache_path]}/#{protocol}.json"
26
27   remote_file json_file do
28     source "https://dns.openstreetmap.org/#{protocol}.json"
29     compile_time true
30     ignore_failure true
31   end
32
33   hosts[protocol] = if File.exist?(json_file)
34                       JSON.parse(IO.read(json_file)).filter_map do |name, address|
35                         name unless name.split(".").first == node[:hostname] ||
36                                     name.end_with?(".oob") ||
37                                     address.start_with?("10.")
38                       end
39                     else
40                       []
41                     end
42 end
43
44 template "/etc/prometheus/exporters/smokeping.yml" do
45   source "smokeping.yml.erb"
46   owner "root"
47   group "root"
48   mode "644"
49   variables :ip4_hosts => hosts["ipv4"], :ip6_hosts => hosts["ipv6"]
50 end
51
52 prometheus_exporter "smokeping" do
53   port 9374
54   environment "GOMAXPROCS" => "1"
55   options "--config.file=/etc/prometheus/exporters/smokeping.yml"
56   capability_bounding_set "CAP_NET_RAW"
57   ambient_capabilities "CAP_NET_RAW"
58   private_users false
59   subscribes :restart, "template[/etc/prometheus/exporters/smokeping.yml]"
60 end