diff --git a/defaults/main.yml b/defaults/main.yml index 65d4b86..ba2141e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,7 +16,7 @@ # .. envvar:: checkmk_server__version # # Check_MK software version. -checkmk_server__version: '1.2.8p16' +checkmk_server__version: '1.2.8p20' # .. envvar:: checkmk_server__version_suffix @@ -460,6 +460,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 }}' @@ -486,7 +487,7 @@ checkmk_server__contact_defaults: checkmk_server__site_cfg_contactgroups: - name: 'define_contactgroups' value: - all: 'Everybody' + all: 'Everything' # .. envvar:: checkmk_server__site_cfg_rules @@ -565,6 +566,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 @@ -577,6 +592,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..b40a425 100644 --- a/docs/defaults-configuration.rst +++ b/docs/defaults-configuration.rst @@ -56,6 +56,40 @@ 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. 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. Cannot be combined with the ``url`` parameter. + +``url`` + 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: 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/wato.yml b/tasks/wato.yml index 4f8242d..e01e06f 100644 --- a/tasks/wato.yml +++ b/tasks/wato.yml @@ -3,6 +3,50 @@ # Check_MK multisite/WATO configuration # +- 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' + 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 + with_items: '{{ checkmk_server__site_packages }}' + 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_flattened: + - '{{ checkmk_server__register_mkp_download.results }}' + - '{{ checkmk_server__register_mkp_upload.results }}' + tags: + - 'role::checkmk_server:mkp' + - name: Generate Check_MK WATO multisite definitions template: src: '{{ lookup("template_src", "etc/check_mk/multisite.d/wato/" + item | basename) }}' diff --git a/templates/macros/checkmk_config.j2 b/templates/macros/checkmk_config.j2 index d95a3cb..5033af9 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 %} @@ -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 %} 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: diff --git a/vars/main.yml b/vars/main.yml index 519d222..ebbddad 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'