当前位置: 首页>>代码示例>>Python>>正文


Python ZenScriptBase.setupLogging方法代码示例

本文整理汇总了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')
开发者ID:dougsyer,项目名称:Zenoss-Examples-and-Tools,代码行数:32,代码来源:OldJobsCleaner.py

示例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')
开发者ID:dougsyer,项目名称:Zenoss-Examples-and-Tools,代码行数:32,代码来源:MaintWindowCleaner.py


注:本文中的Products.ZenUtils.ZenScriptBase.ZenScriptBase.setupLogging方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。