def test_querying_for_stats(self, send_request):

        def mock_send_request(*args, **kwargs):
            if kwargs["path"] == "summary.performance/12345":
                return {"summary": {"hours": []}}
            if kwargs["path"] == "checks":
                return {"checks": [{"name": "Foo", "id": 12345}]}

        send_request.side_effect = mock_send_request

        pingdom = Pingdom(self.config)

        uptime = pingdom.stats(
            check_name='Foo',
            start=datetime(2012, 12, 31, 18, 0, 0),
            end=datetime(2013, 1, 1, 18, 0, 0)
        )

        send_request.assert_called_with(
            path="summary.performance/12345",
            user="******",
            password="******",
            app_key="12345",
            url_params={
                "includeuptime": "true",
                "from": unix_timestamp(datetime(2012, 12, 31, 18, 0, 0)),
                "to": unix_timestamp(datetime(2013, 1, 1, 18, 0, 0)),
                "resolution": "hour"
            }
        )

        assert_that(uptime, is_([]))
Пример #2
0
    def test_response_unixtime_converted_to_isodate(self, mock_get_request):
        mock_response = Mock()
        mock_response.json.return_value = {
            'summary': {
                'hours': [{
                    'starttime': 1356998400
                }, {
                    'starttime': 1356998500
                }]
            }
        }
        mock_get_request.return_value = mock_response

        pingdom = Pingdom(self.config)

        mock_check_id = Mock()
        mock_check_id.return_value = '12345'
        pingdom.check_id = mock_check_id
        uptime = pingdom.stats(check_name='Foo',
                               start=date(2012, 12, 31),
                               end=date(2013, 1, 1))

        assert_that(uptime[0]['starttime'],
                    is_(datetime(2013, 1, 1, 0, tzinfo=pytz.UTC)))
        assert_that(uptime[1]['starttime'],
                    is_(datetime(2013, 1, 1, 0, 1, 40, tzinfo=pytz.UTC)))
Пример #3
0
    def test_querying_for_stats(self, send_request):
        def mock_send_request(*args, **kwargs):
            if kwargs["path"] == "summary.performance/12345":
                return {"summary": {"hours": []}}
            if kwargs["path"] == "checks":
                return {"checks": [{"name": "Foo", "id": 12345}]}

        send_request.side_effect = mock_send_request

        pingdom = Pingdom(self.config)

        uptime = pingdom.stats(check_name='Foo',
                               start=datetime(2012, 12, 31, 18, 0, 0),
                               end=datetime(2013, 1, 1, 18, 0, 0))

        send_request.assert_called_with(
            path="summary.performance/12345",
            user="******",
            password="******",
            app_key="12345",
            url_params={
                "includeuptime": "true",
                "from": unix_timestamp(datetime(2012, 12, 31, 18, 0, 0)),
                "to": unix_timestamp(datetime(2013, 1, 1, 18, 0, 0)),
                "resolution": "hour"
            })

        assert_that(uptime, is_([]))
Пример #4
0
    def test_stats_returns_none_when_there_is_an_error(self, send_request):
        send_request.side_effect = requests.exceptions.HTTPError()

        pingdom = Pingdom(self.config)
        mock_check_id = Mock()
        mock_check_id.return_value = '12345'
        pingdom.check_id = mock_check_id
        uptime = pingdom.stats(check_name="don't care",
                               start=date(2012, 12, 31),
                               end=date(2013, 1, 1))
        assert_that(uptime, is_(None))
    def test_stats_returns_none_when_there_is_an_error(self, send_request):
        send_request.side_effect = requests.exceptions.HTTPError()

        pingdom = Pingdom(self.config)
        mock_check_id = Mock()
        mock_check_id.return_value = '12345'
        pingdom.check_id = mock_check_id
        uptime = pingdom.stats(
            check_name="don't care",
            start=date(2012, 12, 31),
            end=date(2013, 1, 1))
        assert_that(uptime, is_(None))
def main():
    configure_logging()

    args = arguments.parse_args(name="Pingdom")

    start_dt, end_dt = parse_time_range(args.start_at, args.end_at)

    pingdom = Pingdom(args.credentials)

    check_name = args.query['query']['name']
    pingdom_stats = pingdom.stats(check_name, start_dt, end_dt)

    push_stats_to_data_set(
        pingdom_stats,
        check_name,
        data_set_url=args.query['target']['data_set'],
        data_set_token=args.query['target']['token'])
    def test_response_unixtime_converted_to_isodate(self, mock_get_request):
        mock_response = Mock()
        mock_response.json.return_value = {
            'summary': {
                'hours': [{'starttime': 1356998400}, {'starttime': 1356998500}]
            }
        }
        mock_get_request.return_value = mock_response

        pingdom = Pingdom(self.config)

        mock_check_id = Mock()
        mock_check_id.return_value = '12345'
        pingdom.check_id = mock_check_id
        uptime = pingdom.stats(
            check_name='Foo',
            start=date(2012, 12, 31),
            end=date(2013, 1, 1))

        assert_that(uptime[0]['starttime'],
                    is_(datetime(2013, 1, 1, 0, tzinfo=pytz.UTC)))
        assert_that(uptime[1]['starttime'],
                    is_(datetime(2013, 1, 1, 0, 1, 40, tzinfo=pytz.UTC)))