本文整理汇总了Python中Products.ZenUtils.ZenScriptBase.ZenScriptBase.setupLogging方法的典型用法代码示例。如果您正苦于以下问题:Python ZenScriptBase.setupLogging方法的具体用法?Python ZenScriptBase.setupLogging怎么用?Python ZenScriptBase.setupLogging使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.ZenUtils.ZenScriptBase.ZenScriptBase
的用法示例。
在下文中一共展示了ZenScriptBase.setupLogging方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import setupLogging [as 别名]
self.jm = dmd.JobManager
self.log = log
self.clean_older_than_days = 95
def __call__(self):
now = datetime.datetime.now()
delta = datetime.timedelta(self.clean_older_than_days)
x_days_ago = now - delta
jobs_to_go = [job.id for job in self.jm.getAllJobs() if job.finished and job.finished < x_days_ago]
if jobs_to_go:
self.log.info('Deleting %s Jobs', len(jobs_to_go))
self.deleteOldJobs(jobs_to_go)
return
self.log.info('No maintenance windows needed to be removed')
@transact
def deleteOldJobs(self, jobs):
self.log.info('Removing %d jobs', len(jobs))
map(self.jm.deleteJob, jobs)
if __name__ == "__main__":
jccmd = ZenScriptBase(connect=True)
jccmd.setupLogging()
jccmd.log.info('OldJobsClaner Cleanup Script running')
JOB_CLEANER = OldJobsCleaner(jccmd.dmd, jccmd.log)
JOB_CLEANER()
jccmd.log.info('Old Job Cleaner completed sucessfully')
示例2: len
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import setupLogging [as 别名]
work = [(mw.nextEvent(now), mw) for mw in workList]
work.sort()
# note that None is less than any number of seconds
while len(work):
t, mw = work[0]
if t: break
if mw.enabled:
old_windows.append(mw)
self.log.info("Never going to run Maintenance "
"Window %s for %s again, adding to list for removal",
mw.getId(), mw.target().getId())
work.pop(0)
return old_windows
@transact
def removeOldWindows(self, windows):
self.log.info('Removing %d Windows Now' % len(windows))
for win in windows:
winId = win.id
parent = win.productionState()
parent.manage_deleteMaintenanceWindow(maintenanceIds=(winId))
if __name__ == "__main__":
mwcmd = ZenScriptBase(connect=True)
mwcmd.setupLogging()
mwcmd.log.info('Starting Maintenance mode Cleaning Script')
MWC = MaintWindowCleaner(mwcmd.dmd, mwcmd.log)
MWC()
mwcmd.log.info('Maintenance Mode Cleaner completed sucessfully')