From 086b96b7c61de5633efa82adc5a9fa4761ec8fa5 Mon Sep 17 00:00:00 2001 From: Swann Croiset Date: Tue, 13 Sep 2016 16:35:55 +0200 Subject: [PATCH] Support activate_alarming and enable_notification With activate_alarming=false, AFDs are not configured in Nagios, if 'activate_alarming' is not set the AFDs are configured. if AFDs are configured and 'enable_notification' and is true, the notification are enabled. Change-Id: I561fae6e7e62f237bee58771c91c6344332f239d blueprint: alarming-refactoring --- .../functions/afds_to_nagios_services.rb | 37 +++++++--- .../manifests/nagios/hosts.pp | 6 +- .../functions/afds_to_nagios_services_spec.rb | 71 +++++++++++++++++-- 3 files changed, 93 insertions(+), 21 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 10e7255..e48ea88 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 @@ -75,22 +75,37 @@ Would return: node_clusters.each do |node, clusters| clusters << "default" if clusters.empty? - node_services = {} clusters.each do |cluster| + notifications_enabled = 0 afds_map = afds.select {|c, a| a.has_key?('apply_to_node') and a['apply_to_node'] == cluster} - afds_map.each do |c, a| - a['alarms'].keys.each do |source| - node_services["#{node}.#{cluster}.#{source}"] = "#{ cluster }.#{ source }".gsub(/\s+/, '_') + afds_map.each do |logical_cluster, a| + node_services = {} + if not a.has_key?('activate_alerting') + configure=true + elsif a['activate_alerting'] == true + configure=true + else + configure=false + end + + if configure + if a.has_key?('enable_notification') and a['enable_notification'] == true + notifications_enabled = 1 + end + a['alarms'].keys.each do |source| + node_services["#{node}.#{logical_cluster}.#{source}"] = "#{ logical_cluster }.#{ source }".gsub(/\s+/, '_') + end + end + + unless node_services.empty? then + result["#{ logical_cluster } checks for #{ node }"] = { + 'hostname' => node, + 'services' => node_services, + 'notifications_enabled' => notifications_enabled, + } end end end - - unless node_services.empty? then - result["#{ clusters.to_a.sort.join(', ') } checks for #{ node }"] = { - 'hostname' => node, - 'services' => node_services - } - end end return result diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/hosts.pp b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/hosts.pp index 30f1d4a..c4887eb 100644 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/hosts.pp +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/hosts.pp @@ -74,16 +74,14 @@ class lma_infra_alerting::nagios::hosts ( $role_key, $node_profiles, $node_cluster_alarms) - #$afd_service_defaults = {'notifications_enabled' => 0} - create_resources(lma_infra_alerting::nagios::services, $afd_nodes, {}) + create_resources(lma_infra_alerting::nagios::services, $afd_nodes) $afd_services = afds_to_nagios_services($hosts, $host_name_key, $role_key, $node_profiles, $service_cluster_alarms) - $afd_service_defaults = {'notifications_enabled' => 0} - create_resources(lma_infra_alerting::nagios::services, $afd_services, $afd_service_defaults) + create_resources(lma_infra_alerting::nagios::services, $afd_services) if empty($node_profiles) and empty($node_cluster_alarms) { $node_uid= hiera('uid') 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 3d441fe..a8a22be 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 @@ -16,6 +16,16 @@ require 'spec_helper' describe 'afds_to_nagios_services' do all_nodes = [ + {"fqdn" => "node-5.test.domain.local", + "internal_address" => "10.109.5.5", + "internal_netmask" => "255.255.255.0", + "name" => "node-5", + "node_roles" => ["elasticsearch_kibana"], + "storage_address" => "10.109.10.2", + "storage_netmask" => "255.255.255.0", + "swift_zone" => "1", + "uid" => "5", + "user_node_name" => "slave-03_alerting"}, {"fqdn" => "node-1.test.domain.local", "internal_address" => "10.109.2.5", "internal_netmask" => "255.255.255.0", @@ -58,16 +68,29 @@ describe 'afds_to_nagios_services' do "swift_zone" => "2", "uid" => "2", "user_node_name" => "slave-02_compute_cinder"}, + {"fqdn" => "node-42.test.domain.local", + "internal_address" => "10.109.2.42", + "internal_netmask" => "255.255.255.0", + "name" => "node-2", + "node_roles" => ["foo-role"], + "storage_address" => "10.109.4.42", + "storage_netmask" => "255.255.255.0", + "swift_zone" => "2", + "uid" => "42", + "user_node_name" => "slave-42_foo-role"}, ] role_to_cluster = { "controller" => {"roles" => ["primary-controller", "controller"]}, "compute" => {"roles" => ["compute"]}, - "storage" => {"roles" => ["cinder", "ceph-osd"]} + "storage" => {"roles" => ["cinder", "ceph-osd"]}, + "elasticsearch" => {"roles" => ["elasticsearch_kibana"]}, + "foo" => {"roles" => ["foo-role"]} } afds = { "controller" => { "apply_to_node" => "controller", + "enable_notification" => true, "alarms" => { "system-ctrl" => ["cpu-critical-controller", "cpu-warning-controller"], "fs" => ["fs-critical", "fs-warning"] @@ -75,6 +98,7 @@ describe 'afds_to_nagios_services' do }, "compute" => { "apply_to_node" => "compute", + "enable_notification" => true, "alarms" => { "system-compute" => ["cpu-critical-compute", "cpu-warning-compute"], "fs" => ["fs-critical", "fs-critical-compute", "fs-warning"] @@ -82,13 +106,31 @@ describe 'afds_to_nagios_services' do }, "storage" => { "apply_to_node" => "storage", + "enable_notification" => true, "alarms" => { "system-storage" => ["cpu-critical-storage", "cpu-warning-storage"], "fs" => ["fs-critical-storage", "fs-warning-storage"] } }, + "elasticsearch-cluster" => { + "apply_to_node" => "elasticsearch", + "activate_alerting" => true, + "alarms" => { + "cpu" => ["cpu-critical-es"], + "fs" => ["fs-critical-es", "fs-warning-es"] + } + }, "default" => { "apply_to_node" => "default", + "activate_alerting" => true, + "alarms" => { + "cpu" => ["cpu-critical-default"], + "fs" => ["fs-critical", "fs-warning"] + } + }, + "bar-cluster" => { + "apply_to_node" => "bar", + "activate_alerting" => false, "alarms" => { "cpu" => ["cpu-critical-default"], "fs" => ["fs-critical", "fs-warning"] @@ -100,30 +142,47 @@ describe 'afds_to_nagios_services' do { "default checks for node-1" => { "hostname" => "node-1", + "notifications_enabled" => 0, "services" => { "node-1.default.cpu" => "default.cpu", "node-1.default.fs" => "default.fs", }}, "controller checks for node-3" => { "hostname" => "node-3", + "notifications_enabled" => 1, "services" => { "node-3.controller.fs" => "controller.fs", "node-3.controller.system-ctrl" => "controller.system-ctrl" }}, - "default checks for node-4" => { + "elasticsearch-cluster checks for node-4" => { "hostname" => "node-4", + "notifications_enabled" => 0, "services" => { - "node-4.default.cpu" => "default.cpu", - "node-4.default.fs" => "default.fs" + "node-4.elasticsearch-cluster.cpu" => "elasticsearch-cluster.cpu", + "node-4.elasticsearch-cluster.fs" => "elasticsearch-cluster.fs" }}, - "compute, storage checks for node-2" => { + "elasticsearch-cluster checks for node-5" => { + "hostname" => "node-5", + "notifications_enabled" => 0, + "services" => { + "node-5.elasticsearch-cluster.cpu" => "elasticsearch-cluster.cpu", + "node-5.elasticsearch-cluster.fs" => "elasticsearch-cluster.fs" + }}, + "compute checks for node-2" => { "hostname" => "node-2", + "notifications_enabled" => 1, "services" => { "node-2.compute.fs" => "compute.fs", "node-2.compute.system-compute" => "compute.system-compute", + }}, + "storage checks for node-2" => { + "hostname" => "node-2", + "notifications_enabled" => 1, + "services" => { "node-2.storage.fs" => "storage.fs", "node-2.storage.system-storage" => "storage.system-storage" - }}}) + }} + }) } end end