Skip to content

Commit

Permalink
Merge pull request debops-contrib#19 from ganto/webapi
Browse files Browse the repository at this point in the history
Add service discovery trigger via WebAPI
  • Loading branch information
ganto authored Jul 29, 2016
2 parents 0dffd81 + fde7be3 commit cb22f54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ checkmk_agent__hostname: '{{ ansible_fqdn }}'
checkmk_agent__host_attributes:
tag_agent: '{{ "cmk-agent-ssh" if "ssh" in checkmk_agent else "cmk-agent" }}'


# .. envvar:: checkmk_agent__discovery_mode
#
# Service discovery mode. Possible values are ``new`` (only find new services),
# ``remove`` (remove exceeding services), ``fixall`` (remove exceeding and add
# new services), ``refresh`` (clean all autochecks and discover from scratch)
# and ``False`` (don't run service discovery).
checkmk_agent__discovery_mode: 'new'

# .. )))

# .. Agent xinetd options (((
Expand Down
18 changes: 17 additions & 1 deletion tasks/autojoin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,28 @@
failed_when: (not "json" in checkmk_agent__register_update_host) or
(checkmk_agent__register_update_host.json.result_code != 0)

- name: Run service discovery
uri:
url: '{{ checkmk_agent__autojoin_url }}?action=discover_services&mode={{ checkmk_agent__discovery_mode }}&_username={{ checkmk_agent__autojoin_user }}&_secret={{ checkmk_agent__autojoin_secret }}&output_format=json'
method: 'POST'
body: 'request={ "hostname": "{{ checkmk_agent__hostname }}" }'
return_content: yes
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
(checkmk_agent__register_discover_services.json.result_code == 0) and
((checkmk_agent__register_discover_services.json.result | regex_replace("^.*Added ([0-9]+),.*$", "\\1")|int > 0) or
(checkmk_agent__register_discover_services.json.result | regex_replace("^.*Removed ([0-9]+),.*$", "\\1")|int > 0))
failed_when: (not "json" in checkmk_agent__register_discover_services) or
(checkmk_agent__register_discover_services.json.result_code != 0)

- name: Activate WebAPI changes
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) }}'
checkmk_agent__register_update_host.changed|d(False) or
checkmk_agent__register_discover_services.changed|d(False) }}'
register: checkmk_agent__register_activate
changed_when: ("json" in checkmk_agent__register_activate) and
(checkmk_agent__register_activate.json.result_code == 0)
Expand Down

0 comments on commit cb22f54

Please sign in to comment.