Rule Set commands with HTTP-API Troubleshooting

CMK version : 1.6.0p9
OS version : CentOS 7

Error message : Expecting property name: line 1 column 2 (char 1)

Description of the problem : I’m trying to test the new HTTP-API, in combination with Rule Set commands. But this seems to be not working. Does anybody have experience with this?

Troublshoot steps:

  1. Get the needed information with get_ruleset
    Command:

[vagrant@checkmk ~]$ curl localhost/test/check_mk/webapi.py?action=get_ruleset&_username=automation&_secret=4c550ece-c5eb-4456-b04a-b5fa4df4c18e&output_format=python" -d ‘request={“ruleset_name”:“checkgroup_parameters:filesystem”}’

Result:

{‘result’: {‘ruleset’: {‘’: [{‘condition’: {}, ‘value’: {‘levels’: (80.0, 90.0)}, ‘options’: {‘description’: u’Create rule after Curl command’}}]}, ‘configuration_hash’: ‘b4765a55eca77acc5b0a57e1d2ef9be4’}, ‘result_code’: 0}

  1. Make change from 80% to 81% with set_ruleset
    Command:

[vagrant@checkmk ~]$ curl “localhost/test/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret=4c550ece-c5eb-4456-b04a-b5fa4df4c18e&output_format=python” -d “request={‘ruleset_name’:‘checkgroup_parameters:filesystem’,‘ruleset’: {‘’: [{‘conditions’: {}, ‘value’: {‘levels’: (81.0, 90.0)}, ‘options’: {}}]}, ‘configuration_hash’: ‘b4765a55eca77acc5b0a57e1d2ef9be4’}}”

Result:

{‘result’: u"Check_MK exception: Failed to parse JSON request: ‘{‘ruleset_name’:‘checkgroup_parameters:filesystem’,‘ruleset’: {’‘: [{‘conditions’: {}, ‘value’: {‘levels’: (81.0, 90.0)},
‘options’: {}}]}}}’: Expecting property name: line 1 column 2 (char 1)", ‘result_code’: 1}

But according the URL it is a valid JSON Free Online JSON Validator - FreeFormatter.com

Side note:
Documentation has some typo in it

6.1. get_ruleset

root@linux# **curl “myserver/mysite/check_mk/webapi.py?action=get_ruleset&_username=automation&_secret=myautomationsecret&output_format=python” -d ‘request={“ruleset_name”:“checkgroup_paramters:filesystem”}’

checkgroup_paramters:filesystem should be checkgroup_parameters:filesystem (with e in parameters)

And I’m aware that not everything support JSON

Due to restriction of max 2 URL in post, I had to edit my file.
I remove http in curl command and documentation to HTTP API is https://checkmk.com/cms_web_api_references.html#Rule%20Set%20commands

This is not a valid python dict.

{
    'ruleset_name':'checkgroup_parameters:filesystem',
    'ruleset': {
        '': [{
            'conditions': {
            }, 
            'value': {'levels': (81.0, 90.0)},
            'options': {}
            }]      <---- , missing
        },    <----- too much
    'configuration_hash': 'b4765a55eca77acc5b0a57e1d2ef9be4'
    }
}

“configuration_hash” must be inside the “ruleset” entry.

Thanks, I changed it and it’s still complaining.

This is the code with configuration_hash (validator http://jsonviewer.stack.hu/)
afbeelding
And one without configuration_hash, because this is optional (according to documentation)
afbeelding

But still

[vagrant@checkmk ~]$ curl “http://localhost/test/check_mk/webapi.py?action=get_ruleset&_username=automation&_secret=4c550ece-c5eb-4456-b04a-b5fa4df4c18e&output_format=python” -d ‘request={“ruleset_name”:“checkgroup_parameters:filesystem”}’

{‘result’: {‘ruleset’: {‘’: [{‘condition’: {}, ‘value’: {‘levels’: (80.0, 90.0)}, ‘options’: {‘description’: u’Test’}}]}, ‘configuration_hash’: ‘31e1fa53de0ad7fae26561062d0ead67’}, ‘result_code’: 0}

[vagrant@checkmk ~]$ curl “http://localhost/test/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret=4c550ece-c5eb-4456-b04a-b5fa4df4c18e&output_format=python” -d “request={‘ruleset_name’:‘checkgroup_parameters:filesystem’,‘ruleset’:{‘’:[{‘conditions’:{‘host_specs’:,‘service_specs’:,‘host_tags’:},‘options’:{},‘value’:{‘levels’:(90.0,95.0)}}]}}”

{‘result’: u"Check_MK exception: Failed to parse JSON request: ‘{‘ruleset_name’:‘checkgroup_parameters:filesystem’,‘ruleset’:{’‘:[{‘conditions’:{‘host_specs’:,‘service_specs’:,‘host_tags’:},‘options’:{},‘value’:{‘levels’:(90.0,95.0)}}]}}’: Expecting property name: line 1 column 2 (char 1)", ‘result_code’: 1}

[vagrant@checkmk ~]$ curl “http://localhost/test/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret=4c550ece-c5eb-4456-b04a-b5fa4df4c18e&output_format=python” -d “request={‘ruleset_name’:‘checkgroup_parameters:filesystem’,‘ruleset’:{‘’:[{‘conditions’:{‘host_specs’:,‘service_specs’:,‘host_tags’:},‘options’:{},‘value’:{‘levels’:(90.0,95.0)}}], ‘configuration_hash’: ‘31e1fa53de0ad7fae26561062d0ead67’}}”

{‘result’: u"Check_MK exception: Failed to parse JSON request: ‘{‘ruleset_name’:‘checkgroup_parameters:filesystem’,‘ruleset’:{’‘:[{‘conditions’:{‘host_specs’:,‘service_specs’:,‘host_tags’:},‘options’:{},‘value’:{‘levels’:(90.0,95.0)}}], ‘configuration_hash’: ‘31e1fa53de0ad7fae26561062d0ead67’}}’: Expecting property name: line 1 column 2 (char 1)", ‘result_code’: 1}

Thank you for this, the API just crashed when using the incorrect parameter, but we seen this bad design in the API before, the documentation is still incorrect, and that’s bad.

Just to share: I wrote a script to update ruleset using Python :slight_smile:

1 Like