|
| 1 | +""" |
| 2 | +Create a new timeseries widget with product_analytics data source |
| 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.dashboard_reflow_type import DashboardReflowType |
| 10 | +from datadog_api_client.v1.model.formula_and_function_event_aggregation import FormulaAndFunctionEventAggregation |
| 11 | +from datadog_api_client.v1.model.formula_and_function_event_query_definition import ( |
| 12 | + FormulaAndFunctionEventQueryDefinition, |
| 13 | +) |
| 14 | +from datadog_api_client.v1.model.formula_and_function_event_query_definition_compute import ( |
| 15 | + FormulaAndFunctionEventQueryDefinitionCompute, |
| 16 | +) |
| 17 | +from datadog_api_client.v1.model.formula_and_function_event_query_definition_search import ( |
| 18 | + FormulaAndFunctionEventQueryDefinitionSearch, |
| 19 | +) |
| 20 | +from datadog_api_client.v1.model.formula_and_function_events_data_source import FormulaAndFunctionEventsDataSource |
| 21 | +from datadog_api_client.v1.model.formula_and_function_response_format import FormulaAndFunctionResponseFormat |
| 22 | +from datadog_api_client.v1.model.timeseries_widget_definition import TimeseriesWidgetDefinition |
| 23 | +from datadog_api_client.v1.model.timeseries_widget_definition_type import TimeseriesWidgetDefinitionType |
| 24 | +from datadog_api_client.v1.model.timeseries_widget_legend_column import TimeseriesWidgetLegendColumn |
| 25 | +from datadog_api_client.v1.model.timeseries_widget_legend_layout import TimeseriesWidgetLegendLayout |
| 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_display_type import WidgetDisplayType |
| 29 | +from datadog_api_client.v1.model.widget_formula import WidgetFormula |
| 30 | +from datadog_api_client.v1.model.widget_legacy_live_span import WidgetLegacyLiveSpan |
| 31 | +from datadog_api_client.v1.model.widget_line_type import WidgetLineType |
| 32 | +from datadog_api_client.v1.model.widget_line_width import WidgetLineWidth |
| 33 | +from datadog_api_client.v1.model.widget_request_style import WidgetRequestStyle |
| 34 | + |
| 35 | +body = Dashboard( |
| 36 | + title="Example-Dashboard with product_analytics datasource", |
| 37 | + widgets=[ |
| 38 | + Widget( |
| 39 | + definition=TimeseriesWidgetDefinition( |
| 40 | + title="", |
| 41 | + show_legend=True, |
| 42 | + legend_layout=TimeseriesWidgetLegendLayout.AUTO, |
| 43 | + legend_columns=[ |
| 44 | + TimeseriesWidgetLegendColumn.AVG, |
| 45 | + TimeseriesWidgetLegendColumn.MIN, |
| 46 | + TimeseriesWidgetLegendColumn.MAX, |
| 47 | + TimeseriesWidgetLegendColumn.VALUE, |
| 48 | + TimeseriesWidgetLegendColumn.SUM, |
| 49 | + ], |
| 50 | + time=WidgetLegacyLiveSpan(), |
| 51 | + type=TimeseriesWidgetDefinitionType.TIMESERIES, |
| 52 | + requests=[ |
| 53 | + TimeseriesWidgetRequest( |
| 54 | + formulas=[ |
| 55 | + WidgetFormula( |
| 56 | + formula="query1", |
| 57 | + ), |
| 58 | + ], |
| 59 | + queries=[ |
| 60 | + FormulaAndFunctionEventQueryDefinition( |
| 61 | + data_source=FormulaAndFunctionEventsDataSource.PRODUCT_ANALYTICS, |
| 62 | + name="query1", |
| 63 | + search=FormulaAndFunctionEventQueryDefinitionSearch( |
| 64 | + query="test_level:test", |
| 65 | + ), |
| 66 | + indexes=[ |
| 67 | + "*", |
| 68 | + ], |
| 69 | + compute=FormulaAndFunctionEventQueryDefinitionCompute( |
| 70 | + aggregation=FormulaAndFunctionEventAggregation.COUNT, |
| 71 | + ), |
| 72 | + group_by=[], |
| 73 | + ), |
| 74 | + ], |
| 75 | + response_format=FormulaAndFunctionResponseFormat.TIMESERIES, |
| 76 | + style=WidgetRequestStyle( |
| 77 | + palette="dog_classic", |
| 78 | + line_type=WidgetLineType.SOLID, |
| 79 | + line_width=WidgetLineWidth.NORMAL, |
| 80 | + ), |
| 81 | + display_type=WidgetDisplayType.LINE, |
| 82 | + ), |
| 83 | + ], |
| 84 | + ), |
| 85 | + ), |
| 86 | + ], |
| 87 | + layout_type=DashboardLayoutType.ORDERED, |
| 88 | + reflow_type=DashboardReflowType.AUTO, |
| 89 | +) |
| 90 | + |
| 91 | +configuration = Configuration() |
| 92 | +with ApiClient(configuration) as api_client: |
| 93 | + api_instance = DashboardsApi(api_client) |
| 94 | + response = api_instance.create_dashboard(body=body) |
| 95 | + |
| 96 | + print(response) |
0 commit comments