addresses
end
- def internal_ipaddress
- ipaddresses(:role => :internal).first
+ def internal_ipaddress(options = {})
+ ipaddresses(options.merge(:role => :internal)).first
end
- def external_ipaddress
- ipaddresses(:role => :external).first
+ def external_ipaddress(options = {})
+ ipaddresses(options.merge(:role => :external)).first
end
end
end
# limitations under the License.
#
+include_recipe "networking"
+
+if node.internal_ipaddress
+ node.default[:prometheus][:mode] = "internal"
+ node.default[:prometheus][:address] = node.internal_ipaddress
+elsif node[:networking][:wireguard][:enabled]
+ node.default[:prometheus][:mode] = "wireguard"
+ node.default[:prometheus][:address] = node[:networking][:wireguard][:address]
+
+ search(:node, "roles:prometheus") do |server|
+ node.default[:networking][:wireguard][:peers] << {
+ :public_key => server[:networking][:wireguard][:public_key],
+ :allowed_ips => server[:networking][:wireguard][:address],
+ :endpoint => "#{server.name}:51820"
+ }
+ end
+else
+ node.default[:prometheus][:mode] = "external"
+ node.default[:prometheus][:address] = node.external_ipaddress(:family => :inet)
+end
+
prometheus_exporter "node" do
port 9100
package_options "--no-install-recommends"
include_recipe "apache"
include_recipe "apt"
+include_recipe "networking"
passwords = data_bag_item("prometheus", "passwords")
package "prometheus"
-clients = search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name)
+jobs = {}
+
+search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client|
+ if client[:prometheus][:mode] == "wireguard"
+ node.default[:networking][:wireguard][:peers] << {
+ :public_key => client[:networking][:wireguard][:public_key],
+ :allowed_ips => client[:networking][:wireguard][:address],
+ :endpoint => "#{client.name}:51820"
+ }
+ end
-prometheus_jobs = clients.sort_by(&:name).each_with_object({}) do |client, jobs|
client[:prometheus][:exporters].each do |name, address|
jobs[name] ||= []
jobs[name] << { :address => address, :name => client.name }
owner "root"
group "root"
mode "644"
- variables :jobs => prometheus_jobs
+ variables :jobs => jobs
end
service "prometheus" do
subscribes :restart, "template[#{defaults_name}]"
end
+ firewall_rule "accept-prometheus-#{new_resource.name}" do
+ action :accept
+ source "osm"
+ dest "fw"
+ proto "tcp:syn"
+ dest_ports new_resource.port
+ only_if { node[:prometheus][:mode] == "external" }
+ end
+
node.default[:prometheus][:exporters][new_resource.exporter] = listen_address
end
end
def listen_address
- "#{node.internal_ipaddress}:#{new_resource.port}"
+ "#{node[:prometheus][:address]}:#{new_resource.port}"
end
def service_name