Skip to content

Commit

Permalink
adds get_host_status() and get_service_status()
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Jun 25, 2024
1 parent 9a87531 commit 30bbf18
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
Binary file removed check_mk_api/check_mk_api-5.7.0.mkp
Binary file not shown.
Binary file added check_mk_api/check_mk_api-5.8.0.mkp
Binary file not shown.
21 changes: 21 additions & 0 deletions check_mk_api/checkmkapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,16 @@
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;(host&nbsp;group,&nbsp;etag)</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-get_host_status"><strong>get_host_status</strong></a>(self, sites=[], query='', columns=[])</dt><dd><span class="code">Get&nbsp;host&nbsp;status<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;sites:&nbsp;Restrict&nbsp;the&nbsp;query&nbsp;to&nbsp;this&nbsp;particular&nbsp;site.<br>
&nbsp;&nbsp;&nbsp;&nbsp;query:&nbsp;An&nbsp;query&nbsp;expression&nbsp;of&nbsp;the&nbsp;Livestatus&nbsp;'hosts'&nbsp;table&nbsp;in&nbsp;nested&nbsp;dictionary&nbsp;form.<br>
&nbsp;&nbsp;&nbsp;&nbsp;columns:&nbsp;The&nbsp;desired&nbsp;columns&nbsp;of&nbsp;the&nbsp;hosts&nbsp;table.&nbsp;If&nbsp;left&nbsp;empty,&nbsp;a&nbsp;default&nbsp;set&nbsp;of&nbsp;columns&nbsp;is&nbsp;used.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;(list&nbsp;of&nbsp;dicts&nbsp;in&nbsp;"value",&nbsp;etag)</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-get_host_tag_group"><strong>get_host_tag_group</strong></a>(self, name)</dt><dd><span class="code">Show&nbsp;a&nbsp;host&nbsp;tag&nbsp;group<br>
&nbsp;<br>
Args:<br>
Expand Down Expand Up @@ -557,6 +567,17 @@
&nbsp;&nbsp;&nbsp;&nbsp;list&nbsp;of&nbsp;rulesets<br>
&nbsp;&nbsp;&nbsp;&nbsp;etag</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-get_service_status"><strong>get_service_status</strong></a>(self, sites=[], query='', columns=[], host_name='')</dt><dd><span class="code">Get&nbsp;service&nbsp;status<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;sites:&nbsp;Restrict&nbsp;the&nbsp;query&nbsp;to&nbsp;this&nbsp;particular&nbsp;site.<br>
&nbsp;&nbsp;&nbsp;&nbsp;query:&nbsp;An&nbsp;query&nbsp;expression&nbsp;of&nbsp;the&nbsp;Livestatus&nbsp;'services'&nbsp;table&nbsp;in&nbsp;nested&nbsp;dictionary&nbsp;form.<br>
&nbsp;&nbsp;&nbsp;&nbsp;columns:&nbsp;The&nbsp;desired&nbsp;columns&nbsp;of&nbsp;the&nbsp;services&nbsp;table.&nbsp;If&nbsp;left&nbsp;empty,&nbsp;a&nbsp;default&nbsp;set&nbsp;of&nbsp;columns&nbsp;is&nbsp;used.<br>
&nbsp;&nbsp;&nbsp;&nbsp;host_name:&nbsp;A&nbsp;hostname.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;(list&nbsp;of&nbsp;dicts&nbsp;in&nbsp;"value",&nbsp;etag)</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-get_timeperiod"><strong>get_timeperiod</strong></a>(self, name)</dt><dd><span class="code">Show&nbsp;a&nbsp;time&nbsp;period<br>
&nbsp;<br>
Args:<br>
Expand Down
76 changes: 76 additions & 0 deletions check_mk_api/lib/python3/checkmkapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,82 @@ def edit_host_group(self, name, title, etag="*"):
data={
"alias": title,
})

# .--Host Status---------------------------------------------------------.
# | _ _ _ ____ _ _ |
# | | | | | ___ ___| |_ / ___|| |_ __ _| |_ _ _ ___ |
# | | |_| |/ _ \/ __| __| \___ \| __/ _` | __| | | / __| |
# | | _ | (_) \__ \ |_ ___) | || (_| | |_| |_| \__ \ |
# | |_| |_|\___/|___/\__| |____/ \__\__,_|\__|\__,_|___/ |
# | |
# +----------------------------------------------------------------------+
# | |
# '----------------------------------------------------------------------'
#.

def get_host_status(self, sites=[], query="", columns=[]):
"""Get host status
Args:
sites: Restrict the query to this particular site.
query: An query expression of the Livestatus 'hosts' table in nested dictionary form.
columns: The desired columns of the hosts table. If left empty, a default set of columns is used.
Returns:
(list of dicts in "value", etag)
"""
data = {}
if sites:
data["sites"] = sites
if query:
data["query"] = query
if columns:
data["columns"] = columns
return self._request(
self._get_url,
"/domain-types/host/collections/all",
data = data,
)

# .--Service Status------------------------------------------------------.
# | ____ _ ____ _ _ |
# | / ___| ___ _ ____ _(_) ___ ___ / ___|| |_ __ _| |_ _ _ ___ |
# | \___ \ / _ \ '__\ \ / / |/ __/ _ \ \___ \| __/ _` | __| | | / __| |
# | ___) | __/ | \ V /| | (_| __/ ___) | || (_| | |_| |_| \__ \ |
# | |____/ \___|_| \_/ |_|\___\___| |____/ \__\__,_|\__|\__,_|___/ |
# | |
# +----------------------------------------------------------------------+
# | |
# '----------------------------------------------------------------------'
#.

def get_service_status(self, sites=[], query="", columns=[], host_name=""):
"""Get service status
Args:
sites: Restrict the query to this particular site.
query: An query expression of the Livestatus 'services' table in nested dictionary form.
columns: The desired columns of the services table. If left empty, a default set of columns is used.
host_name: A hostname.
Returns:
(list of dicts in "value", etag)
"""

data = {}
if sites:
data["sites"] = sites
if query:
data["query"] = query
if columns:
data["columns"] = columns
if hsot_name:
data["host_name"] = host_name
return self._request(
self._get_url,
"/domain-types/service/collections/all",
data = data,
)


#
Expand Down

0 comments on commit 30bbf18

Please sign in to comment.