From 0cfbf2fc493405ea2b6907940f6a9d9f4017b5d0 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Wed, 18 Jan 2017 08:23:46 +0100 Subject: [PATCH 1/6] Use proper 'changed' filter --- tasks/autojoin.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/autojoin.yml b/tasks/autojoin.yml index 550e869..ccce520 100644 --- a/tasks/autojoin.yml +++ b/tasks/autojoin.yml @@ -64,9 +64,9 @@ uri: url: '{{ checkmk_agent__autojoin_url }}?action=activate_changes&_username={{ checkmk_agent__autojoin_user }}&_secret={{ checkmk_agent__autojoin_secret }}&output_format=json' return_content: yes - when: '{{ checkmk_agent__register_add_host.changed|d(False) or - checkmk_agent__register_update_host.changed|d(False) or - checkmk_agent__register_discover_services.changed|d(False) }}' + when: '{{ (checkmk_agent__register_add_host | changed) or + (checkmk_agent__register_update_host | changed) or + (checkmk_agent__register_discover_services | changed) }}' register: checkmk_agent__register_activate changed_when: ("json" in checkmk_agent__register_activate) and (checkmk_agent__register_activate.json.result_code == 0) From cd424b6e502d444e64aea95817f983a5877f6fee Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Mon, 23 Jan 2017 07:48:52 +0100 Subject: [PATCH 2/6] Enlarge timeout for WebAPI discovery and activation Some hosts with a huge number of processes and devices or tool issues might not be fully discovered within 30 seconds. The same might be true for activating changes especally after adding new hosts which contain many hundered service checks. --- tasks/autojoin.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/autojoin.yml b/tasks/autojoin.yml index ccce520..4fde29f 100644 --- a/tasks/autojoin.yml +++ b/tasks/autojoin.yml @@ -51,6 +51,7 @@ method: 'POST' body: 'request={ "hostname": "{{ checkmk_agent__hostname }}" }' return_content: yes + timeout: 120 when: '{{ checkmk_agent__discovery_mode|d() in [ "new", "remove", "fixall", "refresh" ] }}' register: checkmk_agent__register_discover_services changed_when: ("json" in checkmk_agent__register_discover_services) and @@ -64,6 +65,7 @@ uri: url: '{{ checkmk_agent__autojoin_url }}?action=activate_changes&_username={{ checkmk_agent__autojoin_user }}&_secret={{ checkmk_agent__autojoin_secret }}&output_format=json' return_content: yes + timeout: 120 when: '{{ (checkmk_agent__register_add_host | changed) or (checkmk_agent__register_update_host | changed) or (checkmk_agent__register_discover_services | changed) }}' From 72ffafcd1df4ba3b84128913f0ac143889ecd6e4 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Mon, 23 Jan 2017 17:37:06 +0100 Subject: [PATCH 3/6] Delegate WebAPI calls to Check_MK server if possible Direct WebAPI access to the Check_MK server might not be available from all hosts. If we know the Check_MK server, run the WebAPI call there. --- defaults/main.yml | 8 ++++++-- tasks/autojoin.yml | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index e87f851..064c416 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -40,7 +40,8 @@ checkmk_agent__allow: [] # .. envvar:: checkmk_agent__server [[[ # # Ansible inventory name of Check_MK server. By default it will be autodetected -# via `debops_service_checkmk_server` host group configuration. +# via `debops_service_checkmk_server` host group configuration. If the Check_MK +# server is not managed by Ansible, set this to `False`. checkmk_agent__server: '{{ groups["debops_service_checkmk_server"][0] if ("debops_service_checkmk_server" in groups) and (groups["debops_service_checkmk_server"] | length > 0) @@ -65,7 +66,10 @@ checkmk_agent__site: '{{ hostvars[checkmk_agent__server].ansible_local.checkmk_s # ]]] # .. envvar:: checkmk_agent__autojoin [[[ # -# Automatically add agent host to the Check_MK monitoring site. +# Automatically add agent host to the Check_MK monitoring site. If the Check_MK +# server is not managed by Ansible and you want automated agent registration to +# work, manually define at least :envvar:`checkmk_agent__autojoin_url`, +# :envvar:`checkmk_agent__autojoin_secret` and :envvar:`checkmk_agent__user_key`. checkmk_agent__autojoin: '{{ True if checkmk_agent__autojoin_url else False }}' # ]]] diff --git a/tasks/autojoin.yml b/tasks/autojoin.yml index 4fde29f..1863397 100644 --- a/tasks/autojoin.yml +++ b/tasks/autojoin.yml @@ -13,6 +13,7 @@ method: 'POST' body: 'request={ "hostname": "{{ checkmk_agent__hostname }}" }' return_content: yes + delegate_to: '{{ checkmk_agent__server if checkmk_agent__server else omit }}' register: checkmk_agent__register_get_host always_run: True changed_when: False @@ -24,6 +25,7 @@ method: 'POST' body: 'request={ "hostname": "{{ checkmk_agent__hostname }}", "folder": "/", "attributes": {{ checkmk_agent__fact_host_attributes|to_json }} }' return_content: yes + delegate_to: '{{ checkmk_agent__server if checkmk_agent__server else omit }}' when: '{{ checkmk_agent__register_get_host.json.result == "No such host" }}' register: checkmk_agent__register_add_host changed_when: ("json" in checkmk_agent__register_add_host) and @@ -37,6 +39,7 @@ method: 'POST' body: 'request={ "hostname": "{{ checkmk_agent__hostname }}", "attributes": {{ checkmk_agent__fact_host_attributes|to_json }} }' return_content: yes + delegate_to: '{{ checkmk_agent__server if checkmk_agent__server else omit }}' when: '{{ checkmk_agent__register_add_host.skipped|d(False) and (not checkmk_agent__host_attributes|to_nice_json == checkmk_agent__register_get_host.json.result.attributes|d({})|to_nice_json) }}' register: checkmk_agent__register_update_host @@ -52,6 +55,7 @@ body: 'request={ "hostname": "{{ checkmk_agent__hostname }}" }' return_content: yes timeout: 120 + delegate_to: '{{ checkmk_agent__server if checkmk_agent__server else omit }}' when: '{{ checkmk_agent__discovery_mode|d() in [ "new", "remove", "fixall", "refresh" ] }}' register: checkmk_agent__register_discover_services changed_when: ("json" in checkmk_agent__register_discover_services) and @@ -66,6 +70,7 @@ url: '{{ checkmk_agent__autojoin_url }}?action=activate_changes&_username={{ checkmk_agent__autojoin_user }}&_secret={{ checkmk_agent__autojoin_secret }}&output_format=json' return_content: yes timeout: 120 + delegate_to: '{{ checkmk_agent__server if checkmk_agent__server else omit }}' when: '{{ (checkmk_agent__register_add_host | changed) or (checkmk_agent__register_update_host | changed) or (checkmk_agent__register_discover_services | changed) }}' From 94a70e9248a8aa619dbc2bb5985fec9285d5e252 Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Mon, 23 Jan 2017 18:16:18 +0100 Subject: [PATCH 4/6] Make inventory host group for Check_MK server configurable --- defaults/main.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 064c416..681f5fe 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -37,14 +37,20 @@ checkmk_agent__allow: [] # Monitoring site integration [[[ # ------------------------------- +# .. envvar:: checkmk_agent__server_inventory_group [[[ +# +# Ansible inventory host group used to lookup the Check_MK server. +checkmk_agent__server_inventory_group: 'debops_service_checkmk_server' + + # ]]] # .. envvar:: checkmk_agent__server [[[ # # Ansible inventory name of Check_MK server. By default it will be autodetected -# via `debops_service_checkmk_server` host group configuration. If the Check_MK -# server is not managed by Ansible, set this to `False`. -checkmk_agent__server: '{{ groups["debops_service_checkmk_server"][0] - if ("debops_service_checkmk_server" in groups) and - (groups["debops_service_checkmk_server"] | length > 0) +# via :envvar:`checkmk_agent__server_inventory_group` host group configuration. +# If the Check_MK server is not managed by Ansible, set this to `False`. +checkmk_agent__server: '{{ groups[checkmk_agent__server_inventory_group][0] + if (checkmk_agent__server_inventory_group in groups) and + (groups[checkmk_agent__server_inventory_group] | length > 0) else "" }}' # ]]] From b64d364790ae181f63b531b0dcbfa4b15584c0ea Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 24 Jan 2017 06:42:44 +0100 Subject: [PATCH 5/6] Update changelog --- CHANGES.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index bddf76b..38f0f2e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,28 @@ The current role maintainer_ is ganto_. .. _debops-contrib.checkmk_agent master: https://github.com/debops-contrib/ansible-checkmk_agent/compare/v0.1.1...master +Added +~~~~~ + +- New inventory variable :envvar:`checkmk_agent__server_inventory_group` which + can be used to define custom Ansible host group name for Check_MK server + lookup. [ganto_] + +Changed +~~~~~~~ + +- Raise HTTP timeout for discovery and activation WebAPI calls to 120s to avoid + timeout issues on large hosts with many service checks. [ganto_] + +- If possible run WebAPI invocation for automated agent registration and host + attribute updates on the Check_MK server to avoid possible firewall issues. + [ganto_] + +Fixed +~~~~~ + +- Correctly use Ansible `changed` task filter. [ganto_] + `debops-contrib.checkmk_agent v0.1.1` - 2017-01-23 -------------------------------------------------- From cb475483e678dea03ce7153fcf1583e42de12adb Mon Sep 17 00:00:00 2001 From: Reto Gantenbein Date: Tue, 24 Jan 2017 06:50:54 +0100 Subject: [PATCH 6/6] Fix use of 'skipped' Ansible filter --- CHANGES.rst | 2 +- tasks/autojoin.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 38f0f2e..981ad58 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -36,7 +36,7 @@ Changed Fixed ~~~~~ -- Correctly use Ansible `changed` task filter. [ganto_] +- Correctly use Ansible `changed` and `skipped` task filters. [ganto_] `debops-contrib.checkmk_agent v0.1.1` - 2017-01-23 diff --git a/tasks/autojoin.yml b/tasks/autojoin.yml index 1863397..3d47e8f 100644 --- a/tasks/autojoin.yml +++ b/tasks/autojoin.yml @@ -40,8 +40,8 @@ body: 'request={ "hostname": "{{ checkmk_agent__hostname }}", "attributes": {{ checkmk_agent__fact_host_attributes|to_json }} }' return_content: yes delegate_to: '{{ checkmk_agent__server if checkmk_agent__server else omit }}' - when: '{{ checkmk_agent__register_add_host.skipped|d(False) and - (not checkmk_agent__host_attributes|to_nice_json == checkmk_agent__register_get_host.json.result.attributes|d({})|to_nice_json) }}' + when: '{{ (checkmk_agent__register_add_host | skipped) and + (not checkmk_agent__host_attributes|to_nice_json == checkmk_agent__register_get_host.json.result.attributes|d({})|to_nice_json) }}' register: checkmk_agent__register_update_host changed_when: ("json" in checkmk_agent__register_update_host) and (checkmk_agent__register_update_host.json.result_code == 0)