Skip to content

Commit

Permalink
adds create_rule and delete_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Nov 19, 2024
1 parent a16a246 commit bf3429f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
Binary file removed check_mk_api/check_mk_api-5.8.1.mkp
Binary file not shown.
Binary file added check_mk_api/check_mk_api-5.9.0.mkp
Binary file not shown.
36 changes: 26 additions & 10 deletions check_mk_api/checkmkapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
<td class="section-title" colspan=3>&nbsp;<br><strong class="bigsection">Modules</strong></td></tr>

<tr><td class="decor pkg-content-decor"><span class="code">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td><td>&nbsp;</td>
<td class="singlecolumn"><table><tr><td class="multicolumn"><a href="configparser.html">configparser</a><br>
<a href="json.html">json</a><br>
</td><td class="multicolumn"><a href="os.html">os</a><br>
<a href="requests.html">requests</a><br>
</td><td class="multicolumn"><a href="sys.html">sys</a><br>
<td class="singlecolumn"><table><tr><td class="multicolumn"><a href="json.html">json</a><br>
<a href="os.html">os</a><br>
</td><td class="multicolumn"><a href="requests.html">requests</a><br>
<a href="time.html">time</a><br>
</td><td class="multicolumn"><a href="warnings.html">warnings</a><br>
</td></tr></table></td></tr></table><p>
</td><td class="multicolumn"></td></tr></table></td></tr></table><p>
<table class="section">
<tr class="decor index-decor heading-text">
<td class="section-title" colspan=3>&nbsp;<br><strong class="bigsection">Classes</strong></td></tr>
Expand Down Expand Up @@ -189,6 +187,19 @@
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;(rule,&nbsp;etag)</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-create_rule"><strong>create_rule</strong></a>(self, ruleset_name, folder, value_raw, conditions={}, properties={})</dt><dd><span class="code">Creates&nbsp;a&nbsp;rule<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;ruleset_name<br>
&nbsp;&nbsp;&nbsp;&nbsp;folder<br>
&nbsp;&nbsp;&nbsp;&nbsp;conditions<br>
&nbsp;&nbsp;&nbsp;&nbsp;properties<br>
&nbsp;&nbsp;&nbsp;&nbsp;value_raw<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;rule<br>
&nbsp;&nbsp;&nbsp;&nbsp;etag</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-create_timeperiod"><strong>create_timeperiod</strong></a>(self, name, alias, active_time_ranges, exceptions=[], exclude=[])</dt><dd><span class="code">Create&nbsp;a&nbsp;time&nbsp;period<br>
&nbsp;<br>
Args:<br>
Expand Down Expand Up @@ -266,6 +277,11 @@
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;Nothing</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-delete_rule"><strong>delete_rule</strong></a>(self, rule_id)</dt><dd><span class="code">Delete&nbsp;a&nbsp;rule<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;rule_id:&nbsp;The&nbsp;ID&nbsp;of&nbsp;the&nbsp;rule.</span></dd></dl>

<dl><dt><a name="CMKRESTAPI-delete_timeperiod"><strong>delete_timeperiod</strong></a>(self, name, etag)</dt><dd><span class="code">Delete&nbsp;a&nbsp;time&nbsp;period<br>
&nbsp;<br>
Args:<br>
Expand Down Expand Up @@ -640,10 +656,10 @@
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</span></dd>
<dd><span class="code">dictionary&nbsp;for&nbsp;instance&nbsp;variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</span></dd>
<dd><span class="code">list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object</span></dd>
</dl>
</td></tr></table> <p>
<table class="section">
Expand All @@ -670,10 +686,10 @@
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><span class="code">dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</span></dd>
<dd><span class="code">dictionary&nbsp;for&nbsp;instance&nbsp;variables</span></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><span class="code">list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</span></dd>
<dd><span class="code">list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object</span></dd>
</dl>
</td></tr></table></td></tr></table>
</body></html>
39 changes: 39 additions & 0 deletions check_mk_api/lib/python3/checkmkapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,33 @@ def get_rulesets(self):
# '----------------------------------------------------------------------'
#.

def create_rule(self, ruleset_name, folder, value_raw, conditions={}, properties={}):
"""Creates a rule
Args:
ruleset_name
folder
conditions
properties
value_raw
Returns:
rule
etag
"""
return self._request(
self._post_url,
"domain-types/rule/collections/all",
data={
'ruleset': ruleset_name,
'properties': properties,
'value_raw': value_raw,
'folder': folder,
'conditions': conditions,
},
)


def get_rules(self, ruleset_name):
"""Gets rules from ruleset by name
Expand All @@ -1082,6 +1109,18 @@ def get_rules(self, ruleset_name):
data={'ruleset_name': ruleset_name},
)

def delete_rule(self, rule_id):
"""Delete a rule
Args:
rule_id: The ID of the rule.
"""
return self._request(
self._delete_url,
f"/objects/rule/{rule_id}",
)


# .--Host Tag Groups-----------------------------------------------------.
# | _ _ _ _____ |
# | | | | | ___ ___| |_ |_ _|_ _ __ _ |
Expand Down

0 comments on commit bf3429f

Please sign in to comment.