Bug 1467317 - [python-aodhclient] No validation check for 'query' params of alarm type 'event'
[python-aodhclient] No validation check for 'query' params of alarm type 'event'
Status: ASSIGNED
Product: Red Hat OpenStack
Classification: Red Hat
Component: python-aodhclient (Show other bugs)
10.0 (Newton)
Unspecified Unspecified
low Severity low
: zstream
: 10.0 (Newton)
Assigned To: RHOS Maint
nlevinki
: Triaged, ZStream
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-07-03 07:34 EDT by Sachin
Modified: 2017-09-15 13:03 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Sachin 2017-07-03 07:34:23 EDT
Description of problem:


Following error message in /var/log/aodh/listener.log when event of type "compute.instance.power_on.*" or "compute.instance.power_off.*"
~~~
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event [-] Failed to evaluate alarm (id=cf5cc083-e26f-4f46-9c89-c14384fbc1fd) triggered by event = {u'event_type': u'compute.instance.power_off.start', u'traits': [[u'state', 1, u'active'], [u'user_id', 1, u'3135a4d6ee88496e8349fe31b7c4531c'], [u'service', 1, u'compute'], [u'disk_gb', 2, 20], [u'instance_type', 1, u'm1.small'], [u'tenant_id', 1, u'd29ece8f67244b6daa1b9e6dcd694d29'], [u'root_gb', 2, 20], [u'ephemeral_gb', 2, 0], [u'instance_type_id', 2, 2], [u'vcpus', 2, 1], [u'memory_mb', 2, 2048], [u'instance_id', 1, u'18e78bfd-0261-4fec-8629-389e50a281f5'], [u'host', 1, u'osp10.localdomain'], [u'request_id', 1, u'req-e6675564-770c-4b02-b5bb-7aa3dd06c983'], [u'project_id', 1, u'd29ece8f67244b6daa1b9e6dcd694d29'], [u'launched_at', 4, u'2017-05-23T07:00:51']], u'message_signature': u'45440456165bf24b335e7105652b2aa677cccb0b060537ee071c1229a687c852', u'raw': {}, u'generated': u'2017-07-03T11:23:15.806567', u'message_id': u'1154659f-eb85-4691-b332-8344e292171b'}.
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event Traceback (most recent call last):
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event   File "/usr/lib/python2.7/site-packages/aodh/evaluator/event.py", line 178, in evaluate_events
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event     self._evaluate_alarm(alarm, event)
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event   File "/usr/lib/python2.7/site-packages/aodh/evaluator/event.py", line 241, in _evaluate_alarm
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event     if not _compare(condition):
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event   File "/usr/lib/python2.7/site-packages/aodh/evaluator/event.py", line 238, in _compare
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event     return condition['op'](v, condition['value'])
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event TypeError: 'unicode' object is not callable
2017-07-03 07:23:15.897 2570 ERROR aodh.evaluator.event 
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event [-] Failed to evaluate alarm (id=cf5cc083-e26f-4f46-9c89-c14384fbc1fd) triggered by event = {u'event_type': u'compute.instance.power_off.end', u'traits': [[u'state', 1, u'stopped'], [u'user_id', 1, u'3135a4d6ee88496e8349fe31b7c4531c'], [u'service', 1, u'compute'], [u'disk_gb', 2, 20], [u'instance_type', 1, u'm1.small'], [u'tenant_id', 1, u'd29ece8f67244b6daa1b9e6dcd694d29'], [u'root_gb', 2, 20], [u'ephemeral_gb', 2, 0], [u'instance_type_id', 2, 2], [u'vcpus', 2, 1], [u'memory_mb', 2, 2048], [u'instance_id', 1, u'18e78bfd-0261-4fec-8629-389e50a281f5'], [u'host', 1, u'osp10.localdomain'], [u'request_id', 1, u'req-e6675564-770c-4b02-b5bb-7aa3dd06c983'], [u'project_id', 1, u'd29ece8f67244b6daa1b9e6dcd694d29'], [u'launched_at', 4, u'2017-05-23T07:00:51']], u'message_signature': u'a813a999675be3e974f1370beafca89495cc131f855d9eefc43362da6020df4d', u'raw': {}, u'generated': u'2017-07-03T11:23:18.921098', u'message_id': u'97a9dcfa-1ada-430b-a518-1f9c18f0f67e'}.
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event Traceback (most recent call last):
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event   File "/usr/lib/python2.7/site-packages/aodh/evaluator/event.py", line 178, in evaluate_events
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event     self._evaluate_alarm(alarm, event)
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event   File "/usr/lib/python2.7/site-packages/aodh/evaluator/event.py", line 241, in _evaluate_alarm
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event     if not _compare(condition):
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event   File "/usr/lib/python2.7/site-packages/aodh/evaluator/event.py", line 238, in _compare
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event     return condition['op'](v, condition['value'])
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event TypeError: 'unicode' object is not callable
2017-07-03 07:23:18.932 2570 ERROR aodh.evaluator.event 
~~~


Version-Release number of selected component (if applicable):
~~~
[root@osp10 ~]# rpm -qa | grep aodh
openstack-aodh-notifier-3.0.1-6.el7ost.noarch
python-aodhclient-0.7.0-1.el7ost.noarch
openstack-aodh-evaluator-3.0.1-6.el7ost.noarch
openstack-aodh-common-3.0.1-6.el7ost.noarch
openstack-aodh-api-3.0.1-6.el7ost.noarch
puppet-aodh-9.5.0-1.el7ost.noarch
python-aodh-3.0.1-6.el7ost.noarch
openstack-aodh-listener-3.0.1-6.el7ost.noarch
~~~

How reproducible:
Always


Steps to Reproduce:
1. Create aodh alarm of type event
~~~
aodh --debug alarm create \
	   --type event \
	   --name instance_off \
	   --description 'event_instance_power_off' \
	   --enable True \
	   --event-type "compute.instance.power_off.*" \
	   --alarm-action 'log://' \
	   --ok-action 'log://' \
	   --insufficient-data-action 'log://' \
	   --query --query '{"=": {"id": "aodh --debug alarm create \
	   --type event \
	   --name instance_on \
	   --description 'event_instance_power_off' \
	   --enable True \
	   --event-type "compute.instance.power_off.*" \
	   --alarm-action 'log://' \
	   --ok-action 'log://' \
	   --insufficient-data-action 'log://' \
	   --query --query '{"=": {"id": "bb912729-fa51-443b-bac6-bf4c795f081d"}}' \
           --resource-type instance

~~~

2. Shutdown instance
~~~
openstack server stop 18e78bfd-0261-4fec-8629-389e50a281f5
~~~

Actual results:
Throws error


Expected results:
Should trigger alarm

Additional info:
Comment 2 Julien Danjou 2017-07-03 11:07:28 EDT
Your query is in the wrong format, and it seems there is not validation in Aodh API, sigh.

Check the documentation for the proper format. It's:

https://github.com/openstack/aodh/blob/master/doc/source/event-alarm.rst#usage

Leaving the bug opened as it's a bug not validating the entry.
Comment 3 Sachin 2017-07-15 03:10:33 EDT
@Julien Thanks. The docs was useful

Following query worked!
~~~
aodh --debug alarm create \
	 --type event \
	 --name instance_off \
	 --description 'event_instance_power_off' \
	 --event-type "compute.instance.power_off.*" \
	 --enable True \
	 --query "traits.instance_id=string::bb912729-fa51-443b-bac6-f4c795f081d" \
	 --alarm-action 'log://' \
	 --ok-action 'log://' \
	 --insufficient-data-action 'log://' \
	 --resource-type instance
~~~

Changing bug title

Note You need to log in before you can comment on or make changes to this bug.