From b69cd345dd41101e5225634fbbea0d774220c23e Mon Sep 17 00:00:00 2001 From: Karl Goetz Date: Tue, 11 Apr 2017 14:32:37 +1000 Subject: [PATCH] Start of contact groups for issue #5 Contact groups are a useful way of sending alerts and avoiding single person failures. I can't quite figure out what I need to do yet so I'm goint to put this on the backburner while I consider issues #7 and #9. --- tasks/configure-shinken.yml | 25 +++++++++++++++++++++++++ templates/contactgroup-admin.cfg.tmpl | 14 ++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 templates/contactgroup-admin.cfg.tmpl diff --git a/tasks/configure-shinken.yml b/tasks/configure-shinken.yml index 6dbbd8b..7cf57ea 100644 --- a/tasks/configure-shinken.yml +++ b/tasks/configure-shinken.yml @@ -9,6 +9,31 @@ notify: - restart shinken arbiter +# Following Jinja magic thanks to mikecee +# - name: Build list of admin users +# set_fact: +# admin_users="{{ shinken_contacts | sum(attribute='is_admin', start=[]) | unique }}" + +# - debug: +# msg: "{{ shinken_contacts.0 }}" +# +# - name: Populate admins list +# set_fact: +# admin_users: "{{ admin_users|default([]) | combine( item.name ) }}" +# with_items: shinken_contacts +# when: item.is_admin == 1 +# +# - name: Install admins contact group +# # with_items: "{{ admin_users }}" +# with_items: "{{ shinken_contacts }}" +# template: +# src: contactgroup-admin.cfg.tmpl +# dest: /etc/shinken/contactgroups/admin.cfg +# notify: +# - restart shinken arbiter + +# TODO: after figuring out admins, do that for users too + - name: Create configuration for services to monitor with_items: "{{ shinken_services }}" template: diff --git a/templates/contactgroup-admin.cfg.tmpl b/templates/contactgroup-admin.cfg.tmpl new file mode 100644 index 0000000..07eafd9 --- /dev/null +++ b/templates/contactgroup-admin.cfg.tmpl @@ -0,0 +1,14 @@ +# {{ ansible_managed }} +{% set admin_users = [0] -%} +{% for key, value in item.iteritems() %} + {% if key == 'is_admin' and value == '1' %} + {% set admin_users.append('item.name') %} + {% endif %} +{% endfor %} + +define contactgroup{ + contactgroup_name admins + alias admins + members {{ admin_users }} +} +