Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor rule configuration updates and enhancements #48

Merged
merged 6 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'


Expand All @@ -512,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
Expand Down Expand Up @@ -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
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