From bd2cf68b83a65c8c0837ebf659260c1e1f25643a Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Mon, 26 Oct 2015 11:46:34 +0100 Subject: [PATCH] Align with the new alarm schema The Hiera data has a new schema for defining alarms. This change updates the afds_to_nagios_services Puppet function to reflect this. Change-Id: I018f110f7f832df03744d9e9f18833e71a6b9ed4 Depends-On: I0648add1396773f871508103c9255b82c11afb46 --- .../functions/afds_to_nagios_services.rb | 26 +++++-------- .../functions/afds_to_nagios_services_spec.rb | 38 +++++++++---------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/lib/puppet/parser/functions/afds_to_nagios_services.rb b/deployment_scripts/puppet/modules/lma_infra_alerting/lib/puppet/parser/functions/afds_to_nagios_services.rb index 4ff88d0..be0d3d0 100644 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/lib/puppet/parser/functions/afds_to_nagios_services.rb +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/lib/puppet/parser/functions/afds_to_nagios_services.rb @@ -20,16 +20,16 @@ It expects 5 arguments: 1. An array of nodes, each node being described as a hash. 2. The key containing the node's name. 3. The key containing the node's role. -4. The mapping between clusters and node's roles -4. The mapping between cluster and the AFD alarms +4. The mapping between AFD profiles and node's roles +4. The mapping between AFD profiles and alarms *Examples:* $hash = afds_to_nagios_services( [{'name' => 'node-1', role => 'primary-controller'}, {'name' => 'node-2', role => 'controller'}], 'name', 'role', - [{'control_nodes' => ['primary-controller', 'controller']}], - [{'control_nodes' => [{'cpu' => ['alarm1']}, {'fs' => ['alarm1']}]}] + {'control_nodes' => ['primary-controller', 'controller']}, + {'control_nodes' => {'cpu' => ['alarm1'], 'fs' => ['alarm1']}} ) Would return: @@ -52,9 +52,9 @@ Would return: name_key = arguments[1] role_key = arguments[2] role_to_cluster = arguments[3] - raise(Puppet::ParseError, "arg3 isn't an array!") if ! role_to_cluster.is_a?(Array) + raise(Puppet::ParseError, "arg3 isn't a hash!") if ! role_to_cluster.is_a?(Hash) afds = arguments[4] - raise(Puppet::ParseError, "arg4 isn't an array!") if ! afds.is_a?(Array) + raise(Puppet::ParseError, "arg4 isn't a hash!") if ! afds.is_a?(Hash) result = {} @@ -65,10 +65,8 @@ Would return: unless node_clusters.has_key?(node_name) then node_clusters[node_name] = Set.new([]) end - role_to_cluster.each do |x| - x.each do |cluster, roles| - node_clusters[node_name] << cluster if roles.include?(node[role_key]) - end + role_to_cluster.each do |cluster, roles| + node_clusters[node_name] << cluster if roles.include?(node[role_key]) end end @@ -78,12 +76,8 @@ Would return: node_services = {} clusters.each do |cluster| - afds.each do |x| - (x[cluster] || []).each do |y| - y.keys.sort.each do |source| - node_services["#{node}.#{cluster}.#{source}"] = "#{ cluster }.#{ source }".gsub(/\s+/, '_') - end - end + (afds[cluster] || {}).keys.each do |source| + node_services["#{node}.#{cluster}.#{source}"] = "#{ cluster }.#{ source }".gsub(/\s+/, '_') end end diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/spec/functions/afds_to_nagios_services_spec.rb b/deployment_scripts/puppet/modules/lma_infra_alerting/spec/functions/afds_to_nagios_services_spec.rb index 50cb652..4336dc8 100644 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/spec/functions/afds_to_nagios_services_spec.rb +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/spec/functions/afds_to_nagios_services_spec.rb @@ -80,25 +80,25 @@ describe 'afds_to_nagios_services' do "user_node_name" => "slave-02_compute_cinder"} ] - role_to_cluster = [ - {"controller" => ["primary-controller", "controller"]}, - {"compute" => ["compute"]}, - {"storage" => ["cinder", "ceph-osd"]} - ] - afds = [ - {"controller" => [ - {"system" => ["cpu-critical-controller", "cpu-warning-controller"]}, - {"fs" => ["fs-critical", "fs-warning"]}]}, - {"compute" => [ - {"system" => ["cpu-critical-compute", "cpu-warning-compute"]}, - {"fs" => ["fs-critical", "fs-critical-compute", "fs-warning"]}]}, - {"storage" => [ - {"system" => ["cpu-critical-storage", "cpu-warning-storage"]}, - {"fs" => ["fs-critical-storage", "fs-warning-storage"]}]}, - {"default" => [ - {"cpu" => ["cpu-critical-default"]}, - {"fs" => ["fs-critical", "fs-warning"]}]} - ] + role_to_cluster = { + "controller" => ["primary-controller", "controller"], + "compute" => ["compute"], + "storage" => ["cinder", "ceph-osd"] + } + afds = { + "controller" => { + "system" => ["cpu-critical-controller", "cpu-warning-controller"], + "fs" => ["fs-critical", "fs-warning"]}, + "compute" => { + "system" => ["cpu-critical-compute", "cpu-warning-compute"], + "fs" => ["fs-critical", "fs-critical-compute", "fs-warning"]}, + "storage" => { + "system" => ["cpu-critical-storage", "cpu-warning-storage"], + "fs" => ["fs-critical-storage", "fs-warning-storage"]}, + "default" => { + "cpu" => ["cpu-critical-default"], + "fs" => ["fs-critical", "fs-warning"]} + } describe 'with argumentss' do it { should run.with_params(all_nodes, 'name', 'role', role_to_cluster, afds).and_return( {"default checks for node-1" => {