Set_ruleset Folder configuration_hash does not exist

Good morning,

I’m trying to automate some adding some rules to folder however I’m experiencing issues that I can’t explain and fix and documentation is extremely vague. I’m trying to add this rule automatically via API:

agent_config.setdefault(‘systemd’, [])

agent_config[‘systemd’] = [
( True, [], ALL_HOSTS, {‘description’: u’Systemd’} ),
] + agent_config[‘systemd’]

get_ruleset gives me this result:

curl “http://localhost/test/check_mk/webapi.py?action=get_ruleset&_username=automation&_secret=myautomation&output_format=python” -d ‘request={“ruleset_name”:“agent_config:systemd”}’
{‘result’: {‘ruleset’: {}, ‘configuration_hash’: ‘99914b932bd37a50b983c5e7c90ae93b’}, ‘result_code’: 0}

my API call look like that:

curl “http://localhost/test/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret=myautomation&request_format=python” -d “request={‘ruleset_name’:‘agent_config:systemd’,‘ruleset’: {’’: [{‘conditions’: {‘host_specs’: [’@all’], ‘host_tags’: []}, ‘options’: {}, ‘value’: True}],‘configuration_hash’: ‘99914b932bd37a50b983c5e7c90ae93b’}}”

and result in:
{“result”: “Check_MK exception: Folder configuration_hash does not exist”, “result_code”: 1}

I tried to use hash from get_folder but got the same.

I would appreciate your help as I have around 100 rules to set that I need to automate and I am already stuck for longer than I expected

Many thanks

The result of your first “get_ruleset” looks like that there is nothing set at the moment. I’m correct?
If you sent without configuration hash, the new rule should be created without internal checking.
I would check after the “get_ruleset” if my “ruleset” dictionary is empty, and then decide if i must sent a configuration hash or not.

1 Like

@andreas-doehler You’re right. There was no rule in this folder. I removed config_hash from the end and this executed fine.
So to make it clear, configuration_hash should be used when the rule already exist but I want to modify it right ?

Yes, if i remember it correctly then the configuration hash is used by the system to check if something is changed or not. Your hash is a hash of a empty rule, i think there could be a logic problem if the existing rule is empty :slight_smile:

Thank you for help @andreas-doehler

The configuration_hash has to be put outside the rule_set dict when posting. You mixed the position of a }. Instead of two }} after configuration_hash put one before the comma in front of configuration_hash.

Thanks for your input @r.sander however, I’m following documentation. Example shows:
root@linux# curl “http://myserver/mysite/check_mk/webapi.py?action=set_ruleset&_username=automation&_secret=myautomationsecret&request_format=python” -d "request={‘ruleset_name’:‘checkgroup_parameters:filesystem’,‘ruleset’: {’’: [{‘conditions’: {‘host_specs’: [‘myserver123’], ‘service_specs’: [u’/media/customers$’], ‘host_tags’: []}, ‘options’: {}, ‘value’: {‘levels’: (90.0, 95.0)}}],‘configuration_hash’: ‘e069408225932bbfe2a485f22b9fc40e’}}"

So does it mean, official documentation has to be changed ?

maybe, I was just looking at the result you got where configuration_hash is also outside the ruleset dict. Have you tried it that way?

maybe, I was just looking at the result you got where configuration_hash is also outside the ruleset dict. Have you tried it that way?

I did not as I’m trying to deal with something else.