From 7948edcfb0ea02ec1470ae09f4f7b7be2217ca75 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 27 Feb 2007 18:54:32 +0000 Subject: [PATCH] - Initial checkin of new API implementation --- PLC/EventObjects.py | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 PLC/EventObjects.py diff --git a/PLC/EventObjects.py b/PLC/EventObjects.py new file mode 100644 index 00000000..8f579146 --- /dev/null +++ b/PLC/EventObjects.py @@ -0,0 +1,54 @@ +# +# Functions for interacting with the events table in the database +# +# Tony Mack +# Copyright (C) 2006 The Trustees of Princeton University +# +# $Id: Events.py,v 1.11 2007/01/19 17:50:46 tmack Exp $ +# + +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 + +class EventObject(Row): + """ + Representation of a row in the event_object table. + """ + + table_name = 'event_object' + primary_key = 'event_id' + fields = { + 'event_object.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"), + '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"), + '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_id': Parameter(int, "ID of objects affected by this event"), + 'object_type': Parameter(str, "What type of object is this event affecting") + } + +class EventObjects(Table): + """ + Representation of row(s) from the event_object table in the database. + """ + + def __init__(self, api, event_filter = None, columns = None): + Table.__init__(self, api, EventObject, columns) + sql = "SELECT %s FROM event_object, events WHERE True" % \ + ", ".join(self.columns) + if event_filter is not None: + if isinstance(event_filter, (list, tuple, set)): + event_filter = Filter(EventObject.fields, {'event_id': event_filter}) + elif isinstance(event_filter, dict): + event_filter = Filter(EventObject.fields, event_filter) + sql += " AND (%s) " % event_filter.sql(api) + sql += " AND events.event_id = event_object.event_id " + sql += " ORDER BY %s" % EventObject.primary_key + self.selectall(sql) -- 2.47.0