當前位置: 首頁>>代碼示例>>Python>>正文


Python Timeperiod.explode方法代碼示例

本文整理匯總了Python中alignak.objects.timeperiod.Timeperiod.explode方法的典型用法代碼示例。如果您正苦於以下問題:Python Timeperiod.explode方法的具體用法?Python Timeperiod.explode怎麽用?Python Timeperiod.explode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在alignak.objects.timeperiod.Timeperiod的用法示例。


在下文中一共展示了Timeperiod.explode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_maintenance_period_host

# 需要導入模塊: from alignak.objects.timeperiod import Timeperiod [as 別名]
# 或者: from alignak.objects.timeperiod.Timeperiod import explode [as 別名]
    def test_maintenance_period_host(self):
        """Test a host enter in maintenance_period
        
        :return: None
        """
        # Get the host
        host = self._sched.hosts.find_by_name("test_host_0")
        host.checks_in_progress = []
        host.act_depend_of = []
        # Not any downtime yet !
        assert host.downtimes == {}

        # Make the host be UP
        self.scheduler_loop(1, [[host, 0, 'UP']])

        # we created a new timeperiod from now -5 minutes to now + 55 minutes
        begin = datetime.now() - timedelta(minutes=5)
        end = datetime.now() + timedelta(minutes=55)

        h_begin = format(begin, '%H:%M')
        if format(begin, '%H') == '23' and format(begin, '%M') >= 55:
            h_begin = '00:00'
        h_end = format(end, '%H:%M')
        end = end - timedelta(seconds=int(format(end, '%S')))
        timestamp_end = int(time.mktime(end.timetuple()))

        data = {
            'timeperiod_name': 'maintenance',
            'sunday': h_begin + '-' + h_end,
            'monday': h_begin + '-' + h_end,
            'tuesday': h_begin + '-' + h_end,
            'wednesday': h_begin + '-' + h_end,
            'thursday': h_begin + '-' + h_end,
            'friday': h_begin + '-' + h_end,
            'saturday': h_begin + '-' + h_end
        }
        timeperiod = Timeperiod(data)
        timeperiod.explode()
        self._scheduler.timeperiods[timeperiod.uuid] = timeperiod
        host.maintenance_period = timeperiod.uuid

        # Make the host be UP again
        self.scheduler_loop(1, [[host, 0, 'UP']])

        assert 1 == len(host.downtimes)
        # The host is still in a downtime period
        assert host.in_scheduled_downtime
        downtime = list(host.downtimes.values())[0]
        assert downtime.fixed
        assert downtime.is_in_effect
        assert not downtime.can_be_deleted
        assert downtime.end_time == timestamp_end
        assert downtime.comment == 'This downtime was automatically scheduled by Alignak because ' \
                                   'of a maintenance period.'
開發者ID:Alignak-monitoring,項目名稱:alignak,代碼行數:56,代碼來源:test_maintenance_period.py


注:本文中的alignak.objects.timeperiod.Timeperiod.explode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。