Package ZenEvents :: Module MySqlSendEvent :: Class MySqlSendEventMixin
[hide private]
[frames] | no frames]

Class MySqlSendEventMixin

source code

Mix-in class that takes a MySQL db connection and builds inserts that sends the event to the backend.

Instance Methods [hide private]
string
sendEvent(self, event)
Send an event to the backend.
source code
string
doSendEvent(self, event)
Actually write the sanitized event into the database
source code
device object
_findByIp(self, ipaddress, networks)
Find and ip by looking up it up in the Networks catalog.
source code
DMD object, evt
getNetworkRoot(self, evt)
Return the network root and event
source code
Event class
applyEventContext(self, evt)
Apply event and devices contexts to the event.
source code
Event class
applyDeviceContext(self, device, evt)
Apply event attributes from device context.
source code
 
_sendHeartbeat(self, event)
Add a heartbeat record to the heartbeat table.
source code
 
buildStatusInsert(self, statusdata, table, evid)
Build an insert statement for the status table that looks like this: insert into status set device='box', count=1, ...
source code
string
buildDetailInsert(self, evid, detaildict)
Build an insert to add detail values from an event to the details table.
source code
string
buildInsert(self, datadict, table)
Build a insert statement for that looks like this: insert into status set field='value', field=1, ...
source code
string
buildClearUpdate(self, evt, clearcls)
Build an update statement that will clear related events.
source code
tuple of dictionaries
eventDataMaps(self, event)
Return tuple (statusdata, detaildata) for this event.
source code
string
escape(self, value)
Prepare string values for db by escaping special characters.
source code
Method Details [hide private]

sendEvent(self, event)

source code 
Send an event to the backend.
Parameters:
  • event (Event class) - an event
Returns: string
event id or None

doSendEvent(self, event)

source code 
Actually write the sanitized event into the database
Parameters:
  • event (Event class) - event
Returns: string
event id or None

_findByIp(self, ipaddress, networks)

source code 
Find and ip by looking up it up in the Networks catalog.
Parameters:
  • ipaddress (string) - IP address
  • networks (DMD object) - DMD network object
Returns: device object
device object

getNetworkRoot(self, evt)

source code 
Return the network root and event
Parameters:
  • evt (Event class) - event
Returns: DMD object, evt
DMD object and the event

applyEventContext(self, evt)

source code 
Apply event and devices contexts to the event. Only valid if this object has zeo connection.
Parameters:
  • evt (Event class) - event
Returns: Event class
updated event

applyDeviceContext(self, device, evt)

source code 
Apply event attributes from device context.
Parameters:
  • device (device object) - device from DMD
  • evt (Event class) - event
Returns: Event class
updated event

_sendHeartbeat(self, event)

source code 
Add a heartbeat record to the heartbeat table.
Parameters:
  • event (Event class) - event

buildStatusInsert(self, statusdata, table, evid)

source code 

Build an insert statement for the status table that looks like this:
insert into status set device='box', count=1, ...
    on duplicate key update count=count+1, lastTime=23424.34;

@param statusdata: event
@type statusdata: dictionary
@param table: name of the table to insert into
@type table: string
@param evid: event id
@type evid: string
@return: MySQL insert command string
@rtype: string

buildDetailInsert(self, evid, detaildict)

source code 
Build an insert to add detail values from an event to the details table.
Parameters:
  • evid (string) - event id
  • detaildict (dictionary) - event
Returns: string
MySQL insert command string

buildInsert(self, datadict, table)

source code 
Build a insert statement for that looks like this: insert into status set field='value', field=1, ...
Parameters:
  • datadict (dictionary) - event
  • table (string) - name of the table to insert into
Returns: string
MySQL insert command string

buildClearUpdate(self, evt, clearcls)

source code 
Build an update statement that will clear related events.
Parameters:
  • evt (Event class) - event
  • clearcls (list of strings) - other fields to use to define 'related events'
Returns: string
MySQL update command string

eventDataMaps(self, event)

source code 
Return tuple (statusdata, detaildata) for this event.
Parameters:
  • event (Event class) - event
Returns: tuple of dictionaries
(statusdata, detaildata)

escape(self, value)

source code 
Prepare string values for db by escaping special characters.
Parameters:
  • value (string) - string containing possibly nasty characters
Returns: string
escaped string