X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FEvents.py;h=e006694c5261177fc88493a5cb5db9321e46f94c;hb=refs%2Fheads%2Fpython3;hp=e87cbbe49d826b07fc2ca053b4a7c92a326c7dff;hpb=c575b7396f84f929087440a6b1c5c08b59bf723e;p=plcapi.git diff --git a/PLC/Events.py b/PLC/Events.py index e87cbbe..e006694 100644 --- a/PLC/Events.py +++ b/PLC/Events.py @@ -4,8 +4,6 @@ # Tony Mack # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: Events.py,v 1.10 2006/12/20 14:07:22 tmack Exp $ -# from PLC.Faults import * from PLC.Parameter import Parameter @@ -15,26 +13,27 @@ from PLC.Table import Row, Table class Event(Row): """ - Representation of a row in the events table. + Representation of a row in the events table. """ - + table_name = 'events' primary_key = 'event_id' fields = { '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"), + 'auth_type': Parameter(int, "Type of auth used. i.e. AuthMethod"), 'fault_code': Parameter(int, "Event fault code"), - '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"), - 'object_type': Parameter(str, "What type of object is this event affecting"), + '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", ro = True), - 'object_ids': Parameter([int], "IDs of objects affected by this event") - } + '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. """ @@ -47,18 +46,18 @@ 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: self.api.db.commit() self['object_ids'].append(object_id) - + class Events(Table): """ - Representation of row(s) from the events table in the database. + Representation of row(s) from the events table in the database. """ def __init__(self, api, event_filter = None, columns = None): @@ -68,10 +67,11 @@ class Events(Table): ", ".join(self.columns) if event_filter is not None: - if isinstance(event_filter, (list, tuple, set)): + if isinstance(event_filter, (list, tuple, set, int)): event_filter = Filter(Event.fields, {'event_id': event_filter}) elif isinstance(event_filter, dict): event_filter = Filter(Event.fields, event_filter) - sql += " AND (%s)" % event_filter.sql(api) - sql += " ORDER BY %s" % Event.primary_key + else: + raise PLCInvalidArgument("Wrong event object filter %r"%event_filter) + sql += " AND (%s) %s" % event_filter.sql(api) self.selectall(sql)