Bug 1315861

Summary: API.events.list() won't filter by code
Product: [oVirt] ovirt-engine Reporter: nicolas
Component: Search-BackendAssignee: Eli Mesika <emesika>
Status: CLOSED NOTABUG QA Contact: Pavel Stehlik <pstehlik>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 3.6.3.3CC: bugs, juan.hernandez
Target Milestone: ---Flags: rule-engine: planning_ack?
rule-engine: devel_ack?
rule-engine: testing_ack?
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-03-09 09:16:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description nicolas 2016-03-08 19:34:41 UTC
Description of problem:

I actually didn't know if file this as a bug or a RFE. Our management has asked us for some indicators including how much times has been started a VNC session on a single day.

To do so, I've tried to filter the events list with this query:

In [1]: api.events.list(query='code=167')
Out[1]: []

An empty list is returned while there's about 400 events in the DB with code 167.

An example object:

{
 '_Base__context': 38197328,
 'actions': None,
 'cluster': <ovirtsdk.xml.params.Cluster object at 0x9ec30d0>,
 'code': 167,
 'comment': None,
 'correlation_id': None,
 'creation_status': None,
 'custom_data': None,
 'custom_id': -1,
 'data_center': None,
 'description': 'User XXX is connected to VM YYY',
 'extensiontype_': None,
 'flood_rate': 30,
 'host': <ovitsdk.xml.params.Host object at 0x9ebc3410>,
 'href': '/api/events/43476',
 'id': '43476',
 'link': [],
 'name': None,
 'origin': 'oVirt',
 'severity': 'normal',
 'storage_domain': None,
 'template': <ovirtsdk.xml.params.Template object at 0x9ec3090>,
 'time': datetime.datetime(2016, 3, 8, 10, 48, 37, 69000, tzinfo=<ovirtsdk.xml.params._FixedOffsetTZ object at 0x9ec33d0>),
 'user': None,
 'vm': <ovirtsdk.xml.params.VM object at 0x9ec3390>
}

If not a bug, could filtering based on event code be implemented?

Version-Release number of selected component (if applicable):

3.6.3.0

Comment 1 Juan Hernández 2016-03-09 09:14:40 UTC
The text that you put in the "query" parameter is translated into the "search" parameter of the API, so that call to the "list" method is translated into something like this:

  GET /ovirt-engine/api/events?search=code%3D167

The syntax of this "search" parameter is the same used in the search bar of the GUI, and it uses the same names used by the database and there are some differences with the names used in the API. For example, what is "code" in the API is "type" in the database. This means that you can make your script work just replacing "code" with "type":

  api.events.list(query='type=167')

There is more information about the query syntax here:

  https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Virtualization/3.5/html-single/Administration_Guide/index.html#Performing_Searches_in_Red_Hat_Enterprise_Virtualization

Section "F.1.19. Searching for Events" describes events.