Example #1
0
    def test_post_to_bucket_serializes_datetimes(self, requests):
        bucket = Bucket(None, None)

        bucket.post({'key': datetime(2012, 12, 12)})

        requests.post.assert_called_with(
            url=mock.ANY,
            headers=mock.ANY,
            data='{"key": "2012-12-12T00:00:00+00:00"}'
        )
Example #2
0
    def test_post_data_to_bucket(self, requests):
        bucket = Bucket('foo', 'bar')

        bucket.post({'key': 'value'})

        requests.post.assert_called_with(
            url='foo',
            headers={
                'Authorization': 'Bearer bar',
                'Content-type': 'application/json'
            },
            data='{"key": "value"}'
        )
        'check': name_of_check
    }


def truncate_hour_fraction(a_datetime):
    return a_datetime.replace(minute=0, second=0, microsecond=0)


if __name__ == '__main__':
    app_path = os.path.dirname(os.path.realpath(__file__))
    logfile_path = os.path.join(app_path, 'log')
    set_up_logging('pingdom', logging.DEBUG, logfile_path)

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

    collection_date = datetime.now()
    if args.end_at:
        collection_date = args.end_at

    pingdom = Pingdom(args.credentials)

    check_name = args.query['query']['name']
    timestamp = truncate_hour_fraction(collection_date)
    pingdom_stats = pingdom.stats_for_24_hours(check_name, timestamp)

    bucket_url = args.query['target']['bucket']
    bucket_token = args.query['target']['token']
    bucket = Bucket(url=bucket_url, token=bucket_token)
    bucket.post([convert_from_pingdom_to_backdrop(thing, check_name) for
                 thing in pingdom_stats])