]> git.openstreetmap.org Git - chef.git/commitdiff
Add support for junos exporter
authorTom Hughes <tom@compton.nu>
Wed, 2 Aug 2023 21:24:14 +0000 (22:24 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 3 Aug 2023 08:00:15 +0000 (09:00 +0100)
cookbooks/prometheus/attributes/default.rb
cookbooks/prometheus/files/default/id_rsa.pub [new file with mode: 0644]
cookbooks/prometheus/recipes/default.rb
cookbooks/prometheus/recipes/server.rb
cookbooks/prometheus/resources/exporter.rb
cookbooks/prometheus/templates/default/prometheus.yml.erb
roles/fafnir.rb
roles/ironbelly.rb

index 7ea8bfd1d169e38c675c6a4c5d759bd27cf68bab..0fe80895e3791473e4d79ba802d05b65f88c775e 100644 (file)
@@ -1,5 +1,6 @@
 default[:prometheus][:addresses] = {}
 default[:prometheus][:exporters] = {}
+default[:prometheus][:junos] = {}
 default[:prometheus][:snmp] = {}
 default[:prometheus][:metrics] = {}
 default[:prometheus][:files] = []
diff --git a/cookbooks/prometheus/files/default/id_rsa.pub b/cookbooks/prometheus/files/default/id_rsa.pub
new file mode 100644 (file)
index 0000000..41565df
--- /dev/null
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCwBRhz6gJsBcf5xf1WWEdhm6DjOnVlB5CHn48qEDYk4Gy5j62ZsKq+pBmHIJ1SeoR2ezlsMgKyPouzRkIQgh3Mc1qcy0fmr/szsDwhswKjODyk7vfnkEH5bK70W2/WrrBmBi1RGp03hCnJqWFG5uLaYiO2MjkyihTSoLM4XWj71aohbmOhIQiHB8td24JS+3tsGqNe+UhtKWjk2BJ0lqIhDvpOmuLjxGPMVGzBaC4a18jMYFxZs1AxXf/veLP5cduxA7KxT5nWnun2QsW/P0AThBGkhTny/a2GdmQ/aKAmYftFwnBUtgJtGuo/GXkd5Up8BienJzbZ16HhKFl23cXAuFIV7EJwu8bClzCJQtMUE+7rhAX9StDris1P9e1ldjalUSFBMzPHkhf3nHAju3E14URH8DrnfA8kNrnYvYwCgeH3mAu+yht/6mzZWkoaF94AkJVCQ8KRxsuUO9tZO/hLONMuG5FCao1dofnNtvc797XYWS4X6pjBMW5BpANrFrk= prometheus@openstreetmap.org
index cecfbc74d37c56a92c9ec3f3e32c160f768e8692..0c4bc59da61575abcd2ec1c01c2e1fbd6145c949 100644 (file)
@@ -115,6 +115,23 @@ prometheus_exporter "node" do
   metric_relabel metric_relabel
 end
 
+unless node[:prometheus][:junos].empty?
+  targets = node[:prometheus][:junos].collect { |_, details| details[:address] }.sort.join(",")
+
+  prometheus_exporter "junos" do
+    port 9326
+    options %W[
+      --ssh.user=prometheus
+      --ssh.keyfile=/var/lib/prometheus/junos-exporter/id_rsa
+      --ssh.targets=#{targets}
+      --lacp.enabled=true
+      --power.enabled=false
+    ]
+    ssh true
+    register_target false
+  end
+end
+
 unless node[:prometheus][:snmp].empty?
   prometheus_exporter "snmp" do
     port 9116
index 4ca2d3909b219e798b4ec9c570a96907e9d41ae5..a480a83239b5ad4f924524431892e3345d16660b 100644 (file)
@@ -120,6 +120,7 @@ search(:node, "roles:gateway") do |gateway|
 end
 
 jobs = {}
+junos_targets = []
 snmp_targets = []
 
 search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client|
@@ -162,6 +163,15 @@ search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name).each do |client
     }
   end
 
+  Hash(client[:prometheus][:junos]).each do |instance, details|
+    junos_targets << {
+      :instance => instance,
+      :target => details[:address],
+      :address => client[:prometheus][:addresses]["junos"],
+      :labels => Array(details[:labels])
+    }
+  end
+
   Hash(client[:prometheus][:snmp]).each do |instance, details|
     snmp_targets << {
       :instance => instance,
@@ -214,7 +224,7 @@ template "/etc/prometheus/prometheus.yml" do
   owner "root"
   group "root"
   mode "644"
-  variables :jobs => jobs, :snmp_targets => snmp_targets, :certificates => certificates
+  variables :jobs => jobs, :junos_targets => junos_targets, :snmp_targets => snmp_targets, :certificates => certificates
 end
 
 template "/etc/prometheus/alert_rules.yml" do
index e2d8ca7daf3bd49b68ade0640551150247d4ec9c..5075c5d6ae3a6ed17e928008a030659e3f15990a 100644 (file)
@@ -47,8 +47,27 @@ property :scrape_interval, :kind_of => String
 property :scrape_timeout, :kind_of => String
 property :metric_relabel, :kind_of => Array
 property :register_target, :kind_of => [TrueClass, FalseClass], :default => true
+property :ssh, [true, false]
 
 action :create do
+  if new_resource.ssh && new_resource.user.nil?
+    keys = data_bag_item("prometheus", "keys")
+
+    directory "/var/lib/private/prometheus/#{new_resource.exporter}-exporter" do
+      mode "700"
+      recursive true
+    end
+
+    file "/var/lib/private/prometheus/#{new_resource.exporter}-exporter/id_rsa" do
+      content keys["ssh"].join("\n")
+      mode "400"
+    end
+
+    cookbook_file "/var/lib/private/prometheus/#{new_resource.exporter}-exporter/id_rsa.pub" do
+      mode "644"
+    end
+  end
+
   systemd_service service_name do
     after "network-online.target"
     wants "network-online.target"
@@ -60,6 +79,7 @@ action :create do
     environment new_resource.environment
     exec_start "#{executable_path} #{new_resource.command} #{executable_options}"
     sandbox :enable_network => true
+    state_directory "prometheus/#{new_resource.exporter}-exporter" if new_resource.ssh && new_resource.user.nil?
     protect_proc new_resource.protect_proc if new_resource.property_is_set?(:protect_proc)
     proc_subset new_resource.proc_subset if new_resource.property_is_set?(:proc_subset)
     capability_bounding_set new_resource.capability_bounding_set if new_resource.property_is_set?(:capability_bounding_set)
index daa10a4959c2d2cf9964e1233b4658a8019755cc..02ade7d8e225d9e94dd7b2df6bbd6bbc3f9929d8 100644 (file)
@@ -85,6 +85,26 @@ scrape_configs:
 <% end -%>
 <% end -%>
 <% end -%>
+  - job_name: junos
+    scrape_interval: 5m
+    scrape_timeout: 4m
+    static_configs:
+<% @junos_targets.sort_by { |t| t[:instance] }.each do |target| -%>
+      - targets:
+          - "<%= target[:target] %>/<%= target[:address] %>"
+        labels:
+          instance: <%= target[:instance] %>
+<% target[:labels].sort.each do |name, value| -%>
+          <%= name %>: <%= value %>
+<% end -%>
+<% end -%>
+    relabel_configs:
+      - source_labels: [__address__]
+        regex: "([^/]+)/.*"
+        target_label: __param_target
+      - source_labels: [__address__]
+        regex: "[^/]+/(.*)"
+        target_label: __address__
   - job_name: snmp
     scrape_interval: 5m
     scrape_timeout: 2m
index 5734379ae0d51f86cd3c8e5057b07e77d8656b34..a48f623ca142d0bb22cc38c1fc472f4a240c2165 100644 (file)
@@ -43,6 +43,9 @@ default_attributes(
     }
   },
   :prometheus => {
+    :junos => {
+      "switch1" => { :address => "184.104.226.97", :labels => { "site" => "dublin" } }
+    },
     :snmp => {
       "pdu1" => { :address => "10.0.64.100", :modules => %w[apcups], :labels => { "site" => "dublin" } },
       "pdu2" => { :address => "10.0.64.101", :modules => %w[apcups], :labels => { "site" => "dublin" } },
index 6cf1f9e79b90e34a795f72897ea478542f3e0694..0cb7817e06fe0536005bcc8d8d148899796fa170 100644 (file)
@@ -52,6 +52,9 @@ default_attributes(
     }
   },
   :prometheus => {
+    :junos => {
+      "switch1" => { :address => "184.104.179.129", :labels => { "site" => "amsterdam" } }
+    },
     :snmp => {
       "pdu1" => { :address => "10.0.48.100", :modules => %w[apcups], :labels => { "site" => "amsterdam" } },
       "pdu2" => { :address => "10.0.48.101", :modules => %w[apcups], :labels => { "site" => "amsterdam" } },