Discussion:
[Check_mk (english)] Issue with ignored_services API call
Wessley.Hutton
2018-10-23 09:33:06 UTC
Permalink
Hello

I can't get the ignored_services request to the WATO API to work.

I have configure an ignored service in WATO and then I use get rule set via the API to get the configuration format, and I get a configuration input file to use with Curl like :-

request={
'ruleset_name':'ignored_services',
'ruleset': {
'': [
{'conditions': {
'negate': False,
'host_specs': ['pcr-b2024-1'],
'service_specs': [u'Interface 16 Optical'],
'host_tags': []},
'options': {}}
]
}
}

When I use the API call to set this I get the following error message :-

{"result": "Unhandled exception: Traceback (most recent call last):\n File \"/omd/sites/test/share/check_mk/web/htdocs/webapi.py\", line 251, in page_api\n action_resp
onse = api_actions[action][\"handler\"](request_object)\n File \"/omd/sites/test/share/check_mk/web/plugins/webapi/webapi.py\", line 640, in _set\n value = rule[\"valu
e\"]\nKeyError: 'value'\n", "result_code": 1}

And looking around line 640 in webapi.py :-

for rule in rules:
value = rule["value"]
try:
rule_vs.validate_datatype(value, "test_value")
rule_vs.validate_value(value, "test_value")
except MKException, e:
raise MKException("ERROR: %s. Affected Rule %r" % (str(e), rule))


This is implying to me that it is expecting a value configuration item and there isn't one. Looking at the other configurations I have found for setting rule sets via the API they all appear to have a value setting.

Is this a bug or am I doing something stupid ? I can get the ignored_checks API call to work but that has a value configuration item, the names of the checks to be ignored.

Cheers

Wessley


[cid:***@01D46ABB.C7D63580]
[cid:***@01D46ABB.C7D63580]
Wessley Hutton | Senior Systems Programmer, IT Service and Support
Information Technology
The Open University, Level 0 North, Berrill Building, Walton Hall, Milton Keynes, MK7 6AA
Tel: +44 (0) 1908 652728
[cid:***@01D46ABB.C7D63580]

-- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). The Open University is authorised and regulated by the Financial Conduct Authority in relation to its secondary activity of credit broking.
Andreas Döhler
2018-10-23 12:48:34 UTC
Permalink
Hi Wessley,

i tested your api request and get the same error. There is an error inside
the set_ruleset function as it checks for the key "value" inside our
submitted dictionary.
Only rules with an value option can have this key. I made a small fix that
the submitted value key is only checked if it exists.

Now it is working in my tests for the rules without values like
"disabled_services".

change i made is

641 # Verify all rules
642 rule_vs = watolib.Ruleset(ruleset_name).rulespec.valuespec
643 for folder_path, rules in new_ruleset.items():
644 for rule in rules:
645 value = rule["value"]
646 try:
647 rule_vs.validate_datatype(value, "test_value")
648 rule_vs.validate_value(value, "test_value")
649 except MKException, e:
650 raise MKException("ERROR: %s. Affected Rule %r" %
(str(e), rule))

to

641 # Verify all rules
642 rule_vs = watolib.Ruleset(ruleset_name).rulespec.valuespec
643 for folder_path, rules in new_ruleset.items():
644 for rule in rules:
if value in rule:
645 value = rule["value"]
646 try:
647 rule_vs.validate_datatype(value, "test_value")
648 rule_vs.validate_value(value, "test_value")
649 except MKException, e:
650 raise MKException("ERROR: %s. Affected Rule
%r" % (str(e), rule))

I submitted this also as an bugfix to the MK team.

Best regards
Andreas
Hello
I can’t get the ignored_services request to the WATO API to work.
I have configure an ignored service in WATO and then I use get rule set
via the API to get the configuration format, and I get a configuration
input file to use with Curl like :-
request={
'ruleset_name':'ignored_services',
'ruleset': {
'': [
{'conditions': {
'negate': False,
'host_specs': ['pcr-b2024-1'],
'service_specs': [u'Interface 16 Optical'],
'host_tags': []},
'options': {}}
]
}
}
When I use the API call to set this I get the following error message :-
{"result": "Unhandled exception: Traceback (most recent call last):\n
File \"/omd/sites/test/share/check_mk/web/htdocs/webapi.py\", line 251, in
page_api\n action_resp
onse = api_actions[action][\"handler\"](request_object)\n File
\"/omd/sites/test/share/check_mk/web/plugins/webapi/webapi.py\", line 640,
in _set\n value = rule[\"valu
e\"]\nKeyError: 'value'\n", "result_code": 1}
And looking around line 640 in webapi.py :-
value = rule["value"]
rule_vs.validate_datatype(value, "test_value")
rule_vs.validate_value(value, "test_value")
raise MKException("ERROR: %s. Affected Rule %r" % (str(e), rule))
This is implying to me that it is expecting a value configuration item and
there isn’t one. Looking at the other configurations I have found for
setting rule sets via the API they all appear to have a value setting.
Is this a bug or am I doing something stupid ? I can get the
ignored_checks API call to work but that has a value configuration item,
the names of the checks to be ignored.
Cheers
Wessley
*Wessley Hutton* | Senior Systems Programmer, IT Service and Support
Information Technology
The Open University, Level 0 North, Berrill Building, Walton Hall, Milton Keynes, MK7 6AA
*Tel: +44 (0) 1908 652728 <+44%201908%20652728>*
-- The Open University is incorporated by Royal Charter (RC 000391), an
exempt charity in England & Wales and a charity registered in Scotland (SC
038302). The Open University is authorised and regulated by the Financial
Conduct Authority in relation to its secondary activity of credit broking.
_______________________________________________
checkmk-en mailing list
Manage your subscription or unsubscribe
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
Wessley.Hutton
2018-10-23 13:56:05 UTC
Permalink
Andreas

Your fix doesn’t work for me, even after upgrading from 1.5.0p5 to 1.5.0p7. I get the following error message now :-


{"result": "Unhandled exception: Traceback (most recent call last):\n File \"/omd/sites/test/share/check_mk/web/htdocs/webapi.py\", line 251, in page_api\n action_respo
nse = api_actions[action][\"handler\"](request_object)\n File \"/omd/sites/test/share/check_mk/web/plugins/webapi/webapi.py\", line 645, in _set\n if value in rule:\nKe
yError: 'value'\n", "result_code": 1}


Cheers


Wessley


[cid:***@01D46AE0.84D50AC0]
[cid:***@01D46AE0.84D50AC0]
Wessley Hutton | Senior Systems Programmer, IT Service and Support
Information Technology
The Open University, Level 0 North, Berrill Building, Walton Hall, Milton Keynes, MK7 6AA
Tel: +44 (0) 1908 652728
[cid:***@01D46AE0.84D50AC0]


From: Andreas Döhler <***@gmail.com>
Sent: 23 October 2018 13:49
To: Wessley.Hutton <***@open.ac.uk>
Cc: checkmk-***@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Issue with ignored_services API call

Hi Wessley,

i tested your api request and get the same error. There is an error inside the set_ruleset function as it checks for the key "value" inside our submitted dictionary.
Only rules with an value option can have this key. I made a small fix that the submitted value key is only checked if it exists.

Now it is working in my tests for the rules without values like "disabled_services".

change i made is

641 # Verify all rules
642 rule_vs = watolib.Ruleset(ruleset_name).rulespec.valuespec
643 for folder_path, rules in new_ruleset.items():
644 for rule in rules:
645 value = rule["value"]
646 try:
647 rule_vs.validate_datatype(value, "test_value")
648 rule_vs.validate_value(value, "test_value")
649 except MKException, e:
650 raise MKException("ERROR: %s. Affected Rule %r" % (str(e), rule))

to

641 # Verify all rules
642 rule_vs = watolib.Ruleset(ruleset_name).rulespec.valuespec
643 for folder_path, rules in new_ruleset.items():
644 for rule in rules:
if value in rule:
645 value = rule["value"]
646 try:
647 rule_vs.validate_datatype(value, "test_value")
648 rule_vs.validate_value(value, "test_value")
649 except MKException, e:
650 raise MKException("ERROR: %s. Affected Rule %r" % (str(e), rule))

I submitted this also as an bugfix to the MK team.

Best regards
Andreas


Wessley.Hutton <***@open.ac.uk<mailto:***@open.ac.uk>> schrieb am Di., 23. Okt. 2018 um 11:38 Uhr:
Hello

I can’t get the ignored_services request to the WATO API to work.

I have configure an ignored service in WATO and then I use get rule set via the API to get the configuration format, and I get a configuration input file to use with Curl like :-

request={
'ruleset_name':'ignored_services',
'ruleset': {
'': [
{'conditions': {
'negate': False,
'host_specs': ['pcr-b2024-1'],
'service_specs': [u'Interface 16 Optical'],
'host_tags': []},
'options': {}}
]
}
}

When I use the API call to set this I get the following error message :-

{"result": "Unhandled exception: Traceback (most recent call last):\n File \"/omd/sites/test/share/check_mk/web/htdocs/webapi.py\", line 251, in page_api\n action_resp
onse = api_actions[action][\"handler\"](request_object)\n File \"/omd/sites/test/share/check_mk/web/plugins/webapi/webapi.py\", line 640, in _set\n value = rule[\"valu
e\"]\nKeyError: 'value'\n", "result_code": 1}

And looking around line 640 in webapi.py :-

for rule in rules:
value = rule["value"]
try:
rule_vs.validate_datatype(value, "test_value")
rule_vs.validate_value(value, "test_value")
except MKException, e:
raise MKException("ERROR: %s. Affected Rule %r" % (str(e), rule))


This is implying to me that it is expecting a value configuration item and there isn’t one. Looking at the other configurations I have found for setting rule sets via the API they all appear to have a value setting.

Is this a bug or am I doing something stupid ? I can get the ignored_checks API call to work but that has a value configuration item, the names of the checks to be ignored.

Cheers

Wessley


[cid:***@01D46ABB.C7D63580]
[cid:***@01D46ABB.C7D63580]
Wessley Hutton | Senior Systems Programmer, IT Service and Support
Information Technology
The Open University, Level 0 North, Berrill Building, Walton Hall, Milton Keynes, MK7 6AA
Tel: +44 (0) 1908 652728<tel:+44%201908%20652728>
[cid:***@01D46ABB.C7D63580]

-- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). The Open University is authorised and regulated by the Financial Conduct Authority in relation to its secondary activity of credit broking.
_______________________________________________
checkmk-en mailing list
checkmk-***@lists.mathias-kettner.de<mailto:checkmk-***@lists.mathias-kettner.de>
Manage your subscription or unsubscribe
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
Andreas Döhler
2018-10-23 14:00:21 UTC
Permalink
Sorry one mistake from my side.

The if line must look like

if "value" in rule:

I forgot the quotation marks.

Best regards
Andreas
Post by Andreas Döhler
Andreas
Your fix doesn’t work for me, even after upgrading from 1.5.0p5 to
1.5.0p7. I get the following error message now :-
{"result": "Unhandled exception: Traceback (most recent call last):\n
File \"/omd/sites/test/share/check_mk/web/htdocs/webapi.py\", line 251, in
page_api\n action_respo
nse = api_actions[action][\"handler\"](request_object)\n File
\"/omd/sites/test/share/check_mk/web/plugins/webapi/webapi.py\", line 645,
in _set\n if value in rule:\nKe
yError: 'value'\n", "result_code": 1}
Cheers
Wessley
*Wessley Hutton* | Senior Systems Programmer, IT Service and Support
Information Technology
The Open University, Level 0 North, Berrill Building, Walton Hall, Milton Keynes, MK7 6AA
*Tel: +44 (0) 1908 652728 <+44%201908%20652728>*
*Sent:* 23 October 2018 13:49
*Subject:* Re: [Check_mk (english)] Issue with ignored_services API call
Hi Wessley,
i tested your api request and get the same error. There is an error inside
the set_ruleset function as it checks for the key "value" inside our
submitted dictionary.
Only rules with an value option can have this key. I made a small fix that
the submitted value key is only checked if it exists.
Now it is working in my tests for the rules without values like "disabled_services".
change i made is
641 # Verify all rules
642 rule_vs = watolib.Ruleset(ruleset_name).rulespec.valuespec
645 value = rule["value"]
647 rule_vs.validate_datatype(value, "test_value")
648 rule_vs.validate_value(value, "test_value")
650 raise MKException("ERROR: %s. Affected Rule %r" % (str(e), rule))
to
641 # Verify all rules
642 rule_vs = watolib.Ruleset(ruleset_name).rulespec.valuespec
645 value = rule["value"]
647 rule_vs.validate_datatype(value, "test_value")
648 rule_vs.validate_value(value, "test_value")
650 raise MKException("ERROR: %s. Affected Rule
%r" % (str(e), rule))
I submitted this also as an bugfix to the MK team.
Best regards
Andreas
Hello
I can’t get the ignored_services request to the WATO API to work.
I have configure an ignored service in WATO and then I use get rule set
via the API to get the configuration format, and I get a configuration
input file to use with Curl like :-
request={
'ruleset_name':'ignored_services',
'ruleset': {
'': [
{'conditions': {
'negate': False,
'host_specs': ['pcr-b2024-1'],
'service_specs': [u'Interface 16 Optical'],
'host_tags': []},
'options': {}}
]
}
}
When I use the API call to set this I get the following error message :-
{"result": "Unhandled exception: Traceback (most recent call last):\n
File \"/omd/sites/test/share/check_mk/web/htdocs/webapi.py\", line 251, in
page_api\n action_resp
onse = api_actions[action][\"handler\"](request_object)\n File
\"/omd/sites/test/share/check_mk/web/plugins/webapi/webapi.py\", line 640,
in _set\n value = rule[\"valu
e\"]\nKeyError: 'value'\n", "result_code": 1}
And looking around line 640 in webapi.py :-
value = rule["value"]
rule_vs.validate_datatype(value, "test_value")
rule_vs.validate_value(value, "test_value")
raise MKException("ERROR: %s. Affected Rule %r" % (str(e), rule))
This is implying to me that it is expecting a value configuration item and
there isn’t one. Looking at the other configurations I have found for
setting rule sets via the API they all appear to have a value setting.
Is this a bug or am I doing something stupid ? I can get the
ignored_checks API call to work but that has a value configuration item,
the names of the checks to be ignored.
Cheers
Wessley
*Wessley Hutton* | Senior Systems Programmer, IT Service and Support
Information Technology
The Open University, Level 0 North, Berrill Building, Walton Hall, Milton Keynes, MK7 6AA
*Tel: +44 (0) 1908 652728 <+44%201908%20652728>*
-- The Open University is incorporated by Royal Charter (RC 000391), an
exempt charity in England & Wales and a charity registered in Scotland (SC
038302). The Open University is authorised and regulated by the Financial
Conduct Authority in relation to its secondary activity of credit broking.
_______________________________________________
checkmk-en mailing list
Manage your subscription or unsubscribe
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
Loading...