brennerm / check-mk-web-api

Python library to talk to the Check_Mk Web API
https://brennerm.github.io/check-mk-web-api/
MIT License
53 stars 26 forks source link

API calls not working #1

Closed phantium closed 7 years ago

phantium commented 7 years ago

Hi,

I was excited to see this Python API implementation, however it seems I cannot get it to work. We use Check_MK Enterprise version 1.2.8p15, which version was this tested on?

Thanks!

In [4]: api.get_host("HOSTNAME")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-b7308340d256> in <module>()
----> 1 api.get_host("HOSTNAME")

/usr/lib/python3.4/site-packages/check_mk_web_api/__init__.py in get_host(self, hostname, effective_attributes)
    208         }
    209
--> 210         return self.make_request('get_host', query_params=query_params, data=data)
    211
    212     def get_all_hosts(self, effective_attributes: bool=False):

/usr/lib/python3.4/site-packages/check_mk_web_api/__init__.py in make_request(self, action, query_params, data)
    120             raise CheckMkWebApiResponseException(response)
    121
--> 122         body = json.loads(response.read().decode())
    123         result = body['result']
    124

/usr/lib64/python3.4/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    316             parse_int is None and parse_float is None and
    317             parse_constant is None and object_pairs_hook is None and not kw):
--> 318         return _default_decoder.decode(s)
    319     if cls is None:
    320         cls = JSONDecoder

/usr/lib64/python3.4/json/decoder.py in decode(self, s, _w)
    341
    342         """
--> 343         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    344         end = _w(s, end).end()
    345         if end != len(s):

/usr/lib64/python3.4/json/decoder.py in raw_decode(self, s, idx)
    359             obj, end = self.scan_once(s, idx)
    360         except StopIteration as err:
--> 361             raise ValueError(errmsg("Expecting value", s, err.value)) from None
    362         return obj, end

ValueError: Expecting value: line 1 column 1 (char 0)
brennerm commented 7 years ago

Hey @phantium, I tested the implementation against Check_MK 1.2.8p18 Raw Edition. The Enterprise Edition is not available to me.

It seems like the response from your Web API does not contain valid JSON. To verify this I'd like to ask you clone the repository and add the following in front of the line 122 of check_mk_web_api/init.py:

print(response.read().decode())

Please repeat your execution with this change applied and post the output. Thanks for your contribution.

phantium commented 7 years ago

Thanks @brennerm, when having this added it actually told me I provided the wrong automation secret. While I thought I had checked that, I apparently did not.

Seems to work fine now 👍

brennerm commented 7 years ago

Great news, I will add a proper exception handling for the next version.

brennerm commented 7 years ago

A proper exception has been introduced in version 1.1.