Hello,
My problem is simple : i want to create a rule via the WEB API. To do so, i am doing these steps :
- Retrieve the name of the ruleset via curl "http://myserver/mysite/check_mk/webapi.py?action=get_rulesets_info&_username=automation&_secret=myautomationsecret&output_format=python"
- Parse this answer & find the name of the ruleset matching a specific Title “State & Count of processes” for example
- Create manually a rule and read its syntax in ~/etc/checkmk/conf.d/wato/rules.mk
- Use the set_ruleset API method to create the rule such as below with the matching syntax.
curl “http://myserver/mysite/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret=myautomationsecret&request_format=python” -d “request={‘ruleset_name’:‘inventory_processes_rules’, {‘condition’: {}, ‘value’: {‘default_params’: {‘cpu_rescale_max’: True}, ‘match’: ‘~(.)tomcat2(.)’, ‘descr’: ‘tomcat2’}, ‘options’: {‘description’: u’tomcat2’}}}”
However, this ruleset and the one below (i have tried with 2 different rules of process) are not working.
(i am a new user so i can post only 2 “links”, i am removing http:// to be able to post this question…)
curl “…myserver/mysite/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret=myautomationsecret&request_format=python” -d “request={‘ruleset_name’:‘static_checks:ps’, ‘ruleset’: { ‘’: [{ ‘conditions’: { ‘host_name’: [‘26.0.48.43’], ‘host_tags’: [] }, ‘options’: {‘description’: u’testnumber2’},‘value’: (‘ps’, ‘tomcat’, {‘process’: ‘/test/’, ‘cpu_rescale_max’: True, ‘user’: ‘~toto’}) }], } }”
They both raise an invalid rule error.
{“result”: “Check_MK exception: Invalid rule {‘conditions’: {‘host_name’: [‘26.0.48.43’], ‘host_tags’: []}, ‘options’: {‘description’: u’testnumber2’}, ‘value’: (‘ps’, ‘tomcat’, {‘process’: ‘/test/’, ‘cpu_rescale_max’: True, ‘user’: ‘~toto’})}”, “result_code”: 1}
What i am doing wrong ? Is there any way to solve this ?
The example in the document is for the ruleset “checkgroup_parameters:filesystem” which is quite different from processes, so i didn’t dare to copy paste the same syntax even if the conditions are similar…
Thanks a lot in advance, this API is very useful and i wish i could use it better.
Tom