nagios-charmers team mailing list archive
-
nagios-charmers team
-
Mailing list archive
-
Message #00979
[Merge] ~addyess/charm-nagios:lp1841358_multiple_admin_emails into charm-nagios:master
Adam Dyess has proposed merging ~addyess/charm-nagios:lp1841358_multiple_admin_emails into charm-nagios:master.
Commit message:
[Bug 1841358] Fix/Feature for setting multiple email addresses to receive nagios admin alerts
Requested reviews:
Mihaela Andronic (mihaela)
Canonical BootStack CREs (canonical-bootstack-cre)
Nagios Charm developers (nagios-charmers)
For more details, see:
https://code.launchpad.net/~addyess/charm-nagios/+git/charm-nagios/+merge/387045
--
Your team Nagios Charm developers is requested to review the proposed merge of ~addyess/charm-nagios:lp1841358_multiple_admin_emails into charm-nagios:master.
diff --git a/.gitignore b/.gitignore
index e650362..15e0730 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@ data/*.pem
data/*.key
data/*.crt
data/*.csr
+.tox/
+.idea/
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 9d48829..9ec5c65 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,10 @@ export PYTHONPATH := hooks
default:
echo Nothing to do
+lint:
+ @echo "Running flake8"
+ @tox -e lint
+
# Primitive test runner. Someone please fix this.
test:
tests/00-setup
diff --git a/hooks/templates/contacts-cfg.tmpl b/hooks/templates/contacts-cfg.tmpl
index 8f28acf..f182fcf 100644
--- a/hooks/templates/contacts-cfg.tmpl
+++ b/hooks/templates/contacts-cfg.tmpl
@@ -17,19 +17,19 @@
###############################################################################
# In this simple config file, a single contact will receive all alerts.
-
+{% for contact in contacts %}
define contact{
- contact_name root
- alias Root
+ contact_name {{ contact['contact_name'] }}
+ alias {{ contact['alias'] }}
service_notification_period {{ admin_service_notification_period }}
host_notification_period {{ admin_host_notification_period }}
service_notification_options {{ admin_service_notification_options }}
host_notification_options {{ admin_host_notification_options }}
service_notification_commands {{ admin_service_notification_commands }}
host_notification_commands {{ admin_host_notification_commands }}
- email {{ admin_email }}
+ email {{ contact['email'] }}
}
-
+{% endfor %}
###############################################################################
diff --git a/hooks/test-common.py b/hooks/test-common.py
index db19d41..b7be677 100644
--- a/hooks/test-common.py
+++ b/hooks/test-common.py
@@ -39,7 +39,7 @@ if not os.path.exists(o2.name):
raise RuntimeError(o2.name)
y.kill_tag('monitors:2')
-y.cleanup_untagged(['monitors:1','monitors:3'])
+y.cleanup_untagged(['monitors:1', 'monitors:3'])
if os.path.exists(o.name):
raise RuntimeError(o2.name)
diff --git a/hooks/upgrade-charm b/hooks/upgrade-charm
index a80743b..2625ba3 100755
--- a/hooks/upgrade-charm
+++ b/hooks/upgrade-charm
@@ -160,8 +160,39 @@ def enable_pagerduty_config():
if os.path.isfile(pagerduty_cron):
os.remove(pagerduty_cron)
- # Update contacts for admin
+ # Multiple Email Contacts
contactgroup_members = hookenv.config("contactgroup-members")
+ contacts = []
+ admin_email = list(
+ filter(None, set(hookenv.config('admin_email').split(',')))
+ )
+ if len(admin_email) == 0:
+ hookenv.log("admin_email is unset, this isn't valid config")
+ hookenv.status_set("blocked", "admin_email is not configured")
+ exit(0)
+ hookenv.status_set("active", "ready")
+ if len(admin_email) == 1:
+ hookenv.log("Setting one admin email address '%s'" % admin_email[0])
+ contacts = [{
+ 'contact_name': 'root',
+ 'alias': 'Root',
+ 'email': admin_email[0]
+ }]
+ elif len(admin_email) > 1:
+ hookenv.log("Setting %d admin email addresses" % len(admin_email))
+ contacts = [
+ {
+ 'contact_name': email,
+ 'alias': email,
+ 'email': email
+ }
+ for email in admin_email
+ ]
+ contactgroup_members = ', '.join([
+ c['contact_name'] for c in contacts
+ ])
+
+ # Update contacts for admin
if enable_pagerduty:
# avoid duplicates
if "pagerduty" not in contactgroup_members:
@@ -173,7 +204,7 @@ def enable_pagerduty_config():
'admin_host_notification_options': hookenv.config('admin_host_notification_options'),
'admin_service_notification_commands': hookenv.config('admin_service_notification_commands'),
'admin_host_notification_commands': hookenv.config('admin_host_notification_commands'),
- 'admin_email': hookenv.config('admin_email'),
+ 'contacts': contacts,
'contactgroup_members': contactgroup_members}
with open('hooks/templates/contacts-cfg.tmpl', 'r') as f:
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..18da390
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,50 @@
+[tox]
+skipsdist=True
+;envlist = unit, functional
+skip_missing_interpreters = True
+
+[testenv]
+basepython = python3
+setenv =
+ PYTHONPATH = .
+
+;[testenv:unit]
+;commands =
+; {toxworkdir}/../tests/download_nagios_plugin3.py
+; pytest -v --ignore {toxinidir}/tests/functional \
+; --cov=lib \
+; --cov=reactive \
+; --cov=actions \
+; --cov-report=term \
+; --cov-report=annotate:reports/annotated \
+; --cov-report=html:reports/html
+;deps = -r{toxinidir}/tests/unit/requirements.txt
+; -r{toxinidir}/requirements.txt
+;setenv = PYTHONPATH={toxinidir}/lib:{envdir}/lib/python3.8
+;
+;[testenv:functional]
+;passenv =
+; HOME
+; CHARM_BUILD_DIR
+; PATH
+; PYTEST_KEEP_MODEL
+; PYTEST_CLOUD_NAME
+; PYTEST_CLOUD_REGION
+; PYTEST_MODEL
+;commands = pytest -v --ignore {toxinidir}/tests/unit
+;deps = -r{toxinidir}/tests/functional/requirements.txt
+; -r{toxinidir}/requirements.txt
+
+[testenv:lint]
+commands = flake8
+deps = flake8
+
+[flake8]
+exclude =
+ .git,
+ __pycache__,
+ .tox,
+ hooks/charmhelpers
+ bin
+max-line-length = 120
+max-complexity = 10