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


Python timeperiod.Timeperiod类代码示例

本文整理汇总了Python中alignak.objects.timeperiod.Timeperiod的典型用法代码示例。如果您正苦于以下问题:Python Timeperiod类的具体用法?Python Timeperiod怎么用?Python Timeperiod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Timeperiod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_simple_with_multiple_time

    def test_simple_with_multiple_time(self):
        """
        Test timeperiod with 2 ranges:
          * tuesday 00:00-07:00
          * tuesday 21:30-24:00

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
        print(july_the_12)

        # Then a simple same day
        print("Cheking validity for", time.asctime(time.localtime(july_the_12)))
        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 00:00-07:00,21:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("RES:", t_next)
        self.assertEqual("Tue Jul 13 00:00:00 2010", t_next)

        # Now ask about at 00:00 time?
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 00:00:00", "%d %b %Y %H:%M:%S"))
        # Then a simple same day
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("Next?", t_next)
        self.assertEqual("Tue Jul 13 00:00:00 2010", t_next)
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:29,代码来源:test_timeperiods.py

示例2: test_resolve_daterange_case23

    def test_resolve_daterange_case23(self):
        """ Test resolve daterange, case 23

        :return: None
        """
        timeperiod = Timeperiod()
        entry = 'sunday 00:00-24:00'
        timeperiod.resolve_daterange(timeperiod.dateranges, entry)

        assert 'sunday' == timeperiod.dateranges[0].day
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:10,代码来源:test_dateranges.py

示例3: test_maintenance_period_host

    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,代码行数:54,代码来源:test_maintenance_period.py

示例4: test_timeperiod_no_daterange

    def test_timeperiod_no_daterange(self):
        """
        Test with a timeperiod have no daterange

        :return: None
        """
        now = time.time()

        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges, '1999-01-28  00:00-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(now)
        self.assertIsNone(t_next)
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:12,代码来源:test_timeperiods.py

示例5: test_get_valid_time

    def test_get_valid_time(self):
        """
        Test get next valid time

        :return: None
        """
        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges, 'monday 00:00-24:00')
        first_nov = int(time.mktime(time.strptime("26 Oct 2010 00:00:00", "%d %b %Y %H:%M:%S")))
        print(first_nov)
        start = timeperiod.get_next_valid_time_from_t(first_nov)
        self.assertIsNotNone(start)
        start = time.asctime(time.localtime(start))
        self.assertEqual("Mon Nov  1 00:00:00 2010", start)
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:14,代码来源:test_timeperiods.py

示例6: test_resolve_daterange_case3

    def test_resolve_daterange_case3(self):
        t = Timeperiod()
        entry = '2015-07-26 - 2016-08-20    00:00-24:00'
        t.resolve_daterange(t.dateranges, entry)

        self.assertEqual(2015, t.dateranges[0].syear)
        self.assertEqual(7, t.dateranges[0].smon)
        self.assertEqual(26, t.dateranges[0].smday)
        self.assertEqual(0, t.dateranges[0].swday)
        self.assertEqual(0, t.dateranges[0].swday_offset)
        self.assertEqual(2016, t.dateranges[0].eyear)
        self.assertEqual(8, t.dateranges[0].emon)
        self.assertEqual(20, t.dateranges[0].emday)
        self.assertEqual(0, t.dateranges[0].ewday)
        self.assertEqual(0, t.dateranges[0].ewday_offset)
        self.assertEqual(0, t.dateranges[0].skip_interval)
        self.assertEqual('00:00-24:00', t.dateranges[0].other)
开发者ID:LionelR,项目名称:alignak,代码行数:17,代码来源:test_dateranges.py

示例7: test_resolve_daterange_case5

    def test_resolve_daterange_case5(self):
        t = Timeperiod()
        entry = 'tuesday 1 october - friday 2 may / 6 00:00-24:00'
        t.resolve_daterange(t.dateranges, entry)

        self.assertEqual(0, t.dateranges[0].syear)
        self.assertEqual(10, t.dateranges[0].smon)
        self.assertEqual(0, t.dateranges[0].smday)
        self.assertEqual(1, t.dateranges[0].swday)
        self.assertEqual(1, t.dateranges[0].swday_offset)
        self.assertEqual(0, t.dateranges[0].eyear)
        self.assertEqual(5, t.dateranges[0].emon)
        self.assertEqual(0, t.dateranges[0].emday)
        self.assertEqual(4, t.dateranges[0].ewday)
        self.assertEqual(2, t.dateranges[0].ewday_offset)
        self.assertEqual(6, t.dateranges[0].skip_interval)
        self.assertEqual('00:00-24:00', t.dateranges[0].other)
开发者ID:LionelR,项目名称:alignak,代码行数:17,代码来源:test_dateranges.py

示例8: test_resolve_daterange_case12

    def test_resolve_daterange_case12(self):
        t = Timeperiod()
        entry = 'tuesday 3 july - friday 2 september 00:00-24:00'
        t.resolve_daterange(t.dateranges, entry)

        self.assertEqual(0, t.dateranges[0].syear)
        self.assertEqual(7, t.dateranges[0].smon)
        self.assertEqual(0, t.dateranges[0].smday)
        self.assertEqual(1, t.dateranges[0].swday)
        self.assertEqual(3, t.dateranges[0].swday_offset)
        self.assertEqual(0, t.dateranges[0].eyear)
        self.assertEqual(9, t.dateranges[0].emon)
        self.assertEqual(0, t.dateranges[0].emday)
        self.assertEqual(4, t.dateranges[0].ewday)
        self.assertEqual(2, t.dateranges[0].ewday_offset)
        self.assertEqual(0, t.dateranges[0].skip_interval)
        self.assertEqual('00:00-24:00', t.dateranges[0].other)
开发者ID:LionelR,项目名称:alignak,代码行数:17,代码来源:test_dateranges.py

示例9: test_simple_timeperiod

    def test_simple_timeperiod(self):
        """
        Test a timeperiod with one timerange

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
        print(july_the_12)

        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print(t_next)
        self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:17,代码来源:test_timeperiods.py

示例10: test_resolve_daterange_case22

    def test_resolve_daterange_case22(self):
        t = Timeperiod()
        entry = 'day 3      00:00-24:00'
        t.resolve_daterange(t.dateranges, entry)

        self.assertEqual(0, t.dateranges[0].syear)
        self.assertEqual(0, t.dateranges[0].smon)
        self.assertEqual(3, t.dateranges[0].smday)
        self.assertEqual(0, t.dateranges[0].swday)
        self.assertEqual(0, t.dateranges[0].swday_offset)
        self.assertEqual(0, t.dateranges[0].eyear)
        self.assertEqual(0, t.dateranges[0].emon)
        self.assertEqual(3, t.dateranges[0].emday)
        self.assertEqual(0, t.dateranges[0].ewday)
        self.assertEqual(0, t.dateranges[0].ewday_offset)
        self.assertEqual(0, t.dateranges[0].skip_interval)
        self.assertEqual('00:00-24:00', t.dateranges[0].other)
开发者ID:LionelR,项目名称:alignak,代码行数:17,代码来源:test_dateranges.py

示例11: test_resolve_daterange_case17

    def test_resolve_daterange_case17(self):
        t = Timeperiod()
        entry = 'april 10 - may 15          00:00-24:00'
        t.resolve_daterange(t.dateranges, entry)

        self.assertEqual(0, t.dateranges[0].syear)
        self.assertEqual(4, t.dateranges[0].smon)
        self.assertEqual(10, t.dateranges[0].smday)
        self.assertEqual(0, t.dateranges[0].swday)
        self.assertEqual(0, t.dateranges[0].swday_offset)
        self.assertEqual(0, t.dateranges[0].eyear)
        self.assertEqual(5, t.dateranges[0].emon)
        self.assertEqual(15, t.dateranges[0].emday)
        self.assertEqual(0, t.dateranges[0].ewday)
        self.assertEqual(0, t.dateranges[0].ewday_offset)
        self.assertEqual(0, t.dateranges[0].skip_interval)
        self.assertEqual('00:00-24:00', t.dateranges[0].other)
开发者ID:LionelR,项目名称:alignak,代码行数:17,代码来源:test_dateranges.py

示例12: test_get_invalid_time

    def test_get_invalid_time(self):
        """
        Test get next invalid time

        :return: None
        """
        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges, 'monday 00:00-24:00')
        first_nov = int(time.mktime(time.strptime("1 Nov 2010 00:00:00", "%d %b %Y %H:%M:%S")))
        print(first_nov)
        end = timeperiod.get_next_invalid_time_from_t(first_nov)
        end = time.asctime(time.localtime(end))
        self.assertEqual("Tue Nov  2 00:00:00 2010", end)

        first_nov = int(time.mktime(time.strptime("2 Nov 2010 00:00:00", "%d %b %Y %H:%M:%S")))
        print(first_nov)
        end = timeperiod.get_next_invalid_time_from_t(first_nov)
        end = time.asctime(time.localtime(end))
        self.assertEqual("Tue Nov  2 00:00:00 2010", end)
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:19,代码来源:test_timeperiods.py

示例13: test_simple_with_multiple_time_multiple_days

    def test_simple_with_multiple_time_multiple_days(self):
        """
        Test timeperiod with multiple daterange on multiple days:
          * monday 00:00-07:00
          * monday 21:30-24:00
          * tuesday 00:00-07:00
          * tuesday 21:30-24:00

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
        print(july_the_12)

        # Then a simple same day
        timeperiod = Timeperiod()
        print("Cheking validity for", time.asctime(time.localtime(july_the_12)))
        timeperiod.resolve_daterange(timeperiod.dateranges, 'monday 00:00-07:00,21:30-24:00')
        timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 00:00-07:00,21:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("RES:", t_next)
        self.assertEqual("Mon Jul 12 21:30:00 2010", t_next)

        # what about the next invalid?
        t_next_inv = timeperiod.get_next_invalid_time_from_t(july_the_12)
        t_next_inv = time.asctime(time.localtime(t_next_inv))
        print("RES:", t_next_inv)
        self.assertEqual("Mon Jul 12 15:00:00 2010", t_next_inv)

        # what about a valid time and ask next invalid? Like at 22:00h?
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 22:00:00", "%d %b %Y %H:%M:%S"))
        t_next_inv = timeperiod.get_next_invalid_time_from_t(july_the_12)
        t_next_inv = time.asctime(time.localtime(t_next_inv))
        print("RES:", t_next_inv) #, t.is_time_valid(july_the_12)
        self.assertEqual("Tue Jul 13 07:00:01 2010", t_next_inv)

        # Now ask about at 00:00 time?
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 00:00:00", "%d %b %Y %H:%M:%S"))
        print("Cheking validity for", time.asctime(time.localtime(july_the_12)))
        # Then a simple same day
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("Next?", t_next)
        self.assertEqual("Mon Jul 12 00:00:00 2010", t_next)
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:46,代码来源:test_timeperiods.py

示例14: test_resolve_daterange_case5

    def test_resolve_daterange_case5(self):
        """ Test resolve daterange, case 5

        :return: None
        """
        timeperiod = Timeperiod()
        entry = 'tuesday 1 october - friday 2 may / 6 00:00-24:00'
        timeperiod.resolve_daterange(timeperiod.dateranges, entry)

        assert 0 == timeperiod.dateranges[0].syear
        assert 10 == timeperiod.dateranges[0].smon
        assert 0 == timeperiod.dateranges[0].smday
        assert 1 == timeperiod.dateranges[0].swday
        assert 1 == timeperiod.dateranges[0].swday_offset
        assert 0 == timeperiod.dateranges[0].eyear
        assert 5 == timeperiod.dateranges[0].emon
        assert 0 == timeperiod.dateranges[0].emday
        assert 4 == timeperiod.dateranges[0].ewday
        assert 2 == timeperiod.dateranges[0].ewday_offset
        assert 6 == timeperiod.dateranges[0].skip_interval
        assert '00:00-24:00' == timeperiod.dateranges[0].other
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:21,代码来源:test_dateranges.py

示例15: test_resolve_daterange_case12

    def test_resolve_daterange_case12(self):
        """ Test resolve daterange, case 12

        :return: None
        """
        timeperiod = Timeperiod()
        entry = 'tuesday 3 july - friday 2 september 00:00-24:00'
        timeperiod.resolve_daterange(timeperiod.dateranges, entry)

        assert 0 == timeperiod.dateranges[0].syear
        assert 7 == timeperiod.dateranges[0].smon
        assert 0 == timeperiod.dateranges[0].smday
        assert 1 == timeperiod.dateranges[0].swday
        assert 3 == timeperiod.dateranges[0].swday_offset
        assert 0 == timeperiod.dateranges[0].eyear
        assert 9 == timeperiod.dateranges[0].emon
        assert 0 == timeperiod.dateranges[0].emday
        assert 4 == timeperiod.dateranges[0].ewday
        assert 2 == timeperiod.dateranges[0].ewday_offset
        assert 0 == timeperiod.dateranges[0].skip_interval
        assert '00:00-24:00' == timeperiod.dateranges[0].other
开发者ID:Alignak-monitoring,项目名称:alignak,代码行数:21,代码来源:test_dateranges.py


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