Skip to content

Commit

Permalink
Changed parameters and added verify
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-checkmk committed Dec 1, 2023
1 parent 2e01705 commit bfc3cab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
49 changes: 27 additions & 22 deletions plugins/lookup/bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
description:
- Returns the bakery status of a Checkmk server as a string, e.g. 'running'
options:
_terms:
description: site url
server_url:
description: URL of the Checkmk server
required: True
site:
description: site name
required: True
automation_user:
description: automation user for the REST API access
Expand All @@ -40,7 +43,8 @@
msg: "Bakery status is {{ bakery }}"
vars:
bakery: "{{ lookup('checkmk.general.bakery',
server_url + '/' + site,
server_url=http://myserver,
site=mysite,
validate_certs=False,
automation_user=automation_user,
automation_secret=automation_secret
Expand All @@ -67,33 +71,34 @@
class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
self.set_options(var_options=variables, direct=kwargs)
server_url = self.get_option("server_url")
site = self.get_option("site")
user = self.get_option("automation_user")
secret = self.get_option("automation_secret")
validate_certs = self.get_option("validate_certs")

ret = []

for term in terms:
api = CheckMKLookupAPI(
site_url=term,
user=user,
secret=secret,
validate_certs=validate_certs,
)
api = CheckMKLookupAPI(
site_url=server_url + "/" + site,
user=user,
secret=secret,
validate_certs=validate_certs,
)

response = json.loads(
api.get("/domain-types/agent/actions/baking_status/invoke")
)
response = json.loads(
api.get("/domain-types/agent/actions/baking_status/invoke")
)

if "code" in response:
raise AnsibleError(
"Received error for %s - %s: %s"
% (
response.get("url", ""),
response.get("code", ""),
response.get("msg", ""),
)
if "code" in response:
raise AnsibleError(
"Received error for %s - %s: %s"
% (
response.get("url", ""),
response.get("code", ""),
response.get("msg", ""),
)
)

ret.append(response.get("result", {}).get("value").get("state"))
ret.append(response.get("result", {}).get("value").get("state"))
return ret
10 changes: 9 additions & 1 deletion tests/integration/targets/lookup_bakery/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@
automation_secret=automation_secret)
}}"
delegate_to: localhost
register: looked_up_bakery
register: looked_up_bakery

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify bakery status."
ansible.builtin.assert:
that: ("'finished' in looked_up_bakery.msg") or
("'running' in looked_up_bakery.msg") or
("'initialized' in looked_up_bakery.msg") or
("'stopped' in looked_up_bakery.msg") or
("'exception' in looked_up_bakery.msg")

0 comments on commit bfc3cab

Please sign in to comment.