Disable SMTP configuration if needed

If the user disables all notifications then the SMTP configuration is no
more required in UI and there is no need to configure an email address
for the Nagios contact.

Fixes-bug: #1541458

Change-Id: I450fe4e5bd6cd0d2a5bfbd4575c4765ba573b6e6
This commit is contained in:
Swann Croiset 2016-02-03 19:01:49 +01:00
parent a50ac05ca3
commit 2fb43d2935
4 changed files with 71 additions and 48 deletions

View File

@ -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', {})

View File

@ -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,

View File

@ -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_'

View File

@ -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"