Can't create rule with REST API

CMK version: 2.1.0p4
Error message:

Traceback (most recent call last):
  File "./cmk_rest_api.py", line 90, in <module>
    raise RuntimeError(pprint.pformat(send.json()))
RuntimeError: {'detail': "Value ['cert', {'cert_days': [29, 14]}] is not allowed here.",
 'status': 400,
 'title': "Problem in (sub-)field 'mode_sel'"}

When I try to make an HTTP service rule with the REST API, this error occurs in the “value_raw” section. The string I use in this section is copy-pasted from another rule I read from the API, so it shouldn’t be wrong. I think it’s a bug in the API.

1 Like

Found the problem: the given square brackets [] need to be round brackets (). But I still don’t know why the API output is with square brackets

2 Likes

Thanks @paulr282 for taking the time to post after resolving your own issue. I just ran into the same thing today and your post allowed me to solve the problem quickly.

Personally I think this should be considered a bug in the API. In my opinion, the input and output formats should be the same. With that said, maybe there are reasons that they need to be different in this specific case.

Note also that the Export this rule for API link in the web UI does provide the correct format that uses round brackets.

I also solved it coincidentally by the Export in the UI.

1 Like

This is a big issue if you want to automate via Ansible - Ansible also changes the brackets from “()” to “[]” and converts it to valid JSON which is not usable on the API. This is an API bug and should be fixed in my opinion - It would be feasible to use standard JSON. This issue is also present with the GitHub - tribe29/ansible-checkmk: Ansible integration of CheckMK collection - It is almost impossible to use variables in the YAML due to this problem.

2 Likes

I wrote up a longer explanation why it is not simple for us to use JSON for vaule_raw, on github. [BUG] Rule Module not correct? · Issue #153 · tribe29/ansible-collection-tribe29.checkmk · GitHub

I would really love to have JSON, but getting there without breaking existing MKPs and customer installations is a difficult problem.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.