Skip to content

Commit

Permalink
removes API errors on stderr
Browse files Browse the repository at this point in the history
use try/except and catch the HTTPError
  • Loading branch information
gurubert committed Dec 19, 2023
1 parent a3346e8 commit c215342
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Binary file removed check_mk_api/check_mk_api-5.5.0.mkp
Binary file not shown.
Binary file added check_mk_api/check_mk_api-5.5.1.mkp
Binary file not shown.
7 changes: 3 additions & 4 deletions check_mk_api/checkmkapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
<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>
<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"><a href="time.html">time</a><br>
<a href="warnings.html">warnings</a><br>
</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
16 changes: 10 additions & 6 deletions check_mk_api/lib/python3/checkmkapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import json
import time
import sys
# import sys
import configparser
import json

Expand Down Expand Up @@ -89,8 +89,8 @@ def _check_response(self, resp):
else:
data = {}
etag = resp.headers.get('ETag', '').strip('"')
if resp.status_code >= 400:
sys.stderr.write("%r\n" % data)
# if resp.status_code >= 400:
# sys.stderr.write("%r\n" % data)
return data, etag, resp

def _get_url(self, uri, data={}):
Expand Down Expand Up @@ -1369,7 +1369,9 @@ def create_notification_rule(self, rule_config):
"""
data, etag, resp = self._post_url(
"domain-types/notification_rule/collections/all",
data=rule_config,
data={
"rule_config": rule_config,
},
)
if resp.status_code == 200:
return data, etag
Expand Down Expand Up @@ -1438,7 +1440,9 @@ def edit_notification_rule(self, rule_id, rule_config):
"""
data, etag, resp = self._put_url(
f"objects/notification_rule/{rule_id}",
data=params
data={
"rule_config": rule_config,
},
)
if resp.status_code == 200:
return data, etag
Expand Down Expand Up @@ -1503,7 +1507,7 @@ def _api_request(self, api_url, params, data=None):
else:
return eval(resp.text)
else:
sys.stderr.write("%s\n" % resp.text)
# sys.stderr.write("%s\n" % resp.text)
resp.raise_for_status()

def view(self, view_name, **kwargs):
Expand Down

0 comments on commit c215342

Please sign in to comment.