diff --git a/deployment_scripts/puppet/manifests/nagios.pp b/deployment_scripts/puppet/manifests/nagios.pp index 4d08a6a..f64d1df 100644 --- a/deployment_scripts/puppet/manifests/nagios.pp +++ b/deployment_scripts/puppet/manifests/nagios.pp @@ -18,17 +18,29 @@ $env_id = hiera('deployment_id') $plugin = hiera('lma_infrastructure_alerting') $password = $plugin['nagios_password'] -$send_to = $plugin['send_to'] -$send_from = $plugin['send_from'] -$smtp_host = $plugin['smtp_host'] -$smtp_auth = $plugin['smtp_auth'] -$smtp_user = $plugin['smtp_user'] -$smtp_password = $plugin['smtp_password'] +if $notify_warning == false and + $notify_critical == false and + $notify_unknown == false and + $notify_recovery == false { -$notify_warning = $plugin['notify_warning'] -$notify_critical = $plugin['notify_critical'] -$notify_unknown = $plugin['notify_unknown'] -$notify_recovery = $plugin['notify_recovery'] + $send_to = undef + $send_from = undef + $smtp_host = undef + $smtp_auth = undef + $smtp_password = undef +} else { + $send_to = $plugin['send_to'] + $send_from = $plugin['send_from'] + $smtp_host = $plugin['smtp_host'] + $smtp_auth = $plugin['smtp_auth'] + $smtp_user = $plugin['smtp_user'] + $smtp_password = $plugin['smtp_password'] + + $notify_warning = $plugin['notify_warning'] + $notify_critical = $plugin['notify_critical'] + $notify_unknown = $plugin['notify_unknown'] + $notify_recovery = $plugin['notify_recovery'] +} $lma_collector = hiera_hash('lma_collector', {}) diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/contact.pp b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/contact.pp index e6860bf..7cad31d 100644 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/contact.pp +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/nagios/contact.pp @@ -19,7 +19,7 @@ class lma_infra_alerting::nagios::contact( $ensure = present, - $send_to = $lma_infra_alerting::params::nagios_contact_email, + $send_to = undef, $notify_warning = true, $notify_critical = true, $notify_recovery = true, @@ -35,8 +35,6 @@ class lma_infra_alerting::nagios::contact( ) inherits lma_infra_alerting::params{ - validate_string($send_to) - nagios::contactgroup { $contact_groups: ensure => $ensure, prefix => $lma_infra_alerting::params::nagios_config_filename_prefix, @@ -81,13 +79,19 @@ class lma_infra_alerting::nagios::contact( $_host_notify_options = join($host_notify_options, ',') } - $alias = regsubst($send_to, '@', '_AT_') - if is_array($contact_groups){ - $_contact_groups_string = join($contact_groups, '_') - }else{ + if $send_to { + $alias = regsubst($send_to, '@', '_AT_') + if is_array($contact_groups){ + $_contact_groups_string = join($contact_groups, '_') + }else{ + $_contact_groups_string = $contact_groups + } + } else { + $alias = 'noop' $_contact_groups_string = $contact_groups } $contact_name = "${_contact_groups_string}_${alias}" + nagios::contact { $contact_name: ensure => $ensure, prefix => $lma_infra_alerting::params::nagios_config_filename_prefix, diff --git a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/params.pp b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/params.pp index 6f259dc..8bd761c 100644 --- a/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/params.pp +++ b/deployment_scripts/puppet/modules/lma_infra_alerting/manifests/params.pp @@ -24,7 +24,6 @@ class lma_infra_alerting::params { $nagios_cmd_check_ssh = 'check_ssh' $nagios_contactgroup = 'openstack' - $nagios_contact_email = 'root@localhost' # All configuration files for nagios will be prepended with this prefix $nagios_config_filename_prefix = 'lma_' diff --git a/environment_config.yaml b/environment_config.yaml index d9edf6f..14ff3d0 100644 --- a/environment_config.yaml +++ b/environment_config.yaml @@ -9,37 +9,66 @@ attributes: source: '\S' error: "Invalid value" + notify_critical: + type: "checkbox" + weight: 43 + value: true + label: "Receive CRITICAL notifications by email" + + notify_warning: + type: "checkbox" + weight: 44 + value: true + label: "Receive WARNING notifications by email" + + notify_unknown: + type: "checkbox" + weight: 45 + value: true + label: "Receive UNKNOWN notifications by email" + + notify_recovery: + type: "checkbox" + weight: 46 + value: true + label: "Receive RECOVERY notifications by email" + send_to: value: '' label: 'The recipient email address' description: 'The recipient for the alert notifications' - weight: 43 + weight: 47 type: "text" regex: &email source: '[a-z0-9!#$%&*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.?)?[a-z0-9]?(?:[a-z0-9-]*[a-z0-9])?' error: "Invalid Email" + restrictions: &disable_notifications + - condition: "settings:lma_infrastructure_alerting.notify_critical.value == false and settings:lma_infrastructure_alerting.notify_warning.value == false and settings:lma_infrastructure_alerting.notify_unknown.value == false and settings:lma_infrastructure_alerting.notify_recovery.value == false" + action: "disable" send_from: value: '' label: 'The sender email address' description: '' - weight: 44 + weight: 48 type: "text" regex: *email + restrictions: *disable_notifications smtp_host: value: '' label: 'SMTP server IP and port' description: 'ie: 10.2.2.3:25' - weight: 45 + weight: 49 type: "text" regex: source: '^[a-zA-Z\d][a-zA-Z\d_\-.]+(:[0-9]+)?$' error: 'Invalid address or name' + restrictions: *disable_notifications smtp_auth: type: "radio" - weight: 47 + weight: 50 value: "none" label: "SMTP authentication method" values: @@ -51,45 +80,24 @@ attributes: label: "Plain" - data: "cram-md5" label: "CRAMMD5" + restrictions: *disable_notifications smtp_user: value: '' label: 'SMTP user' description: '' - weight: 48 + weight: 51 type: "text" restrictions: &no_auth - condition: "settings:lma_infrastructure_alerting.smtp_auth.value == 'none'" action: "disable" + - condition: "settings:lma_infrastructure_alerting.notify_critical.value == false and settings:lma_infrastructure_alerting.notify_warning.value == false and settings:lma_infrastructure_alerting.notify_unknown.value == false and settings:lma_infrastructure_alerting.notify_recovery.value == false" + action: "disable" smtp_password: value: '' label: 'SMTP password' description: '' - weight: 49 + weight: 52 type: "password" restrictions: *no_auth - - notify_critical: - type: "checkbox" - weight: 50 - value: true - label: "Receive CRITICAL notifications by email" - - notify_warning: - type: "checkbox" - weight: 51 - value: true - label: "Receive WARNING notifications by email" - - notify_unknown: - type: "checkbox" - weight: 52 - value: true - label: "Receive UNKNOWN notifications by email" - - notify_recovery: - type: "checkbox" - weight: 53 - value: true - label: "Receive RECOVERY notifications by email"