You can subscribe to this list here.
2007 |
Jan
|
Feb
(65) |
Mar
(276) |
Apr
(544) |
May
(638) |
Jun
(225) |
Jul
(204) |
Aug
(294) |
Sep
(532) |
Oct
(506) |
Nov
(324) |
Dec
(359) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(208) |
Feb
(225) |
Mar
(248) |
Apr
(388) |
May
(222) |
Jun
(47) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <sv...@ze...> - 2007-02-23 20:54:52
|
Author: jstevens Date: 2007-02-23 14:54:50 -0600 (Fri, 23 Feb 2007) New Revision: 4120 Modified: trunk/Products/ZenEvents/zenactions.py trunk/Products/ZenModel/DataRoot.py trunk/Products/ZenModel/UserSettings.py trunk/Products/ZenModel/skins/zenmodel/editSettings.pt Log: fixes #855 * From Address for emails now attribute of dmd and not in zenactions.conf Modified: trunk/Products/ZenEvents/zenactions.py =================================================================== --- trunk/Products/ZenEvents/zenactions.py 2007-02-23 19:43:01 UTC (rev 4119) +++ trunk/Products/ZenEvents/zenactions.py 2007-02-23 20:54:50 UTC (rev 4120) @@ -129,8 +129,6 @@ self.schedule = Schedule(self.options, self.dmd) self.actions = [] self.loadActionRules() - if not self.options.fromaddr: - self.options.fromaddr = "zenoss@%s" % socket.getfqdn() self.updateCheck = UpdateCheck() self.sendEvent(Event.Event(device=socket.getfqdn(), eventClass=App_Start, @@ -368,7 +366,6 @@ self.maintenance(zem) self.heartbeatEvents() - def runCycle(self): try: start = time.time() @@ -472,7 +469,7 @@ emsgAlternative.attach(plaintext) emsgAlternative.attach(html) emsg['Subject'] = fmt - emsg['From'] = self.options.fromaddr + emsg['From'] = self.dmd.getEmailFrom() emsg['To'] = addr emsg['Date'] = DateTime().rfc822() result, errorMsg = Utils.sendEmail(emsg, self.dmd.smtpHost, @@ -491,9 +488,6 @@ self.parser.add_option('--cycletime', dest='cycletime', default=60, type="int", help="check events every cycletime seconds") - self.parser.add_option('--fromaddr', - dest='fromaddr', default="", - help="address from which email is sent") self.parser.add_option( '--zopeurl', dest='zopeurl', default='http://%s:%d' % (socket.getfqdn(), 8080), Modified: trunk/Products/ZenModel/DataRoot.py =================================================================== --- trunk/Products/ZenModel/DataRoot.py 2007-02-23 19:43:01 UTC (rev 4119) +++ trunk/Products/ZenModel/DataRoot.py 2007-02-23 20:54:50 UTC (rev 4120) @@ -14,6 +14,7 @@ import re from AccessControl import ClassSecurityInfo +from AccessControl import getSecurityManager from OFS.OrderedFolder import OrderedFolder from OFS.CopySupport import CopyError, eNotSupported from ImageFile import ImageFile @@ -28,6 +29,7 @@ from Products.ZenRelations.RelSchema import * from Commandable import Commandable import DateTime +import socket from AccessControl import Permissions as permissions @@ -67,6 +69,7 @@ smtpUser = '' smtpPass = '' smtpUseTLS = 0 + emailFrom = '' _properties=( {'id':'title', 'type': 'string', 'mode':'w'}, @@ -90,6 +93,7 @@ {'id':'smtpUser', 'type': 'string', 'mode':'w'}, {'id':'smtpPass', 'type': 'string', 'mode':'w'}, {'id':'smtpUseTLS', 'type': 'int', 'mode':'w'}, + {'id':'emailFrom', 'type': 'string', 'mode':'w'}, ) _relations = ( @@ -404,5 +408,10 @@ ''' raise 'Not supported on DataRoot' - + def getEmailFrom(self): + ''' Return self.emailFrom or a suitable default + ''' + return self.emailFrom or 'zenossuser_%s@%s' % ( + getSecurityManager().getUser().getId(), socket.getfqdn()) + InitializeClass(DataRoot) Modified: trunk/Products/ZenModel/UserSettings.py =================================================================== --- trunk/Products/ZenModel/UserSettings.py 2007-02-23 19:43:01 UTC (rev 4119) +++ trunk/Products/ZenModel/UserSettings.py 2007-02-23 20:54:50 UTC (rev 4120) @@ -573,7 +573,7 @@ thisUser = self.getUser() srcId = thisUser.getId() srcSettings = self.getUserSettings(srcId) - srcAddress = srcSettings.email or 'zenossuser_%s@%s' % (srcId, fqdn) + srcAddress = self.dmd.getEmailFrom() # Read body from file probably body = ('This is a test message sent by %s' % srcId + ' from the Zenoss installation on %s.' % fqdn) Modified: trunk/Products/ZenModel/skins/zenmodel/editSettings.pt =================================================================== --- trunk/Products/ZenModel/skins/zenmodel/editSettings.pt 2007-02-23 19:43:01 UTC (rev 4119) +++ trunk/Products/ZenModel/skins/zenmodel/editSettings.pt 2007-02-23 20:54:50 UTC (rev 4120) @@ -40,6 +40,13 @@ </td> </tr> <tr> + <td class="tableheader" align="left">From Address for Emails</td> + <td class="tablevalues"> + <input class="tablevalues" type="text" name="emailFrom" + tal:attributes="value here/emailFrom|string:" /> + </td> + </tr> + <tr> <td class="tableheader" align="left">Use TLS?</td> <td class="tablevalues"> <input type="hidden" name="smtpUseTLS:int:default" value="0"> |
From: <sv...@ze...> - 2007-02-23 19:43:04
|
Author: marc Date: 2007-02-23 13:43:01 -0600 (Fri, 23 Feb 2007) New Revision: 4119 Modified: trunk/Products/ZenRelations/RelationshipBase.py Log: #1000 * fixed remoteClass() when importing a class from a different module * also see r4110 Modified: trunk/Products/ZenRelations/RelationshipBase.py =================================================================== --- trunk/Products/ZenRelations/RelationshipBase.py 2007-02-23 18:34:23 UTC (rev 4118) +++ trunk/Products/ZenRelations/RelationshipBase.py 2007-02-23 19:43:01 UTC (rev 4119) @@ -104,7 +104,10 @@ if not classdef: schema = self.__primary_parent__.lookupSchema(self.id) baseModule = getattr(self, "zenRelationsBaseModule", "") - classdef = importClass(schema.remoteClass, baseModule) + try: + classdef = importClass(schema.remoteClass, baseModule) + except ZenImportError: + classdef = importClass(schema.remoteClass) self._v_remoteClass = classdef return classdef |
From: <sv...@ze...> - 2007-02-23 18:34:55
|
Author: marc Date: 2007-02-23 12:34:23 -0600 (Fri, 23 Feb 2007) New Revision: 4118 Modified: trunk/Products/ZenEvents/ActionRule.py trunk/Products/ZenEvents/Availability.py trunk/Products/ZenEvents/DbAccessBase.py trunk/Products/ZenEvents/DbConnectionPool.py trunk/Products/ZenEvents/EventCommand.py trunk/Products/ZenEvents/EventManagerBase.py trunk/Products/ZenEvents/MySqlEventManager.py trunk/Products/ZenEvents/MySqlSendEvent.py trunk/Products/ZenEvents/tests/testMySqlEventManager.py trunk/Products/ZenEvents/tests/testMySqlSendEvent.py trunk/Products/ZenEvents/zenactions.py trunk/Products/ZenModel/Device.py trunk/Products/ZenModel/PerformanceConf.py trunk/Products/ZenModel/migrate/clearid.py trunk/Products/ZenModel/migrate/command.py trunk/Products/ZenModel/migrate/devicepriority.py trunk/Products/ZenModel/migrate/eventclassmapping.py trunk/Products/ZenModel/migrate/innodb.py trunk/Products/ZenModel/migrate/reindex_history.py trunk/Products/ZenReports/plugins/threshold.py Log: #996 * Changed DbAccessBase to handle more than one connection at a time. Modified: trunk/Products/ZenEvents/ActionRule.py =================================================================== --- trunk/Products/ZenEvents/ActionRule.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/ActionRule.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -197,12 +197,12 @@ """ try: zem = self.dmd.ZenEventManager - zem.connect() + conn = zem.connect() delcmd = "delete from alert_state where %s" % self.sqlwhere() log.debug("clear alert state '%s'", delcmd) - curs = zem.cursor() + curs = conn.cursor() curs.execute(delcmd) - finally: zem.close() + finally: zem.close(conn) def sqlwhere(self): """Return sql where to select alert_state data for this event. Modified: trunk/Products/ZenEvents/Availability.py =================================================================== --- trunk/Products/ZenEvents/Availability.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/Availability.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -120,8 +120,8 @@ devices = {} try: - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute(s) while 1: rows = curs.fetchmany() @@ -135,7 +135,7 @@ devices[k] += last - first except KeyError: devices[k] = last - first - finally: zem.close() + finally: zem.close(conn) total = endDate - startDate if self.device: deviceList = [dmd.Devices.findDevice(self.device)] Modified: trunk/Products/ZenEvents/DbAccessBase.py =================================================================== --- trunk/Products/ZenEvents/DbAccessBase.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/DbAccessBase.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -5,39 +5,22 @@ class DbAccessBase(object): _cpool = DbConnectionPool() - _currConn = None def __init__(self): - try: - self.connect() # Create a connection (and Pool) - finally: self.close() # Return the connection - - def conn(self): - if not self._currConn: - #self.connect() - raise Exception, "Stray conn() or cursor() call: Call connect() before and close() after" - return self._currConn - - def cursor(self): - return self.conn().cursor() + self.close(self.connect()) # Create and return a connection - def close(self): - if self._currConn: - self._cpool.put(self._currConn) - self._currConn = None + def close(self, conn): + self._cpool.put(conn) def connect(self): """Load our database driver and connect to the database.""" - if self._currConn: - raise Exception, "A connection has already been retrieved, call close() when finished." - else: - self._currConn = self._cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - + return self._cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) + def cleanstring(self, value): """Remove the trailing \x00 off the end of a string.""" if type(value) in types.StringTypes: Modified: trunk/Products/ZenEvents/DbConnectionPool.py =================================================================== --- trunk/Products/ZenEvents/DbConnectionPool.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/DbConnectionPool.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -7,16 +7,27 @@ from Queue import Queue, Empty, Full +import logging +log = logging.getLogger("zen.DbConnectionPool") + POOL_SIZE = 5 KEEP_ALIVE = 28800 class DbConnectionPool(Queue): + def __new__(type): + if not '_the_instance' in type.__dict__: + type._the_instance = object.__new__(type) + return type._the_instance + + ''' instance = None def __new__(cls, *args, **kargs): if cls.instance is None: cls.instance = object.__new__(cls, *args, **kargs) + log.debug('Returning single instance of DbConnectionPool') return cls.instance + ''' def __init__(self): Queue.__init__(self, POOL_SIZE) @@ -26,13 +37,15 @@ try: putstamp,obj = Queue.get(self, block) - if time.time() - putstamp >= KEEP_ALIVE: + if time.time() - putstamp >= KEEP_ALIVE: + log.debug('Retrieved a stale connection; Pool size: %s' % self.qsize()) obj.close() return self._createConnection(host=host, port=port, username=username, password=password, database=database) - else: + else: + log.debug('Retrieved a connection; Pool size: %s' % self.qsize()) return obj except Empty: @@ -44,11 +57,13 @@ def put(self, obj, block=0): try: Queue.put(self, (time.time(),obj), block) + log.debug('Returned a connection; Pool size: %s' % self.qsize()) except Full: pass def _createConnection(self, host=None, port=None, username=None, password=None, database=None): + log.debug('Creating a new connection; Pool size: %s' % self.qsize()) conn = None """ if self.backend == "omnibus": Modified: trunk/Products/ZenEvents/EventCommand.py =================================================================== --- trunk/Products/ZenEvents/EventCommand.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/EventCommand.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -77,11 +77,11 @@ """ try: zem = self.dmd.ZenEventManager - zem.connect() + conn = zem.connect() delcmd = "delete from alert_state where %s" % self.sqlwhere() curs = self.dmd.ZenEventManager.cursor() curs.execute(delcmd) - finally: zem.close() + finally: zem.close(conn) security.declareProtected('Manage EventManager', 'manage_editEventCommand') Modified: trunk/Products/ZenEvents/EventManagerBase.py =================================================================== --- trunk/Products/ZenEvents/EventManagerBase.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/EventManagerBase.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -299,8 +299,8 @@ retdata = self.checkCache(select) if not retdata: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(select) retdata = [] # iterate through the data results and convert to python @@ -309,7 +309,7 @@ row = map(self.convert, resultFields, row) evt = ZEvent(self, resultFields, row) retdata.append(evt) - finally: self.close() + finally: self.close(conn) self.addToCache(select, retdata) self.cleanCache() return retdata @@ -364,8 +364,8 @@ selectevent += " %s = '%s'" % (idfield, evid) if self.backend=="omnibus": selectevent += ";" try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() #print selectevent curs.execute(selectevent) evrow = curs.fetchone() @@ -399,7 +399,7 @@ text = row[2] logs.append((user, date, text)) event._logs = logs - finally: self.close() + finally: self.close(conn) self.addToCache(cachekey, event) self.cleanCache() @@ -431,12 +431,12 @@ statusCount = self.checkCache(select) if not statusCount: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() #print select curs.execute(select) statusCount = curs.fetchone()[0] - finally: self.close() + finally: self.close(conn) self.addToCache(select,statusCount) return statusCount @@ -456,8 +456,8 @@ statusCache = self.checkCache(select) if not statusCache: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(select) statusCache=[] orgdict={} @@ -470,7 +470,7 @@ orgdict[orgname] += 1 statusCache = orgdict.items() self.addToCache(select,statusCache) - finally: self.close() + finally: self.close(conn) countevts = 0 for key, value in statusCache: if key.startswith(org.getOrganizerName()): @@ -491,8 +491,8 @@ statusCache = self.checkCache(select) if not statusCache: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(select) statusCache=[] orgdict={} @@ -512,7 +512,7 @@ if limit: statusCache = statusCache[:limit] self.addToCache(select,statusCache) - finally: self.close() + finally: self.close(conn) return statusCache @@ -553,8 +553,8 @@ if not statusCache: try: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(select) statusCache = [ [d,int(c),int(s)] for d,c,s in curs.fetchall() ] #statusCache = list(curs.fetchall()) @@ -562,7 +562,7 @@ statusCache.reverse() if limit: statusCache = statusCache[:limit] - finally: self.close() + finally: self.close(conn) except: log.exception(select) raise @@ -585,15 +585,15 @@ if not statusCache: try: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(select) statusCache = {} for dev, count in curs.fetchall(): dev = self.cleanstring(dev) statusCache[dev] = count self.addToCache(select,statusCache) - finally: self.close() + finally: self.close(conn) except: log.exception("status failed for device %s", device) return -1 @@ -638,8 +638,8 @@ if not statusCache: statusCache = [] try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(sel) res = list(curs.fetchall()) res.sort(lambda x,y: cmp(x[2],y[2])) @@ -655,7 +655,7 @@ if limit: statusCache = statusCache[:limit] cleanup() - finally: self.close() + finally: self.close(conn) return statusCache @@ -674,8 +674,8 @@ statusCache = self.checkCache(select) if not statusCache: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(select) statusCache ={} for dev, comp, count in curs.fetchall(): @@ -683,7 +683,7 @@ comp = self.cleanstring(comp) statusCache[dev+comp] = count self.addToCache(select,statusCache) - finally: self.close() + finally: self.close(conn) return statusCache.get(device+component, 0) @@ -711,12 +711,12 @@ statusCache = self.checkCache(select) if statusCache: return statusCache try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(select) statusCache = [ uid[0] for uid in curs.fetchall() if uid[0] ] self.addToCache(select,statusCache) - finally: self.close() + finally: self.close(conn) return statusCache @@ -986,8 +986,8 @@ fieldlist = [] sql = "describe %s;" % self.statusTable try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(sql) for row in curs.fetchall(): fieldlist.append(row[0]) @@ -999,7 +999,7 @@ schema[col] = type if schema: self._schema = schema self._fieldlist = fieldlist - finally: self.close() + finally: self.close(conn) def eventControls(self): @@ -1017,11 +1017,11 @@ 'FROM %s ' % table + whereClause query = stmt + ' ' + whereClause try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() if toLog: curs.execute(insert) curs.execute(query) - finally: self.close() + finally: self.close(conn) self.clearCache() self.manage_clearCache() @@ -1089,10 +1089,10 @@ if devname: delete = "delete from heartbeat where device = '%s'" % devname try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(delete); - finally: self.close() + finally: self.close(conn) if REQUEST: return self.callZenScreen(REQUEST) @@ -1136,8 +1136,8 @@ from %s where evid in ('%s')""" sel = sel % (self.statusTable, "','".join(evids)) try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() curs.execute(sel); for row in curs.fetchall(): evclasskey, curevclass, msg = row @@ -1145,7 +1145,7 @@ evmap = evclass.createInstance(evclasskey) evmap.eventClassKey = evclasskey evmap.example = msg - finally: self.close() + finally: self.close(conn) if REQUEST: if len(evids) == 1 and evmap: return evmap() elif evclass and evmap: return evclass() @@ -1157,10 +1157,10 @@ assert(self == self.dmd.ZenEventManager) self.loadSchema() try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() self.dmd.ZenEventHistory.loadSchema(self.conn()) - finally: self.close() + finally: self.close(conn) if REQUEST: return self.callZenScreen(REQUEST) @@ -1204,11 +1204,11 @@ def manage_clearHeartbeats(self, REQUEST=None): """truncate heartbeat table""" try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() sql = 'truncate table heartbeat' curs.execute(sql) - finally: self.close() + finally: self.close(conn) if REQUEST: return self.callZenScreen(REQUEST) security.declareProtected('Manage EventManager','zmanage_editProperties') @@ -1230,14 +1230,14 @@ return userId = getSecurityManager().getUser().getId() try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() insert = 'INSERT INTO log (evid, userName, text) ' insert += 'VALUES ("%s", "%s", "%s")' % (evid, userId, self.conn().escape_string(message)) curs.execute(insert) - finally: self.close() + finally: self.close(conn) self.clearCache('evid' + evid) if REQUEST: return self.callZenScreen(REQUEST) Modified: trunk/Products/ZenEvents/MySqlEventManager.py =================================================================== --- trunk/Products/ZenEvents/MySqlEventManager.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/MySqlEventManager.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -67,8 +67,8 @@ if sevsum: return sevsum zem = self.dmd.ZenEventManager try: - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute(select) sumdata = {} ownerids = "" @@ -86,7 +86,7 @@ css = self.getEventCssClass(value) ackcount, count = sumdata.get(value, [0,0]) sevsum.append([css, ackcount, int(count)]) - finally: zem.close() + finally: zem.close(conn) self.addToCache(select, sevsum) self.cleanCache() @@ -99,8 +99,8 @@ count = 0 zem = self.dmd.ZenEventManager try: - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() for table in ('status', 'history'): sql = 'select count(*) from status ' \ 'where firstTime >= %s' % since @@ -110,7 +110,7 @@ 'where firstTime >= %s' % since curs.execute(sql) count += curs.fetchall()[0][0] - finally: zem.close() + finally: zem.close(conn) return count InitializeClass(MySqlEventManager) Modified: trunk/Products/ZenEvents/MySqlSendEvent.py =================================================================== --- trunk/Products/ZenEvents/MySqlSendEvent.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/MySqlSendEvent.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -96,8 +96,8 @@ insert = "" statusdata, detaildata = self.eventDataMaps(event) try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() evid = guid.generate() event.evid = evid if event.severity == 0: @@ -125,7 +125,7 @@ evid = None delete = 'DELETE FROM status WHERE clearid IS NOT NULL' execute(curs, delete) - finally: self.close() + finally: self.close(conn) return evid @@ -203,10 +203,10 @@ insert += ", timeout=%s" % evdict['timeout'] try: try: - self.connect() - curs = self.cursor() + conn = self.connect() + curs = conn.cursor() execute(curs, insert) - finally: self.close() + finally: self.close(conn) except ProgrammingError, e: log.error(insert) log.exception(e) Modified: trunk/Products/ZenEvents/tests/testMySqlEventManager.py =================================================================== --- trunk/Products/ZenEvents/tests/testMySqlEventManager.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/tests/testMySqlEventManager.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -31,13 +31,13 @@ transaction.abort() try: zem = self.dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute("truncate status") curs.execute("truncate detail") curs.execute("truncate log") curs.execute("truncate history") - finally: zem.close() + finally: zem.close(conn) zodb.closedb() self.dmd = None self.zem = None Modified: trunk/Products/ZenEvents/tests/testMySqlSendEvent.py =================================================================== --- trunk/Products/ZenEvents/tests/testMySqlSendEvent.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/tests/testMySqlSendEvent.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -22,10 +22,10 @@ transaction.abort() try: zem = self.dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() zem.curs.execute("truncate status") - finally: zem.close() + finally: zem.close(conn) zodb.closedb() self.zem = None Modified: trunk/Products/ZenEvents/zenactions.py =================================================================== --- trunk/Products/ZenEvents/zenactions.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenEvents/zenactions.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -156,10 +156,10 @@ self.log.debug(stmt) zem = self.dmd.ZenEventManager try: - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() result = curs.execute(stmt) - finally: zem.close() + finally: zem.close(conn) return result @@ -169,11 +169,11 @@ self.log.debug(stmt) zem = self.dmd.ZenEventManager try: - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute(stmt) result = curs.fetchall() - finally: zem.close() + finally: zem.close(conn) return result Modified: trunk/Products/ZenModel/Device.py =================================================================== --- trunk/Products/ZenModel/Device.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/Device.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -908,11 +908,11 @@ try: zem = self.dmd.ZenEventManager try: - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute("update status set prodState=%d where device='%s'" % ( self.productionState, self.id)) - finally: zem.close() + finally: zem.close(conn) except OperationalError: log.exception("failed to update events with new prodState") @@ -924,11 +924,11 @@ try: zem = self.dmd.ZenEventManager try: - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute("update status set DevicePriority=%d where device='%s'" % ( self.priority, self.id)) - finally: zem.close() + finally: zem.close(conn) except OperationalError: log.exception("failed to update events with new priority") Modified: trunk/Products/ZenModel/PerformanceConf.py =================================================================== --- trunk/Products/ZenModel/PerformanceConf.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/PerformanceConf.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -148,8 +148,8 @@ # get all the events with /Status/Snmp try: zem = self.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() cmd = ('SELECT device, sum(count) ' + ' FROM status ' + ' WHERE eventClass = "%s"' % Status_Snmp) @@ -158,7 +158,7 @@ cmd += ' GROUP BY device' curs.execute(cmd); counts = dict([(d, c) for d, c in curs.fetchall()]) - finally: zem.close() + finally: zem.close(conn) except Exception, ex: log.exception('Unable to get Snmp Status') raise Modified: trunk/Products/ZenModel/migrate/clearid.py =================================================================== --- trunk/Products/ZenModel/migrate/clearid.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/migrate/clearid.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -66,14 +66,14 @@ def cutover(self, dmd): try: zem = self.dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() cmd = 'ALTER TABLE %s ADD COLUMN (clearid char(25))' self.execute(curs, cmd % 'status') self.execute(curs, cmd % 'history') self.execute(curs, 'DROP TRIGGER status_delete') self.execute(curs, trigger) - finally: zem.close() + finally: zem.close(conn) ClearId() Modified: trunk/Products/ZenModel/migrate/command.py =================================================================== --- trunk/Products/ZenModel/migrate/command.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/migrate/command.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -24,10 +24,10 @@ dmd.Devices._delProperty("zNagiosCycleTime") try: zem = self.dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() for name in 'zenagios', 'zencacti': curs.execute('DELETE FROM heartbeat where component = "%s"' % name) - finally: zem.close() + finally: zem.close(conn) Commands() Modified: trunk/Products/ZenModel/migrate/devicepriority.py =================================================================== --- trunk/Products/ZenModel/migrate/devicepriority.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/migrate/devicepriority.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -63,8 +63,8 @@ def cutover(self, dmd): try: zem = self.dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() cmd = 'ALTER TABLE %s ADD COLUMN ' + \ '(DevicePriority smallint(6) default 3)' for table in ('status', 'history'): @@ -79,6 +79,6 @@ if e[0] != MYSQL_ERROR_TRIGGER_DOESNT_EXIST: raise curs.execute(trigger) - finally: zem.close() + finally: zem.close(conn) DevicePriority() Modified: trunk/Products/ZenModel/migrate/eventclassmapping.py =================================================================== --- trunk/Products/ZenModel/migrate/eventclassmapping.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/migrate/eventclassmapping.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -62,8 +62,8 @@ def cutover(self, dmd): try: zem = dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() for table in ('status', 'history'): try: curs.execute('alter table %s ' % table + @@ -78,6 +78,6 @@ if e[0] != MYSQL_ERROR_TRIGGER_DOESNT_EXIST: raise curs.execute(trigger) - finally: zem.close() + finally: zem.close(conn) EventClassMapping() Modified: trunk/Products/ZenModel/migrate/innodb.py =================================================================== --- trunk/Products/ZenModel/migrate/innodb.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/migrate/innodb.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -16,8 +16,8 @@ def cutover(self, dmd): try: zem = self.dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute('SHOW TABLE STATUS') for row in curs.fetchall(): table, engine = row[:2] @@ -27,6 +27,6 @@ curs.execute('ALTER TABLE %s ENGINE=INNODB' % table) if options and options.find('max_rows=') >= 0: curs.execute('ALTER TABLE %s max_rows=0' % table) - finally: zem.close() + finally: zem.close(conn) Innodb() Modified: trunk/Products/ZenModel/migrate/reindex_history.py =================================================================== --- trunk/Products/ZenModel/migrate/reindex_history.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenModel/migrate/reindex_history.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -27,11 +27,11 @@ def cutover(self, dmd): try: zem = dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() self.execute(curs, 'ALTER TABLE history DROP INDEX DateRange') self.execute(curs, 'ALTER TABLE history ADD INDEX firstTime (firstTime)') self.execute(curs, 'ALTER TABLE history ADD INDEX lastTime (lastTime)') - finally: zem.close() + finally: zem.close(conn) ReindexHistory() Modified: trunk/Products/ZenReports/plugins/threshold.py =================================================================== --- trunk/Products/ZenReports/plugins/threshold.py 2007-02-22 21:21:44 UTC (rev 4117) +++ trunk/Products/ZenReports/plugins/threshold.py 2007-02-23 18:34:23 UTC (rev 4118) @@ -45,8 +45,8 @@ counts = {} try: zem = dmd.ZenEventManager - zem.connect() - curs = zem.cursor() + conn = zem.connect() + curs = conn.cursor() curs.execute(query) startDate = args['startDate'] endDate = args['endDate'] @@ -65,7 +65,7 @@ except KeyError: sum[(device, component, eventClass)] = diff counts[(device, component, eventClass)] = 1 - finally: zem.close() + finally: zem.close(conn) # Look up objects that correspond to the names find = dmd.Devices.findDevice |
Author: marc Date: 2007-02-22 15:21:44 -0600 (Thu, 22 Feb 2007) New Revision: 4117 Modified: trunk/Products/DataCollector/ApplyDataMap.py trunk/Products/DataCollector/plugins/zenoss/snmp/CiscoHSRP.py trunk/Products/DataCollector/zendisc.py trunk/Products/DataCollector/zenmodeler.py trunk/Products/ZenEvents/ActionRule.py trunk/Products/ZenEvents/Availability.py trunk/Products/ZenEvents/DbAccessBase.py trunk/Products/ZenEvents/DbConnectionPool.py trunk/Products/ZenEvents/EventCommand.py trunk/Products/ZenEvents/EventManagerBase.py trunk/Products/ZenEvents/EventServer.py trunk/Products/ZenEvents/MySqlEventManager.py trunk/Products/ZenEvents/MySqlSendEvent.py trunk/Products/ZenEvents/SyslogProcessing.py trunk/Products/ZenEvents/UpdateCheck.py trunk/Products/ZenEvents/tests/testMySqlEventManager.py trunk/Products/ZenEvents/tests/testMySqlSendEvent.py trunk/Products/ZenEvents/zenactions.py trunk/Products/ZenModel/Device.py trunk/Products/ZenModel/PerformanceConf.py trunk/Products/ZenModel/migrate/clearid.py trunk/Products/ZenModel/migrate/command.py trunk/Products/ZenModel/migrate/devicepriority.py trunk/Products/ZenModel/migrate/eventclassmapping.py trunk/Products/ZenModel/migrate/innodb.py trunk/Products/ZenModel/migrate/reindex_history.py trunk/Products/ZenReports/plugins/threshold.py trunk/Products/ZenStatus/zenping.py trunk/Products/ZenStatus/zenstatus.py Log: #966 * DbConnectionPool is now hidden and accessible through DbAccessBase Modified: trunk/Products/DataCollector/ApplyDataMap.py =================================================================== --- trunk/Products/DataCollector/ApplyDataMap.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/DataCollector/ApplyDataMap.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -20,8 +20,6 @@ import logging log = logging.getLogger("zen.ApplyDataMap") -from Products.ZenEvents.DbConnectionPool import DbConnectionPool - zenmarker = "__ZENMARKER__" class ApplyDataMap(object): @@ -50,20 +48,8 @@ 'summary': msg, 'severity': Event.Info, } - zem = self.datacollector.dmd.ZenEventManager - cpool = DbConnectionPool() - conn = cpool.get(backend=zem.backend, - host=zem.host, - port=zem.port, - username=zem.username, - password=zem.password, - database=zem.database) - try: - zem.sendEvent(eventDict, conn) - finally: - cpool.put(conn) + self.datacollector.dmd.ZenEventManager.sendEvent(eventDict) - def processClient(self, device, collectorClient): """Apply datamps to device. """ Modified: trunk/Products/DataCollector/plugins/zenoss/snmp/CiscoHSRP.py =================================================================== --- trunk/Products/DataCollector/plugins/zenoss/snmp/CiscoHSRP.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/DataCollector/plugins/zenoss/snmp/CiscoHSRP.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -14,8 +14,6 @@ import transaction -from Products.ZenUtils.Utils import cleanstring - from CollectorPlugin import SnmpPlugin, GetTableMap class CiscoHSRP(SnmpPlugin): Modified: trunk/Products/DataCollector/zendisc.py =================================================================== --- trunk/Products/DataCollector/zendisc.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/DataCollector/zendisc.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -18,7 +18,6 @@ from Products.ZenEvents.Event import Event, Info from Products.ZenStatus.Ping import Ping from Products.ZenModel.Device import manage_createDevice -from Products.ZenEvents.DbConnectionPool import DbConnectionPool from zenmodeler import ZenModeler @@ -104,20 +103,10 @@ component=comp,eventClass=Status_Ping, summary=msg, severity=sev, agent="Discover") - zem = self.dmd.ZenEventManager - cpool = DbConnectionPool() - conn = cpool.get(backend=zem.backend, - host=zem.host, - port=zem.port, - username=zem.username, - password=zem.password, - database=zem.database) - try: - zem.sendEvent(evt, conn) - finally: - cpool.put(conn) + self.dmd.ZenEventManager.sendEvent(evt) + def sendDiscoveredEvent(self, ipobj, sev=2): """Send an device discovered event. """ @@ -133,19 +122,9 @@ component=comp,eventClass=Status_Snmp, summary=msg, severity=sev, agent="Discover") - zem = self.dmd.ZenEventManager - cpool = DbConnectionPool() - conn = cpool.get(backend=zem.backend, - host=zem.host, - port=zem.port, - username=zem.username, - password=zem.password, - database=zem.database) - try: - zem.sendEvent(evt, conn) - finally: - cpool.put(conn) + self.dmd.ZenEventManager.sendEvent(evt) + def discoverDevices(self, ips, devicepath="/Discovered", prodState=1000): @@ -194,18 +173,7 @@ severity=Info, agent="Discover") if self.options.snmpMissing: - zem = self.dmd.ZenEventManager - cpool = DbConnectionPool() - conn = cpool.get(backend=zem.backend, - host=zem.host, - port=zem.port, - username=zem.username, - password=zem.password, - database=zem.database) - try: - zem.sendEvent(evt, conn) - finally: - cpool.put(conn) + self.dmd.ZenEventManager.sendEvent(evt) except Exception, e: self.log.exception("failed device discovery for '%s'", ip) Modified: trunk/Products/DataCollector/zenmodeler.py =================================================================== --- trunk/Products/DataCollector/zenmodeler.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/DataCollector/zenmodeler.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -30,8 +30,6 @@ from Exceptions import * -from Products.ZenEvents.DbConnectionPool import DbConnectionPool - defaultPortScanTimeout = 5 defaultParallel = 40 defaultProtocol = "ssh" @@ -320,18 +318,7 @@ device=socket.getfqdn(), timeout=self.cycletime*3) if self.dmd: - zem = self.dmd.ZenEventManager - cpool = DbConnectionPool() - conn = cpool.get(backend=zem.backend, - host=zem.host, - port=zem.port, - username=zem.username, - password=zem.password, - database=zem.database) - try: - zem.sendEvent(evt, conn) - finally: - cpool.put(conn) + self.dmd.ZenEventManager.sendEvent(evt) else: self.stop() Modified: trunk/Products/ZenEvents/ActionRule.py =================================================================== --- trunk/Products/ZenEvents/ActionRule.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/ActionRule.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -20,8 +20,6 @@ from Products.ZenUtils import Time from Products.ZenEvents.EventFilter import EventFilter -from DbConnectionPool import DbConnectionPool - from ActionRuleWindow import ActionRuleWindow def _downcase(s): return s[0:1].lower() + s[1:] @@ -197,21 +195,14 @@ def _clearAlertState(self): """Clear state in alert_state before we are deleted. """ - cpool = DbConnectionPool() - conn = cpool.get(backend=self.dmd.ZenEventManager.backend, - host=self.dmd.ZenEventManager.host, - port=self.dmd.ZenEventManager.port, - username=self.dmd.ZenEventManager.username, - password=self.dmd.ZenEventManager.password, - database=self.dmd.ZenEventManager.database) - curs = conn.cursor() try: + zem = self.dmd.ZenEventManager + zem.connect() delcmd = "delete from alert_state where %s" % self.sqlwhere() log.debug("clear alert state '%s'", delcmd) + curs = zem.cursor() curs.execute(delcmd) - finally: - curs.close() - cpool.put(conn) + finally: zem.close() def sqlwhere(self): """Return sql where to select alert_state data for this event. Modified: trunk/Products/ZenEvents/Availability.py =================================================================== --- trunk/Products/ZenEvents/Availability.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/Availability.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -7,8 +7,6 @@ from AccessControl import ClassSecurityInfo -from DbConnectionPool import DbConnectionPool - CACHE_TIME = 60. _cache = Map.Locked(Map.Timed({}, CACHE_TIME)) @@ -95,11 +93,12 @@ """Run the report, returning an Availability object for each device""" # Note: we don't handle overlapping "down" events, so down # time could get get double-counted. + zem = dmd.ZenEventManager cols = 'device, component, firstTime, lastTime' endDate = self.endDate or time.time() startDate = self.startDate if not startDate: - days = dmd.ZenEventManager.defaultAvailabilityDays + days = zem.defaultAvailabilityDays startDate = time.time() - days*60*60*24 env = self.__dict__.copy() env.update(locals()) @@ -120,15 +119,9 @@ ') AS U ' % env) devices = {} - cpool = DbConnectionPool() - conn = cpool.get(backend=dmd.ZenEventManager.backend, - host=dmd.ZenEventManager.host, - port=dmd.ZenEventManager.port, - username=dmd.ZenEventManager.username, - password=dmd.ZenEventManager.password, - database=dmd.ZenEventManager.database) - curs = conn.cursor() try: + zem.connect() + curs = zem.cursor() curs.execute(s) while 1: rows = curs.fetchmany() @@ -142,9 +135,7 @@ devices[k] += last - first except KeyError: devices[k] = last - first - finally: - curs.close() - cpool.put(conn) + finally: zem.close() total = endDate - startDate if self.device: deviceList = [dmd.Devices.findDevice(self.device)] Modified: trunk/Products/ZenEvents/DbAccessBase.py =================================================================== --- trunk/Products/ZenEvents/DbAccessBase.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/DbAccessBase.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -1,58 +1,44 @@ import types -import struct -import DateTime +from DbConnectionPool import DbConnectionPool class DbAccessBase(object): + + _cpool = DbConnectionPool() + _currConn = None - def __init__(self, backend=None, host=None, port=None, username=None, - password=None, database=None): - self.backend = backend - self.host = host - self.port = port - self.username = username - self.password = password - self.database = database - self.connect() - + def __init__(self): + try: + self.connect() # Create a connection (and Pool) + finally: self.close() # Return the connection + + def conn(self): + if not self._currConn: + #self.connect() + raise Exception, "Stray conn() or cursor() call: Call connect() before and close() after" + return self._currConn + def cursor(self): - return self.conn.cursor() + return self.conn().cursor() def close(self): - self.conn.close() - self.conn = None + if self._currConn: + self._cpool.put(self._currConn) + self._currConn = None def connect(self): - """Load our database driver and connect to the database.""" - self.conn = None - if self.backend == "omnibus": - import Sybase - self.conn = Sybase.connect(self.database,self.username, - self.password) - elif self.backend == "mysql": - import MySQLdb - import MySQLdb.converters - mysqlconv = MySQLdb.converters.conversions.copy() - from MySQLdb.constants import FIELD_TYPE - mysqlconv[FIELD_TYPE.DATETIME] = DateTime.DateTime - mysqlconv[FIELD_TYPE.TIMESTAMP] = DateTime.DateTime - # FIXME for some reason it thinks my int is a long -EAD - mysqlconv[FIELD_TYPE.LONG] = int - if hasattr(self, 'host'): - host, database = self.host, self.database - else: - host, database = self.database, 'events' - self.conn = MySQLdb.connect(host=host, user=self.username, - port=self.port, passwd=self.password, - db=database, conv=mysqlconv) - self.conn.autocommit(1) - elif self.backend == "oracle": - import DCOracle2 - connstr = "%s/%s@%s" % (self.username, self.password, self.database) - self.conn = DCOracle2.connect(connstr) - - - def cleanstring(value): + """Load our database driver and connect to the database.""" + if self._currConn: + raise Exception, "A connection has already been retrieved, call close() when finished." + else: + self._currConn = self._cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) + + def cleanstring(self, value): """Remove the trailing \x00 off the end of a string.""" if type(value) in types.StringTypes: return value.rstrip("\x00") Modified: trunk/Products/ZenEvents/DbConnectionPool.py =================================================================== --- trunk/Products/ZenEvents/DbConnectionPool.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/DbConnectionPool.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -1,11 +1,12 @@ import MySQLdb +import MySQLdb.converters +from MySQLdb.constants import FIELD_TYPE import time +import DateTime from Queue import Queue, Empty, Full -from DbAccessBase import DbAccessBase - POOL_SIZE = 5 KEEP_ALIVE = 28800 @@ -22,36 +23,53 @@ def get(self, backend=None, host=None, port=None, username=None, password=None, database=None, block=0): - try: putstamp,obj = Queue.get(self, block) - # don't return stale connection, this needs to match whatever your - # connection keep alive value is in MySQL - if time.time() - putstamp >= KEEP_ALIVE: obj.close() - return DbAccessBase(backend=backend, - host=host, - port=port, - username=username, - password=password, - database=database) + return self._createConnection(host=host, port=port, + username=username, + password=password, + database=database) else: return obj except Empty: - return DbAccessBase(backend=backend, - host=host, - port=port, - username=username, - password=password, - database=database) + return self._createConnection(host=host, port=port, + username=username, + password=password, + database=database) def put(self, obj, block=0): - try: Queue.put(self, (time.time(),obj), block) except Full: pass + def _createConnection(self, host=None, port=None, + username=None, password=None, database=None): + conn = None + """ + if self.backend == "omnibus": + import Sybase + self.conn = Sybase.connect(self.database,self.username, + self.password) + elif self.backend == "oracle": + import DCOracle2 + connstr = "%s/%s@%s" % (self.username, self.password, self.database) + self.conn = DCOracle2.connect(connstr) + elif self.backend == "mysql": + """ + mysqlconv = MySQLdb.converters.conversions.copy() + mysqlconv[FIELD_TYPE.DATETIME] = DateTime.DateTime + mysqlconv[FIELD_TYPE.TIMESTAMP] = DateTime.DateTime + # FIXME for some reason it thinks my int is a long -EAD + mysqlconv[FIELD_TYPE.LONG] = int + if not host: + host, database = database, 'events' + conn = MySQLdb.connect(host=host, user=username, + port=port, passwd=password, + db=database, conv=mysqlconv) + conn.autocommit(1) + return conn \ No newline at end of file Modified: trunk/Products/ZenEvents/EventCommand.py =================================================================== --- trunk/Products/ZenEvents/EventCommand.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/EventCommand.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -7,7 +7,6 @@ from Products.ZenRelations.RelSchema import * from Globals import InitializeClass from EventFilter import EventFilter -from DbConnectionPool import DbConnectionPool class EventCommand(ZenModelRM, Commandable, EventFilter, ZenPackable): @@ -76,20 +75,13 @@ def _clearAlertState(self): """Clear state in alert_state before we are deleted. """ - cpool = DbConnectionPool() - conn = cpool.get(backend=self.dmd.ZenEventManager.backend, - host=self.dmd.ZenEventManager.host, - port=self.dmd.ZenEventManager.port, - username=self.dmd.ZenEventManager.username, - password=self.dmd.ZenEventManager.password, - database=self.dmd.ZenEventManager.database) - curs = conn.cursor() try: + zem = self.dmd.ZenEventManager + zem.connect() delcmd = "delete from alert_state where %s" % self.sqlwhere() + curs = self.dmd.ZenEventManager.cursor() curs.execute(delcmd) - finally: - curs.close() - cpool.put(conn) + finally: zem.close() security.declareProtected('Manage EventManager', 'manage_editEventCommand') Modified: trunk/Products/ZenEvents/EventManagerBase.py =================================================================== --- trunk/Products/ZenEvents/EventManagerBase.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/EventManagerBase.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -51,10 +51,9 @@ import time -from DbConnectionPool import DbConnectionPool -from Products.ZenUtils.Utils import cleanstring +from DbAccessBase import DbAccessBase -class EventManagerBase(ZenModelRM, ObjectCache): +class EventManagerBase(ZenModelRM, ObjectCache, DbAccessBase): """ Data connector to backend of the event management system. """ @@ -241,6 +240,8 @@ self.database=database self.host=host self.port=port + DbAccessBase.__init__(self) + self.defaultWhere = defaultWhere self.defaultOrderby="%s desc, %s desc" % ( self.severityField, self.lastTimeField) @@ -297,15 +298,9 @@ #print select retdata = self.checkCache(select) if not retdata: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(select) retdata = [] # iterate through the data results and convert to python @@ -314,9 +309,7 @@ row = map(self.convert, resultFields, row) evt = ZEvent(self, resultFields, row) retdata.append(evt) - finally: - curs.close() - cpool.put(conn) + finally: self.close() self.addToCache(select, retdata) self.cleanCache() return retdata @@ -370,15 +363,9 @@ selectevent += " from %s where" % self.statusTable selectevent += " %s = '%s'" % (idfield, evid) if self.backend=="omnibus": selectevent += ";" - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() #print selectevent curs.execute(selectevent) evrow = curs.fetchone() @@ -407,14 +394,12 @@ jrows = curs.fetchall() logs = [] for row in jrows: - user = cleanstring(row[0]) + user = self.cleanstring(row[0]) date = self.dateString(row[1]) text = row[2] logs.append((user, date, text)) event._logs = logs - finally: - curs.close() - cpool.put(conn) + finally: self.close() self.addToCache(cachekey, event) self.cleanCache() @@ -445,21 +430,14 @@ select = "select count(*) from %s where %s" % (self.statusTable, where) statusCount = self.checkCache(select) if not statusCount: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() #print select curs.execute(select) statusCount = curs.fetchone()[0] - finally: - curs.close() - cpool.put(conn) + finally: self.close() + self.addToCache(select,statusCount) return statusCount @@ -477,20 +455,14 @@ #print select statusCache = self.checkCache(select) if not statusCache: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(select) statusCache=[] orgdict={} for row in curs.fetchall(): - orgfield = cleanstring(row[0]) + orgfield = self.cleanstring(row[0]) if not orgfield: continue if orgfield.startswith("|"): orgfield = orgfield[1:] for orgname in orgfield.split("|"): @@ -498,9 +470,7 @@ orgdict[orgname] += 1 statusCache = orgdict.items() self.addToCache(select,statusCache) - finally: - curs.close() - cpool.put(conn) + finally: self.close() countevts = 0 for key, value in statusCache: if key.startswith(org.getOrganizerName()): @@ -520,20 +490,14 @@ select += where statusCache = self.checkCache(select) if not statusCache: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(select) statusCache=[] orgdict={} for row in curs.fetchall(): - orgfield = cleanstring(row[0]) + orgfield = self.cleanstring(row[0]) if not orgfield: continue if orgfield.startswith("|"): orgfield = orgfield[1:] for orgname in orgfield.split("|"): @@ -548,9 +512,7 @@ if limit: statusCache = statusCache[:limit] self.addToCache(select,statusCache) - finally: - curs.close() - cpool.put(conn) + finally: self.close() return statusCache @@ -590,15 +552,9 @@ statusCache = self.checkCache(select) if not statusCache: try: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(select) statusCache = [ [d,int(c),int(s)] for d,c,s in curs.fetchall() ] #statusCache = list(curs.fetchall()) @@ -606,9 +562,7 @@ statusCache.reverse() if limit: statusCache = statusCache[:limit] - finally: - curs.close() - cpool.put(conn) + finally: self.close() except: log.exception(select) raise @@ -630,24 +584,16 @@ statusCache = self.checkCache(select) if not statusCache: try: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(select) statusCache = {} for dev, count in curs.fetchall(): - dev = cleanstring(dev) + dev = self.cleanstring(dev) statusCache[dev] = count self.addToCache(select,statusCache) - finally: - curs.close() - cpool.put(conn) + finally: self.close() except: log.exception("status failed for device %s", device) return -1 @@ -691,15 +637,9 @@ cleanup = lambda : None if not statusCache: statusCache = [] - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(sel) res = list(curs.fetchall()) res.sort(lambda x,y: cmp(x[2],y[2])) @@ -715,9 +655,7 @@ if limit: statusCache = statusCache[:limit] cleanup() - finally: - curs.close() - cpool.put(conn) + finally: self.close() return statusCache @@ -735,25 +673,17 @@ select += where statusCache = self.checkCache(select) if not statusCache: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(select) statusCache ={} for dev, comp, count in curs.fetchall(): - dev = cleanstring(dev) - comp = cleanstring(comp) + dev = self.cleanstring(dev) + comp = self.cleanstring(comp) statusCache[dev+comp] = count self.addToCache(select,statusCache) - finally: - curs.close() - cpool.put(conn) + finally: self.close() return statusCache.get(device+component, 0) @@ -780,21 +710,13 @@ #print select statusCache = self.checkCache(select) if statusCache: return statusCache - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(select) statusCache = [ uid[0] for uid in curs.fetchall() if uid[0] ] self.addToCache(select,statusCache) - finally: - curs.close() - cpool.put(conn) + finally: self.close() return statusCache @@ -933,17 +855,7 @@ count = 0 for event in events: try: - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - try: - self.sendEvent(event, conn) - finally: - cpool.put(conn) + self.sendEvent(event) count += 1 except Exception, ex: log.exception(ex) @@ -951,7 +863,7 @@ security.declareProtected('Send Events', 'sendEvent') - def sendEvent(self, event, conn): + def sendEvent(self, event): """Send an event to the backend. """ raise NotImplementedError @@ -964,7 +876,7 @@ def convert(self, field, value): """Perform convertion of value coming from database value if nessesary. """ - value = cleanstring(value) + value = self.cleanstring(value) #FIXME this is commented out because we often need severity as a # number (like in ZEvent.getCssClass) and sorting. Need to have # both fields at some point @@ -1073,19 +985,13 @@ schema = {} fieldlist = [] sql = "describe %s;" % self.statusTable - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(sql) for row in curs.fetchall(): fieldlist.append(row[0]) - col = cleanstring(row[0]) + col = self.cleanstring(row[0]) if self.backend == "omnibus": type = row[1] in (1, 4, 7, 8) #different date types elif self.backend == "mysql": @@ -1093,9 +999,7 @@ schema[col] = type if schema: self._schema = schema self._fieldlist = fieldlist - finally: - curs.close() - cpool.put(conn) + finally: self.close() def eventControls(self): @@ -1112,20 +1016,12 @@ 'SELECT evid, "%s", "%s" ' % (userId, reason) + \ 'FROM %s ' % table + whereClause query = stmt + ' ' + whereClause - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() if toLog: curs.execute(insert) curs.execute(query) - finally: - curs.close() - cpool.put(conn) + finally: self.close() self.clearCache() self.manage_clearCache() @@ -1141,17 +1037,7 @@ eventClassKey = REQUEST['eventClassKey'], eventClass = REQUEST['eclass'], ) - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - try: - evid = self.sendEvent(eventDict, conn) - finally: - cpool.put(conn) + evid = self.sendEvent(eventDict) if REQUEST: REQUEST['RESPONSE'].redirect('/zport/dmd/Events/viewEvents') @@ -1202,19 +1088,11 @@ def manage_deleteHeartbeat(self, devname, REQUEST=None): if devname: delete = "delete from heartbeat where device = '%s'" % devname - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(delete); - finally: - curs.close() - cpool.put(conn) + finally: self.close() if REQUEST: return self.callZenScreen(REQUEST) @@ -1257,15 +1135,9 @@ sel = """select eventClassKey, eventClass, message from %s where evid in ('%s')""" sel = sel % (self.statusTable, "','".join(evids)) - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() curs.execute(sel); for row in curs.fetchall(): evclasskey, curevclass, msg = row @@ -1273,9 +1145,7 @@ evmap = evclass.createInstance(evclasskey) evmap.eventClassKey = evclasskey evmap.example = msg - finally: - curs.close() - cpool.put(conn) + finally: self.close() if REQUEST: if len(evids) == 1 and evmap: return evmap() elif evclass and evmap: return evclass() @@ -1286,17 +1156,11 @@ """get the conversion information from the omnibus server""" assert(self == self.dmd.ZenEventManager) self.loadSchema() - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) try: - self.dmd.ZenEventHistory.loadSchema(conn) - finally: - cpool.put(conn) + self.connect() + curs = self.cursor() + self.dmd.ZenEventHistory.loadSchema(self.conn()) + finally: self.close() if REQUEST: return self.callZenScreen(REQUEST) @@ -1339,20 +1203,12 @@ security.declareProtected('Manage EventManager','manage_clearHeartbeats') def manage_clearHeartbeats(self, REQUEST=None): """truncate heartbeat table""" - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - cursor = conn.cursor() try: + self.connect() + curs = self.cursor() sql = 'truncate table heartbeat' - cursor.execute(sql) - finally: - cursor.close() - cpool.put(conn) + curs.execute(sql) + finally: self.close() if REQUEST: return self.callZenScreen(REQUEST) security.declareProtected('Manage EventManager','zmanage_editProperties') @@ -1373,23 +1229,15 @@ if not evid: return userId = getSecurityManager().getUser().getId() - cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - database=self.database) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() insert = 'INSERT INTO log (evid, userName, text) ' insert += 'VALUES ("%s", "%s", "%s")' % (evid, userId, - conn.escape_string(message)) + self.conn().escape_string(message)) curs.execute(insert) - finally: - curs.close() - cpool.put(conn) + finally: self.close() self.clearCache('evid' + evid) if REQUEST: return self.callZenScreen(REQUEST) Modified: trunk/Products/ZenEvents/EventServer.py =================================================================== --- trunk/Products/ZenEvents/EventServer.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/EventServer.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -31,8 +31,6 @@ from ZenEventClasses import App_Start, App_Stop from twisted.internet import reactor, defer -from DbConnectionPool import DbConnectionPool - class Stats: totalTime = 0. totalEvents = 0 @@ -104,18 +102,7 @@ def sendEvent(self, evt): "wrapper for sending an event" self.zem._p_jar.sync() - cpool = DbConnectionPool() - conn = cpool.get(backend=self.zem.backend, - host=self.zem.host, - port=self.zem.port, - username=self.zem.username, - password=self.zem.password, - database=self.zem.database) - try: - self.zem.sendEvent(evt, conn) - finally: - cpool.put(conn) - + self.zem.sendEvent(evt) def sendEvents(self, evts): Modified: trunk/Products/ZenEvents/MySqlEventManager.py =================================================================== --- trunk/Products/ZenEvents/MySqlEventManager.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/MySqlEventManager.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -10,8 +10,6 @@ from MySqlSendEvent import MySqlSendEventMixin from Exceptions import * -from DbConnectionPool import DbConnectionPool - def manage_addMySqlEventManager(context, id=None, evtuser="root", evtpass="", evtdb="events", history=False, REQUEST=None): '''make an MySqlEventManager''' @@ -67,16 +65,10 @@ #print select sevsum = self.checkCache(select) if sevsum: return sevsum - - cpool = DbConnectionPool() - conn = cpool.get(backend=self.dmd.ZenEventManager.backend, - host=self.dmd.ZenEventManager.host, - port=self.dmd.ZenEventManager.port, - username=self.dmd.ZenEventManager.username, - password=self.dmd.ZenEventManager.password, - database=self.dmd.ZenEventManager.database) - curs = conn.cursor() + zem = self.dmd.ZenEventManager try: + zem.connect() + curs = zem.cursor() curs.execute(select) sumdata = {} ownerids = "" @@ -94,9 +86,7 @@ css = self.getEventCssClass(value) ackcount, count = sumdata.get(value, [0,0]) sevsum.append([css, ackcount, int(count)]) - finally: - curs.close() - cpool.put(conn) + finally: zem.close() self.addToCache(select, sevsum) self.cleanCache() @@ -106,16 +96,11 @@ ''' since is number of seconds since epoch, see documentation for python time.time() ''' - cpool = DbConnectionPool() - conn = cpool.get(backend=self.dmd.ZenEventManager.backend, - host=self.dmd.ZenEventManager.host, - port=self.dmd.ZenEventManager.port, - username=self.dmd.ZenEventManager.username, - password=self.dmd.ZenEventManager.password, - database=self.dmd.ZenEventManager.database) - curs = conn.cursor() count = 0 + zem = self.dmd.ZenEventManager try: + zem.connect() + curs = zem.cursor() for table in ('status', 'history'): sql = 'select count(*) from status ' \ 'where firstTime >= %s' % since @@ -125,9 +110,7 @@ 'where firstTime >= %s' % since curs.execute(sql) count += curs.fetchall()[0][0] - finally: - curs.close() - cpool.put(conn) + finally: zem.close() return count InitializeClass(MySqlEventManager) Modified: trunk/Products/ZenEvents/MySqlSendEvent.py =================================================================== --- trunk/Products/ZenEvents/MySqlSendEvent.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/MySqlSendEvent.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -29,14 +29,14 @@ send the event to the backend. """ - def sendEvent(self, event, conn): + def sendEvent(self, event): """Send an event to the backend. """ if type(event) == types.DictType: event = buildEventFromDict(event) if getattr(event, 'eventClass', Unknown) == Heartbeat: - return self._sendHeartbeat(event, conn) + return self._sendHeartbeat(event) for field in self.requiredEventFields: if not hasattr(event, field): @@ -56,7 +56,7 @@ # check again for heartbeat after context processing if getattr(event, 'eventClass', Unknown) == Heartbeat: - return self._sendHeartbeat(event, conn) + return self._sendHeartbeat(event) if not hasattr(event, 'dedupid'): @@ -82,7 +82,7 @@ evid = None try: try: - evid = self.doSendEvent(event, conn) + evid = self.doSendEvent(event) except ProgrammingError, e: log.exception(e) except OperationalError, e: @@ -92,11 +92,12 @@ cleanup() return evid - def doSendEvent(self, event, conn): + def doSendEvent(self, event): insert = "" statusdata, detaildata = self.eventDataMaps(event) - curs = conn.cursor() try: + self.connect() + curs = self.cursor() evid = guid.generate() event.evid = evid if event.severity == 0: @@ -124,8 +125,7 @@ evid = None delete = 'DELETE FROM status WHERE clearid IS NOT NULL' execute(curs, delete) - finally: - curs.close() + finally: self.close() return evid @@ -180,7 +180,7 @@ return evt - def _sendHeartbeat(self, event, conn): + def _sendHeartbeat(self, event): """Build insert to add heartbeat record to heartbeat table. """ evdict = {} @@ -202,11 +202,11 @@ insert += " on duplicate key update lastTime=Null" insert += ", timeout=%s" % evdict['timeout'] try: - curs = conn.cursor() try: + self.connect() + curs = self.cursor() execute(curs, insert) - finally: - curs.close() + finally: self.close() except ProgrammingError, e: log.error(insert) log.exception(e) Modified: trunk/Products/ZenEvents/SyslogProcessing.py =================================================================== --- trunk/Products/ZenEvents/SyslogProcessing.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/SyslogProcessing.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -23,7 +23,6 @@ from Event import Event from Exceptions import ZenBackendFailure from syslog_h import * -from DbConnectionPool import DbConnectionPool # Regular expressions that parse syslog tags from different sources parsers = ( @@ -85,18 +84,7 @@ evt = self.parseTag(evt, msg) #rest of msg now in summary of event evt = self.buildEventClassKey(evt) - zem = self.dmd.ZenEventManager - cpool = DbConnectionPool() - conn = cpool.get(backend=zem.backend, - host=zem.host, - port=zem.port, - username=zem.username, - password=zem.password, - database=zem.database) - try: - zem.sendEvent(evt, conn) - finally: - cpool.put(conn) + self.dmd.ZenEventManager.sendEvent(evt) def parsePRI(self, evt, msg): Modified: trunk/Products/ZenEvents/UpdateCheck.py =================================================================== --- trunk/Products/ZenEvents/UpdateCheck.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/UpdateCheck.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -17,7 +17,6 @@ import urllib import string import time -from DbConnectionPool import DbConnectionPool URL = 'http://update.zenoss.org/cgi-bin/version' @@ -105,21 +104,10 @@ import socket summary = ('A new version of Zenoss (%s) has been released' % available.short()) - zem = self.dmd.ZenEventManager - cpool = DbConnectionPool() - conn = cpool.get(backend=zem.backend, - host=zem.host, - port=zem.port, - username=zem.username, - password=zem.password, - database=zem.database) - try: - zem.sendEvent(Event.Event(device=socket.getfqdn(), + self.dmd.ZenEventManager.sendEvent(Event.Event(device=socket.getfqdn(), eventClass=Status_Update, severity=Event.Info, - summary=summary), conn) - finally: - cpool.put(conn) + summary=summary)) return True Modified: trunk/Products/ZenEvents/tests/testMySqlEventManager.py =================================================================== --- trunk/Products/ZenEvents/tests/testMySqlEventManager.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/tests/testMySqlEventManager.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -6,7 +6,6 @@ from Products.ZenUtils.ZCmdBase import ZCmdBase from Products.ZenEvents.Event import Event from Products.ZenEvents.Exceptions import * -from DbConnectionPool import DbConnectionPool zodb = ZCmdBase(noopts=True) @@ -30,22 +29,15 @@ def tearDown(self): transaction.abort() - cpool = DbConnectionPool() - conn = cpool.get(backend=self.dmd.ZenEventManager.backend, - host=self.dmd.ZenEventManager.host, - port=self.dmd.ZenEventManager.port, - username=self.dmd.ZenEventManager.username, - password=self.dmd.ZenEventManager.password, - database=self.dmd.ZenEventManager.database) - curs = conn.cursor() try: + zem = self.dmd.ZenEventManager + zem.connect() + curs = zem.cursor() curs.execute("truncate status") curs.execute("truncate detail") curs.execute("truncate log") curs.execute("truncate history") - finally: - curs.close() - cpool.put(conn) + finally: zem.close() zodb.closedb() self.dmd = None self.zem = None Modified: trunk/Products/ZenEvents/tests/testMySqlSendEvent.py =================================================================== --- trunk/Products/ZenEvents/tests/testMySqlSendEvent.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/tests/testMySqlSendEvent.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -10,7 +10,6 @@ from Products.ZenEvents.MySqlSendEvent import MySqlSendEventThread from Products.ZenEvents.Event import Event from Products.ZenEvents.Exceptions import * -from DbConnectionPool import DbConnectionPool class MySqlSendEventThreadTest(unittest.TestCase): @@ -21,19 +20,12 @@ def tearDown(self): transaction.abort() - cpool = DbConnectionPool() - conn = cpool.get(backend=self.dmd.ZenEventManager.backend, - host=self.dmd.ZenEventManager.host, - port=self.dmd.ZenEventManager.port, - username=self.dmd.ZenEventManager.username, - password=self.dmd.ZenEventManager.password, - database=self.dmd.ZenEventManager.database) - curs = conn.cursor() try: - curs.execute("truncate status") - finally: - curs.close() - cpool.put(conn) + zem = self.dmd.ZenEventManager + zem.connect() + curs = zem.cursor() + zem.curs.execute("truncate status") + finally: zem.close() zodb.closedb() self.zem = None Modified: trunk/Products/ZenEvents/zenactions.py =================================================================== --- trunk/Products/ZenEvents/zenactions.py 2007-02-22 19:00:32 UTC (rev 4116) +++ trunk/Products/ZenEvents/zenactions.py 2007-02-22 21:21:44 UTC (rev 4117) @@ -35,7 +35,6 @@ from twisted.internet import reactor from twisted.internet.protocol import ProcessProtocol from DateTime import DateTime -from DbConnectionPool import DbConnectionPool def _capitalize(s): return s[0:1].upper() + s[1:] @@ -151,18 +150,31 @@ self.log.debug("action:%s for:%s loaded", ar.getId(), userid) - def execute(self, db, stmt): + def execute(self, stmt): + result = None self.lastCommand = stmt self.log.debug(stmt) - return db.cursor().execute(stmt) + zem = self.dmd.ZenEventManager + try: + zem.connect() + curs = zem.cursor() + result = curs.execute(stmt) + finally: zem.close() + return result - def query(self, db, stmt): + def query(self, stmt): + result = None self.lastCommand = stmt self.log.debug(stmt) - curs = db.cursor() - curs.execute(stmt) - return curs.fetchall() + zem = self.dmd.ZenEventManager + try: + zem.connect() + curs = zem.cursor() + curs.execute(stmt) + result = curs.fetchall() + finally: zem.close() + return result def getUrl(self, evid): @@ -189,7 +201,7 @@ '?evid=%s&zenScreenName=viewEvents' % evid - def processRules(self, db, zem): + def processRules(self, zem): """Run through all rules matching them against events. """ for ar in self.actions: @@ -197,7 +209,7 @@ self.lastCommand = None # call sendPage or sendEmail actfunc = getattr(self, "send"+ar.action.title()) - self.processEvent(db, zem, ar, actfunc) + self.processEvent(zem, ar, actfunc) except (SystemExit, KeyboardInterrupt, OperationalError, POSError): raise except: @@ -205,12 +217,12 @@ self.log.warning(self.lastCommand) self.log.exception("action:%s",ar.getId()) - def checkVersion(self, db, zem): - self.updateCheck.check(db, zem) + def checkVersion(self, zem): + self.updateCheck.check(self.dmd, zem) import transaction transaction.commit() - def processEvent(self, db, zem, context, action): + def processEvent(self, zem, context, action): fields = context.getEventFields() userid = context.getUserid() # get new events @@ -218,7 +230,7 @@ if context.delay > 0: nwhere += " and firstTime + %s < UNIX_TIMESTAMP()" % context.delay q = self.newsel % (",".join(fields), nwhere, userid, context.getId()) - for result in self.query(db, q): + for result in self.query(q): evid = result[-1] data = dict(zip(fields, map(zem.convert, fields, result[:-1]))) data['eventUrl'] = self.getUrl(evid) @@ -233,13 +245,13 @@ data['severityString'] = zem.getSeverityString(severity) if action(context, data, False): addcmd = self.addstate % (evid, userid, context.getId()) - self.execute(db, addcmd) + self.execute(addcmd) # get clear events historyFields = [("h.%s" % f) for f in fields] historyFields = ','.join(historyFields) q = self.clearsel % (historyFields, userid, context.getId()) - for result in self.query(db, q): + for result in self.query(q): evid = result[-1] data = dict(zip(fields, map(zem.convert, fields, result[:-1]))) @@ -254,7 +266,7 @@ data.update({}.fromkeys(cfields, "")) # pull in the clear event data - for values in self.query(db, q): + for values in self.query(q): values = map(zem.convert, fields, values) data.update(dict(zip(cfields, values))) @@ -267,31 +279,31 @@ data['severityString'] = zem.getSeverityString(severity) action(context, data, True) delcmd = self.clearstate % (evid, userid, co... [truncated message content] |
From: <sv...@ze...> - 2007-02-22 19:00:49
|
Author: jstevens Date: 2007-02-22 13:00:32 -0600 (Thu, 22 Feb 2007) New Revision: 4116 Modified: trunk/Products/ZenModel/migrate/devicepriority.py trunk/Products/ZenModel/migrate/eventclassmapping.py Log: * Both scripts more intelligently handle exceptions from mysql now * some other syntax fixes related to recent db connection queueing Modified: trunk/Products/ZenModel/migrate/devicepriority.py =================================================================== --- trunk/Products/ZenModel/migrate/devicepriority.py 2007-02-22 15:04:09 UTC (rev 4115) +++ trunk/Products/ZenModel/migrate/devicepriority.py 2007-02-22 19:00:32 UTC (rev 4116) @@ -13,6 +13,9 @@ __version__ = "$Revision$"[11:-2] import Migrate +from MySQLdb import OperationalError +import MySQLdb.constants.ER as ER +MYSQL_ERROR_TRIGGER_DOESNT_EXIST = 1360 trigger = """ CREATE TRIGGER status_delete BEFORE DELETE ON status @@ -57,30 +60,31 @@ "Add a DevicePriority column to the status and history tables" version = Migrate.Version(1, 1, 0) - def execute(self, s, cmd): - from MySQLdb import OperationalError - try: - s.execute(cmd) - except OperationalError: - pass - def cutover(self, dmd): from Products.ZenEvents.DbConnectionPool import DbConnectionPool cpool = DbConnectionPool() - conn = cpool.get(backend=self.dmd.ZenEventManager.backend, - host=self.dmd.ZenEventManager.host, - port=self.dmd.ZenEventManager.port, - username=self.dmd.ZenEventManager.username, - password=self.dmd.ZenEventManager.password, - database=self.dmd.ZenEventManager.database) + conn = cpool.get(dmd.ZenEventManager.backend, + host=dmd.ZenEventManager.host, + port=dmd.ZenEventManager.port, + username=dmd.ZenEventManager.username, + password=dmd.ZenEventManager.password, + database=dmd.ZenEventManager.database) curs = conn.cursor() try: cmd = 'ALTER TABLE %s ADD COLUMN ' + \ '(DevicePriority smallint(6) default 3)' - self.execute(curs, cmd % 'status') - self.execute(curs, cmd % 'history') - self.execute(curs, 'DROP TRIGGER status_delete') - self.execute(curs, trigger) + for table in ('status', 'history'): + try: + curs.execute(cmd % table) + except OperationalError, e: + if e[0] != ER.DUP_FIELDNAME: + raise + try: + curs.execute('DROP TRIGGER status_delete') + except OperationalError, e: + if e[0] != MYSQL_ERROR_TRIGGER_DOESNT_EXIST: + raise + curs.execute(trigger) finally: curs.close() cpool.put(conn) Modified: trunk/Products/ZenModel/migrate/eventclassmapping.py =================================================================== --- trunk/Products/ZenModel/migrate/eventclassmapping.py 2007-02-22 15:04:09 UTC (rev 4115) +++ trunk/Products/ZenModel/migrate/eventclassmapping.py 2007-02-22 19:00:32 UTC (rev 4116) @@ -11,6 +11,9 @@ import logging log = logging.getLogger("zen.migrate") +import MySQLdb.constants.ER as ER +MYSQL_ERROR_TRIGGER_DOESNT_EXIST = 1360 + trigger = """ CREATE TRIGGER status_delete BEFORE DELETE ON status FOR EACH ROW INSERT INTO history SET @@ -67,18 +70,19 @@ database=dmd.ZenEventManager.database) curs = conn.cursor() try: - tables = ('status', 'history') - for table in tables: - curs.execute('desc %s' % table) - r = curs.fetchall() - if not [f for f in r if f[0] == 'eventClassMapping']: + for table in ('status', 'history'): + try: curs.execute('alter table %s ' % table + 'add column eventClassMapping ' 'varchar(128) default ""') + except OperationalError, e: + if e[0] != ER.DUP_FIELDNAME: + raise try: curs.execute('drop trigger status_delete') - except OperationalError: - pass + except OperationalError, e: + if e[0] != MYSQL_ERROR_TRIGGER_DOESNT_EXIST: + raise curs.execute(trigger) finally: curs.close() |
From: <sv...@ze...> - 2007-02-22 15:04:16
|
Author: marc Date: 2007-02-22 09:04:09 -0600 (Thu, 22 Feb 2007) New Revision: 4115 Modified: trunk/Products/DataCollector/zendisc.py trunk/Products/DataCollector/zenmodeler.py Log: #996 * fixed imports to DbConnectionPool Modified: trunk/Products/DataCollector/zendisc.py =================================================================== --- trunk/Products/DataCollector/zendisc.py 2007-02-22 14:55:25 UTC (rev 4114) +++ trunk/Products/DataCollector/zendisc.py 2007-02-22 15:04:09 UTC (rev 4115) @@ -18,7 +18,7 @@ from Products.ZenEvents.Event import Event, Info from Products.ZenStatus.Ping import Ping from Products.ZenModel.Device import manage_createDevice -from DbConnectionPool import DbConnectionPool +from Products.ZenEvents.DbConnectionPool import DbConnectionPool from zenmodeler import ZenModeler Modified: trunk/Products/DataCollector/zenmodeler.py =================================================================== --- trunk/Products/DataCollector/zenmodeler.py 2007-02-22 14:55:25 UTC (rev 4114) +++ trunk/Products/DataCollector/zenmodeler.py 2007-02-22 15:04:09 UTC (rev 4115) @@ -30,7 +30,7 @@ from Exceptions import * -from DbConnectionPool import DbConnectionPool +from Products.ZenEvents.DbConnectionPool import DbConnectionPool defaultPortScanTimeout = 5 defaultParallel = 40 |
From: <sv...@ze...> - 2007-02-22 14:55:28
|
Author: marc Date: 2007-02-22 08:55:25 -0600 (Thu, 22 Feb 2007) New Revision: 4114 Modified: trunk/Products/ZenEvents/EventServer.py trunk/Products/ZenEvents/zenactions.py trunk/Products/ZenStatus/zenping.py trunk/Products/ZenStatus/zenstatus.py Log: #996 * More files needed to use DbConnectionPool Modified: trunk/Products/ZenEvents/EventServer.py =================================================================== --- trunk/Products/ZenEvents/EventServer.py 2007-02-22 14:47:16 UTC (rev 4113) +++ trunk/Products/ZenEvents/EventServer.py 2007-02-22 14:55:25 UTC (rev 4114) @@ -31,6 +31,8 @@ from ZenEventClasses import App_Start, App_Stop from twisted.internet import reactor, defer +from DbConnectionPool import DbConnectionPool + class Stats: totalTime = 0. totalEvents = 0 @@ -102,7 +104,18 @@ def sendEvent(self, evt): "wrapper for sending an event" self.zem._p_jar.sync() - self.zem.sendEvent(evt) + cpool = DbConnectionPool() + conn = cpool.get(backend=self.zem.backend, + host=self.zem.host, + port=self.zem.port, + username=self.zem.username, + password=self.zem.password, + database=self.zem.database) + try: + self.zem.sendEvent(evt, conn) + finally: + cpool.put(conn) + def sendEvents(self, evts): Modified: trunk/Products/ZenEvents/zenactions.py =================================================================== --- trunk/Products/ZenEvents/zenactions.py 2007-02-22 14:47:16 UTC (rev 4113) +++ trunk/Products/ZenEvents/zenactions.py 2007-02-22 14:55:25 UTC (rev 4114) @@ -392,7 +392,18 @@ def sendEvent(self, evt): """Send event to the system. """ - self.dmd.ZenEventManager.sendEvent(evt) + zem = self.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(evt, conn) + finally: + cpool.put(conn) def sendHeartbeat(self): Modified: trunk/Products/ZenStatus/zenping.py =================================================================== --- trunk/Products/ZenStatus/zenping.py 2007-02-22 14:47:16 UTC (rev 4113) +++ trunk/Products/ZenStatus/zenping.py 2007-02-22 14:55:25 UTC (rev 4114) @@ -30,6 +30,7 @@ from Products.ZenEvents.ZenEventClasses import Status_Ping from Products.ZenEvents.Event import Event, EventHeartbeat from Products.ZenUtils.ZCmdBase import ZCmdBase +from Products.ZenEvents.DbConnectionPool import DbConnectionPool from twisted.internet import reactor, defer @@ -68,8 +69,19 @@ def sendEvent(self, evt): "wrapper for sending an event" - self.zem.sendEvent(evt) + cpool = DbConnectionPool() + conn = cpool.get(backend=self.zem.backend, + host=self.zem.host, + port=self.zem.port, + username=self.zem.username, + password=self.zem.password, + database=self.zem.database) + try: + self.zem.sendEvent(evt, conn) + finally: + cpool.put(conn) + def sendPingEvent(self, pj): "Send an event based on a ping job to the event backend." evt = Event(device=pj.hostname, Modified: trunk/Products/ZenStatus/zenstatus.py =================================================================== --- trunk/Products/ZenStatus/zenstatus.py 2007-02-22 14:47:16 UTC (rev 4113) +++ trunk/Products/ZenStatus/zenstatus.py 2007-02-22 14:55:25 UTC (rev 4114) @@ -17,6 +17,7 @@ from Products.ZenEvents.ZenEventClasses import App_Start, App_Stop from Products.ZenEvents.Event import Event, EventHeartbeat from Products.ZenUtils.ZCmdBase import ZCmdBase +from Products.ZenEvents.DbConnectionPool import DbConnectionPool import ZenTcpClient class ZenStatus(ZCmdBase): @@ -154,7 +155,17 @@ """Send an event for this monitor. """ try: - self.zem.sendEvent(evt) + cpool = DbConnectionPool() + conn = cpool.get(backend=self.zem.backend, + host=self.zem.host, + port=self.zem.port, + username=self.zem.username, + password=self.zem.password, + database=self.zem.database) + try: + self.zem.sendEvent(evt, conn) + finally: + cpool.put(conn) except OperationalError, e: self.log.warn("failed sending event: %s", e) |
From: <sv...@ze...> - 2007-02-22 14:47:45
|
Author: marc Date: 2007-02-22 08:47:16 -0600 (Thu, 22 Feb 2007) New Revision: 4113 Modified: trunk/Products/DataCollector/ApplyDataMap.py Log: #996 * fixed import of DbConnectionPool Modified: trunk/Products/DataCollector/ApplyDataMap.py =================================================================== --- trunk/Products/DataCollector/ApplyDataMap.py 2007-02-22 14:36:35 UTC (rev 4112) +++ trunk/Products/DataCollector/ApplyDataMap.py 2007-02-22 14:47:16 UTC (rev 4113) @@ -20,7 +20,7 @@ import logging log = logging.getLogger("zen.ApplyDataMap") -from DbConnectionPool import DbConnectionPool +from Products.ZenEvents.DbConnectionPool import DbConnectionPool zenmarker = "__ZENMARKER__" |
From: <sv...@ze...> - 2007-02-22 14:37:01
|
Author: marc Date: 2007-02-22 08:36:35 -0600 (Thu, 22 Feb 2007) New Revision: 4112 Modified: trunk/Products/DataCollector/ApplyDataMap.py trunk/Products/DataCollector/zendisc.py trunk/Products/DataCollector/zenmodeler.py trunk/Products/ZenEvents/SyslogProcessing.py trunk/Products/ZenEvents/UpdateCheck.py Log: #996 * more places needed to use the connection manager Modified: trunk/Products/DataCollector/ApplyDataMap.py =================================================================== --- trunk/Products/DataCollector/ApplyDataMap.py 2007-02-21 22:39:57 UTC (rev 4111) +++ trunk/Products/DataCollector/ApplyDataMap.py 2007-02-22 14:36:35 UTC (rev 4112) @@ -20,6 +20,8 @@ import logging log = logging.getLogger("zen.ApplyDataMap") +from DbConnectionPool import DbConnectionPool + zenmarker = "__ZENMARKER__" class ApplyDataMap(object): @@ -48,9 +50,20 @@ 'summary': msg, 'severity': Event.Info, } - self.datacollector.dmd.ZenEventManager.sendEvent(eventDict) - + zem = self.datacollector.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(eventDict, conn) + finally: + cpool.put(conn) + def processClient(self, device, collectorClient): """Apply datamps to device. """ Modified: trunk/Products/DataCollector/zendisc.py =================================================================== --- trunk/Products/DataCollector/zendisc.py 2007-02-21 22:39:57 UTC (rev 4111) +++ trunk/Products/DataCollector/zendisc.py 2007-02-22 14:36:35 UTC (rev 4112) @@ -18,6 +18,7 @@ from Products.ZenEvents.Event import Event, Info from Products.ZenStatus.Ping import Ping from Products.ZenModel.Device import manage_createDevice +from DbConnectionPool import DbConnectionPool from zenmodeler import ZenModeler @@ -103,7 +104,18 @@ component=comp,eventClass=Status_Ping, summary=msg, severity=sev, agent="Discover") - self.dmd.ZenEventManager.sendEvent(evt) + zem = self.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(evt, conn) + finally: + cpool.put(conn) def sendDiscoveredEvent(self, ipobj, sev=2): @@ -121,9 +133,19 @@ component=comp,eventClass=Status_Snmp, summary=msg, severity=sev, agent="Discover") - self.dmd.ZenEventManager.sendEvent(evt) + zem = self.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(evt, conn) + finally: + cpool.put(conn) - def discoverDevices(self, ips, devicepath="/Discovered", prodState=1000): @@ -172,7 +194,18 @@ severity=Info, agent="Discover") if self.options.snmpMissing: - self.dmd.ZenEventManager.sendEvent(evt) + zem = self.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(evt, conn) + finally: + cpool.put(conn) except Exception, e: self.log.exception("failed device discovery for '%s'", ip) Modified: trunk/Products/DataCollector/zenmodeler.py =================================================================== --- trunk/Products/DataCollector/zenmodeler.py 2007-02-21 22:39:57 UTC (rev 4111) +++ trunk/Products/DataCollector/zenmodeler.py 2007-02-22 14:36:35 UTC (rev 4112) @@ -30,6 +30,8 @@ from Exceptions import * +from DbConnectionPool import DbConnectionPool + defaultPortScanTimeout = 5 defaultParallel = 40 defaultProtocol = "ssh" @@ -318,7 +320,18 @@ device=socket.getfqdn(), timeout=self.cycletime*3) if self.dmd: - self.dmd.ZenEventManager.sendEvent(evt) + zem = self.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(evt, conn) + finally: + cpool.put(conn) else: self.stop() Modified: trunk/Products/ZenEvents/SyslogProcessing.py =================================================================== --- trunk/Products/ZenEvents/SyslogProcessing.py 2007-02-21 22:39:57 UTC (rev 4111) +++ trunk/Products/ZenEvents/SyslogProcessing.py 2007-02-22 14:36:35 UTC (rev 4112) @@ -23,6 +23,7 @@ from Event import Event from Exceptions import ZenBackendFailure from syslog_h import * +from DbConnectionPool import DbConnectionPool # Regular expressions that parse syslog tags from different sources parsers = ( @@ -84,7 +85,18 @@ evt = self.parseTag(evt, msg) #rest of msg now in summary of event evt = self.buildEventClassKey(evt) - self.zem.sendEvent(evt) + zem = self.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(evt, conn) + finally: + cpool.put(conn) def parsePRI(self, evt, msg): Modified: trunk/Products/ZenEvents/UpdateCheck.py =================================================================== --- trunk/Products/ZenEvents/UpdateCheck.py 2007-02-21 22:39:57 UTC (rev 4111) +++ trunk/Products/ZenEvents/UpdateCheck.py 2007-02-22 14:36:35 UTC (rev 4112) @@ -17,6 +17,7 @@ import urllib import string import time +from DbConnectionPool import DbConnectionPool URL = 'http://update.zenoss.org/cgi-bin/version' @@ -104,10 +105,22 @@ import socket summary = ('A new version of Zenoss (%s) has been released' % available.short()) - zem.sendEvent(Event.Event(device=socket.getfqdn(), - eventClass=Status_Update, - severity=Event.Info, - summary=summary)) + zem = self.dmd.ZenEventManager + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + zem.sendEvent(Event.Event(device=socket.getfqdn(), + eventClass=Status_Update, + severity=Event.Info, + summary=summary), conn) + finally: + cpool.put(conn) + return True if __name__ == "__main__": |
From: <sv...@ze...> - 2007-02-21 22:39:58
|
Author: marc Date: 2007-02-21 16:39:57 -0600 (Wed, 21 Feb 2007) New Revision: 4111 Modified: trunk/Products/ZenEvents/DbAccessBase.py trunk/Products/ZenEvents/DbConnectionPool.py trunk/Products/ZenEvents/EventManagerBase.py Log: #996 * Cleanup of code Modified: trunk/Products/ZenEvents/DbAccessBase.py =================================================================== --- trunk/Products/ZenEvents/DbAccessBase.py 2007-02-21 19:53:48 UTC (rev 4110) +++ trunk/Products/ZenEvents/DbAccessBase.py 2007-02-21 22:39:57 UTC (rev 4111) @@ -5,7 +5,8 @@ class DbAccessBase(object): - def __init__(self, backend, host, port, username, password, database): + def __init__(self, backend=None, host=None, port=None, username=None, + password=None, database=None): self.backend = backend self.host = host self.port = port Modified: trunk/Products/ZenEvents/DbConnectionPool.py =================================================================== --- trunk/Products/ZenEvents/DbConnectionPool.py 2007-02-21 19:53:48 UTC (rev 4110) +++ trunk/Products/ZenEvents/DbConnectionPool.py 2007-02-21 22:39:57 UTC (rev 4111) @@ -20,12 +20,13 @@ def __init__(self): Queue.__init__(self, POOL_SIZE) - def get(self, backend, host, port, username, password, database, block=0): + def get(self, backend=None, host=None, port=None, username=None, + password=None, database=None, block=0): try: putstamp,obj = Queue.get(self, block) - # don't return stale connection, this needs to match whatever your + # don't return stale connection, this needs to match whatever your # connection keep alive value is in MySQL if time.time() - putstamp >= KEEP_ALIVE: Modified: trunk/Products/ZenEvents/EventManagerBase.py =================================================================== --- trunk/Products/ZenEvents/EventManagerBase.py 2007-02-21 19:53:48 UTC (rev 4110) +++ trunk/Products/ZenEvents/EventManagerBase.py 2007-02-21 22:39:57 UTC (rev 4111) @@ -521,7 +521,12 @@ statusCache = self.checkCache(select) if not statusCache: cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(select) @@ -586,7 +591,12 @@ if not statusCache: try: cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(select) @@ -621,7 +631,12 @@ if not statusCache: try: cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(select) @@ -677,7 +692,12 @@ if not statusCache: statusCache = [] cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(sel) @@ -716,7 +736,12 @@ statusCache = self.checkCache(select) if not statusCache: cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(select) @@ -756,7 +781,12 @@ statusCache = self.checkCache(select) if statusCache: return statusCache cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(select) @@ -904,7 +934,12 @@ for event in events: try: cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) try: self.sendEvent(event, conn) finally: @@ -1039,7 +1074,12 @@ fieldlist = [] sql = "describe %s;" % self.statusTable cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(sql) @@ -1073,7 +1113,12 @@ 'FROM %s ' % table + whereClause query = stmt + ' ' + whereClause cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: if toLog: curs.execute(insert) @@ -1097,7 +1142,12 @@ eventClass = REQUEST['eclass'], ) cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) try: evid = self.sendEvent(eventDict, conn) finally: @@ -1153,7 +1203,12 @@ if devname: delete = "delete from heartbeat where device = '%s'" % devname cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(delete); @@ -1203,7 +1258,12 @@ from %s where evid in ('%s')""" sel = sel % (self.statusTable, "','".join(evids)) cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: curs.execute(sel); @@ -1227,7 +1287,12 @@ assert(self == self.dmd.ZenEventManager) self.loadSchema() cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) try: self.dmd.ZenEventHistory.loadSchema(conn) finally: @@ -1275,7 +1340,12 @@ def manage_clearHeartbeats(self, REQUEST=None): """truncate heartbeat table""" cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) cursor = conn.cursor() try: sql = 'truncate table heartbeat' @@ -1304,7 +1374,12 @@ return userId = getSecurityManager().getUser().getId() cpool = DbConnectionPool() - conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) curs = conn.cursor() try: insert = 'INSERT INTO log (evid, userName, text) ' |
From: <sv...@ze...> - 2007-02-21 19:54:15
|
Author: marc Date: 2007-02-21 13:53:48 -0600 (Wed, 21 Feb 2007) New Revision: 4110 Added: trunk/Products/ZenEvents/DbConnectionPool.py Modified: trunk/Products/ZenEvents/ActionRule.py trunk/Products/ZenEvents/Availability.py trunk/Products/ZenEvents/DbAccessBase.py trunk/Products/ZenEvents/EventClass.py trunk/Products/ZenEvents/EventCommand.py trunk/Products/ZenEvents/EventManagerBase.py trunk/Products/ZenEvents/MySqlEventManager.py trunk/Products/ZenEvents/MySqlSendEvent.py trunk/Products/ZenEvents/tests/testMySqlEventManager.py trunk/Products/ZenEvents/tests/testMySqlSendEvent.py trunk/Products/ZenEvents/zenactions.py trunk/Products/ZenModel/Device.py trunk/Products/ZenModel/migrate/clearid.py trunk/Products/ZenModel/migrate/command.py trunk/Products/ZenModel/migrate/devicepriority.py trunk/Products/ZenModel/migrate/eventclassmapping.py trunk/Products/ZenModel/migrate/innodb.py trunk/Products/ZenModel/migrate/reindex_history.py trunk/Products/ZenReports/plugins/threshold.py Log: #996 * Added DbConnectionPool * Changed connection calls to use DbConnectionPool Modified: trunk/Products/ZenEvents/ActionRule.py =================================================================== --- trunk/Products/ZenEvents/ActionRule.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/ActionRule.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -20,6 +20,8 @@ from Products.ZenUtils import Time from Products.ZenEvents.EventFilter import EventFilter +from DbConnectionPool import DbConnectionPool + from ActionRuleWindow import ActionRuleWindow def _downcase(s): return s[0:1].lower() + s[1:] @@ -195,14 +197,22 @@ def _clearAlertState(self): """Clear state in alert_state before we are deleted. """ - db = self.dmd.ZenEventManager.connect() - curs = db.cursor() - delcmd = "delete from alert_state where %s" % self.sqlwhere() - log.debug("clear alert state '%s'", delcmd) - curs.execute(delcmd) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + delcmd = "delete from alert_state where %s" % self.sqlwhere() + log.debug("clear alert state '%s'", delcmd) + curs.execute(delcmd) + finally: + curs.close() + cpool.put(conn) - def sqlwhere(self): """Return sql where to select alert_state data for this event. """ Modified: trunk/Products/ZenEvents/Availability.py =================================================================== --- trunk/Products/ZenEvents/Availability.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/Availability.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -7,6 +7,7 @@ from AccessControl import ClassSecurityInfo +from DbConnectionPool import DbConnectionPool CACHE_TIME = 60. @@ -117,13 +118,20 @@ ' UNION ' ' SELECT %(cols)s FROM status %(w)s ' ') AS U ' % env) - c = dmd.ZenEventManager.connect() + devices = {} + cpool = DbConnectionPool() + conn = cpool.get(backend=dmd.ZenEventManager.backend, + host=dmd.ZenEventManager.host, + port=dmd.ZenEventManager.port, + username=dmd.ZenEventManager.username, + password=dmd.ZenEventManager.password, + database=dmd.ZenEventManager.database) + curs = conn.cursor() try: - e = c.cursor() - e.execute(s) + curs.execute(s) while 1: - rows = e.fetchmany() + rows = curs.fetchmany() if not rows: break for row in rows: device, component, first, last = row @@ -135,7 +143,8 @@ except KeyError: devices[k] = last - first finally: - c.close() + curs.close() + cpool.put(conn) total = endDate - startDate if self.device: deviceList = [dmd.Devices.findDevice(self.device)] Modified: trunk/Products/ZenEvents/DbAccessBase.py =================================================================== --- trunk/Products/ZenEvents/DbAccessBase.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/DbAccessBase.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -5,11 +5,28 @@ class DbAccessBase(object): + def __init__(self, backend, host, port, username, password, database): + self.backend = backend + self.host = host + self.port = port + self.username = username + self.password = password + self.database = database + self.connect() + + def cursor(self): + return self.conn.cursor() + + def close(self): + self.conn.close() + self.conn = None + def connect(self): """Load our database driver and connect to the database.""" + self.conn = None if self.backend == "omnibus": import Sybase - db = Sybase.connect(self.database,self.username, + self.conn = Sybase.connect(self.database,self.username, self.password) elif self.backend == "mysql": import MySQLdb @@ -24,18 +41,17 @@ host, database = self.host, self.database else: host, database = self.database, 'events' - db = MySQLdb.connect(host=host, user=self.username, + self.conn = MySQLdb.connect(host=host, user=self.username, port=self.port, passwd=self.password, db=database, conv=mysqlconv) - db.autocommit(1) + self.conn.autocommit(1) elif self.backend == "oracle": import DCOracle2 connstr = "%s/%s@%s" % (self.username, self.password, self.database) - db = DCOracle2.connect(connstr) - return db + self.conn = DCOracle2.connect(connstr) - def cleanstring(self, value): + def cleanstring(value): """Remove the trailing \x00 off the end of a string.""" if type(value) in types.StringTypes: return value.rstrip("\x00") Added: trunk/Products/ZenEvents/DbConnectionPool.py Modified: trunk/Products/ZenEvents/EventClass.py =================================================================== --- trunk/Products/ZenEvents/EventClass.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/EventClass.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -20,6 +20,7 @@ from Products.ZenModel.ZenPackable import ZenPackable from Products.ZenModel.ManagedEntity import ManagedEntity +from Products.ZenUtils.Utils import prepId as globalPrepId def manage_addEventClass(context, id="Events", REQUEST=None): """make a event class""" @@ -184,11 +185,14 @@ idx = insts[-1].sequence + 1 return idx - + def prepId(self, id, subchar='_'): + return globalPrepId(id, subchar) + def createInstance(self, id=None, REQUEST=None): """Add an EventClassInst to this EventClass. """ if id: + id = self.prepId(id) c=0 while self.instances._getOb(id,False): c+=1 Modified: trunk/Products/ZenEvents/EventCommand.py =================================================================== --- trunk/Products/ZenEvents/EventCommand.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/EventCommand.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -7,6 +7,7 @@ from Products.ZenRelations.RelSchema import * from Globals import InitializeClass from EventFilter import EventFilter +from DbConnectionPool import DbConnectionPool class EventCommand(ZenModelRM, Commandable, EventFilter, ZenPackable): @@ -75,11 +76,20 @@ def _clearAlertState(self): """Clear state in alert_state before we are deleted. """ - db = self.ZenEventManager.connect() - curs = db.cursor() - delcmd = "delete from alert_state where %s" % self.sqlwhere() - curs.execute(delcmd) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + delcmd = "delete from alert_state where %s" % self.sqlwhere() + curs.execute(delcmd) + finally: + curs.close() + cpool.put(conn) security.declareProtected('Manage EventManager', 'manage_editEventCommand') Modified: trunk/Products/ZenEvents/EventManagerBase.py =================================================================== --- trunk/Products/ZenEvents/EventManagerBase.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/EventManagerBase.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -33,7 +33,6 @@ from interfaces import IEventList, IEventStatus, ISendEvents -from DbAccessBase import DbAccessBase from ZEvent import ZEvent from EventDetail import EventDetail from BetterEventDetail import BetterEventDetail @@ -52,7 +51,10 @@ import time -class EventManagerBase(ZenModelRM, DbAccessBase, ObjectCache): +from DbConnectionPool import DbConnectionPool +from Products.ZenUtils.Utils import cleanstring + +class EventManagerBase(ZenModelRM, ObjectCache): """ Data connector to backend of the event management system. """ @@ -234,13 +236,12 @@ defaultWhere='',defaultOrderby='',defaultResultFields=[]): self.id = id self.title = title - self.username = username - self.password = password - self.database = database - self.host = host - self.port = port + self.username=username + self.password=password + self.database=database + self.host=host + self.port=port self.defaultWhere = defaultWhere - self.defaultOrderby="%s desc, %s desc" % ( self.severityField, self.lastTimeField) @@ -296,17 +297,26 @@ #print select retdata = self.checkCache(select) if not retdata: - db = self.connect() - curs = db.cursor() - curs.execute(select) - retdata = [] - # iterate through the data results and convert to python - # objects - for row in curs.fetchall(): - row = map(self.convert, resultFields, row) - evt = ZEvent(self, resultFields, row) - retdata.append(evt) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) + curs = conn.cursor() + try: + curs.execute(select) + retdata = [] + # iterate through the data results and convert to python + # objects + for row in curs.fetchall(): + row = map(self.convert, resultFields, row) + evt = ZEvent(self, resultFields, row) + retdata.append(evt) + finally: + curs.close() + cpool.put(conn) self.addToCache(select, retdata) self.cleanCache() return retdata @@ -354,49 +364,58 @@ cachekey = '%s%s' % (idfield, evid) event = self.checkCache(cachekey) if event: return event - db = self.connect() fields = self.getFieldList() selectevent = "select " selectevent += ", ".join(fields) selectevent += " from %s where" % self.statusTable selectevent += " %s = '%s'" % (idfield, evid) if self.backend=="omnibus": selectevent += ";" - - #print selectevent - curs = db.cursor() - curs.execute(selectevent) - evrow = curs.fetchone() - if not evrow: - raise (ZenEventNotFound,"Event evid %s not found" % evid) - evdata = map(self.convert, fields, evrow) - if better: - event = BetterEventDetail(self, fields, evdata) - else: - event = EventDetail(self, fields, evdata) - event = event.__of__(self) + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) + curs = conn.cursor() + try: + #print selectevent + curs.execute(selectevent) + evrow = curs.fetchone() + if not evrow: + raise (ZenEventNotFound,"Event evid %s not found" % evid) + evdata = map(self.convert, fields, evrow) + if better: + event = BetterEventDetail(self, fields, evdata) + else: + event = EventDetail(self, fields, evdata) + event = event.__of__(self) - selectdetail = "select name, value from %s where" % self.detailTable - selectdetail += " evid = '%s'" % event.evid - if self.backend=="omnibus": selectevent += ";" - #print selectdetail - curs.execute(selectdetail) - event._details = curs.fetchall() + selectdetail = "select name, value from %s where" % self.detailTable + selectdetail += " evid = '%s'" % event.evid + if self.backend=="omnibus": selectevent += ";" + #print selectdetail + curs.execute(selectdetail) + event._details = curs.fetchall() - selectlogs = "select userName, ctime, text" - selectlogs += " from %s where" % self.logTable - selectlogs += " evid = '%s' order by ctime desc" % event.evid - if self.backend=="omnibus": selectevent += ";" - #print selectlogs - curs.execute(selectlogs) - jrows = curs.fetchall() - logs = [] - for row in jrows: - user = self.cleanstring(row[0]) - date = self.dateString(row[1]) - text = row[2] - logs.append((user, date, text)) - event._logs = logs - db.close() + selectlogs = "select userName, ctime, text" + selectlogs += " from %s where" % self.logTable + selectlogs += " evid = '%s' order by ctime desc" % event.evid + if self.backend=="omnibus": selectevent += ";" + #print selectlogs + curs.execute(selectlogs) + jrows = curs.fetchall() + logs = [] + for row in jrows: + user = cleanstring(row[0]) + date = self.dateString(row[1]) + text = row[2] + logs.append((user, date, text)) + event._logs = logs + finally: + curs.close() + cpool.put(conn) + self.addToCache(cachekey, event) self.cleanCache() return event @@ -426,13 +445,21 @@ select = "select count(*) from %s where %s" % (self.statusTable, where) statusCount = self.checkCache(select) if not statusCount: - db = self.connect() - curs = db.cursor() - #print select - curs.execute(select) - statusCount = curs.fetchone()[0] - curs.close() - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) + curs = conn.cursor() + try: + #print select + curs.execute(select) + statusCount = curs.fetchone()[0] + finally: + curs.close() + cpool.put(conn) self.addToCache(select,statusCount) return statusCount @@ -450,21 +477,30 @@ #print select statusCache = self.checkCache(select) if not statusCache: - db = self.connect() - curs = db.cursor() - curs.execute(select) - statusCache=[] - orgdict={} - for row in curs.fetchall(): - orgfield = self.cleanstring(row[0]) - if not orgfield: continue - if orgfield.startswith("|"): orgfield = orgfield[1:] - for orgname in orgfield.split("|"): - orgdict.setdefault(orgname, 0) - orgdict[orgname] += 1 - statusCache = orgdict.items() - self.addToCache(select,statusCache) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, + host=self.host, + port=self.port, + username=self.username, + password=self.password, + database=self.database) + curs = conn.cursor() + try: + curs.execute(select) + statusCache=[] + orgdict={} + for row in curs.fetchall(): + orgfield = cleanstring(row[0]) + if not orgfield: continue + if orgfield.startswith("|"): orgfield = orgfield[1:] + for orgname in orgfield.split("|"): + orgdict.setdefault(orgname, 0) + orgdict[orgname] += 1 + statusCache = orgdict.items() + self.addToCache(select,statusCache) + finally: + curs.close() + cpool.put(conn) countevts = 0 for key, value in statusCache: if key.startswith(org.getOrganizerName()): @@ -484,28 +520,32 @@ select += where statusCache = self.checkCache(select) if not statusCache: - db = self.connect() - curs = db.cursor() - curs.execute(select) - statusCache=[] - orgdict={} - for row in curs.fetchall(): - orgfield = self.cleanstring(row[0]) - if not orgfield: continue - if orgfield.startswith("|"): orgfield = orgfield[1:] - for orgname in orgfield.split("|"): - if not orgname: continue - count, total = orgdict.setdefault(orgname, (0,0)) - count+=1 - total+=row[1] - orgdict[orgname] = (count,total) - statusCache = [ [n, c[0], int(c[1])] for n, c in orgdict.items() ] - statusCache.sort(lambda x,y: cmp(x[1],y[1])) - statusCache.reverse() - if limit: - statusCache = statusCache[:limit] - self.addToCache(select,statusCache) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(select) + statusCache=[] + orgdict={} + for row in curs.fetchall(): + orgfield = cleanstring(row[0]) + if not orgfield: continue + if orgfield.startswith("|"): orgfield = orgfield[1:] + for orgname in orgfield.split("|"): + if not orgname: continue + count, total = orgdict.setdefault(orgname, (0,0)) + count+=1 + total+=row[1] + orgdict[orgname] = (count,total) + statusCache = [ [n, c[0], int(c[1])] for n, c in orgdict.items() ] + statusCache.sort(lambda x,y: cmp(x[1],y[1])) + statusCache.reverse() + if limit: + statusCache = statusCache[:limit] + self.addToCache(select,statusCache) + finally: + curs.close() + cpool.put(conn) return statusCache @@ -545,16 +585,20 @@ statusCache = self.checkCache(select) if not statusCache: try: - db = self.connect() - curs = db.cursor() - curs.execute(select) - statusCache = [ [d,int(c),int(s)] for d,c,s in curs.fetchall() ] - #statusCache = list(curs.fetchall()) - statusCache.sort(lambda x,y: cmp(x[1],y[1])) - statusCache.reverse() - if limit: - statusCache = statusCache[:limit] - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(select) + statusCache = [ [d,int(c),int(s)] for d,c,s in curs.fetchall() ] + #statusCache = list(curs.fetchall()) + statusCache.sort(lambda x,y: cmp(x[1],y[1])) + statusCache.reverse() + if limit: + statusCache = statusCache[:limit] + finally: + curs.close() + cpool.put(conn) except: log.exception(select) raise @@ -576,15 +620,19 @@ statusCache = self.checkCache(select) if not statusCache: try: - db = self.connect() - curs = db.cursor() - curs.execute(select) - statusCache = {} - for dev, count in curs.fetchall(): - dev = self.cleanstring(dev) - statusCache[dev] = count - self.addToCache(select,statusCache) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(select) + statusCache = {} + for dev, count in curs.fetchall(): + dev = cleanstring(dev) + statusCache[dev] = count + self.addToCache(select,statusCache) + finally: + curs.close() + cpool.put(conn) except: log.exception("status failed for device %s", device) return -1 @@ -628,25 +676,28 @@ cleanup = lambda : None if not statusCache: statusCache = [] - if db is None: - db = self.connect() - cleanup = db.close - curs = db.cursor() - curs.execute(sel) - res = list(curs.fetchall()) - res.sort(lambda x,y: cmp(x[2],y[2])) - devclass = self.getDmdRoot("Devices") - for devname, comp, dtime in res: - dtime = "%d" % int(time.time()-dtime.timeTime()) - dev = devclass.findDevice(devname) - if dev and not simple: - alink = "<a href='%s'>%s</a>" % ( - dev.getPrimaryUrlPath(), dev.id) - else: alink = devname - statusCache.append([alink, comp, dtime]) - if limit: - statusCache = statusCache[:limit] - cleanup() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(sel) + res = list(curs.fetchall()) + res.sort(lambda x,y: cmp(x[2],y[2])) + devclass = self.getDmdRoot("Devices") + for devname, comp, dtime in res: + dtime = "%d" % int(time.time()-dtime.timeTime()) + dev = devclass.findDevice(devname) + if dev and not simple: + alink = "<a href='%s'>%s</a>" % ( + dev.getPrimaryUrlPath(), dev.id) + else: alink = devname + statusCache.append([alink, comp, dtime]) + if limit: + statusCache = statusCache[:limit] + cleanup() + finally: + curs.close() + cpool.put(conn) return statusCache @@ -664,16 +715,20 @@ select += where statusCache = self.checkCache(select) if not statusCache: - db = self.connect() - curs = db.cursor() - curs.execute(select) - statusCache ={} - for dev, comp, count in curs.fetchall(): - dev = self.cleanstring(dev) - comp = self.cleanstring(comp) - statusCache[dev+comp] = count - self.addToCache(select,statusCache) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(select) + statusCache ={} + for dev, comp, count in curs.fetchall(): + dev = cleanstring(dev) + comp = cleanstring(comp) + statusCache[dev+comp] = count + self.addToCache(select,statusCache) + finally: + curs.close() + cpool.put(conn) return statusCache.get(device+component, 0) @@ -700,12 +755,16 @@ #print select statusCache = self.checkCache(select) if statusCache: return statusCache - db = self.connect() - curs = db.cursor() - curs.execute(select) - statusCache = [ uid[0] for uid in curs.fetchall() if uid[0] ] - self.addToCache(select,statusCache) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(select) + statusCache = [ uid[0] for uid in curs.fetchall() if uid[0] ] + self.addToCache(select,statusCache) + finally: + curs.close() + cpool.put(conn) return statusCache @@ -842,19 +901,22 @@ """Send a group of events to the backend. """ count = 0 - db = self.connect() for event in events: try: - self.sendEvent(event, db) + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + try: + self.sendEvent(event, conn) + finally: + cpool.put(conn) count += 1 except Exception, ex: log.exception(ex) - db.close() return count security.declareProtected('Send Events', 'sendEvent') - def sendEvent(self, event, db=None): + def sendEvent(self, event, conn): """Send an event to the backend. """ raise NotImplementedError @@ -867,7 +929,7 @@ def convert(self, field, value): """Perform convertion of value coming from database value if nessesary. """ - value = self.cleanstring(value) + value = cleanstring(value) #FIXME this is commented out because we often need severity as a # number (like in ZEvent.getCssClass) and sorting. Need to have # both fields at some point @@ -884,11 +946,7 @@ """Return a list of all fields in the status table of the backend. """ if not getattr(self, '_fieldlist', None): - db = self.connect() - try: - self.loadSchema(db) - finally: - db.close() + self.loadSchema() return self._fieldlist def getEventStates(self): @@ -975,17 +1033,19 @@ raise NotImplementedError - def loadSchema(self, db): + def loadSchema(self): """Load schema from database. If field is a date set value to true.""" schema = {} fieldlist = [] sql = "describe %s;" % self.statusTable - curs = db.cursor() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() try: curs.execute(sql) for row in curs.fetchall(): fieldlist.append(row[0]) - col = self.cleanstring(row[0]) + col = cleanstring(row[0]) if self.backend == "omnibus": type = row[1] in (1, 4, 7, 8) #different date types elif self.backend == "mysql": @@ -995,6 +1055,7 @@ self._fieldlist = fieldlist finally: curs.close() + cpool.put(conn) def eventControls(self): @@ -1011,11 +1072,15 @@ 'SELECT evid, "%s", "%s" ' % (userId, reason) + \ 'FROM %s ' % table + whereClause query = stmt + ' ' + whereClause - db = self.connect() - curs = db.cursor() - if toLog: curs.execute(insert) - curs.execute(query) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + if toLog: curs.execute(insert) + curs.execute(query) + finally: + curs.close() + cpool.put(conn) self.clearCache() self.manage_clearCache() @@ -1031,7 +1096,12 @@ eventClassKey = REQUEST['eventClassKey'], eventClass = REQUEST['eclass'], ) - evid = self.sendEvent(eventDict) + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + try: + evid = self.sendEvent(eventDict, conn) + finally: + cpool.put(conn) if REQUEST: REQUEST['RESPONSE'].redirect('/zport/dmd/Events/viewEvents') @@ -1082,10 +1152,14 @@ def manage_deleteHeartbeat(self, devname, REQUEST=None): if devname: delete = "delete from heartbeat where device = '%s'" % devname - db = self.connect() - curs = db.cursor() - curs.execute(delete); - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(delete); + finally: + curs.close() + cpool.put(conn) if REQUEST: return self.callZenScreen(REQUEST) @@ -1128,16 +1202,20 @@ sel = """select eventClassKey, eventClass, message from %s where evid in ('%s')""" sel = sel % (self.statusTable, "','".join(evids)) - db = self.connect() - curs = db.cursor() - curs.execute(sel); - for row in curs.fetchall(): - evclasskey, curevclass, msg = row - if curevclass != Unknown or not evclasskey: continue - evmap = evclass.createInstance(evclasskey) - evmap.eventClassKey = evclasskey - evmap.example = msg - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + curs.execute(sel); + for row in curs.fetchall(): + evclasskey, curevclass, msg = row + if curevclass != Unknown or not evclasskey: continue + evmap = evclass.createInstance(evclasskey) + evmap.eventClassKey = evclasskey + evmap.example = msg + finally: + curs.close() + cpool.put(conn) if REQUEST: if len(evids) == 1 and evmap: return evmap() elif evclass and evmap: return evclass() @@ -1147,10 +1225,13 @@ def manage_refreshConversions(self, REQUEST=None): """get the conversion information from the omnibus server""" assert(self == self.dmd.ZenEventManager) - db = self.connect() - self.loadSchema(db) - self.dmd.ZenEventHistory.loadSchema(db) - db.close() + self.loadSchema() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + try: + self.dmd.ZenEventHistory.loadSchema(conn) + finally: + cpool.put(conn) if REQUEST: return self.callZenScreen(REQUEST) @@ -1193,14 +1274,15 @@ security.declareProtected('Manage EventManager','manage_clearHeartbeats') def manage_clearHeartbeats(self, REQUEST=None): """truncate heartbeat table""" - db = self.connect() - cursor = db.cursor() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + cursor = conn.cursor() try: sql = 'truncate table heartbeat' cursor.execute(sql) finally: cursor.close() - db.close() + cpool.put(conn) if REQUEST: return self.callZenScreen(REQUEST) security.declareProtected('Manage EventManager','zmanage_editProperties') @@ -1221,14 +1303,18 @@ if not evid: return userId = getSecurityManager().getUser().getId() - db = self.connect() - insert = 'INSERT INTO log (evid, userName, text) ' - insert += 'VALUES ("%s", "%s", "%s")' % (evid, - userId, - db.escape_string(message)) - curs = db.cursor() - curs.execute(insert) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.backend, host=self.host, port=self.port, username=self.username, password=self.password, database=self.database) + curs = conn.cursor() + try: + insert = 'INSERT INTO log (evid, userName, text) ' + insert += 'VALUES ("%s", "%s", "%s")' % (evid, + userId, + conn.escape_string(message)) + curs.execute(insert) + finally: + curs.close() + cpool.put(conn) self.clearCache('evid' + evid) if REQUEST: return self.callZenScreen(REQUEST) Modified: trunk/Products/ZenEvents/MySqlEventManager.py =================================================================== --- trunk/Products/ZenEvents/MySqlEventManager.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/MySqlEventManager.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -10,6 +10,8 @@ from MySqlSendEvent import MySqlSendEventMixin from Exceptions import * +from DbConnectionPool import DbConnectionPool + def manage_addMySqlEventManager(context, id=None, evtuser="root", evtpass="", evtdb="events", history=False, REQUEST=None): '''make an MySqlEventManager''' @@ -65,26 +67,37 @@ #print select sevsum = self.checkCache(select) if sevsum: return sevsum - db = self.connect() - curs = db.cursor() - curs.execute(select) - sumdata = {} - ownerids = "" - for row in curs.fetchall(): - sev, count, acks = row[:3] - if hasattr(acks, 'tostring'): - acks = acks.tostring() - if type(acks) in types.StringTypes: - acks = acks.split(",") - ackcount = sum([int(n) for n in acks if n.strip()]) - sumdata[sev] = (ackcount, count) - sevsum = [] - for name, value in self.getSeverities(): - if value < severity: continue - css = self.getEventCssClass(value) - ackcount, count = sumdata.get(value, [0,0]) - sevsum.append([css, ackcount, int(count)]) - db.close() + + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + curs.execute(select) + sumdata = {} + ownerids = "" + for row in curs.fetchall(): + sev, count, acks = row[:3] + if hasattr(acks, 'tostring'): + acks = acks.tostring() + if type(acks) in types.StringTypes: + acks = acks.split(",") + ackcount = sum([int(n) for n in acks if n.strip()]) + sumdata[sev] = (ackcount, count) + sevsum = [] + for name, value in self.getSeverities(): + if value < severity: continue + css = self.getEventCssClass(value) + ackcount, count = sumdata.get(value, [0,0]) + sevsum.append([css, ackcount, int(count)]) + finally: + curs.close() + cpool.put(conn) + self.addToCache(select, sevsum) self.cleanCache() return sevsum @@ -93,8 +106,14 @@ ''' since is number of seconds since epoch, see documentation for python time.time() ''' - db = self.connect() - curs = db.cursor() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() count = 0 try: for table in ('status', 'history'): @@ -108,7 +127,7 @@ count += curs.fetchall()[0][0] finally: curs.close() - db.close() + cpool.put(conn) return count InitializeClass(MySqlEventManager) Modified: trunk/Products/ZenEvents/MySqlSendEvent.py =================================================================== --- trunk/Products/ZenEvents/MySqlSendEvent.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/MySqlSendEvent.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -9,7 +9,6 @@ from ZEO.Exceptions import ClientDisconnected import Products.ZenUtils.guid as guid -from DbAccessBase import DbAccessBase from Event import Event, EventHeartbeat, buildEventFromDict from ZenEventClasses import Heartbeat, Unknown from Products.ZenEvents.Exceptions import * @@ -30,14 +29,14 @@ send the event to the backend. """ - def sendEvent(self, event, db=None): + def sendEvent(self, event, conn): """Send an event to the backend. """ if type(event) == types.DictType: event = buildEventFromDict(event) if getattr(event, 'eventClass', Unknown) == Heartbeat: - return self._sendHeartbeat(event, db) + return self._sendHeartbeat(event, conn) for field in self.requiredEventFields: if not hasattr(event, field): @@ -57,7 +56,7 @@ # check again for heartbeat after context processing if getattr(event, 'eventClass', Unknown) == Heartbeat: - return self._sendHeartbeat(event, db) + return self._sendHeartbeat(event, conn) if not hasattr(event, 'dedupid'): @@ -83,10 +82,7 @@ evid = None try: try: - if db == None: - db = self.connect() - cleanup = db.close - evid = self.doSendEvent(event, db) + evid = self.doSendEvent(event, conn) except ProgrammingError, e: log.exception(e) except OperationalError, e: @@ -96,37 +92,40 @@ cleanup() return evid - def doSendEvent(self, event, db): + def doSendEvent(self, event, conn): insert = "" statusdata, detaildata = self.eventDataMaps(event) - curs = db.cursor() - evid = guid.generate() - event.evid = evid - if event.severity == 0: - event._action = "history" - clearcls = event.clearClasses() - if clearcls: - execute(curs, self.buildClearUpdate(event, clearcls)) - insert = ('insert into log ' - '(evid, userName, text) ' - 'select evid, "admin", "auto cleared"' - ' from status where clearid = "%s"' % evid) - execute(curs, insert) - stmt = self.buildStatusInsert(statusdata, event._action, evid) - rescount = execute(curs, stmt) - if detaildata and rescount == 1: - execute(curs, self.buildDetailInsert(evid, detaildata)) - if rescount != 1: - sql = ('select evid from %s where dedupid="%s"' % ( - event._action, event.dedupid)) - execute(curs, sql) - rs = curs.fetchone() - if rs: - evid = rs[0] - else: - evid = None - delete = 'DELETE FROM status WHERE clearid IS NOT NULL' - execute(curs, delete) + curs = conn.cursor() + try: + evid = guid.generate() + event.evid = evid + if event.severity == 0: + event._action = "history" + clearcls = event.clearClasses() + if clearcls: + execute(curs, self.buildClearUpdate(event, clearcls)) + insert = ('insert into log ' + '(evid, userName, text) ' + 'select evid, "admin", "auto cleared"' + ' from status where clearid = "%s"' % evid) + execute(curs, insert) + stmt = self.buildStatusInsert(statusdata, event._action, evid) + rescount = execute(curs, stmt) + if detaildata and rescount == 1: + execute(curs, self.buildDetailInsert(evid, detaildata)) + if rescount != 1: + sql = ('select evid from %s where dedupid="%s"' % ( + event._action, event.dedupid)) + execute(curs, sql) + rs = curs.fetchone() + if rs: + evid = rs[0] + else: + evid = None + delete = 'DELETE FROM status WHERE clearid IS NOT NULL' + execute(curs, delete) + finally: + curs.close() return evid @@ -181,7 +180,7 @@ return evt - def _sendHeartbeat(self, event, db=None): + def _sendHeartbeat(self, event, conn): """Build insert to add heartbeat record to heartbeat table. """ evdict = {} @@ -203,20 +202,17 @@ insert += " on duplicate key update lastTime=Null" insert += ", timeout=%s" % evdict['timeout'] try: - close = False - if db == None: - db = self.connect() - close = True - curs = db.cursor() - execute(curs, insert) - if close: db.close() + curs = conn.cursor() + try: + execute(curs, insert) + finally: + curs.close() except ProgrammingError, e: log.error(insert) log.exception(e) except OperationalError, e: raise ZenBackendFailure(str(e)) - def buildStatusInsert(self, statusdata, table, evid): """ Build an insert statement for the status table that looks like this: @@ -314,7 +310,7 @@ -class MySqlSendEvent(DbAccessBase, MySqlSendEventMixin): +class MySqlSendEvent(MySqlSendEventMixin): """ class that can connect to backend must be passed: username - backend username to use @@ -348,8 +344,7 @@ value = getattr(zem, att) setattr(self, att, value) self._fieldlist = zem.getFieldList() - - + def stop(self): pass @@ -368,7 +363,6 @@ self.setName("SendEventThread") self._evqueue = Queue() - def sendEvent(self, evt): """Called from main thread to put an event on to the send queue. """ @@ -377,17 +371,15 @@ def run(self): log.info("starting") - db = self.connect() while not self._evqueue.empty() or self.running: try: - evt = self._evqueue.get(True,1) - MySqlSendEvent.sendEvent(self, evt, db) + evt = self._evqueue.get(True,1) + MySqlSendEvent.sendEvent(self, evt) except Empty: pass except OperationalError: log.warn(e) - except Exception, e: - log.exception(e) - db.close() + except Exception, e: + log.exception(e) log.info("stopped") Modified: trunk/Products/ZenEvents/tests/testMySqlEventManager.py =================================================================== --- trunk/Products/ZenEvents/tests/testMySqlEventManager.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/tests/testMySqlEventManager.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -6,6 +6,7 @@ from Products.ZenUtils.ZCmdBase import ZCmdBase from Products.ZenEvents.Event import Event from Products.ZenEvents.Exceptions import * +from DbConnectionPool import DbConnectionPool zodb = ZCmdBase(noopts=True) @@ -29,13 +30,22 @@ def tearDown(self): transaction.abort() - db = self.zem.connect() - curs = db.cursor() - curs.execute("truncate status") - curs.execute("truncate detail") - curs.execute("truncate log") - curs.execute("truncate history") - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + curs.execute("truncate status") + curs.execute("truncate detail") + curs.execute("truncate log") + curs.execute("truncate history") + finally: + curs.close() + cpool.put(conn) zodb.closedb() self.dmd = None self.zem = None Modified: trunk/Products/ZenEvents/tests/testMySqlSendEvent.py =================================================================== --- trunk/Products/ZenEvents/tests/testMySqlSendEvent.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/tests/testMySqlSendEvent.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -10,8 +10,8 @@ from Products.ZenEvents.MySqlSendEvent import MySqlSendEventThread from Products.ZenEvents.Event import Event from Products.ZenEvents.Exceptions import * +from DbConnectionPool import DbConnectionPool - class MySqlSendEventThreadTest(unittest.TestCase): def setUp(self): @@ -21,10 +21,19 @@ def tearDown(self): transaction.abort() - db = self.zem.connect() - curs = db.cursor() - curs.execute("truncate status") - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + curs.execute("truncate status") + finally: + curs.close() + cpool.put(conn) zodb.closedb() self.zem = None Modified: trunk/Products/ZenEvents/zenactions.py =================================================================== --- trunk/Products/ZenEvents/zenactions.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenEvents/zenactions.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -35,6 +35,7 @@ from twisted.internet import reactor from twisted.internet.protocol import ProcessProtocol from DateTime import DateTime +from DbConnectionPool import DbConnectionPool def _capitalize(s): return s[0:1].upper() + s[1:] @@ -349,13 +350,21 @@ """ self.loadActionRules() zem = self.dmd.ZenEventManager - db = zem.connect() - self.eventCommands(db, zem) - self.processRules(db, zem) - self.checkVersion(self.dmd, zem) - self.maintenance(db, zem) - self.heartbeatEvents(db) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=zem.backend, + host=zem.host, + port=zem.port, + username=zem.username, + password=zem.password, + database=zem.database) + try: + self.eventCommands(conn, zem) + self.processRules(conn, zem) + self.checkVersion(self.dmd, zem) + self.maintenance(conn, zem) + self.heartbeatEvents(conn) + finally: + cpool.put(conn) def runCycle(self): Modified: trunk/Products/ZenModel/Device.py =================================================================== --- trunk/Products/ZenModel/Device.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenModel/Device.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -60,6 +60,8 @@ from ZenDate import ZenDate from Exceptions import * +from Products.ZenEvents.DbConnectionPool import DbConnectionPool + def manage_createDevice(context, deviceName, devicePath="/Discovered", tag="", serialNumber="", zSnmpCommunity="", zSnmpPort=161, zSnmpVer="v1", @@ -906,11 +908,20 @@ """ self.productionState = int(state) try: - db = self.ZenEventManager.connect() - curs = db.cursor() - curs.execute("update status set prodState=%d where device='%s'" % ( - self.productionState, self.id)) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + curs.execute("update status set prodState=%d where device='%s'" % ( + self.productionState, self.id)) + finally: + curs.close() + cpool.put(conn) except OperationalError: log.exception("failed to update events with new prodState") @@ -920,11 +931,20 @@ """ self.priority = int(priority) try: - db = self.ZenEventManager.connect() - curs = db.cursor() - curs.execute("update status set DevicePriority=%d where device='%s'" % ( - self.priority, self.id)) - db.close() + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + curs.execute("update status set DevicePriority=%d where device='%s'" % ( + self.priority, self.id)) + finally: + curs.close() + cpool.put(conn) except OperationalError: log.exception("failed to update events with new priority") Modified: trunk/Products/ZenModel/migrate/clearid.py =================================================================== --- trunk/Products/ZenModel/migrate/clearid.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenModel/migrate/clearid.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -64,12 +64,24 @@ pass def cutover(self, dmd): - c = dmd.ZenEventManager.connect() - s = c.cursor() - cmd = 'ALTER TABLE %s ADD COLUMN (clearid char(25))' - self.execute(s, cmd % 'status') - self.execute(s, cmd % 'history') - self.execute(s, 'DROP TRIGGER status_delete') - self.execute(s, trigger) + from Products.ZenEvents.DbConnectionPool import DbConnectionPool + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + cmd = 'ALTER TABLE %s ADD COLUMN (clearid char(25))' + self.execute(curs, cmd % 'status') + self.execute(curs, cmd % 'history') + self.execute(curs, 'DROP TRIGGER status_delete') + self.execute(curs, trigger) + finally: + curs.close() + cpool.put(conn) + ClearId() Modified: trunk/Products/ZenModel/migrate/command.py =================================================================== --- trunk/Products/ZenModel/migrate/command.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenModel/migrate/command.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -22,10 +22,20 @@ os.path.join(os.environ['ZENHOME'], 'libexec')) if dmd.Devices.hasProperty("zNagiosCycleTime"): dmd.Devices._delProperty("zNagiosCycleTime") - c = dmd.ZenEventManager.connect() - s = c.cursor() - for name in 'zenagios', 'zencacti': - s.execute('DELETE FROM heartbeat where component = "%s"' % name) - + from Products.ZenEvents.DbConnectionPool import DbConnectionPool + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd.ZenEventManager.username, + password=self.dmd.ZenEventManager.password, + database=self.dmd.ZenEventManager.database) + curs = conn.cursor() + try: + for name in 'zenagios', 'zencacti': + curs.execute('DELETE FROM heartbeat where component = "%s"' % name) + finally: + curs.close() + cpool.put(conn) Commands() Modified: trunk/Products/ZenModel/migrate/devicepriority.py =================================================================== --- trunk/Products/ZenModel/migrate/devicepriority.py 2007-02-20 17:26:40 UTC (rev 4109) +++ trunk/Products/ZenModel/migrate/devicepriority.py 2007-02-21 19:53:48 UTC (rev 4110) @@ -65,14 +65,24 @@ pass def cutover(self, dmd): - c = dmd.ZenEventManager.connect() - s = c.cursor() - cmd = 'ALTER TABLE %s ADD COLUMN ' + \ - '(DevicePriority smallint(6) default 3)' - self.execute(s, cmd % 'status') - self.execute(s, cmd % 'history') - self.execute(s, 'DROP TRIGGER status_delete') - self.execute(s, trigger) - c.close() + from Products.ZenEvents.DbConnectionPool import DbConnectionPool + cpool = DbConnectionPool() + conn = cpool.get(backend=self.dmd.ZenEventManager.backend, + host=self.dmd.ZenEventManager.host, + port=self.dmd.ZenEventManager.port, + username=self.dmd... [truncated message content] |
From: <sv...@ze...> - 2007-02-20 17:27:21
|
Author: chris Date: 2007-02-20 11:26:40 -0600 (Tue, 20 Feb 2007) New Revision: 4109 Modified: trunk/inst/build-functions.sh Log: include killing off of any zenoss processes that are running prior to compilation. this avoids a conflict with port 8100 (zeo). fixes #933 Modified: trunk/inst/build-functions.sh =================================================================== --- trunk/inst/build-functions.sh 2007-02-19 23:24:11 UTC (rev 4108) +++ trunk/inst/build-functions.sh 2007-02-20 17:26:40 UTC (rev 4109) @@ -391,6 +391,9 @@ # purge the last backup purge_backup + # kill off any running zenoss processes + kill_running + # build the external libs and download zenoss compile |
From: <sv...@ze...> - 2007-02-19 23:24:45
|
Author: ecn Date: 2007-02-19 17:24:11 -0600 (Mon, 19 Feb 2007) New Revision: 4108 Modified: trunk/Products/ZenModel/Device.py trunk/Products/ZenModel/PerformanceConf.py trunk/Products/ZenRRD/zenperfsnmp.py trunk/Products/ZenRRD/zenprocess.py Log: run faster & jump higher * move snmp status loading to a separate function * one function means one mysql call Modified: trunk/Products/ZenModel/Device.py =================================================================== --- trunk/Products/ZenModel/Device.py 2007-02-19 02:44:23 UTC (rev 4107) +++ trunk/Products/ZenModel/Device.py 2007-02-19 23:24:11 UTC (rev 4108) @@ -412,7 +412,7 @@ return cmps def getSnmpConnInfo(self): - return (self.id, self.getSnmpStatus(), + return (self.id, (self.manageIp, self.zSnmpPort), (self.zSnmpCommunity, self.zSnmpVer, self.zSnmpTimeout, self.zSnmpTries)) Modified: trunk/Products/ZenModel/PerformanceConf.py =================================================================== --- trunk/Products/ZenModel/PerformanceConf.py 2007-02-19 02:44:23 UTC (rev 4107) +++ trunk/Products/ZenModel/PerformanceConf.py 2007-02-19 23:24:11 UTC (rev 4108) @@ -34,6 +34,8 @@ from Products.ZenUtils.Exceptions import ZentinelException from Products.ZenUtils.Utils import basicAuthUrl +from Products.ZenEvents.ZenEventClasses import Status_Snmp + from Monitor import Monitor from StatusColor import StatusColor @@ -128,7 +130,7 @@ for dev in self.devices(): if devname and dev.id != devname: continue dev = dev.primaryAq() - if dev.monitorDevice() and dev.getSnmpStatus() != -1: + if dev.monitorDevice(): try: result.append(dev.getSnmpOidTargets()) except POSError: raise @@ -137,6 +139,32 @@ return result + security.declareProtected('View','getDevices') + def getSnmpStatus(self, devname=None): + "Return the failure counts for Snmp" + result = [] + counts = {} + try: + # get all the events with /Status/Snmp + db = self.ZenEventManager.connect() + curs = db.cursor() + cmd = ('SELECT device, sum(count) ' + + ' FROM status ' + + ' WHERE eventClass = "%s"' % Status_Snmp) + if devname: + cmd += ' AND device = "%s"' % devname + cmd += ' GROUP BY device' + curs.execute(cmd); + counts = dict([(d, c) for d, c in curs.fetchall()]) + db.close() + except Exception, ex: + log.exception('Unable to get Snmp Status') + raise + if devname: + return [(devname, counts.get(devname, 0))] + return [(dev.id, counts.get(dev.id, 0)) for dev in self.devices()] + + def getOSProcessConf(self, devname=None): '''Get the OS Process configuration for all devices. ''' @@ -144,7 +172,7 @@ for dev in self.devices(): if devname and dev.id != devname: continue dev = dev.primaryAq() - if dev.monitorDevice() and dev.getSnmpStatus() != -1: + if dev.monitorDevice(): try: procinfo = dev.getOSProcessConf() if procinfo is None: continue Modified: trunk/Products/ZenRRD/zenperfsnmp.py =================================================================== --- trunk/Products/ZenRRD/zenperfsnmp.py 2007-02-19 02:44:23 UTC (rev 4107) +++ trunk/Products/ZenRRD/zenperfsnmp.py 2007-02-19 23:24:11 UTC (rev 4108) @@ -220,10 +220,13 @@ self.syncdb() driveLater(self.configCycleInterval * 60, self.startUpdateConfig) - + yield self.model.callRemote('getDevices', self.options.device) self.updateDeviceList(driver.next()) + yield self.model.callRemote('getSnmpStatus', self.options.device) + self.updateSnmpStatus(driver.next()) + yield self.model.callRemote('propertyItems') self.setPropertyItems(driver.next()) @@ -264,7 +267,7 @@ def updateAgentProxy(self, - deviceName, snmpStatus, ip, port, community, + deviceName, ip, port, community, version, timeout, tries, maxoids=40): "create or update proxy" # find any cached proxy @@ -277,7 +280,7 @@ protocol=self.snmpPort.protocol, allowCache=True) p.oidMap = {} - p.snmpStatus = SnmpStatus(snmpStatus) + p.snmpStatus = SnmpStatus(0) p.singleOidMode = False else: p.ip = ip @@ -289,10 +292,16 @@ p.maxoids = maxoids return p + def updateSnmpStatus(self, status): + "Update the Snmp failure counts from Status database" + countMap = dict(status) + for name, proxy in self.proxies.items(): + proxy.snmpStatus.count = countMap.get(name, 0) + def updateDeviceConfig(self, snmpTargets): 'Save the device configuration and create an SNMP proxy to talk to it' - (deviceName, snmpStatus, hostPort, snmpConfig), oidData, maxOIDs = snmpTargets + (deviceName, hostPort, snmpConfig), oidData, maxOIDs = snmpTargets if not oidData: return (ip, port)= hostPort (community, version, timeout, tries) = snmpConfig @@ -301,7 +310,7 @@ version = '1' else: version = '2' - p = self.updateAgentProxy(deviceName, snmpStatus, + p = self.updateAgentProxy(deviceName, ip, port, str(community), version, timeout, tries, maxOIDs) for name, oid, path, dsType, createCmd, minmax, thresholds in oidData: Modified: trunk/Products/ZenRRD/zenprocess.py =================================================================== --- trunk/Products/ZenRRD/zenprocess.py 2007-02-19 02:44:23 UTC (rev 4107) +++ trunk/Products/ZenRRD/zenprocess.py 2007-02-19 23:24:11 UTC (rev 4108) @@ -248,7 +248,7 @@ yield self.fetchConfig(); n = driver.next() removed = Set(self.devices.keys()) - for (name, snmpStatus, addr, snmpConf), procs in n: + for (name, addr, snmpConf), procs in n: community, version, timeout, tries = snmpConf removed.discard(name) d = self.devices.setdefault(name, Device()) @@ -260,15 +260,24 @@ d.tries = tries d.updateConfig(procs) d.protocol = self.snmpPort.protocol - d.snmpStatus = snmpStatus for r in removed: del self.devices[r] + yield self.model.callRemote('getSnmpStatus', self.options.device) + self.updateSnmpStatus(driver.next()) + # fetch pids with an SNMP scan yield self.findPids(self.devices.values()); driver.next() driveLater(self.configCycleInterval * 60, self.start) + def updateSnmpStatus(self, updates): + for name, count in updates: + d = self.devices.get(name) + if d: + d.snmpStatus = count + + def findPids(self, devices): "Scan all devices for process names and args" jobs = NJobs(PARALLEL_JOBS, self.scanDevice, devices) |
From: <sv...@ze...> - 2007-02-19 02:44:50
|
Author: ahajda Date: 2007-02-18 20:44:23 -0600 (Sun, 18 Feb 2007) New Revision: 4107 Modified: trunk/wmi/Samba/source/lib/com/dcom/main.c trunk/wmi/Samba/source/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm trunk/wmi/Samba/source/wmi/wbemdata.c Log: pidl now generates async and sync versions of dcom proxy calls Modified: trunk/wmi/Samba/source/lib/com/dcom/main.c =================================================================== --- trunk/wmi/Samba/source/lib/com/dcom/main.c 2007-02-16 23:25:12 UTC (rev 4106) +++ trunk/wmi/Samba/source/lib/com/dcom/main.c 2007-02-19 02:44:23 UTC (rev 4107) @@ -324,7 +324,8 @@ * idl_iface_by_uuid can't return NULL */ /* status = dcerpc_secondary_context(p, &p2, idl_iface_by_uuid(&iid)); */ status = dcerpc_alter_context(p, p, &idl_iface_by_uuid(&iid)->syntax_id, &p->transfer_syntax); - } + } else + status = NT_STATUS_OK; *pp = p; return status; } Modified: trunk/wmi/Samba/source/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm =================================================================== --- trunk/wmi/Samba/source/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm 2007-02-16 23:25:12 UTC (rev 4106) +++ trunk/wmi/Samba/source/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm 2007-02-19 02:44:23 UTC (rev 4107) @@ -89,33 +89,99 @@ my $name = $fn->{NAME}; my $uname = uc $name; + ##### *_state struct ######################################### $res.=" -static " . mapType($fn->{RETURN_TYPE}) . " dcom_proxy_$interface->{NAME}_$name(struct $interface->{NAME} *d, TALLOC_CTX *mem_ctx" . Parse::Pidl::Samba4::COM::Header::GetArgumentProtoList($fn) . ") +struct dcom_proxy_$interface->{NAME}_${name}_state { + struct $interface->{NAME} *d; + struct ORPCTHAT that; + struct $name r; +"; + foreach my $a (@{$fn->{ELEMENTS}}) { + next unless (has_property($a, "out")); + if (Parse::Pidl::Typelist::typeIs($a->{TYPE}, "INTERFACE")) { +# if (!has_property($a, "in")) { + $res.="\tstruct $a->{TYPE} " . "*"x$a->{POINTERS} ."$a->{NAME};\n" +# } + } + } + $res.="};\n"; + #### *_continue ############################################## + $res.=" +static void dcom_proxy_$interface->{NAME}_${name}_continue(struct rpc_request *req) { - struct dcerpc_pipe *p; - NTSTATUS status = dcom_get_pipe((struct IUnknown *)d, &p); - struct $name r; - struct ORPCTHAT that; + struct composite_context *c; + struct dcom_proxy_$interface->{NAME}_${name}_state *s; + NTSTATUS status; + uint32_t flags; - if (NT_STATUS_IS_ERR(status)) { - return "; - if ($fn->{RETURN_TYPE} eq "NTSTATUS") { - $res.="status"; - } elsif ($fn->{RETURN_TYPE} eq "WERROR") { - $res.="ntstatus_to_werror(status)"; - } elsif ($fn->{RETURN_TYPE} eq "uint32") { - $res.="0UL"; + c = talloc_get_type(req->async.private, struct composite_context); + s = talloc_get_type(c->private_data, struct dcom_proxy_$interface->{NAME}_${name}_state); + + flags = req->p->conn->flags; + status = dcerpc_ndr_request_recv(req); + if (!NT_STATUS_IS_OK(status)) { + composite_error(c, status); + return; + } + + if (flags & DCERPC_DEBUG_PRINT_OUT) { + NDR_PRINT_OUT_DEBUG($name, &s->r); + } + +"; + foreach $a (@{$fn->{ELEMENTS}}) { + next unless (has_property($a, "out")); + + if (Parse::Pidl::Typelist::typeIs($a->{TYPE}, "INTERFACE")) { + $res .= +" if (s->r.out.$a->{NAME}) { + status = dcom_IUnknown_from_OBJREF(s->d->ctx, (struct IUnknown **)s->$a->{NAME}, &(**s->r.out.$a->{NAME}).obj); + if (*s->r.out.$a->{NAME}) talloc_free(*s->r.out.$a->{NAME}); + talloc_free(s->r.out.$a->{NAME}); } - $res.="; +"; + } } + $res.=" + if (!NT_STATUS_IS_OK(status)) { + composite_error(c, status); + return; + } - ZERO_STRUCT(r); - r.in.ORPCthis.version.MajorVersion = COM_MAJOR_VERSION; - r.in.ORPCthis.version.MinorVersion = COM_MINOR_VERSION; - r.in.ORPCthis.cid = GUID_random(); - r.out.ORPCthat = &that; + composite_done(c); +} "; - + #### *_async ################################################# + $res.=" +static struct composite_context *dcom_proxy_$interface->{NAME}_${name}_async(struct $interface->{NAME} *d, TALLOC_CTX *mem_ctx" . Parse::Pidl::Samba4::COM::Header::GetArgumentProtoList($fn) . ") +{ + struct composite_context *c; + struct dcom_proxy_$interface->{NAME}_${name}_state *s; + struct dcerpc_pipe *p; + struct rpc_request *req; + NTSTATUS status; + + c = composite_create(mem_ctx, d->ctx->event_ctx); + if (c == NULL) return NULL; + + s = talloc_zero(c, struct dcom_proxy_$interface->{NAME}_${name}_state); + if (composite_nomem(s, c)) return c; + c->private_data = s; + + status = dcom_get_pipe((struct IUnknown *)d, &p); + if (!NT_STATUS_IS_OK(status)) { + composite_error(c, status); + return c; + } + + s->d = d; + + s->r.in.ORPCthis.version.MajorVersion = COM_MAJOR_VERSION; + s->r.in.ORPCthis.version.MinorVersion = COM_MINOR_VERSION; + s->r.in.ORPCthis.cid = GUID_random(); + s->r.out.ORPCthat = &s->that; +"; + # Put arguments into r foreach my $a (@{$fn->{ELEMENTS}}) { next unless (has_property($a, "in")); @@ -125,18 +191,22 @@ my $n; foreach $n (0..$a->{POINTERS}-1) { $res .=sprintf(("\t" x $n)."\tif (%s$a->{NAME}) {\n", ("*" x $n)); - $varname = ("*" x $n) . "r.in.$a->{NAME}"; - $res .=sprintf(("\t" x $n)."\t\t$varname = talloc_zero($ctx, struct MInterfacePointer %s);\n", ("*" x ($a->{POINTERS}-$n-1))); + $varname = ("*" x $n) . "s->r.in.$a->{NAME}"; + $res .=sprintf(("\t" x $n)."\t\t$varname = talloc_zero($ctx, struct MInterfacePointer%s);\n", ("*" x ($a->{POINTERS}-$n-1))); $ctx = $varname; } $n = $a->{POINTERS}-1; $res .=("\t" x $n)."\t\t(${varname})->size = sizeof(struct OBJREF);\n"; - $res .=sprintf(("\t" x $n)."\t\tWERR_NDR_CHECK(dcom_OBJREF_from_IUnknown(&(*$varname).obj, (struct IUnknown *)%s$a->{NAME}));\n", ("*" x ($a->{POINTERS}-1))); + $res .=sprintf(("\t" x $n)."\t\tstatus = dcom_OBJREF_from_IUnknown(&(*$varname).obj, (struct IUnknown *)%s$a->{NAME});\n", ("*" x ($a->{POINTERS}-1))); + $res .= ("\t" x $n)."\t\tif (!NT_STATUS_IS_OK(status)) {\n" + . ("\t" x $n)."\t\t\tcomposite_error(c, status);\n" + . ("\t" x $n)."\t\t\treturn c;\n" + . ("\t" x $n)."\t\t}\n"; for ($n =$a->{POINTERS}; $n > 0; --$n) { $res .=("\t" x $n)."}\n"; } } else { - $res .= "\tr.in.$a->{NAME} = $a->{NAME};\n"; + $res .= "\ts->r.in.$a->{NAME} = $a->{NAME};\n"; } } @@ -145,55 +215,56 @@ next unless (has_property($a, "out")); if (Parse::Pidl::Typelist::typeIs($a->{TYPE}, "INTERFACE")) { if (has_property($a, "in")) { - $res .= "\tr.out.$a->{NAME} = r.in.$a->{NAME};\n" + $res .= "\ts->r.out.$a->{NAME} = s->r.in.$a->{NAME};\n" + . "\ts->$a->{NAME} = $a->{NAME};\n"; } else { $res .= -" r.out.$a->{NAME} = talloc_zero(mem_ctx, struct MInterfacePointer *); - *r.out.$a->{NAME} = talloc_zero(mem_ctx, struct MInterfacePointer); - (*r.out.$a->{NAME})->size = sizeof(struct OBJREF); +" s->r.out.$a->{NAME} = talloc_zero(mem_ctx, struct MInterfacePointer *); + *s->r.out.$a->{NAME} = talloc_zero(mem_ctx, struct MInterfacePointer); + (*s->r.out.$a->{NAME})->size = sizeof(struct OBJREF); + s->$a->{NAME} = $a->{NAME}; "; } } else { - $res .= "\tr.out.$a->{NAME} = $a->{NAME};\n"; + $res .= "\ts->r.out.$a->{NAME} = $a->{NAME};\n"; } } $res .=" if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) { - NDR_PRINT_IN_DEBUG($name, &r); + NDR_PRINT_IN_DEBUG($name, &s->r); } - status = dcerpc_ndr_request(p, &d->obj.u_objref.u_standard.std.ipid, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, &r); + req = dcerpc_ndr_request_send(p, &d->obj.u_objref.u_standard.std.ipid, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, &s->r); + if (composite_nomem(req, c)) return c; - if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) { - NDR_PRINT_OUT_DEBUG($name, &r); - } - + req->async.private = c; + req->async.callback = dcom_proxy_$interface->{NAME}_${name}_continue; + return c; +} "; + #### sync ######################################################### + $res.=" +static " . mapType($fn->{RETURN_TYPE}) . " dcom_proxy_$interface->{NAME}_$name(struct $interface->{NAME} *d, TALLOC_CTX *mem_ctx" . Parse::Pidl::Samba4::COM::Header::GetArgumentProtoList($fn) . ") +{ + struct composite_context *c; + struct dcom_proxy_$interface->{NAME}_${name}_state *s; + NTSTATUS status; - # Put r info back into arguments - foreach $a (@{$fn->{ELEMENTS}}) { - next unless (has_property($a, "out")); + c = dcom_proxy_$interface->{NAME}_${name}_async(d, mem_ctx" . join("", map(", $_->{NAME}", @{$fn->{ELEMENTS}})) . "); + if (c) { + s = talloc_get_type(c->private_data, struct dcom_proxy_$interface->{NAME}_${name}_state); + status = composite_wait(c); + } - if (Parse::Pidl::Typelist::typeIs($a->{TYPE}, "INTERFACE")) { - $res .= -" if (r.out.$a->{NAME}) { - WERR_NDR_CHECK(dcom_IUnknown_from_OBJREF(d->ctx, (struct IUnknown **)$a->{NAME}, &(**r.out.$a->{NAME}).obj)); - talloc_free(*r.out.$a->{NAME}); - talloc_free(r.out.$a->{NAME}); - } "; - } - + if ($fn->{RETURN_TYPE} eq "NTSTATUS") { + $res.="\treturn c?status:NT_STATUS_NO_MEMORY;\n"; + } elsif ($fn->{RETURN_TYPE} eq "WERROR") { + $res.="\treturn c? (NT_STATUS_IS_OK(status)?s->r.out.result:ntstatus_to_werror(status)):WERR_NOMEM;\n"; + } elsif ($fn->{RETURN_TYPE} eq "uint32") { + $res.="\t return 0UL;\n"; } - - if (($fn->{RETURN_TYPE} ne "void")) { - my %err_map = ("WERROR" => "ntstatus_to_werror(status)", "uint32" => "0"); - my $err_exp = $err_map{$fn->{RETURN_TYPE}}; - print STDERR "Unknown return type: $fn->{RETURN_TYPE}\n" if !defined $err_exp; - $res .= "\tif (!NT_STATUS_IS_OK(status)) return $err_exp;\n"; - $res .= "\treturn r.out.result;\n"; - } - $res .= "}\n\n"; + $res.="}\n"; } ##################################################################### @@ -250,8 +321,10 @@ $res .= "#include \"includes.h\"\n" . "#include \"librpc/rpc/dcerpc.h\"\n" . "#include \"lib/com/dcom/dcom.h\"\n" . - "#include \"$comh_filename\"\n"; + "#include \"$comh_filename\"\n" . + "#include \"libcli/composite/composite.h\"\n"; + foreach (@{$pidl}) { next if ($_->{TYPE} ne "INTERFACE"); next if has_property($_, "local"); Modified: trunk/wmi/Samba/source/wmi/wbemdata.c =================================================================== --- trunk/wmi/Samba/source/wmi/wbemdata.c 2007-02-16 23:25:12 UTC (rev 4106) +++ trunk/wmi/Samba/source/wmi/wbemdata.c 2007-02-19 02:44:23 UTC (rev 4107) @@ -161,7 +161,7 @@ WERROR IWbemClassObject_GetMethod(struct IWbemClassObject *d, TALLOC_CTX *mem_ctx, const char *name, uint32_t flags, struct IWbemClassObject **in, struct IWbemClassObject **out) { - int i; + uint32_t i; struct WbemClassObject *wco; wco = (struct WbemClassObject *)d->object_data; @@ -176,7 +176,7 @@ void WbemClassObject_CreateInstance(struct WbemClassObject *wco) { - int i; + uint32_t i; wco->instance = talloc_zero(wco, struct WbemInstance); wco->instance->default_flags = talloc_array(wco->instance, uint8_t, wco->obj_class->__PROPERTY_COUNT); @@ -569,6 +569,12 @@ return status; } +int IEnumWbemClassObject_data_destructor(struct IEnumWbemClassObject_data *ecod) +{ +// struct REMINTERFACEREF rif[2] = { {ecod->pFSE->obj.u_objref.u_standard.std.ipid, 5, 0}, {ecod->pSE->obj.u_objref.u_standard.std.ipid, 5, 0} }; + return 0; +} + WERROR IEnumWbemClassObject_SmartNext(struct IEnumWbemClassObject *d, TALLOC_CTX *mem_ctx, int32_t lTimeout, uint32_t uCount, struct WbemClassObject **apObjects, uint32_t *puReturned) { WERROR result; @@ -597,6 +603,8 @@ ecod->guid1 = GUID_random(); ecod->guid2 = GUID_random(); + + talloc_set_destructor(ecod, IEnumWbemClassObject_data_destructor); } result = IWbemWCOSmartEnum_Next(ecod->pSE, loc_ctx, &ecod->guid1, lTimeout, uCount, 1, &ecod->guid2, puReturned, &size, &data); |
From: <sv...@ze...> - 2007-02-16 23:25:14
|
Author: edahl Date: 2007-02-16 17:25:12 -0600 (Fri, 16 Feb 2007) New Revision: 4106 Modified: trunk/Products/ZenEvents/SyslogProcessing.py Log: * minor tweek to r4068 fixes #999 Modified: trunk/Products/ZenEvents/SyslogProcessing.py =================================================================== --- trunk/Products/ZenEvents/SyslogProcessing.py 2007-02-16 22:37:32 UTC (rev 4105) +++ trunk/Products/ZenEvents/SyslogProcessing.py 2007-02-16 23:25:12 UTC (rev 4106) @@ -136,9 +136,8 @@ msg = m.group(2).strip() msglist = msg.split() if self.parsehost and not self.notHostSearch(msglist[0]): - evt.hostname = msglist[0] - evt.device = evt.hostname - slog.debug("parseHEADER hostname=%s", evt.hostname) + evt.device = msglist[0] + slog.debug("parseHEADER hostname=%s", evt.device) msg = " ".join(msglist[1:]) return evt, msg |
From: <sv...@ze...> - 2007-02-16 22:37:34
|
Author: marc Date: 2007-02-16 16:37:32 -0600 (Fri, 16 Feb 2007) New Revision: 4105 Modified: trunk/Products/ZenModel/IpNetwork.py trunk/Products/ZenModel/migrate/menus.py trunk/Products/ZenWidgets/skins/zenui/zenuimacros.pt Log: #759 * Added ZenMenuItem 'Tools/Discover Devices' to all IpNetworks * Added discoverDevices to IpNetwork * zendisc is run as a separate process * NOTE: need to add support for all 'Networks' sweep Modified: trunk/Products/ZenModel/IpNetwork.py =================================================================== --- trunk/Products/ZenModel/IpNetwork.py 2007-02-16 22:09:28 UTC (rev 4104) +++ trunk/Products/ZenModel/IpNetwork.py 2007-02-16 22:37:32 UTC (rev 4105) @@ -13,6 +13,8 @@ __version__ = "$Revision: 1.22 $"[11:-2] +import os +import sys import math import transaction import logging @@ -34,6 +36,8 @@ from Products.ZenModel.Exceptions import * +from Products.ZenUtils.Utils import setWebLoggingStream, clearWebLoggingStream + def manage_addIpNetwork(context, id, netmask=24, REQUEST = None): """make a IpNetwork""" net = IpNetwork(id, netmask=netmask) @@ -42,13 +46,14 @@ net = context._getOb(net.id) net.buildZProperties() net.createCatalog() + #manage_addZDeviceDiscoverer(context) if REQUEST is not None: REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main') - addIpNetwork = DTMLFile('dtml/addIpNetwork',globals()) + # when an ip is added the defaul location will be # into class A->B->C network tree defaultNetworkTree = (8,16,24) @@ -385,6 +390,64 @@ cat = zcat._catalog cat.addIndex('id', makeCaseInsensitiveFieldIndex('id')) zcat.addColumn('getPrimaryId') - - + + + def discoverDevices(self,REQUEST = None): + """ + Load a device into the database connecting its major relations + and collecting its configuration. + """ + if REQUEST: + response = REQUEST.RESPONSE + dlh = self.deviceLoggingHeader() + idx = dlh.rindex("</table>") + response.write(str(dlh[:idx])) + handler = setWebLoggingStream(response) + try: + zendiscCmd = "zendisc run --net=%s" % self.id + log.info('Executing command: %s' % zendiscCmd) + from popen2 import Popen4 + f = Popen4(zendiscCmd) + while 1: + s = f.fromchild.readline() + if not s: break + else: log.info(s) + log.info('Done') + except (SystemExit, KeyboardInterrupt): raise + except ZentinelException, e: + log.critical(e) + except: raise + if REQUEST: + self.loaderFooter(response) + clearWebLoggingStream(handler) + + + def setupLog(self, response): + """setup logging package to send to browser""" + from logging import StreamHandler, Formatter + root = logging.getLogger() + self._v_handler = StreamHandler(response) + fmt = Formatter("""<tr class="tablevalues"> + <td>%(asctime)s</td><td>%(levelname)s</td> + <td>%(name)s</td><td>%(message)s</td></tr> + """, "%Y-%m-%d %H:%M:%S") + self._v_handler.setFormatter(fmt) + root.addHandler(self._v_handler) + root.setLevel(10) + + + def clearLog(self): + log = logging.getLogger() + if getattr(self, "_v_handler", False): + log.removeHandler(self._v_handler) + + + def loaderFooter(self, response): + """add navigation links to the end of the loader output""" + response.write("""<tr class="tableheader"><td colspan="4"> + Navigate to network <a href=%s>%s</a></td></tr>""" + % (self.absolute_url(), self.id)) + response.write("</table></body></html>") + + InitializeClass(IpNetwork) Modified: trunk/Products/ZenModel/migrate/menus.py =================================================================== --- trunk/Products/ZenModel/migrate/menus.py 2007-02-16 22:09:28 UTC (rev 4104) +++ trunk/Products/ZenModel/migrate/menus.py 2007-02-16 22:37:32 UTC (rev 4105) @@ -139,7 +139,6 @@ permissions=('View',), allowed_classes=('Device',) ), - ], 'Device':[ dict( @@ -182,4 +181,15 @@ }) + dmd.Networks.buildMenus( + {'Tools':[ + dict( + id= 'discover', + description= 'Discover Devices', + action= 'discoverDevices', + allowed_classes='IpNetwork' + ), + ] + }) + MenuRelations() Modified: trunk/Products/ZenWidgets/skins/zenui/zenuimacros.pt =================================================================== --- trunk/Products/ZenWidgets/skins/zenui/zenuimacros.pt 2007-02-16 22:09:28 UTC (rev 4104) +++ trunk/Products/ZenWidgets/skins/zenui/zenuimacros.pt 2007-02-16 22:37:32 UTC (rev 4105) @@ -1,6 +1,6 @@ <tal:block metal:define-macro="contextmenu" tal:condition="python:hasattr(here, 'getMenus')" - tal:define="menu_ids menu_ids | python:['View','Edit']"> + tal:define="menu_ids menu_ids | python:['View','Edit','Tools']"> <link href="menus.css" rel="stylesheet" type="text/css" /> |
From: <sv...@ze...> - 2007-02-16 22:09:29
|
Author: chris Date: 2007-02-16 16:09:28 -0600 (Fri, 16 Feb 2007) New Revision: 4104 Modified: tags/zenoss-1.1.1/inst/zenoss.spec Log: * synchronized with tagname by zenpkg Modified: tags/zenoss-1.1.1/inst/zenoss.spec =================================================================== --- tags/zenoss-1.1.1/inst/zenoss.spec 2007-02-16 22:06:43 UTC (rev 4103) +++ tags/zenoss-1.1.1/inst/zenoss.spec 2007-02-16 22:09:28 UTC (rev 4104) @@ -40,8 +40,8 @@ # the RPM meta information Name: zenoss Summary: The Open Source Network Management System -Version: 1.1.0 -Release: 2 +Version: 1.1.1 +Release: 0 License: GPL Vendor: Zenoss, Inc. Packager: Christopher Blunck <ch...@ze...> |
From: <sv...@ze...> - 2007-02-16 22:06:49
|
Author: chris Date: 2007-02-16 16:06:43 -0600 (Fri, 16 Feb 2007) New Revision: 4103 Added: tags/zenoss-1.1.1/ Log: * auto-build of zenoss-1.1.1 by zenpkg Copied: tags/zenoss-1.1.1 (from rev 4102, branches/zenoss-1.1.x) |
From: <sv...@ze...> - 2007-02-16 22:03:58
|
Author: ecn Date: 2007-02-16 16:03:29 -0600 (Fri, 16 Feb 2007) New Revision: 4102 Modified: branches/zenoss-1.1.x/Products/ZenModel/ZVersion.py Log: preparing for 1.1.1 build Modified: branches/zenoss-1.1.x/Products/ZenModel/ZVersion.py =================================================================== --- branches/zenoss-1.1.x/Products/ZenModel/ZVersion.py 2007-02-16 21:47:59 UTC (rev 4101) +++ branches/zenoss-1.1.x/Products/ZenModel/ZVersion.py 2007-02-16 22:03:29 UTC (rev 4102) @@ -1 +1 @@ -VERSION="1.1.0" +VERSION="1.1.1" |
From: <sv...@ze...> - 2007-02-16 21:48:03
|
Author: ecn Date: 2007-02-16 15:47:59 -0600 (Fri, 16 Feb 2007) New Revision: 4101 Modified: branches/zenoss-1.1.x/Products/ZenUtils/Utils.py Log: * backport #943 unicode in id Modified: branches/zenoss-1.1.x/Products/ZenUtils/Utils.py =================================================================== --- branches/zenoss-1.1.x/Products/ZenUtils/Utils.py 2007-02-16 21:45:54 UTC (rev 4100) +++ branches/zenoss-1.1.x/Products/ZenUtils/Utils.py 2007-02-16 21:47:59 UTC (rev 4101) @@ -329,7 +329,7 @@ if len(id) > 1: id = id[1:] else: id = "-" id = _cleanend("",id) - return id + return str(id) def sendEmail(emsg, host, port=25, usetls=0, usr='', pwd=''): ''' Send an email. Return a tuple: |
From: <sv...@ze...> - 2007-02-16 21:45:56
|
Author: ecn Date: 2007-02-16 15:45:54 -0600 (Fri, 16 Feb 2007) New Revision: 4100 Modified: branches/zenoss-1.1.x/inst/build-functions.sh Log: * if you check out 1.1 branch of inst, you should be building 1.1 Modified: branches/zenoss-1.1.x/inst/build-functions.sh =================================================================== --- branches/zenoss-1.1.x/inst/build-functions.sh 2007-02-16 21:19:15 UTC (rev 4099) +++ branches/zenoss-1.1.x/inst/build-functions.sh 2007-02-16 21:45:54 UTC (rev 4100) @@ -42,7 +42,7 @@ # default to extracting the trunk if [ ! "$SVNTAG" ] ; then - export SVNTAG="trunk" + export SVNTAG="branches/zenoss-1.1.x" fi # the base directory for where zenoss will be installed |
From: <sv...@ze...> - 2007-02-16 21:20:06
|
Author: ecn Date: 2007-02-16 15:19:15 -0600 (Fri, 16 Feb 2007) New Revision: 4099 Added: branches/zenoss-1.1.x/inst/externallibs/TwistedSNMP-0.3.13.patch04 Log: #989 back-patching memory "leak" fix to 1.1.1 Added: branches/zenoss-1.1.x/inst/externallibs/TwistedSNMP-0.3.13.patch04 |
From: <sv...@ze...> - 2007-02-16 21:15:49
|
Author: ecn Date: 2007-02-16 15:15:47 -0600 (Fri, 16 Feb 2007) New Revision: 4098 Modified: trunk/Products/ZenEvents/Schedule.py Log: * bulletproof: don't wait for negative time Modified: trunk/Products/ZenEvents/Schedule.py =================================================================== --- trunk/Products/ZenEvents/Schedule.py 2007-02-16 20:13:29 UTC (rev 4097) +++ trunk/Products/ZenEvents/Schedule.py 2007-02-16 21:15:47 UTC (rev 4098) @@ -111,7 +111,7 @@ work = self.makeWorkList(now, self.workList) if work: - wait = work[0][0] - now + wait = max(0, work[0][0] - now) self.log.debug("Waiting %f seconds", wait) self.timer = self.callLater(wait) self.commit() |
From: <sv...@ze...> - 2007-02-16 20:13:32
|
Author: ecn Date: 2007-02-16 14:13:29 -0600 (Fri, 16 Feb 2007) New Revision: 4097 Modified: trunk/inst/docs/HelloWorldZenPack/objects/Hello_Menu.xml Log: * oops... can't add Devices to the ZenPack! Modified: trunk/inst/docs/HelloWorldZenPack/objects/Hello_Menu.xml =================================================================== --- trunk/inst/docs/HelloWorldZenPack/objects/Hello_Menu.xml 2007-02-16 20:09:12 UTC (rev 4096) +++ trunk/inst/docs/HelloWorldZenPack/objects/Hello_Menu.xml 2007-02-16 20:13:29 UTC (rev 4097) @@ -1,8 +1,6 @@ <?xml version="1.0"?> <objects> -<object id='/zport/dmd/Devices' module='Products.ZenModel.DeviceClass' class='DeviceClass'> -<tomanycont id='zenMenus'> -<object id='View' module='Products.ZenModel.ZenMenu' class='ZenMenu'> +<object id='/zport/dmd/Devices/zenMenus/View' module='Products.ZenModel.ZenMenu' class='ZenMenu'> <tomanycont id='zenMenuItems'> <object id='hello' module='Products.ZenModel.ZenMenuItem' class='ZenMenuItem'> <property type="text" id="description" mode="w" > @@ -20,6 +18,4 @@ </object> </tomanycont> </object> -</tomanycont> -</object> </objects> |
From: <sv...@ze...> - 2007-02-16 20:09:40
|
Author: ecn Date: 2007-02-16 14:09:12 -0600 (Fri, 16 Feb 2007) New Revision: 4096 Added: trunk/Products/ZenModel/ZenPackable.py trunk/Products/ZenModel/skins/zenmodel/viewPackDetail.pt trunk/Products/ZenModel/skins/zenmodel/viewZenPacks.pt trunk/Products/ZenWidgets/skins/zenui/dialog_addToZenPack.pt Modified: trunk/Products/ZenEvents/EventClass.py trunk/Products/ZenEvents/EventClassInst.py trunk/Products/ZenEvents/EventCommand.py trunk/Products/ZenModel/DeviceOrganizer.py trunk/Products/ZenModel/Manufacturer.py trunk/Products/ZenModel/MibBase.py trunk/Products/ZenModel/OSProcess.py trunk/Products/ZenModel/Organizer.py trunk/Products/ZenModel/RRDDataPoint.py trunk/Products/ZenModel/RRDDataSource.py trunk/Products/ZenModel/RRDTemplate.py trunk/Products/ZenModel/RRDThreshold.py trunk/Products/ZenModel/Report.py trunk/Products/ZenModel/ReportClass.py trunk/Products/ZenModel/Service.py trunk/Products/ZenModel/ServiceClass.py trunk/Products/ZenModel/ServiceOrganizer.py trunk/Products/ZenModel/ZenMenu.py trunk/Products/ZenModel/ZenModelRM.py trunk/Products/ZenModel/ZenPack.py trunk/Products/ZenModel/ZenPackLoader.py trunk/Products/ZenModel/ZenossInfo.py trunk/Products/ZenModel/migrate/menus.py trunk/Products/ZenModel/migrate/packs.py trunk/Products/ZenModel/skins/zenmodel/deviceOrganizerStatus.pt trunk/Products/ZenRRD/tests/badPackets.py trunk/Products/ZenReports/ReportLoader.py trunk/Products/ZenUtils/zenpack.py Log: * start the authoring environment for zenpacks Modified: trunk/Products/ZenEvents/EventClass.py =================================================================== --- trunk/Products/ZenEvents/EventClass.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenEvents/EventClass.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -17,6 +17,7 @@ from EventClassInst import EventClassInst, EventClassPropertyMixin from Products.ZenModel.Organizer import Organizer +from Products.ZenModel.ZenPackable import ZenPackable from Products.ZenModel.ManagedEntity import ManagedEntity @@ -49,10 +50,8 @@ default_catalog = "eventClassSearch" - zenRelationsBaseModule = "Products.ZenEvents" - - _relations = ( - ("instances", ToManyCont(ToOne,"EventClassInst","eventClass")), + _relations = ZenPackable._relations + ( + ("instances", ToManyCont(ToOne,"Products.ZenEvents.EventClassInst","eventClass")), ) Modified: trunk/Products/ZenEvents/EventClassInst.py =================================================================== --- trunk/Products/ZenEvents/EventClassInst.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenEvents/EventClassInst.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -14,6 +14,7 @@ from Products.ZenRelations.RelSchema import * from Products.ZenModel.ZenModelRM import ZenModelRM from Products.ZenModel.EventView import EventView +from Products.ZenModel.ZenPackable import ZenPackable def manage_addEventClassInst(context, id, REQUEST = None): """make a device class""" @@ -45,7 +46,8 @@ # Why is this a subclass of EventView? -class EventClassInst(EventClassPropertyMixin, ZenModelRM, EventView): +class EventClassInst(EventClassPropertyMixin, ZenModelRM, EventView, + ZenPackable): """ EventClassInst. """ @@ -54,8 +56,6 @@ default_catalog = "eventClassSearch" - zenRelationsBaseModule = "Products.ZenEvents" - actions = ("status", "history", "heartbeat", "drop") transform = '' @@ -72,8 +72,8 @@ ) - _relations = ( - ("eventClass", ToOne(ToMany,"EventClass","instances")), + _relations = ZenPackable._relations + ( + ("eventClass", ToOne(ToMany,"Products.ZenEvents.EventClass","instances")), ) Modified: trunk/Products/ZenEvents/EventCommand.py =================================================================== --- trunk/Products/ZenEvents/EventCommand.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenEvents/EventCommand.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -3,14 +3,13 @@ from Acquisition import aq_parent from Products.ZenModel.ZenModelRM import ZenModelRM from Products.ZenModel.Commandable import Commandable +from Products.ZenModel.ZenPackable import ZenPackable from Products.ZenRelations.RelSchema import * from Globals import InitializeClass from EventFilter import EventFilter -class EventCommand(ZenModelRM, Commandable, EventFilter): +class EventCommand(ZenModelRM, Commandable, EventFilter, ZenPackable): - zenRelationsBaseModule = "Products.ZenEvents" - where = '' command = '' clearCommand = '' @@ -26,8 +25,8 @@ {'id':'delay', 'type':'int', 'mode':'w'}, ) - _relations = ( - ("eventManager", ToOne(ToManyCont, "EventManagerBase", "commands")), + _relations = ZenPackable._relations + ( + ("eventManager", ToOne(ToManyCont, "Products.ZenEvents.EventManagerBase", "commands")), ) factory_type_information = ( Modified: trunk/Products/ZenModel/DeviceOrganizer.py =================================================================== --- trunk/Products/ZenModel/DeviceOrganizer.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/DeviceOrganizer.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -73,7 +73,7 @@ }, ) - _relations = ( + _relations = Organizer._relations + ( ("maintenanceWindows", ToManyCont(ToOne, "MaintenanceWindow", "productionState")), ("adminRoles", ToManyCont(ToOne,"AdministrativeRole","managedObject")), Modified: trunk/Products/ZenModel/Manufacturer.py =================================================================== --- trunk/Products/ZenModel/Manufacturer.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/Manufacturer.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -21,7 +21,9 @@ from Products.ZenRelations.RelSchema import * from ZenModelRM import ZenModelRM +from ZenPackable import ZenPackable + def manage_addManufacturer(context, id=None, REQUEST = None): """make a Manufacturer""" if id: @@ -34,7 +36,7 @@ addManufacturer = DTMLFile('dtml/addManufacturer',globals()) -class Manufacturer(ZenModelRM): +class Manufacturer(ZenModelRM, ZenPackable): """Manufacturer object""" portal_type = meta_type = 'Manufacturer' @@ -56,7 +58,7 @@ {'id':'zip', 'type':'string', 'mode':'w'}, ) - _relations = ( + _relations = ZenPackable._relations + ( ("products", ToManyCont(ToOne,"ProductClass","manufacturer")), ) Modified: trunk/Products/ZenModel/MibBase.py =================================================================== --- trunk/Products/ZenModel/MibBase.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/MibBase.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -5,8 +5,9 @@ ################################################################# from ZenModelRM import ZenModelRM +from ZenPackable import ZenPackable -class MibBase(ZenModelRM): +class MibBase(ZenModelRM, ZenPackable): default_catalog = 'mibSearch' Modified: trunk/Products/ZenModel/OSProcess.py =================================================================== --- trunk/Products/ZenModel/OSProcess.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/OSProcess.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -12,8 +12,9 @@ from Acquisition import aq_chain from OSComponent import OSComponent +from ZenPackable import ZenPackable -class OSProcess(OSComponent, Commandable): +class OSProcess(OSComponent, Commandable, ZenPackable): """Hardware object""" portal_type = meta_type = 'OSProcess' @@ -28,7 +29,7 @@ {'id':'zFailSeverity', 'type':'int', 'mode':'w'}, ) - _relations = OSComponent._relations + ( + _relations = OSComponent._relations + ZenPackable._relations + ( ("os", ToOne(ToManyCont, "OperatingSystem", "processes")), ("osProcessClass", ToOne(ToMany, "OSProcessClass", "instances")), ('userCommands', ToManyCont(ToOne, 'UserCommand', 'commandable')), Modified: trunk/Products/ZenModel/Organizer.py =================================================================== --- trunk/Products/ZenModel/Organizer.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/Organizer.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -21,8 +21,9 @@ from EventView import EventView from ZenModelRM import ZenModelRM +from ZenPackable import ZenPackable -class Organizer(ZenModelRM, EventView): +class Organizer(ZenModelRM, EventView, ZenPackable): """ OrganizerBase class is base for all hierarchical organization classes. It allows Organizers to be addressed and created with file system like @@ -34,7 +35,9 @@ _properties = ( {'id':'description', 'type':'string', 'mode':'w'}, - ) + ) + + _relations = ZenPackable._relations security = ClassSecurityInfo() Modified: trunk/Products/ZenModel/RRDDataPoint.py =================================================================== --- trunk/Products/ZenModel/RRDDataPoint.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/RRDDataPoint.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -23,6 +23,7 @@ from Products.ZenRelations.RelSchema import * from ZenModelRM import ZenModelRM +from ZenPackable import ZenPackable def manage_addRRDDataPoint(context, id, REQUEST = None): """make a RRDDataPoint""" @@ -47,7 +48,7 @@ class RRDDataPointError(Exception): pass -class RRDDataPoint(ZenModelRM): +class RRDDataPoint(ZenModelRM, ZenPackable): meta_type = 'RRDDataPoint' @@ -81,7 +82,7 @@ ) - _relations = ( + _relations = ZenPackable._relations + ( ("datasource", ToOne(ToManyCont,"RRDDataSource","datapoints")), ) Modified: trunk/Products/ZenModel/RRDDataSource.py =================================================================== --- trunk/Products/ZenModel/RRDDataSource.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/RRDDataSource.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -29,6 +29,7 @@ from Products.ZenEvents.ZenEventClasses import Status_Web, Cmd_Fail from ZenModelRM import ZenModelRM +from ZenPackable import ZenPackable def manage_addRRDDataSource(context, id, REQUEST = None): @@ -68,7 +69,7 @@ class RRDDataSourceError(Exception): pass -class RRDDataSource(ZenModelRM): +class RRDDataSource(ZenModelRM, ZenPackable): meta_type = 'RRDDataSource' @@ -125,7 +126,7 @@ ) - _relations = ( + _relations = ZenPackable._relations + ( ("rrdTemplate", ToOne(ToManyCont,"RRDTemplate","datasources")), ("datapoints", ToManyCont(ToOne,"RRDDataPoint","datasource")), ) Modified: trunk/Products/ZenModel/RRDTemplate.py =================================================================== --- trunk/Products/ZenModel/RRDTemplate.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/RRDTemplate.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -14,6 +14,7 @@ from Products.ZenRelations.RelSchema import * from RRDDataPoint import SEPARATOR +from ZenPackable import ZenPackable class ConfigurationError(Exception): pass @@ -46,7 +47,7 @@ -class RRDTemplate(ZenModelRM): +class RRDTemplate(ZenModelRM, ZenPackable): meta_type = 'RRDTemplate' @@ -58,7 +59,7 @@ {'id':'description', 'type':'text', 'mode':'w'}, ) - _relations = ( + _relations = ZenPackable._relations + ( ("deviceClass", ToOne(ToManyCont,"RRDTemplate", "rrdTemplates")), ("datasources", ToManyCont(ToOne,"RRDDataSource", "rrdTemplate")), ("graphs", ToManyCont(ToOne,"RRDGraph", "rrdTemplate")), Modified: trunk/Products/ZenModel/RRDThreshold.py =================================================================== --- trunk/Products/ZenModel/RRDThreshold.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/RRDThreshold.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -9,6 +9,7 @@ from AccessControl import ClassSecurityInfo, Permissions from ZenModelRM import ZenModelRM +from ZenPackable import ZenPackable from Products.ZenRelations.RelSchema import * from Products.ZenUtils.ZenTales import talesEval @@ -41,7 +42,7 @@ addRRDThreshold = DTMLFile('dtml/addRRDThreshold',globals()) -class RRDThreshold(ZenModelRM): +class RRDThreshold(ZenModelRM, ZenPackable): meta_type = 'RRDThreshold' @@ -65,7 +66,7 @@ {'id':'enabled', 'type':'boolean', 'mode':'w'}, ) - _relations = ( + _relations = ZenPackable._relations + ( ("rrdTemplate", ToOne(ToManyCont,"RRDTemplate", "thresholds")), ) Modified: trunk/Products/ZenModel/Report.py =================================================================== --- trunk/Products/ZenModel/Report.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/Report.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -21,7 +21,8 @@ from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from Products.PageTemplates.PageTemplateFile import PageTemplateFile -from ZenModelItem import ZenModelItem +from ZenModelRM import ZenModelRM +from ZenPackable import ZenPackable def manage_addReport(context, id, title = None, text=None, REQUEST = None, submit=None): @@ -58,13 +59,15 @@ __name__='addReport') -class Report(ZopePageTemplate, ZenModelItem): +class Report(ZenModelRM, ZopePageTemplate, ZenPackable): """Report object""" meta_type = 'Report' - # this is depricated don't use!!! + # this is deprecated don't use!!! description = "" + _relations = ZenPackable._relations + security = ClassSecurityInfo() @@ -73,6 +76,7 @@ def __init__(self, id, title = None, text=None, content_type=None): + ZenModelRM.__init__(self, id); ZopePageTemplate.__init__(self, id, text, content_type) self.title = title Modified: trunk/Products/ZenModel/ReportClass.py =================================================================== --- trunk/Products/ZenModel/ReportClass.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ReportClass.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -23,6 +23,7 @@ from Organizer import Organizer from Report import Report +from ZenPackable import ZenPackable def manage_addReportClass(context, id, title = None, REQUEST = None): """make a device class""" Modified: trunk/Products/ZenModel/Service.py =================================================================== --- trunk/Products/ZenModel/Service.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/Service.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -22,11 +22,12 @@ from Products.ZenRelations.RelSchema import * from OSComponent import OSComponent +from ZenPackable import ZenPackable -class Service(OSComponent, Commandable): +class Service(OSComponent, Commandable, ZenPackable): portal_type = meta_type = 'Service' - _relations = OSComponent._relations + ( + _relations = OSComponent._relations + ZenPackable._relations + ( ("serviceclass", ToOne(ToMany,"ServiceClass","instances")), ('userCommands', ToManyCont(ToOne, 'UserCommand', 'commandable')), ) Modified: trunk/Products/ZenModel/ServiceClass.py =================================================================== --- trunk/Products/ZenModel/ServiceClass.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ServiceClass.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -19,6 +19,7 @@ from AccessControl import Permissions from Acquisition import aq_base from Commandable import Commandable +from ZenPackable import ZenPackable from Products.ZenRelations.RelSchema import * @@ -39,7 +40,7 @@ addServiceClass = DTMLFile('dtml/addServiceClass',globals()) -class ServiceClass(ZenModelRM, Commandable): +class ServiceClass(ZenModelRM, Commandable, ZenPackable): meta_type = "ServiceClass" dmdRootName = "Services" default_catalog = "serviceSearch" @@ -57,7 +58,7 @@ {'id':'contact', 'type':'string', 'mode':'w'}, ) - _relations = ( + _relations = ZenPackable._relations + ( ("instances", ToMany(ToOne, "Service", "serviceclass")), ("serviceorganizer", ToOne(ToManyCont,"ServiceOrganizer","serviceclasses")), Modified: trunk/Products/ZenModel/ServiceOrganizer.py =================================================================== --- trunk/Products/ZenModel/ServiceOrganizer.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ServiceOrganizer.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -41,7 +41,7 @@ {'id':'description', 'type':'text', 'mode':'w'}, ) - _relations = ( + _relations = Organizer._relations + ( ("serviceclasses", ToManyCont(ToOne,"ServiceClass","serviceorganizer")), ('userCommands', ToManyCont(ToOne, 'UserCommand', 'commandable')), ) Modified: trunk/Products/ZenModel/ZenMenu.py =================================================================== --- trunk/Products/ZenModel/ZenMenu.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ZenMenu.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -13,8 +13,10 @@ import logging log = logging.getLogger("zen.Menu") +from ZenPackable import ZenPackable -class ZenMenu(ZenModelRM): + +class ZenMenu(ZenModelRM, ZenPackable): """ A Menu object that holds Menu Items. """ @@ -25,7 +27,7 @@ {'id':'description', 'type':'text', 'mode':'w'}, ) - _relations = ( + _relations = ZenPackable._relations + ( ("zenMenuItems", ToManyCont( ToOne, 'ZenMenuItem', 'zenMenus')), ("menuable", ToOne( Modified: trunk/Products/ZenModel/ZenModelRM.py =================================================================== --- trunk/Products/ZenModel/ZenModelRM.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ZenModelRM.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -308,3 +308,20 @@ for item in sub: self.reindex_all(item) return 'done!' + + security.declareProtected('Manage DMD', 'addToZenPack') + def addToZenPack(self, ids=(), organizerPaths=(), pack=None, REQUEST=None): + "Add elements from a displayed list of objects to a ZenPack" + ids = list(ids) + list(organizerPaths) + if ids and pack: + pack = self.dmd.packs._getOb(pack) + for id in ids: + obj = self._getOb(id) + obj.buildRelations() + if pack.objectPaths: + pack.objectPaths = pack.objectPaths[:] + else: + pack.objectPaths = [] + pack.packables._setObject(id, obj) + if REQUEST: + return self.callZenScreen(REQUEST) Modified: trunk/Products/ZenModel/ZenPack.py =================================================================== --- trunk/Products/ZenModel/ZenPack.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ZenPack.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -19,10 +19,48 @@ class ZenPack(ZenModelRM): '''The root of all ZenPacks: has no implementation, but sits here to be the target of the Relation''' + + objectPaths = None + author = '' + organization = '' + url = '' + + _properties = ZenModelRM._properties + ( + {'id':'objectPaths','type':'lines','mode':'w'}, + {'id':'author', 'type':'string', 'mode':'w'}, + {'id':'organization', 'type':'string', 'mode':'w'}, + {'id':'url', 'type':'string', 'mode':'w'}, + ) + _relations = ( ('root', ToOne(ToManyCont, 'DataRoot', 'packs')), + ("packables", ToMany(ToOne, "ZenPackable", "pack")), ) + factory_type_information = ( + { 'immediate_view' : 'viewPackDetail', + 'actions' : + ( + { 'id' : 'viewPackDetail' + , 'name' : 'Detail' + , 'action' : 'viewPackDetail' + , 'permissions' : ( "Manage DMD", ) + }, + ) + }, + ) + + def manage_deletePackable(self, packables=(), REQUEST=None): + "Delete objects from this ZenPack" + from sets import Set + packables = Set(packables) + for obj in self.packables(): + if obj.getPrimaryUrlPath() in packables: + self.packables.removeRelation(obj) + if REQUEST: + return self.callZenScreen(REQUEST) + + from Products.ZenModel.ZenPackLoader import * def zenPackPath(*parts): @@ -40,22 +78,23 @@ return zenPackPath(self.id, *args) - def install(self, cmd): + def install(self, app): for loader in self.loaders: - loader.load(self, cmd) - transaction.commit() + loader.load(self, app) - def remove(self, cmd): + def remove(self, app): for loader in self.loaders: - loader.unload(self, cmd) + loader.unload(self, app) - def list(self, cmd): + def list(self, app): result = [] for loader in self.loaders: result.append((loader.name, - [item for item in loader.list(self, cmd)])) + [item for item in loader.list(self, app)])) return result + + InitializeClass(ZenPack) Modified: trunk/Products/ZenModel/ZenPackLoader.py =================================================================== --- trunk/Products/ZenModel/ZenPackLoader.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ZenPackLoader.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -41,82 +41,66 @@ name = "Set This Name" - def load(self, pack, cmd): + def load(self, pack, app): """Load things from the ZenPack and put it - into the app available on cmd""" + into the app""" - def unload(self, pack, cmd): + def unload(self, pack, app): """Remove things from Zenoss defined in the ZenPack""" - def list(self, pack, cmd): + def list(self, pack, app): "List the items that would be loaded from the given (unpacked) ZenPack" from xml.sax import saxutils, make_parser from xml.sax.handler import ContentHandler -class PathTracker(ContentHandler): - "Keep the object path as we navigate XML" - def __init__(self): - self.stack = [''] - def startElement(self, name, attrs): - id = attrs.get('id', None) - if id: - if self.stack[-1]: - id = self.stack[-1] + '/' + id - else: - id = self.stack[-1] - self.stack.append(id) - def endElement(self, name): - id = self.stack.pop() - def path(self): - return self.stack[-1] - class ZPLObject(ZenPackLoader): name = "Objects" - def load(self, pack, cmd): + def load(self, pack, app): from Products.ZenRelations.ImportRM import ImportRM - importer = ImportRM(noopts=True, app=cmd.app) + class AddToPack(ImportRM): + def endElement(self, name): + if name == 'object': + obj = self.objstack[-1] + log.debug('Now adding %s', obj.getPrimaryUrlPath()) + try: + obj.buildRelations() + obj.addRelation('pack', pack) + except Exception, ex: + log.exception("Error adding pack to %s", + obj.getPrimaryUrlPath()) + + ImportRM.endElement(self, name) + importer = AddToPack(noopts=True, app=app) importer.options.noindex = True for f in self.objectFiles(pack): log.info("Loading %s", f) importer.loadObjectFromXML(xmlfile=f) + def parse(self, filename, handler): parser = make_parser() parser.setContentHandler(handler) parser.parse(open(filename)) - def unload(self, pack, cmd): - class Deleter(PathTracker): - def endElement(self, name): - PathTracker.endElement(self, name) - id = self.path() - if name == 'object' and id: - log.info("Removing %s", id) - path = id.split('/') - id = path.pop() - try: - obj = getObjByPath(cmd.app, path) - obj._delObject(id) - except (AttributeError, KeyError), ex: - log.warning("Unable to remove %s on %s", id, - '/'.join(path)) - for f in self.objectFiles(pack): - self.parse(f, Deleter()) + def unload(self, pack, app): + dmd = app.zport.dmd + for obj in pack.packables(): + path = obj.getPrimaryPath() + path, id = path[:-1], path[-1] + try: + obj = dmd.getObjByPath(path) + obj._delObject(id) + except (AttributeError, KeyError), ex: + log.warning("Unable to remove %s on %s", id, + '/'.join(path)) - def list(self, pack, cmd): - objs = [] - class Collector(PathTracker): - def startElement(self, name, attrs): - PathTracker.startElement(self, name, attrs) - if name == 'object' and self.path(): - objs.append(self.path()) - for f in self.objectFiles(pack): - self.parse(f, Collector()) - return objs + + def list(self, pack, app): + return [obj.getPrimaryUrlPath() for obj in pack.packables()] def objectFiles(self, pack): @@ -124,35 +108,29 @@ return findFiles(pack, 'objects', isXml) -class ZPLReport(ZenPackLoader): +class ZPLReport(ZPLObject): name = "Reports" - def load(self, pack, cmd): - rl = ReportLoader(noopts=True, app=cmd.app) - rl.options = cmd.options + def load(self, pack, app): + class HookReportLoader(ReportLoader): + def loadFile(self, root, id, fullname): + rpt = ReportLoader.loadFile(self, root, id, fullname) + rpt.addRelation('pack', pack) + return rpt + rl = HookReportLoader(noopts=True, app=app) + rl.options.force = True rl.loadDirectory(pack.path('reports')) - def unload(self, pack, cmd): - rl = ReportLoader(noopts=True, app=cmd.app) - rl.unloadDirectory(pack.path('reports')) - - def list(self, pack, cmd): - def rpt(f): - return f.endswith('.rpt') - return [branchAfter(fs[:-4], 'reports', "/zport/dmd/Reports/") - for fs in findFiles(pack, 'reports', rpt)] - - class ZPLDaemons(ZenPackLoader): name = "Daemons" - def load(self, pack, cmd): + def load(self, pack, app): for fs in findFiles(pack, 'daemons'): os.chmod(fs, 0755) - def list(self, pack, cmd): + def list(self, pack, app): return [branchAfter(d, 'daemons') for d in findFiles(pack, 'daemons')] @@ -161,7 +139,7 @@ name = "Modeler Plugins" - def list(self, pack, cmd): + def list(self, pack, app): return [branchAfter(d, 'plugins') for d in findFiles(pack, 'modeler/plugins')] @@ -171,10 +149,11 @@ name = "Skins" - def load(self, pack, cmd): + def load(self, pack, app): from Products.ZenUtils.Skins import registerSkin - registerSkin(cmd.dmd, pack.path('')) + from Products.ZenUtils.Utils import getObjByPath + registerSkin(app.zport.dmd, pack.path('')) - def list(self, pack, cmd): + def list(self, pack, app): return [branchAfter(d, 'skins') for d in findDirectories(pack, 'skins')] Added: trunk/Products/ZenModel/ZenPackable.py Modified: trunk/Products/ZenModel/ZenossInfo.py =================================================================== --- trunk/Products/ZenModel/ZenossInfo.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/ZenossInfo.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -54,6 +54,11 @@ , 'action' : 'zenossVersions' , 'permissions' : ( "Manage DMD", ) }, + { 'id' : 'packs' + , 'name' : 'ZenPacks' + , 'action' : 'viewZenPacks' + , 'permissions' : ( "Manage DMD", ) + }, ) }, ) Modified: trunk/Products/ZenModel/migrate/menus.py =================================================================== --- trunk/Products/ZenModel/migrate/menus.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/migrate/menus.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -171,7 +171,13 @@ description='Delete devices...', action= 'dialog_removeDevices', permissions=('Change Device',) - ) + ), + dict( + id= 'addToZenPack', + description='Add to ZenPack...', + action= 'dialog_addToZenPack', + permissions=('View',) + ), ] }) Modified: trunk/Products/ZenModel/migrate/packs.py =================================================================== --- trunk/Products/ZenModel/migrate/packs.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/migrate/packs.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -11,11 +11,20 @@ $Id:$ ''' import Migrate +log = Migrate.log class Packs(Migrate.Step): version = Migrate.Version(1, 2, 0) def cutover(self, dmd): - dmd.buildRelations() + def recurse(obj): + log.debug(obj.getPrimaryUrlPath()) + try: + obj.buildRelations() + except AttributeError: + pass + for child in obj.objectValues(): + recurse(child) + # recurse(dmd) Packs() Modified: trunk/Products/ZenModel/skins/zenmodel/deviceOrganizerStatus.pt =================================================================== --- trunk/Products/ZenModel/skins/zenmodel/deviceOrganizerStatus.pt 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenModel/skins/zenmodel/deviceOrganizerStatus.pt 2007-02-16 20:09:12 UTC (rev 4096) @@ -21,7 +21,7 @@ } } </script> -<form method="post" tal:attributes="action here/absolute_url_path"> +<form method="post" tal:attributes="action here/absolute_url_path" name="deviceOrganizerStatus"> <input type="hidden" name="zenScreenName" value="deviceOrganizerStatus" /> <table class="zentable" cellpadding="3" cellspacing="1" metal:define-macro="status"> @@ -86,10 +86,11 @@ <input type="hidden" name="zenScreenName" tal:attributes="value template/id"/> <tr> - <th class=tabletitle align=left colspan="6" + <th class=tabletitle align=left colspan="5" tal:content="string:Sub-${here/dmdRootName}"> SubLocations </th> + <div class="devmovemenu" metal:use-macro="here/zenuimacros/macros/devmovemenu"/> </tr> <span tal:condition="objects" tal:omit-tag=""> <tr> Added: trunk/Products/ZenModel/skins/zenmodel/viewPackDetail.pt Added: trunk/Products/ZenModel/skins/zenmodel/viewZenPacks.pt Modified: trunk/Products/ZenRRD/tests/badPackets.py =================================================================== --- trunk/Products/ZenRRD/tests/badPackets.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenRRD/tests/badPackets.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -16,6 +16,7 @@ msg = "0\202\1\324\2\1\0\4\6public\242\202\1\305\2\2\0\203\2\1\2\2\1\0200\202\1\2670\16\6\n+\6\1\2\1\2\2\1\n\2\5\0000\16\6\n+\6\1\2\1\2\2\1\n\3\5\0000\16\6\n+\6\1\2\1\2\2\1\v\2\5\0000\16\6\n+\6\1\2\1\2\2\1\v\3\5\0000\16\6\n+\6\1\2\1\2\2\1\16\2\5\0000\16\6\n+\6\1\2\1\2\2\1\16\3\5\0000\16\6\n+\6\1\2\1\2\2\1\20\2\5\0000\16\6\n+\6\1\2\1\2\2\1\20\3\5\0000\16\6\n+\6\1\2\1\2\2\1\21\2\5\0000\16\6\n+\6\1\2\1\2\2\1\21\3\5\0000\16\6\n+\6\1\2\1\2\2\1\24\2\5\0000\16\6\n+\6\1\2\1\2\2\1\24\3\5\0000\r\6\t+\6\1\2\1\31\1\1\0\5\0000\17\6\v+\6\1\2\1\31\2\3\1\6\n\5\0000\17\6\v+\6\1\2\1\31\2\3\1\6\v\5\0000\17\6\v+\6\1\2\1\31\2\3\1\6\f\5\0000\17\6\v+\6\1\2\1\31\2\3\1\6\4\5\0000\17\6\v+\6\1\2\1\31\2\3\1\6\7\5\0000\17\6\v+\6\1\2\1\31\2\3\1\6\10\5\0000\17\6\v+\6\1\2\1\31\2\3\1\6\t\5\0000\17\6\v+\6\1\4\1\217e\n\1\5\2\5\0000\16\6\n+\6\1\4\1\217e\v2\0\5\0000\16\6\n+\6\1\4\1\217e\v4\0\5\0000\16\6\n+\6\1\4\1\217e\v5\0\5\0000\16\6\n+\6\1\4\1\217e\v6\0\5\0000\16\6\n+\6\1\4\1\217e\4\4\0\5\0000\16\6\n+\6\1\4! \1\217e\4\6\0\5\0" msg = "0*\2\1\0\4\6public\242\35\2\2\0\263\2\1\2\2\1\0010\0210\17\6\v+\6\1\2\1\31\2\3\1\6\f\5\0" msg = '0\x81\x85\x02\x01\x00\x04\x08pawuglux\xa2v\x02\x03\x00\x8b\x01\x02\x01\x00\x02\x01\x000i0\r\x06\t+\x06\x01\x06\x03\x0c\x01\x01\x000\r\x06\t+\x06\x01\x06\x03\x0c\x01\x01\x000\r\x06\t+\x06\x01\x06\x03\x0c\x01\x01\x000\r\x06\t+\x06\x01\x06\x03\x0c\x01\x01\x000\r\x06\t+\x06\x01\x06\x03\x0c\x01\x01\x000\r\x06\t+\x06\x01\x06\x03\x0c\x01\x01\x000\r\x06\t+\x06\x01\x06\x03\x0c\x01\x01\x00' +msg = '0\x82:\xe5\x02\x01\x00\x04\x06public\xa2\x82:\xd6\x02\x03\x00\xc7\xa3\x02\x01\x02\x02\x02\x03\x180\x82:\xc60\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x01\x81\xb00\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x02\x81\xb00\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x01\x81\xb0N\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x02\x81\xb0N\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x01\x81\xb1\x1b\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x02\x81\xb1\x1b\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x01\x81\xb1:\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x02\x81\xb1:\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x01\x81\xb1k\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x02\x81\xb1k\x05\x000\x11\x06\r+\x06\x01\x02\x01\x19\x05\x01\x01\x01\x81\xb1\x7f\x05\x000\x11\x06\r+\x06\x00' r = Response() import pdb Modified: trunk/Products/ZenReports/ReportLoader.py =================================================================== --- trunk/Products/ZenReports/ReportLoader.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenReports/ReportLoader.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -60,11 +60,16 @@ else: continue self.log.info("loading: %s/%s", orgpath, fid) - fdata = file(fullname).read() - rpt = Report(fid, text=fdata) - rorg._setObject(fid, rpt) + self.loadFile(rorg, fid, fullname) + def loadFile(self, root, id, fullname): + fdata = file(fullname).read() + rpt = Report(id, text=fdata) + root._setObject(id, rpt) + return rpt + + if __name__ == "__main__": rl = ReportLoader() rl.loadDatabase() Modified: trunk/Products/ZenUtils/zenpack.py =================================================================== --- trunk/Products/ZenUtils/zenpack.py 2007-02-16 19:44:40 UTC (rev 4095) +++ trunk/Products/ZenUtils/zenpack.py 2007-02-16 20:09:12 UTC (rev 4096) @@ -26,7 +26,7 @@ if self.options.list: for zp in self.dmd.packs(): print '%s (%s)' % (zp.id, sys.modules[zp.__module__].__file__) - for extensionType, lst in zp.list(self): + for extensionType, lst in zp.list(self.app): print ' %s:' % extensionType for item in lst: print ' %s' % item @@ -55,7 +55,8 @@ ex) zp = ZenPackBase(packName) self.dmd.packs._setObject(packName, zp) - zp.install(self) + zp.install(self.app) + transaction.commit() def remove(self, packName): @@ -65,7 +66,7 @@ zp = self.dmd.packs._getOb(packName) except AttributeError, ex: self.stop('There is no ZenPack named "%s"' % packName) - zp.remove(self) + zp.remove(self.app) self.dmd.packs._delObject(packName) root = zenPackPath(packName) for p, ds, fs in os.walk(root, topdown=False): @@ -102,8 +103,8 @@ return packName - def stop(self, *args): - self.log.error(*args) + def stop(self, why): + self.log.error("zenpack stopped: %s", why) import sys sys.exit(1) Added: trunk/Products/ZenWidgets/skins/zenui/dialog_addToZenPack.pt |