Discussion:
[Check_mk (english)] Host Import via API
Thomas Wittmann
2018-08-01 11:51:31 UTC
Permalink
Hello together
according to https://mathias-kettner.de/cms_web_api_references.html
i want to get information about a host (i am using 1.4.0.p31cre on SLES12sp3
But no matter what i try, i get an exception like this:

*Wed Aug 01 13:41:22.662997 2018* *:error * *[pid 17749] [client
127.0.0.1:49286 <http://127.0.0.1:49286>] URI:
'/<sitename>/check_mk/webapi.py'**Wed Aug 01 13:41:22.663000 2018*
*:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] Location: None**Wed Aug 01 13:41:22.663003
2018* *:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] Directory:
'/omd/sites/**<sitename>/share/check_mk/web/htdocs/'**Wed Aug 01
13:41:22.663007 2018* *:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] Filename:
'/omd/sites/**<sitename>/share/check_mk/web/htdocs/webapi.py'**Wed Aug
01 13:41:22.663010 2018* *:error * *[pid 17749] [client
127.0.0.1:49286 <http://127.0.0.1:49286>] PathInfo: ''**Wed Aug 01
13:41:22.664329 2018* *:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] Traceback (most recent call last):**Wed Aug
01 13:41:22.664336 2018* *:error * *[pid 17749] [client
127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line
<b class=line>1540</b>, in HandlerDispatch\n
default=default_handler, arg=req, silent=hlist.silent)**Wed Aug 01
13:41:22.664340 2018* *:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] File
"/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line
<b class=line>1232</b>, in _process_target\n result =
_execute_target(config, req, object, arg)**Wed Aug 01 13:41:22.664342
2018* *:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] File
"/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line
<b class=line>1131</b>, in _execute_target\n result =
object(arg)**Wed Aug 01 13:41:22.664344 2018* *:error * *[pid 17749]
[client 127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/sites/**<sitename>/share/check_mk/web/htdocs/index.py", line <b
class=line>48</b>, in handler\n __builtin__.html =
html_mod_python(mod_python_req, fields)**Wed Aug 01 13:41:22.664347
2018* *:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] File
"/omd/sites/**<sitename>/share/check_mk/web/htdocs/html_mod_python.py",
line <b class=line>74</b>, in __init__\n
self.set_output_format(self.var("output_format", "html").lower())**Wed
Aug 01 13:41:22.664349 2018* *:error * *[pid 17749] [client
127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/sites/**<sitename>/share/check_mk/web/htdocs/htmllib.py", line
<b class=line>1678</b>, in set_output_format\n raise
MKGeneralException(_("Unsupported context type '%s'") % f)**Wed Aug 01
13:41:22.664352 2018* *:error * *[pid 17749] [client 127.0.0.1:49286
<http://127.0.0.1:49286>] MKGeneralException: Unsupported context type
'python -d request={'hostname':'<hostname'}'**Wed Aug 01
13:41:22.664596 2018* *:notice* *[pid 17749] mod_python (pid=17749,
interpreter='OMD_CMK_00'): Importing module
'/omd/sites/<sitename>/share/omd/htdocs/index.py'**Wed Aug 01
13:41:56.183308 2018* *:error * *[pid 30426] [client 127.0.0.1:51712
<http://127.0.0.1:51712>] mod_python (pid=30426, interpreter='*

*<sitename>', phase='PythonHandler', handler='index'): Application error*

These are my first steps into automation and i suspect i am doing
sometzhing wrong with the URL.

Can somebody point me in the right direction?

BR

Tom
Marcel Schulte
2018-08-01 14:28:28 UTC
Permalink
Hi Thomas,

could you please post the complete command resulting in this error? I
think there could be an error in it... ;)

BR,
Marcel
Post by Thomas Wittmann
Hello together
according to https://mathias-kettner.de/cms_web_api_references.html
i want to get information about a host (i am using 1.4.0.p31cre on SLES12sp3
Wed Aug 01 13:41:22.662997 2018 :error [pid 17749] [client 127.0.0.1:49286] URI: '/<sitename>/check_mk/webapi.py'
Wed Aug 01 13:41:22.663000 2018 :error [pid 17749] [client 127.0.0.1:49286] Location: None
Wed Aug 01 13:41:22.663003 2018 :error [pid 17749] [client 127.0.0.1:49286] Directory: '/omd/sites/<sitename>/share/check_mk/web/htdocs/'
Wed Aug 01 13:41:22.663007 2018 :error [pid 17749] [client 127.0.0.1:49286] Filename: '/omd/sites/<sitename>/share/check_mk/web/htdocs/webapi.py'
Wed Aug 01 13:41:22.663010 2018 :error [pid 17749] [client 127.0.0.1:49286] PathInfo: ''
Wed Aug 01 13:41:22.664336 2018 :error [pid 17749] [client 127.0.0.1:49286] File "/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line <b class=line>1540</b>, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent)
Wed Aug 01 13:41:22.664340 2018 :error [pid 17749] [client 127.0.0.1:49286] File "/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line <b class=line>1232</b>, in _process_target\n result = _execute_target(config, req, object, arg)
Wed Aug 01 13:41:22.664342 2018 :error [pid 17749] [client 127.0.0.1:49286] File "/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line <b class=line>1131</b>, in _execute_target\n result = object(arg)
Wed Aug 01 13:41:22.664344 2018 :error [pid 17749] [client 127.0.0.1:49286] File "/omd/sites/<sitename>/share/check_mk/web/htdocs/index.py", line <b class=line>48</b>, in handler\n __builtin__.html = html_mod_python(mod_python_req, fields)
Wed Aug 01 13:41:22.664347 2018 :error [pid 17749] [client 127.0.0.1:49286] File "/omd/sites/<sitename>/share/check_mk/web/htdocs/html_mod_python.py", line <b class=line>74</b>, in __init__\n self.set_output_format(self.var("output_format", "html").lower())
Wed Aug 01 13:41:22.664349 2018 :error [pid 17749] [client 127.0.0.1:49286] File "/omd/sites/<sitename>/share/check_mk/web/htdocs/htmllib.py", line <b class=line>1678</b>, in set_output_format\n raise MKGeneralException(_("Unsupported context type '%s'") % f)
Wed Aug 01 13:41:22.664352 2018 :error [pid 17749] [client 127.0.0.1:49286] MKGeneralException: Unsupported context type 'python -d request={'hostname':'<hostname'}'
Wed Aug 01 13:41:22.664596 2018 :notice [pid 17749] mod_python (pid=17749, interpreter='OMD_CMK_00'): Importing module '/omd/sites/<sitename>/share/omd/htdocs/index.py'
Wed Aug 01 13:41:56.183308 2018 :error [pid 30426] [client 127.0.0.1:51712] mod_python (pid=30426, interpreter='<sitename>', phase='PythonHandler', handler='index'): Application error
These are my first steps into automation and i suspect i am doing sometzhing wrong with the URL.
Can somebody point me in the right direction?
BR
Tom
_______________________________________________
checkmk-en mailing list
Manage your subscription or unsubscribe
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
Vance, Chris
2018-10-25 21:44:08 UTC
Permalink
You could have a look at this library:

https://github.com/brennerm/check-mk-web-api/blob/master/check_mk_web_api/__init__.py

I modified it to use the requests library...
if data:
r = requests.post(url, data="request=" +
json.dumps(data), timeout=300)
else:
r = requests.get(url,timeout=300)
r.raise_for_status()

... It's going to be that check_mk doesn't like the payload or the
request content-type header.

Note:
{'hostname':'<hostname'} isn't valid json. String literals should use
"" , not '' ... ran into that yesterday. Personally, I think that most
of the time it's better to put the data in a dict and json.dumps() it.

-- Chris
Post by Thomas Wittmann
Hello together
according to https://mathias-kettner.de/cms_web_api_references.html
i want to get information about a host (i am using 1.4.0.p31cre on SLES12sp3
'/<sitename>/check_mk/webapi.py'*
None*
*Wed Aug 01 13:41:22.663003 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>]
Directory: '/omd/sites/***<sitename>*/share/check_mk/web/htdocs/'*
'/omd/sites/***<sitename>*/share/check_mk/web/htdocs/webapi.py'*
*Wed Aug 01 13:41:22.663010 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] PathInfo: ''*
*Wed Aug 01 13:41:22.664329 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] Traceback
(most recent call last):*
*Wed Aug 01 13:41:22.664336 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line <b
class=line>1540</b>, in HandlerDispatch\n default=default_handler,
arg=req, silent=hlist.silent)*
*Wed Aug 01 13:41:22.664340 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line <b
class=line>1232</b>, in _process_target\n result =
_execute_target(config, req, object, arg)*
*Wed Aug 01 13:41:22.664342 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/versions/1.4.0p31.cre/lib/python/mod_python/importer.py", line <b
class=line>1131</b>, in _execute_target\n result = object(arg)*
*Wed Aug 01 13:41:22.664344 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/sites/***<sitename>*/share/check_mk/web/htdocs/index.py", line <b
class=line>48</b>, in handler\n __builtin__.html =
html_mod_python(mod_python_req, fields)*
*Wed Aug 01 13:41:22.664347 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/sites/***<sitename>*/share/check_mk/web/htdocs/html_mod_python.py", line <b
class=line>74</b>, in __init__\n
self.set_output_format(self.var("output_format", "html").lower())*
*Wed Aug 01 13:41:22.664349 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>] File
"/omd/sites/***<sitename>*/share/check_mk/web/htdocs/htmllib.py", line <b
class=line>1678</b>, in set_output_format\n raise
MKGeneralException(_("Unsupported context type '%s'") % f)*
*Wed Aug 01 13:41:22.664352 2018* *:error * *[pid 17749] [client 127.0.0.1:49286 <http://127.0.0.1:49286>]
MKGeneralException: Unsupported context type 'python -d
request={'hostname':'<hostname'}'*
*Wed Aug 01 13:41:22.664596 2018* *:notice* *[pid 17749] mod_python (pid=17749, interpreter='OMD_CMK_00'): Importing
module '/omd/sites/<sitename>/share/omd/htdocs/index.py'*
*Wed Aug 01 13:41:56.183308 2018* *:error * *[pid 30426] [client 127.0.0.1:51712 <http://127.0.0.1:51712>]
mod_python (pid=30426, interpreter='***<sitename>*', phase='PythonHandler', handler='index'): Application error
*
These are my first steps into automation and i suspect i am doing
sometzhing wrong with the URL.
Can somebody point me in the right direction?
BR
Tom
Loading...