Adding regex based rulesets to service groups

Hi All,

Hope everyone is safe and well.
I’m trying to automate the addition of regex based rulesets using the API, but can’t seem to find out why it fails. The return code for the curl result output doesn’t help because it doesn’t error out:
{‘result’: None, ‘result_code’: 0}*)

The used API command for troubleshooting is as follows:

curl “http://”$ipaddress":"$port"/"$sitename"/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret="$automation_secret"&request_format=python&output_format=python" -d “request={‘ruleset_name’:‘service_groups’,‘ruleset’: {‘folder1/folder2’: [{‘condition’: {‘service_description’: [{’$regex’: u’App1_Log’}]}, ‘value’: ‘myservicegroup’, ‘options’: {‘description’: u’app1-log’}}, {‘condition’: {‘service_description’: [{’$regex’: u’App2_Log’}]}, ‘value’: ‘myservicegroup’, ‘options’: {‘description’: u’app2-log’}}]}}”

This results in check_mk erroring out on “gui” with :

KeyError (’$regex’)

Traceback:

File “/omd/sites/pcsocmon/share/check_mk/web/app/index.wsgi”, line 101, in _process_request
self._handle_request()
File “/omd/sites/pcsocmon/share/check_mk/web/app/index.wsgi”, line 218, in _handle_request
handler()
File “/omd/sites/pcsocmon/lib/python/cmk/gui/pages.py”, line 152, in
return lambda: handle_class().handle_page()
File “/omd/sites/pcsocmon/lib/python/cmk/gui/pages.py”, line 46, in handle_page
self.page()
File “/omd/sites/pcsocmon/lib/python/cmk/gui/pages.py”, line 128, in
“page”: lambda self: self._wrapped_callable0
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/init.py”, line 438, in page_handler
_wato_page_handler(current_mode, mode_permissions, mode_class)
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/init.py”, line 534, in _wato_page_handler
mode.handle_page()
File “/omd/sites/pcsocmon/lib/python/cmk/gui/plugins/wato/utils/base_modes.py”, line 77, in handle_page
return self.page()
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/pages/rulesets.py”, line 664, in page
self._rule_listing(ruleset)
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/pages/rulesets.py”, line 711, in _rule_listing
self._rule_cells(table, rule)
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/pages/rulesets.py”, line 831, in _rule_cells
self._rule_conditions(rule)
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/pages/rulesets.py”, line 862, in _rule_conditions
VSExplicitConditions(rulespec=self._rulespec).value_to_text(rule.get_rule_conditions()))
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/pages/rulesets.py”, line 1680, in value_to_text
for condition in renderer.render(self._rulespec, conditions):
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/pages/rulesets.py”, line 1748, in render
rendered += list(self._service_conditions(rulespec, conditions))
File “/omd/sites/pcsocmon/lib/python/cmk/gui/wato/pages/rulesets.py”, line 1921, in _service_conditions
[x for x in service_conditions if not isinstance(x, dict) or x["$regex"][-1] == “$”])

Any help would be appreciated.
Cheers
MTV

Could anyone please advise ?

Hi all. His this forum active ?

Hi MTV,
did you try you API Call without unicode str e.g. [{’$regex’: ’App1_Log’}] or masking $ e.g [{’$regex’: u’App1_Log’}]
Cheers,
Christian

Hi ChristianM,

Finally got a hold of the problem, although your answer didn’t solve the issue.

The problem was on the URL and the strings that need to be passed, namely request_format and output_format.

Botth need to be ‘python’ and request_format MUST be after output_format.

Thank you nevertheless.

Cheers
mtv

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