2 # Functions for interacting with the events table in the database
4 # Tony Mack <tmack@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
11 from PLC.Faults import *
12 from PLC.Parameter import Parameter
13 from PLC.Filter import Filter
14 from PLC.Debug import profile
15 from PLC.Table import Row, Table
17 class EventObject(Row):
19 Representation of a row in the event_object table.
22 table_name = 'event_object'
23 primary_key = 'event_id'
25 'event_id': Parameter(int, "Event identifier"),
26 'person_id': Parameter(int, "Identifier of person responsible for event, if any"),
27 'node_id': Parameter(int, "Identifier of node responsible for event, if any"),
28 'fault_code': Parameter(int, "Event fault code"),
29 'call_name': Parameter(str, "Call responsible for this event"),
30 'call': Parameter(str, "Call responsible for this event, including paramters"),
31 'message': Parameter(str, "High level description of this event"),
32 'runtime': Parameter(float, "Runtime of event"),
33 'time': Parameter(int, "Date and time that the event took place, in seconds since UNIX epoch", ro = True),
34 'object_id': Parameter(int, "ID of objects affected by this event"),
35 'object_type': Parameter(str, "What type of object is this event affecting")
38 class EventObjects(Table):
40 Representation of row(s) from the event_object table in the database.
43 def __init__(self, api, event_filter = None, columns = None):
44 Table.__init__(self, api, EventObject, columns)
46 sql = "SELECT %s FROM view_event_objects WHERE True" % \
47 ", ".join(self.columns)
49 if event_filter is not None:
50 if isinstance(event_filter, (list, tuple, set)):
51 event_filter = Filter(EventObject.fields, {'event_id': event_filter})
52 sql += " AND (%s) %s" % event_filter.sql(api, "OR")
53 elif isinstance(event_filter, dict):
54 event_filter = Filter(EventObject.fields, event_filter)
55 sql += " AND (%s) %s" % event_filter.sql(api, "AND")
56 elif isinstance (event_filter, int):
57 event_filter = Filter(EventObject.fields, {'event_id':[event_filter]})
58 sql += " AND (%s) %s" % event_filter.sql(api, "AND")
60 raise PLCInvalidArgument, "Wrong event object filter %r"%event_filter
61 # with new filtering, caller needs to set this explicitly
62 # sql += " ORDER BY %s" % EventObject.primary_key