X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FEvents.py;h=0d319cf22a780e87fc317e82362e79b60d635798;hb=refs%2Fheads%2Fplanetlab-4_0-branch;hp=d05aed3194357c00438c9681f0bc7fee508efefd;hpb=c1e9cd193dad761bf440976eca1825ce996145b9;p=plcapi.git diff --git a/PLC/Events.py b/PLC/Events.py index d05aed3..0d319cf 100644 --- a/PLC/Events.py +++ b/PLC/Events.py @@ -4,11 +4,12 @@ # Tony Mack # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ +# $Id: Events.py 5574 2007-10-25 20:33:17Z thierry $ # from PLC.Faults import * from PLC.Parameter import Parameter +from PLC.Filter import Filter from PLC.Debug import profile from PLC.Table import Row, Table @@ -23,16 +24,18 @@ class Event(Row): 'event_id': Parameter(int, "Event identifier"), 'person_id': Parameter(int, "Identifier of person responsible for event, if any"), 'node_id': Parameter(int, "Identifier of node responsible for event, if any"), - 'event_type': Parameter(str, "Type of event"), - 'object_type': Parameter(str, "Type of object affected by this event"), + 'auth_type': Parameter(int, "Type of auth used. i.e. AuthMethod"), 'fault_code': Parameter(int, "Event fault code"), - 'call': Parameter(str, "Call responsible for this event"), + 'call_name': Parameter(str, "Call responsible for this event"), + 'call': Parameter(str, "Call responsible for this event, including paramters"), + 'message': Parameter(str, "High level description of this event"), 'runtime': Parameter(float, "Runtime of event"), - 'time': Parameter(int, "Date and time that the event took place, in seconds since UNIX epoch"), - 'object_ids': Parameter([int], "IDs of objects affected by this event") + 'time': Parameter(int, "Date and time that the event took place, in seconds since UNIX epoch", ro = True), + 'object_ids': Parameter([int], "IDs of objects affected by this event"), + 'object_types': Parameter([str], "What type of object were affected by this event") } - def add_object(self, object_id, commit = True): + def add_object(self, object_type, object_id, commit = True): """ Relate object to this event. """ @@ -45,8 +48,8 @@ class Event(Row): self['object_ids'] = [] if object_id not in self['object_ids']: - self.api.db.do("INSERT INTO event_object (event_id, object_id)" \ - " VALUES(%(event_id)d, %(object_id)d)", + self.api.db.do("INSERT INTO event_object (event_id, object_id, object_type)" \ + " VALUES(%(event_id)d, %(object_id)d, %(object_type)s)", locals()) if commit: @@ -59,48 +62,18 @@ class Events(Table): Representation of row(s) from the events table in the database. """ - def __init__(self, api, - event_ids = None, - person_ids = None, node_ids = None, - event_types = None, - object_types = None, object_ids = None, - fault_codes = None): - self.api = api - - sql = "SELECT %s from view_events WHERE True" % \ - ", ".join(Event.fields) - - if event_ids: - sql += " AND event_id IN (%s)" % ", ".join(map(str, event_ids)) - - if person_ids: - sql += " AND person_id IN (%s)" % ", ".join(map(str, person_ids)) - - if node_ids: - sql += " AND node_id IN (%s)" % ", ".join(map(str, node_ids)) + def __init__(self, api, event_filter = None, columns = None): + Table.__init__(self, api, Event, columns) - if object_ids: - sql += " AND object_ids in (%s)" % ", ".join(map(str, object_ids)) + sql = "SELECT %s FROM view_events WHERE True" % \ + ", ".join(self.columns) - if event_types: - sql += " AND event_type in (%s)" % ", ".join(api.db.quote(event_types)) - - if object_types: - sql += " AND object_type in (%s)" % ", ".join(api.db.quote(object_types)) - - if fault_codes: - sql += " And fault_code in (%s)" % ", ".join(map(str, fault_codes)) - - rows = self.api.db.selectall(sql) - - for row in rows: - self[row['event_id']] = event = Event(api, row) - for aggregate in ['object_ids']: - if not event.has_key(aggregate) or event[aggregate] is None: - event[aggregate] = [] - else: - elements = event[aggregate].split(',') - try: - event[aggregate] = map(int, elements) - except ValueError: - event[aggregate] = elements + if event_filter is not None: + if isinstance(event_filter, (list, tuple, set)): + event_filter = Filter(Event.fields, {'event_id': event_filter}) + elif isinstance(event_filter, dict): + event_filter = Filter(Event.fields, event_filter) + sql += " AND (%s) %s" % event_filter.sql(api) +# with new filtering, caller needs to set this explicitly +# sql += " ORDER BY %s" % Event.primary_key + self.selectall(sql)