diff --git a/ZenPacks/zenoss/PostgreSQL/util.py b/ZenPacks/zenoss/PostgreSQL/util.py index dbee7ed..dd430f4 100644 --- a/ZenPacks/zenoss/PostgreSQL/util.py +++ b/ZenPacks/zenoss/PostgreSQL/util.py @@ -15,6 +15,7 @@ import sys import time + def addLocalLibPath(): """ Helper to add the ZenPack's lib directory to PYTHONPATH. @@ -24,17 +25,20 @@ def addLocalLibPath(): site.addsitedir(os.path.join(os.path.dirname(__file__), 'lib')) + def datetimeToEpoch(datetime): return time.mktime(datetime.timetuple()) + def datetimeDurationInSeconds(begin, end): d = end - begin # Taken from the implementation of timedelta.total_seconds in Python 2.7. # Added microseconds resolution by introducing a float. return ( - d.microseconds + (d.seconds + d.days * 24 * 3600) * 10**6 - ) / float(10**6) + d.microseconds + (d.seconds + d.days * 24 * 3600) * (10 ** 6) + ) / float(10 ** 6) + class CollectedOrModeledMixin: def getFloatForValue(self, value): @@ -50,7 +54,7 @@ def getFloatForValue(self, value): def getIntForValue(self, value): r = self.getFloatForValue(value) return int(round(r)) if r is not None else None - + def getStringForValue(self, value, format='{0}'): r = self.getFloatForValue(value) if r is None: @@ -58,6 +62,7 @@ def getStringForValue(self, value, format='{0}'): return format.format(r) + def CollectedOrModeledProperty(propertyName): """ This uses a closure to make using CollectedOrModeledMixin easier to use in @@ -71,6 +76,7 @@ def getter(self): addLocalLibPath() from pg8000 import DBAPI + class PgHelper(object): _host = None _port = None @@ -508,4 +514,3 @@ def getTableStatsForDatabase(self, db): cursor.close() return tableStats -