Skip to content

Commit

Permalink
Merge branch 'master' into distributed-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
ganto committed Apr 13, 2017
2 parents 52dd25e + a7ade18 commit 432e67d
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 4 deletions.
26 changes: 24 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}'


Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
# -----------------
Expand Down
34 changes: 34 additions & 0 deletions docs/defaults-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
44 changes: 44 additions & 0 deletions tasks/wato.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}'
Expand Down
5 changes: 3 additions & 2 deletions templates/macros/checkmk_config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

{% macro tmpl_var__key_value(_name, _value) %}

{{ _name }} = {{ _value }}
{{ _name }} = {{ "'" + _value + "'" if (_value is string) else _value }}
{% endmacro %}


Expand Down Expand Up @@ -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 %}
Expand Down
5 changes: 5 additions & 0 deletions tests/reference.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ),
]
10 changes: 10 additions & 0 deletions tests/test_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 432e67d

Please sign in to comment.