From 3c85fa18d3bbaf4263cb98ad840db0349ac1472a Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Mon, 13 Feb 2017 07:12:45 +0100 Subject: [PATCH 01/13] Update to version 1.2.8p17 --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 02559ef..fb15b7f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,7 +9,7 @@ # .. envvar:: checkmk_server__version # # Check_MK software version. -checkmk_server__version: '1.2.8p16' +checkmk_server__version: '1.2.8p17' # .. envvar:: checkmk_server__version_label From 35e1648d1a33c7f0c43a272e18824edd5a9caf26 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 14 Feb 2017 07:24:14 +0100 Subject: [PATCH 02/13] Add rule for setting 'notification_fallback_email' --- defaults/main.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index fb15b7f..3837f36 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -486,6 +486,7 @@ checkmk_server__site_config_map: '{{ checkmk_server__site_cfg_contactgroups + checkmk_server__site_cfg_servicegroups + checkmk_server__site_cfg_datasource_programs + checkmk_server__site_cfg_netif_description + + checkmk_server__site_cfg_notification_defaults + checkmk_server__site_cfg_software_inventory }}' @@ -591,6 +592,20 @@ checkmk_server__site_cfg_software_inventory: else "absent" }}' +# .. envvar:: checkmk_server__site_cfg_notification_defaults +# +# Set fallback email address for rule based notifications. Must be set +# including domain otherwise it won't be accepted by Check_MK. +checkmk_server__site_cfg_notification_defaults: + - name: 'notification_fallback_email' + filename: 'global.mk' + template: 'key_value' + value: '{{ ansible_local.core.admin_public_email[0] + if ("core" in ansible_local) and + ("admin_public_email" in ansible_local.core) + else "root@" + ansible_domain }}' + + # .. envvar:: checkmk_server__site_cfg_netif_description # # Set interface name instead of index for network interface check via From d270b416595436db3e0ee180ab1661e8b015bd8c Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 14 Feb 2017 20:31:10 +0100 Subject: [PATCH 03/13] Properly quote values if string --- templates/macros/checkmk_config.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/macros/checkmk_config.j2 b/templates/macros/checkmk_config.j2 index 2ddc51c..38d7f57 100644 --- a/templates/macros/checkmk_config.j2 +++ b/templates/macros/checkmk_config.j2 @@ -120,7 +120,7 @@ {% macro tmpl_var__key_value(_name, _value) %} -{{ _name }} = {{ _value }} +{{ _name }} = {{ "'" + _value + "'" if (_value is string) else _value }} {% endmacro %} From fddd1f8d8122c38a8863fbb6ae15e12835fe222d Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 14 Feb 2017 20:51:23 +0100 Subject: [PATCH 04/13] Values must be 'str' else 'inventory_processes_rules' will fail --- templates/macros/checkmk_config.j2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/macros/checkmk_config.j2 b/templates/macros/checkmk_config.j2 index 38d7f57..9d1f108 100644 --- a/templates/macros/checkmk_config.j2 +++ b/templates/macros/checkmk_config.j2 @@ -305,11 +305,12 @@ if {{ _name }} == None: {% set _rule = "'" + _value + "'" %} {% elif (_value is mapping) or (_value is sequence) %} {# - # Remove unicode hints for dictionary keys. + # Remove unicode hints for dictionary keys and values. # Substitute lists with tuples: ['foo', 'bar'] -> ('foo', 'bar') # Fix nested lists: ({'foo': (bar)}) -> ('foo', ('bar')) #} {% set _rule = _value | regex_replace("(, |{)u'", "\\1'") | + regex_replace(": u'", ": '") | replace("[", "(") | replace("]", ")") | regex_replace("\({('[\w]+'):", "(\\1,") | replace(")})", "))") %} {% else %} From 9f448d2c97b3c1adba868e0c75ed2a3c1bf1199c Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 14 Feb 2017 20:52:24 +0100 Subject: [PATCH 05/13] Add test/reference for 'custom_checks' configuration --- tests/reference.mk | 5 +++++ tests/test_templates.yml | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/tests/reference.mk b/tests/reference.mk index 4d88eea..02c6687 100644 --- a/tests/reference.mk +++ b/tests/reference.mk @@ -85,3 +85,8 @@ checkgroup_parameters.setdefault('threads', []) checkgroup_parameters['threads'] = [ ( (4000, 8000), ['physical', ], ALL_HOSTS, {'description': u'Physical servers need to handle a lot of threads'} ), ] + checkgroup_parameters['threads'] + + +custom_checks = [ + ( {'service_description': u'Galera Cluster', 'command_line': '$USER1$/check_by_ssh -t 60 -E -H $HOSTADDRESS$ -C "sudo /usr/lib64/nagios/plugins/check_galera_cluster -c 1"'}, [], ['mysql01.example.com', 'mysql02.example.com'] ), +] diff --git a/tests/test_templates.yml b/tests/test_templates.yml index e719a7c..74b451a 100644 --- a/tests/test_templates.yml +++ b/tests/test_templates.yml @@ -123,6 +123,16 @@ value: [ 4000, 8000 ] tags: [ 'physical' ] description: 'Physical servers need to handle a lot of threads' + # custom_checks + - name: 'custom_checks' + filename: 'rules.mk' + template: 'rule' + value: + service_description: 'Galera Cluster' + command_line: '$USER1$/check_by_ssh -t 60 -E -H $HOSTADDRESS$ -C "sudo /usr/lib64/nagios/plugins/check_galera_cluster -c 1"' + hosts: + - 'mysql01.example.com' + - 'mysql02.example.com' tasks: - template: From cc794c5265feeb7c6efa949674cd07353f644a60 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 14 Feb 2017 20:53:13 +0100 Subject: [PATCH 06/13] Define 'custom_checks' variable format --- vars/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vars/main.yml b/vars/main.yml index a46c02c..7b86372 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -37,6 +37,9 @@ checkmk_server__confd_variable_map: checkgroup_parameters: filename: 'rules.mk' template: 'rule_w_default' + custom_checks: + filename: 'rules.mk' + template: 'rule' datasource_programs: filename: 'rules.mk' template: 'rule' From d6074f40cd79cdfdbc85b2a45f688831cf35d1d9 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 14 Feb 2017 20:59:07 +0100 Subject: [PATCH 07/13] Adjust default contract group naming to upstream The 'all' contact group is meant to receive notifications for every service on every host. Therefore follow upstream to call it 'Everything' instead of 'Everybody'. --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 3837f36..1e03a12 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -513,7 +513,7 @@ checkmk_server__contact_defaults: checkmk_server__site_cfg_contactgroups: - name: 'define_contactgroups' value: - all: 'Everybody' + all: 'Everything' # .. envvar:: checkmk_server__site_cfg_rules From 6aa91541d9da43c05d00f449e2ab58eada18ffeb Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Fri, 24 Feb 2017 18:08:17 +0100 Subject: [PATCH 08/13] Update to version 1.2.8p18 --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 1e03a12..0b696e8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,7 +9,7 @@ # .. envvar:: checkmk_server__version # # Check_MK software version. -checkmk_server__version: '1.2.8p17' +checkmk_server__version: '1.2.8p18' # .. envvar:: checkmk_server__version_label From 93f02d186f0ab78d97ce46bb619fe3f36197783c Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Sun, 19 Mar 2017 23:52:38 +0100 Subject: [PATCH 09/13] Add support for installing Check_MK extension packages (MKP) --- defaults/main.yml | 7 +++++++ docs/defaults-configuration.rst | 21 +++++++++++++++++++++ docs/getting-started.rst | 3 +++ tasks/site.yml | 30 ++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 1e03a12..13350be 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -618,6 +618,13 @@ checkmk_server__site_cfg_netif_description: wato: False +# .. envvar:: checkmk_server__site_packages +# +# Additional Check_MK packages (MKP) to be installed. See +# :ref:`checkmk_server__site_packages` for more information. +checkmk_server__site_packages: [] + + # ----------------- # PKI Configuration # ----------------- diff --git a/docs/defaults-configuration.rst b/docs/defaults-configuration.rst index 24b3561..1eeb9d6 100644 --- a/docs/defaults-configuration.rst +++ b/docs/defaults-configuration.rst @@ -56,6 +56,27 @@ following keys: key set with ``privatekey_file``. +.. _checkmk_server__site_packages: + +checkmk_server__site_packages +----------------------------- + +Check_MK has a plugin system where site customizations such as additional +checks can be installed. This is done via ``.mkp`` packages. For more +information see the upstream documentation about `Check_MK extension packages`_. + +.. _Check_MK extension packages: https://mathias-kettner.com/cms_mkps.html + +Packages which should be installed for the current Check_MK site are defined +as a list of YAML dictionaries with the following configuration keys: + +``name`` + Name of the package, required. + +``url`` + Download URL of the ``.mkp`` package archive, required. + + .. _checkmk_server__multisite_users: checkmk_server__multisite_users diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 11da33f..0d451b9 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -52,3 +52,6 @@ Available role tags: ``role::checkmk_server:multisite`` Execute tasks which configure the Check_MK multisite Web interface. + +``role::checkmk_server:mkp`` + Execute tasks to install Check_MK packages. diff --git a/tasks/site.yml b/tasks/site.yml index 64fe6d5..f81619c 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -139,3 +139,33 @@ ignore_errors: '{{ ansible_check_mode }}' register: checkmk_server__register_ssh_public_key when: checkmk_server__sshkeys|d() + +- name: Query installed Check_MK packages + command: mkp list + become_user: '{{ checkmk_server__user }}' + become_flags: '-i' + changed_when: False + always_run: True + register: checkmk_server__register_mkp + tags: + - 'role::checkmk_server:mkp' + +- name: Download Check_MK packages + get_url: + url: '{{ item.url }}' + dest: '{{ checkmk_server__site_home }}/tmp' + when: ('url' in item) and + (item.name not in checkmk_server__register_mkp.stdout_lines) + register: checkmk_server__register_mkp_download + with_items: '{{ checkmk_server__site_packages }}' + tags: + - 'role::checkmk_server:mkp' + +- name: Install Check_MK packages + command: mkp install '{{ item.dest|d() }}' + become_user: '{{ checkmk_server__user }}' + become_flags: '-i' + when: not item.skipped + with_items: '{{ checkmk_server__register_mkp_download.results }}' + tags: + - 'role::checkmk_server:mkp' From 344dc705cc1decb882d7e72e95d939473c906940 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 21 Mar 2017 07:02:52 +0100 Subject: [PATCH 10/13] Correctly used skipped filter --- tasks/site.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/site.yml b/tasks/site.yml index f81619c..16de5dd 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -165,7 +165,7 @@ command: mkp install '{{ item.dest|d() }}' become_user: '{{ checkmk_server__user }}' become_flags: '-i' - when: not item.skipped + when: not (item | skipped) with_items: '{{ checkmk_server__register_mkp_download.results }}' tags: - 'role::checkmk_server:mkp' From 5335762b32ef41bcb4fdf41cdad97f82811039bc Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 21 Mar 2017 07:24:47 +0100 Subject: [PATCH 11/13] Add support for also uploading local package archives --- docs/defaults-configuration.rst | 9 +++++++-- tasks/site.yml | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/defaults-configuration.rst b/docs/defaults-configuration.rst index 1eeb9d6..d8b422c 100644 --- a/docs/defaults-configuration.rst +++ b/docs/defaults-configuration.rst @@ -68,13 +68,18 @@ information see the upstream documentation about `Check_MK extension packages`_. .. _Check_MK extension packages: https://mathias-kettner.com/cms_mkps.html Packages which should be installed for the current Check_MK site are defined -as a list of YAML dictionaries with the following configuration keys: +as a list of YAML dictionaries with the following configuration keys. One of +``path`` or ``url`` must be given: ``name`` Name of the package, required. +``path`` + Optional. Local file system path of the ``.mkp`` package archive on the + Ansible controller. + ``url`` - Download URL of the ``.mkp`` package archive, required. + Optional. Download URL of the ``.mkp`` package archive. .. _checkmk_server__multisite_users: diff --git a/tasks/site.yml b/tasks/site.yml index 16de5dd..c54c0bd 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -161,11 +161,24 @@ tags: - 'role::checkmk_server:mkp' +- name: Upload Check_MK packages + copy: + src: '{{ item.path }}' + dest: '{{ checkmk_server__site_home }}/tmp' + when: ('path' in item) and + (item.name not in checkmk_server__register_mkp.stdout_lines) + register: checkmk_server__register_mkp_upload + with_items: '{{ checkmk_server__site_packages }}' + tags: + - 'role::checkmk_server:mkp' + - name: Install Check_MK packages command: mkp install '{{ item.dest|d() }}' become_user: '{{ checkmk_server__user }}' become_flags: '-i' when: not (item | skipped) - with_items: '{{ checkmk_server__register_mkp_download.results }}' + with_flattened: + - '{{ checkmk_server__register_mkp_download.results }}' + - '{{ checkmk_server__register_mkp_upload.results }}' tags: - 'role::checkmk_server:mkp' From ede8dba4185cbdfbba09f492eefa07c98e44d69f Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 21 Mar 2017 18:12:41 +0100 Subject: [PATCH 12/13] Add optional parameter 'checksum' to package download --- docs/defaults-configuration.rst | 12 ++++++++++-- tasks/site.yml | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/defaults-configuration.rst b/docs/defaults-configuration.rst index d8b422c..b40a425 100644 --- a/docs/defaults-configuration.rst +++ b/docs/defaults-configuration.rst @@ -76,10 +76,18 @@ as a list of YAML dictionaries with the following configuration keys. One of ``path`` Optional. Local file system path of the ``.mkp`` package archive on the - Ansible controller. + Ansible controller. Cannot be combined with the ``url`` parameter. ``url`` - Optional. Download URL of the ``.mkp`` package archive. + Optional. Download URL of the ``.mkp`` package archive. Cannot be combined + with the ``path`` parameter. + +``checksum`` + Optional. Checksum of the download archive given in the ``url`` parameter. + Cannot be combined with the ``path`` parameter. For the accepted parameter + format check the Ansible `get_url module`_ documentation. + +.. _get_url module: https://docs.ansible.com/ansible/get_url_module.html#options .. _checkmk_server__multisite_users: diff --git a/tasks/site.yml b/tasks/site.yml index c54c0bd..b7c178c 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -154,6 +154,7 @@ get_url: url: '{{ item.url }}' dest: '{{ checkmk_server__site_home }}/tmp' + checksum: '{{ item.checksum|d(omit) }}' when: ('url' in item) and (item.name not in checkmk_server__register_mkp.stdout_lines) register: checkmk_server__register_mkp_download From 1023fdfcb3b3a6407f331100ba72aba2c448dc28 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Mon, 3 Apr 2017 17:37:51 +0200 Subject: [PATCH 13/13] Update to version 1.2.8p20 --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index a9b280c..9c8b28b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,7 +9,7 @@ # .. envvar:: checkmk_server__version # # Check_MK software version. -checkmk_server__version: '1.2.8p18' +checkmk_server__version: '1.2.8p20' # .. envvar:: checkmk_server__version_label