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

Output format python is now possible to set and use. #8

Closed Yogibaer75 closed 5 years ago

Yogibaer75 commented 5 years ago

Result is now parsed according to "output_format" settings in query parameters. For some outputs it is necessary to set the format to "python". As an example "rulesets" need the setting for the output format.

Example query looks like this api.make_request('get_ruleset',query_params={"output_format":"python"}, data={"ruleset_name":"host_contactgroups"})

brennerm commented 5 years ago

Thanks for the contribution. Just a few minor change requests from my side.

  1. add a newline after the import of ast
  2. use single instead of double quotes for string
  3. reduce duplicate code in the if-else-block like so
    
    if "output_format" in query_params and query_params["output_format"] == "python":
    body_dict = ast.literal_eval(body)
    else:
    body_dict = json.loads(body)

result = body_dict['result'] if body_dict['result_code'] == 0: return result

Yogibaer75 commented 5 years ago

I made the recommended changes to my commit and I hope that it looks now good.

brennerm commented 5 years ago

Looks great, thanks!