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

Class EventManagerBase

source code

  Products.ZenModel.ZenModelRM.ZenModelRM --+
                                            |
Products.ZenUtils.ObjectCache.ObjectCache --+
                                            |
                               object --+   |
                                        |   |
                DbAccessBase.DbAccessBase --+
                                            |
                                           EventManagerBase

Data connector to backend of the event management system.

Instance Methods [hide private]
 
__init__(self, id, title='', hostname='localhost', username='root', password='', database='events', port=3306, defaultWhere='', defaultOrderby='', defaultResultFields=[])
Sets up event database access and initializes the cache.
source code
tuple
getEventResultFields(self, context)
A wrapper for lookupManagedEntityResultFields accepting an object with an event_key attribute.
source code
list
getEventListME(self, me, **kwargs)
Queries the database for events on a managed entity.
source code
list
getEventBatchME(self, me, selectstatus=None, resultFields=[], where="", orderby="", severity=None, state=2, startdate=None, enddate=None, offset=0, rows=0, getTotalCount=False, filter="", goodevids=[], badevids=[], **kwargs)
Returns a batch of events based on criteria from checked rows on the event console.
source code
 
restrictedUserFilter(self, where)
This is a hook do not delete me!
source code
list
getEventList(self, resultFields=None, where="", orderby="", severity=None, state=2, startdate=None, enddate=None, offset=0, rows=0, getTotalCount=False, filter="", **kwargs)
Fetch a list of events from the database matching certain criteria.
source code
list
getEventSummaryME(self, me, severity=1, state=1, prodState=None)
Return the CSS class, number of acknowledged events, and number of unacknowledged events, per severity, for a ManagedEntity.
source code
list
getEventSummary(self, where="", severity=1, state=1, prodState=None)
Return a list of tuples with number of events and the color of the severity that the number represents.
source code
 
getEventDetailFromStatusOrHistory(self, evid=None, dedupid=None, better=False) source code
EventDetail object
getEventDetail(self, evid=None, dedupid=None, better=False)
Return an EventDetail object for a particular event.
source code
 
getStatusME(self, me, statusclass=None, **kwargs) source code
 
getGenericStatus(self, me)
Return status based on a where clause defined for the me event_type.
source code
 
getOrganizerStatus(self, org, statusclass=None, severity=None, state=0, where="")
see IEventStatus
source code
 
getOrganizerStatusIssues(self, event_key, severity=4, state=0, where="", limit=0)
Return list of tuples (org, count) for all organizers with events.
source code
 
getDevicePingIssues(self, state=2, limit=0)
Return devices with ping problems.
source code
 
getWmiConnIssues(self, state=2, limit=0)
Return devices with WMI connection failures.
source code
 
getDeviceStatusIssues(self, severity=4, state=1, limit=0)
Return only status issues.
source code
 
getDeviceIssues(self, severity=1, state=0, where="", mincount=0, limit=0)
Return list of tuples (device, count, total) of events for all devices with events.
source code
 
getDeviceStatus(self, device, statclass=None, countField=None, severity=3, state=None, where="")
see IEventStatus
source code
 
defaultAvailabilityStart(self) source code
 
defaultAvailabilityEnd(self) source code
 
getAvailability(self, state, **kw) source code
 
getHeartbeat(self, failures=True, simple=False, limit=0, db=None)
Return all heartbeat issues list of tuples (device, component, secs)
source code
 
getHeartbeatObjects(self, failures=True, simple=False, limit=0, db=None) source code
 
getAllComponentStatus(self, statclass, countField=None, severity=3, state=1, where="")
Fetch the counts on all components matching statClass
source code
 
getMaxSeverity(self, me)
Returns the severity of the most severe event.
source code
 
getComponentStatus(self, device, component, statclass=None, countField=None, severity=3, state=1, where="")
see IEventStatus
source code
 
getBatchComponentInfo(self, components)
Given a list of dicts with keys 'device', 'component', make a query to get an overall severity and device status for the group.
source code
 
getEventOwnerListME(self, me, severity=0, state=1)
Return list of event owners based on passed in managed entity.
source code
 
getEventOwnerList(self, where="", severity=0, state=1)
Return a list of userids that correspond to the events in where.
source code
string
lookupManagedEntityWhere(self, me)
Lookup and build where clause for managed entity.
source code
object
lookupManagedEntityField(self, event_key)
Lookup database field for managed entity default using event_key.
source code
 
lookupManagedEntityResultFields(self, event_key)
Gets the column names that should be requested in an event query for this entity type.
source code
 
_wand(self, where, fmt, field, value) source code
 
_setupDateRange(self, startdate=None, enddate=None)
Make a start and end date range that is at least one day long.
source code
 
getAvgFieldLength(self, fieldname) source code
 
sendEvents(self, events)
Send a group of events to the backend.
source code
 
sendEvent(self, event)
Send an event to the backend.
source code
 
convert(self, field, value)
Perform convertion of value coming from database value if nessesary.
source code
 
getFieldList(self)
Return a list of all fields in the status table of the backend.
source code
 
getEventStates(self)
Return a list of possible event states.
source code
 
getEventActions(self)
Return a list of possible event actions.
source code
 
getSeverities(self)
Return a list of tuples of severities [('Warning', 3), ...]
source code
 
getSeverityString(self, severity)
Return a string representation of the severity.
source code
 
getPriorities(self)
Return a list of tuples of priorities [('Warning', 3), ...]
source code
 
getPriorityString(self, priority)
Return the priority name
source code
 
convertEventField(self, field, value, default="")
Convert numeric values commonly found in events to their textual representation.
source code
 
getStatusCssClass(self, status) source code
 
getStatusImgSrc(self, status)
Return the img source for a status number
source code
 
getEventCssClass(self, severity, acked=False)
return the css class name to be used for this event.
source code
 
isDate(self, colName)
Check to see if a column is of type date.
source code
 
dateString(self, value)
Convert a date from database format to string.
source code
 
dateDB(self, value)
Convert a date to its database format.
source code
 
escape(self, value)
Prepare string values for db by escaping special characters.
source code
 
loadSchema(self)
Load schema from database.
source code
 
eventControls(self)
Are there event controls on this event list.
source code
 
updateEvents(self, stmt, whereClause, reason, table="status", toLog=True) source code
 
manage_addEvent(self, REQUEST=None)
Create an event from user supplied data
source code
 
deleteEvents(self, whereClause, reason) source code
 
manage_deleteEvents(self, evids=(), REQUEST=None)
Delete the given event ids
source code
 
undeleteEvents(self, whereClause, reason) source code
 
manage_undeleteEvents(self, evids=(), REQUEST=None)
Move the given event ids into status and delete from history
source code
 
manage_deleteAllEvents(self, devname, REQUEST=None)
Delete the events for a given Device (used for deleting the device
source code
 
manage_deleteHistoricalEvents(self, devname=None, agedDays=None, REQUEST=None)
Delete historical events.
source code
 
manage_deleteHeartbeat(self, devname, REQUEST=None) source code
 
manage_ackEvents(self, evids=(), REQUEST=None)
Ack the given event ids
source code
 
manage_setEventStates(self, eventState=None, evids=(), userid="", REQUEST=None) source code
 
manage_createEventMap(self, eventClass=None, evids=(), REQUEST=None)
Create an event map from an event or list of events.
source code
 
manage_refreshConversions(self, REQUEST=None)
get the conversion information from the database server
source code
 
manage_editCache(self, timeout=5, clearthresh=20, REQUEST=None)
Reset cache values
source code
 
manage_clearCache(self, REQUEST=None)
Reset cache values
source code
 
manage_editEventManager(self, REQUEST=None)
Call zmanage_editProperties then take care of saving a few values to ZenEventHistory
source code
 
manage_clearHeartbeats(self, REQUEST=None)
truncate heartbeat table
source code
 
zmanage_editProperties(self, REQUEST=None)
Need to handle editing of history event fields differently
source code
 
manage_addLogMessage(self, evid=None, message='', REQUEST=None)
Add a log message to an event
source code
 
manage_addCommand(self, id, REQUEST=None)
Add a new EventCommand
source code
 
manage_deleteCommands(self, ids=[], REQUEST=None)
Delete an EventCommand
source code
 
installIntoPortal(self)
Install skins into portal.
source code

Inherited from DbAccessBase.DbAccessBase: cleanstring, close, connect

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  eventStateConversions = 'New', 0, ('Acknowledged', 1), ('Suppr...
  eventActions = 'status', 'history', 'drop'
  severityConversions = 'Critical', 5, ('Error', 4), ('Warning',...
  severities = dict([(b, a) for a, b in severityConversions])
  priorityConversions = 'None',-1, ('Emergency', 0), ('Alert', 1...
  priorities = dict([(b, a) for a, b in priorityConversions])
  statusTable = "status"
  detailTable = "detail"
  logTable = "log"
  lastTimeField = "lastTime"
  firstTimeField = "firstTime"
  deviceField = "device"
  componentField = "component"
  eventClassField = "eventClass"
  severityField = "severity"
  stateField = "eventState"
  countField = "count"
  prodStateField = "prodState"
  DeviceGroupField = "DeviceGroups"
  SystemField = "Systems"
  DeviceWhere = "\"device = '%s'\" % me.getDmdKey()"
  DeviceResultFields = "component", "eventClass", "summary", "fi...
  ComponentWhere = "\"(device = '%s' and component = '%s')\"" " ...
  ComponentResultFields = "eventClass", "summary", "firstTime", ...
  IpAddressWhere = "\"ipAddress='%s'\" % (me.getId())"
  EventClassWhere = "\"eventClass like '%s%%'\" % me.getDmdKey()"
  EventClassInstWhere = """\"eventClass = '%s' and eventClassKey...
  DeviceClassWhere = "\"DeviceClass like '%s%%'\" % me.getDmdKey()"
  LocationWhere = "\"Location like '%s%%'\" % me.getDmdKey()"
  SystemWhere = "\"Systems like '%%|%s%%'\" % me.getDmdKey()"
  DeviceGroupWhere = "\"DeviceGroups like '%%|%s%%'\" % me.getDm...
  defaultResultFields = "device", "component", "eventClass", "su...
  defaultFields = 'eventState', 'severity', 'evid'
  defaultEventId = 'device', 'component', 'eventClass', 'eventKe...
  requiredEventFields = 'device', 'summary', 'severity'
  refreshConversionsForm = DTMLFile('dtml/refreshNcoProduct', gl...
  defaultAvailabilityDays = 7
  defaultPriority = 3
  eventAgingHours = 4
  eventAgingSeverity = 4
  historyMaxAgeDays = 0
  _properties = {'id': 'backend', 'type': 'string', 'mode': 'r',...
  _relations = "commands", ToManyCont(ToOne, "Products.ZenEvents...
  factory_type_information = {'immediate_view': 'editEventManage...
  security = ClassSecurityInfo()

Inherited from DbAccessBase.DbAccessBase (private): _v_cpool

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, id, title='', hostname='localhost', username='root', password='', database='events', port=3306, defaultWhere='', defaultOrderby='', defaultResultFields=[])
(Constructor)

source code 
Sets up event database access and initializes the cache.
Parameters:
  • id (string) - A unique id
  • title (string) - A title
  • hostname (string) - The hostname of the events database server
  • username (string) - The name of a user with permissions to access the events database
  • password (string) - The password of the user
  • database (string) - The name of the events database
  • port (int) - The port on which the database server is listening
  • defaultWhere (string) - The default where clause to use when building queries
  • defaultOrderby (string) - The default order by clause to use when building queries
  • defaultResultFields (list) - DEPRECATED. Currently unused.
Overrides: object.__init__

getEventResultFields(self, context)

source code 
A wrapper for lookupManagedEntityResultFields accepting an object with an event_key attribute.
>>> class dummy(object):
...     event_key = 'Device'
...
>>> d = dummy()
>>> f = dmd.ZenEventManager.getEventResultFields(d)
>>> f==dmd.ZenEventManager.DeviceResultFields
True
>>> d.event_key = 'Robot'
>>> f = dmd.ZenEventManager.getEventResultFields(d)
>>> f==dmd.ZenEventManager.defaultResultFields
True
Parameters:
  • context (ManagedEntity) - An object with an event_key attribute.
Returns: tuple
A sequence of strings representing columns in the database.

getEventListME(self, me, **kwargs)

source code 
Queries the database for events on a managed entity.
Parameters:
Returns: list
ZEvent objects

getEventBatchME(self, me, selectstatus=None, resultFields=[], where="", orderby="", severity=None, state=2, startdate=None, enddate=None, offset=0, rows=0, getTotalCount=False, filter="", goodevids=[], badevids=[], **kwargs)

source code 

Returns a batch of events based on criteria from checked rows on the event console.

The event console can show thousands of events, and we want to support a "Select All" feature; enter this method. It builds a query based on the select status from the console ("All", "None", "Acknowledged", "Unacknowledged") and any checkboxes that have been modified manually.
Parameters:
  • me (ManagedEntity) - The managed entity for which to query events.
  • resultFields (list) - The columns to return from the database.
  • where (string) - The base where clause to modify.
  • orderby (string) - The "ORDER BY" string governing sort order.
  • severity (int) - The minimum severity for which to query.
  • state (int) - The minimum state for which to query.
  • startdate (string, DateTime) - The early date limit
  • enddate (string, DateTime) - The late date limit
  • offset (int) - The row at which to begin returning
  • rows (int) - DEPRECATED The number of rows to return (ignored).
  • getTotalCount (bool) - Whether or not to return a count of the total number of rows
  • filter (string) - A glob by which to filter events
  • goodevids (list) - Ids of events that specifically should be included
  • badevids (list) - Ids of events that specifically should not be included
Returns: list
Ids of matching events

To Do: Remove unused parameters from the method definition

getEventList(self, resultFields=None, where="", orderby="", severity=None, state=2, startdate=None, enddate=None, offset=0, rows=0, getTotalCount=False, filter="", **kwargs)

source code 
Fetch a list of events from the database matching certain criteria.
Parameters:
  • resultFields (list) - The columns to return from the database.
  • where (string) - The base where clause to modify.
  • orderby (string) - The "ORDER BY" string governing sort order.
  • severity (int) - The minimum severity for which to query.
  • state (int) - The minimum state for which to query.
  • startdate (string, DateTime) - The early date limit
  • enddate (string, DateTime) - The late date limit
  • offset (int) - The row at which to begin returning
  • rows (int) - The number of rows to return.
  • getTotalCount (bool) - Whether or not to return a count of the total number of rows
  • filter (string) - A glob by which to filter events
Returns: list
Matching events as ZEvents.

To Do: Remove unused parameters from the method definition

getEventSummaryME(self, me, severity=1, state=1, prodState=None)

source code 
Return the CSS class, number of acknowledged events, and number of unacknowledged events, per severity, for a ManagedEntity.
Parameters:
  • me (ManagedEntity) - The object of the inquiry.
  • severity (int) - The minimum severity for which to retrieve events
  • state (int) - The minimum state for which to retrieve events
  • prodState (int) - The minimum production state for which to retrieve events
Returns: list
List of lists of the form [class, acked count, unacked count].

getEventSummary(self, where="", severity=1, state=1, prodState=None)

source code 

Return a list of tuples with number of events and the color of the severity that the number represents.

This method should not be called directly, but overridden by subclasses.
Parameters:
  • where (string) - The base where clause to modify.
  • severity (int) - The minimum severity for which to retrieve events
  • state (int) - The minimum state for which to retrieve events
  • prodState (int) - The minimum production state for which to retrieve events
Returns: list
List of lists of the form [class, acked count, unacked count].

getEventDetail(self, evid=None, dedupid=None, better=False)

source code 
Return an EventDetail object for a particular event.
Parameters:
  • evid (string) - Event ID
  • dedupid (string) - string used to determine duplicates
  • better (boolean) - provide even more detail than normal?
Returns: EventDetail object
fields from the event

getGenericStatus(self, me)

source code 
Return status based on a where clause defined for the me event_type. No fancy caching done this might be a little slow if there are a lot of events. Where clause is evaled

getEventOwnerList(self, where="", severity=0, state=1)

source code 
Return a list of userids that correspond to the events in where. select distinct ownerid from status where device="win2k.confmon.loc" and eventState > 2

lookupManagedEntityWhere(self, me)

source code 
Lookup and build where clause for managed entity.
Parameters:
  • me (object) - managed entity
Returns: string
where clause

lookupManagedEntityField(self, event_key)

source code 
Lookup database field for managed entity default using event_key.
Parameters:
  • event_key (string) - event
Returns: object
field for the managed entity

lookupManagedEntityResultFields(self, event_key)

source code 

Gets the column names that should be requested in an event query for this entity type.

Returns a set of result fields predefined for this entity type. If none have been defined, returns the default result fields.
>>> f = dmd.ZenEventManager.lookupManagedEntityResultFields('Device')
>>> f==dmd.ZenEventManager.DeviceResultFields
True
>>> f = dmd.ZenEventManager.lookupManagedEntityResultFields('Robot')
>>> f==dmd.ZenEventManager.defaultResultFields
True
Parameters:
  • event_key (string) - The event key of a managed entity.
Returns:
A tuple of strings representing columns in the database.

_setupDateRange(self, startdate=None, enddate=None)

source code 
Make a start and end date range that is at least one day long. returns a start and end date as a proper database element.

sendEvent(self, event)

source code 
Send an event to the backend.
Parameters:
  • event (event object) - event

To Do: implement

escape(self, value)

source code 
Prepare string values for db by escaping special characters.
Parameters:
  • value (string) - string

To Do: implement

loadSchema(self)

source code 
Load schema from database. If field is a date set value to true.

manage_deleteHistoricalEvents(self, devname=None, agedDays=None, REQUEST=None)

source code 

Delete historical events. If devices is given then only delete events for that device. If agedDays is given then only delete events that are older than that many days. devname and agedDays are mutually exclusive. No real reason for this other than there is no current need to use both in same call and I don't want to test the combination. This is an option during device deletion. It is also used by zenactions to keep history table clean.

NB: Device.deleteDevice() is not currently calling this when devices are deleted. See ticket #2996.

manage_addCommand(self, id, REQUEST=None)

source code 
Add a new EventCommand
Parameters:
  • id (string) - new command name
  • REQUEST (Zope REQUEST object) - Zope REQUEST object

manage_deleteCommands(self, ids=[], REQUEST=None)

source code 
Delete an EventCommand
Parameters:
  • ids (list of strings) - commands to delete
  • REQUEST (Zope REQUEST object) - Zope REQUEST object

Class Variable Details [hide private]

eventStateConversions

Value:
'New', 0, ('Acknowledged', 1), ('Suppressed', 2),

severityConversions

Value:
'Critical', 5, ('Error', 4), ('Warning', 3), ('Info', 2), ('Debug', 1)\
, ('Clear', 0),

priorityConversions

Value:
'None',-1, ('Emergency', 0), ('Alert', 1), ('Critical', 2), ('Error', \
3), ('Warning', 4), ('Notice', 6), ('Info', 8), ('Debug', 10),

DeviceResultFields

Value:
"component", "eventClass", "summary", "firstTime", "lastTime", "count"

ComponentWhere

Value:
"\"(device = '%s' and component = '%s')\"" " % (me.device().getDmdKey(\
), me.name())"

ComponentResultFields

Value:
"eventClass", "summary", "firstTime", "lastTime", "count"

EventClassInstWhere

Value:
"""\"eventClass = '%s' and eventClassKey = '%s'\" % (\
                                me.getEventClass(), me.eventClassKey)"\
""

DeviceGroupWhere

Value:
"\"DeviceGroups like '%%|%s%%'\" % me.getDmdKey()"

defaultResultFields

Value:
"device", "component", "eventClass", "summary", "firstTime", "lastTime\
", "count"

defaultEventId

Value:
'device', 'component', 'eventClass', 'eventKey', 'severity'

refreshConversionsForm

Value:
DTMLFile('dtml/refreshNcoProduct', globals())

_properties

Value:
{'id': 'backend', 'type': 'string', 'mode': 'r',}, {'id': 'username', \
'type': 'string', 'mode': 'w'}, {'id': 'password', 'type': 'string', '\
mode': 'w'}, {'id': 'host', 'type': 'string', 'mode': 'w'}, {'id': 'da\
tabase', 'type': 'string', 'mode': 'w'}, {'id': 'port', 'type': 'int',\
 'mode': 'w'}, {'id': 'defaultWhere', 'type': 'text', 'mode': 'w'}, {'\
id': 'defaultOrderby', 'type': 'text', 'mode': 'w'}, {'id': 'defaultRe\
sultFields', 'type': 'lines', 'mode': 'w'}, {'id': 'statusTable', 'typ\
e': 'string', 'mode': 'w'}, {'id': 'detailTable', 'type': 'string', 'm\
...

_relations

Value:
"commands", ToManyCont(ToOne, "Products.ZenEvents.EventCommand", "even\
tManager"),

factory_type_information

Value:
{'immediate_view': 'editEventManager', 'actions':({'id': 'edit', 'name\
': 'Edit', 'action': 'editEventManager', 'permissions':("Manage DMD",)\
}, {'id': 'edit', 'name': 'Fields', 'action': 'editEventManagerFields'\
, 'permissions':("Manage DMD",)}, {'id': 'history_edit', 'name': 'Hist\
ory Fields', 'action': 'editEventManagerHistoryFields', 'permissions':\
("Manage DMD",)}, {'id': 'commands', 'name': 'Commands', 'action': 'li\
stEventCommands', 'permissions':("Manage DMD",)}, {'id': 'changes', 'n\
ame': 'Modifications', 'action': 'viewHistory', 'permissions':(ZEN_VIE\
...