def test_graph_snapshot(self): metric_query = "system.load.1{*}" event_query = "*" end = int(time.time()) start = end - 60 * 60 # go back 1 hour # Test without an event query snap = dog.Graph.create(metric_query=metric_query, start=start, end=end) ok('snapshot_url' in snap, msg=snap) ok('metric_query' in snap, msg=snap) ok('event_query' not in snap, msg=snap) eq(snap['metric_query'], metric_query) snapshot_url = snap['snapshot_url'] while dog.Graph.status(snapshot_url)['status_code'] != 200: time.sleep(self.wait_time) if 'localhost' in dog._api_host: snapshot_url = 'http://%s%s' % (dog.api_host, snapshot_url) assert_snap_not_blank(snapshot_url) assert_snap_has_no_events(snapshot_url) # Test with an event query snap = dog.Graph.create(metric_query=metric_query, start=start, end=end, event_query=event_query) ok('snapshot_url' in snap, msg=snap) ok('metric_query' in snap, msg=snap) ok('event_query' in snap, msg=snap) eq(snap['metric_query'], metric_query) eq(snap['event_query'], event_query) snapshot_url = snap['snapshot_url'] while dog.Graph.status(snapshot_url)['status_code'] != 200: time.sleep(self.wait_time) if 'localhost' in dog._api_host: snapshot_url = 'http://%s%s' % (dog.api_host, snapshot_url) assert_snap_not_blank(snapshot_url) # Test with a graph def graph_def = { "viz": "toplist", "requests": [{ "q": "top(system.disk.free{*} by {device}, 10, 'mean', 'desc')", "style": { "palette": "dog_classic" }, "conditional_formats": [{ "palette": "red", "comparator": ">", "value": 50000000000 }, { "palette": "green", "comparator": ">", "value": 30000000000 }] }] } graph_def = json.dumps(graph_def) snap = dog.Graph.create(graph_def=graph_def, start=start, end=end) ok('snapshot_url' in snap, msg=snap) ok('graph_def' in snap, msg=snap) ok('metric_query' not in snap, msg=snap) ok('event_query' not in snap, msg=snap) eq(snap['graph_def'], graph_def) snapshot_url = snap['snapshot_url'] while dog.Graph.status(snapshot_url)['status_code'] != 200: time.sleep(self.wait_time) if 'localhost' in dog._api_host: snapshot_url = 'http://%s%s' % (dog.api_host, snapshot_url) assert_snap_not_blank(snapshot_url)