|
| 1 | +""" |
| 2 | +Create a new dashboard with formulas and functions events query using flat group by fields |
| 3 | +""" |
| 4 | + |
| 5 | +from datadog_api_client import ApiClient, Configuration |
| 6 | +from datadog_api_client.v1.api.dashboards_api import DashboardsApi |
| 7 | +from datadog_api_client.v1.model.dashboard import Dashboard |
| 8 | +from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType |
| 9 | +from datadog_api_client.v1.model.formula_and_function_event_aggregation import FormulaAndFunctionEventAggregation |
| 10 | +from datadog_api_client.v1.model.formula_and_function_event_query_definition import ( |
| 11 | + FormulaAndFunctionEventQueryDefinition, |
| 12 | +) |
| 13 | +from datadog_api_client.v1.model.formula_and_function_event_query_definition_compute import ( |
| 14 | + FormulaAndFunctionEventQueryDefinitionCompute, |
| 15 | +) |
| 16 | +from datadog_api_client.v1.model.formula_and_function_event_query_definition_search import ( |
| 17 | + FormulaAndFunctionEventQueryDefinitionSearch, |
| 18 | +) |
| 19 | +from datadog_api_client.v1.model.formula_and_function_event_query_group_by_fields import ( |
| 20 | + FormulaAndFunctionEventQueryGroupByFields, |
| 21 | +) |
| 22 | +from datadog_api_client.v1.model.formula_and_function_events_data_source import FormulaAndFunctionEventsDataSource |
| 23 | +from datadog_api_client.v1.model.formula_and_function_response_format import FormulaAndFunctionResponseFormat |
| 24 | +from datadog_api_client.v1.model.timeseries_widget_definition import TimeseriesWidgetDefinition |
| 25 | +from datadog_api_client.v1.model.timeseries_widget_definition_type import TimeseriesWidgetDefinitionType |
| 26 | +from datadog_api_client.v1.model.timeseries_widget_request import TimeseriesWidgetRequest |
| 27 | +from datadog_api_client.v1.model.widget import Widget |
| 28 | +from datadog_api_client.v1.model.widget_layout import WidgetLayout |
| 29 | + |
| 30 | +body = Dashboard( |
| 31 | + title="Example-Dashboard with events flat group_by fields", |
| 32 | + widgets=[ |
| 33 | + Widget( |
| 34 | + definition=TimeseriesWidgetDefinition( |
| 35 | + type=TimeseriesWidgetDefinitionType.TIMESERIES, |
| 36 | + requests=[ |
| 37 | + TimeseriesWidgetRequest( |
| 38 | + response_format=FormulaAndFunctionResponseFormat.TIMESERIES, |
| 39 | + queries=[ |
| 40 | + FormulaAndFunctionEventQueryDefinition( |
| 41 | + data_source=FormulaAndFunctionEventsDataSource.EVENTS, |
| 42 | + name="query1", |
| 43 | + search=FormulaAndFunctionEventQueryDefinitionSearch( |
| 44 | + query="", |
| 45 | + ), |
| 46 | + compute=FormulaAndFunctionEventQueryDefinitionCompute( |
| 47 | + aggregation=FormulaAndFunctionEventAggregation.COUNT, |
| 48 | + ), |
| 49 | + group_by=FormulaAndFunctionEventQueryGroupByFields( |
| 50 | + fields=[ |
| 51 | + "service", |
| 52 | + "host", |
| 53 | + ], |
| 54 | + limit=10, |
| 55 | + ), |
| 56 | + ), |
| 57 | + ], |
| 58 | + ), |
| 59 | + ], |
| 60 | + ), |
| 61 | + layout=WidgetLayout( |
| 62 | + x=0, |
| 63 | + y=0, |
| 64 | + width=4, |
| 65 | + height=2, |
| 66 | + ), |
| 67 | + ), |
| 68 | + ], |
| 69 | + layout_type=DashboardLayoutType.ORDERED, |
| 70 | +) |
| 71 | + |
| 72 | +configuration = Configuration() |
| 73 | +with ApiClient(configuration) as api_client: |
| 74 | + api_instance = DashboardsApi(api_client) |
| 75 | + response = api_instance.create_dashboard(body=body) |
| 76 | + |
| 77 | + print(response) |
0 commit comments