|
| 1 | +""" |
| 2 | +Create a new dashboard with query_table widget and cell_display_mode is trend |
| 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_metric_aggregation import FormulaAndFunctionMetricAggregation |
| 10 | +from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource |
| 11 | +from datadog_api_client.v1.model.formula_and_function_metric_query_definition import ( |
| 12 | + FormulaAndFunctionMetricQueryDefinition, |
| 13 | +) |
| 14 | +from datadog_api_client.v1.model.formula_and_function_response_format import FormulaAndFunctionResponseFormat |
| 15 | +from datadog_api_client.v1.model.formula_type import FormulaType |
| 16 | +from datadog_api_client.v1.model.table_widget_cell_display_mode import TableWidgetCellDisplayMode |
| 17 | +from datadog_api_client.v1.model.table_widget_definition import TableWidgetDefinition |
| 18 | +from datadog_api_client.v1.model.table_widget_definition_type import TableWidgetDefinitionType |
| 19 | +from datadog_api_client.v1.model.table_widget_has_search_bar import TableWidgetHasSearchBar |
| 20 | +from datadog_api_client.v1.model.table_widget_request import TableWidgetRequest |
| 21 | +from datadog_api_client.v1.model.widget import Widget |
| 22 | +from datadog_api_client.v1.model.widget_formula import WidgetFormula |
| 23 | +from datadog_api_client.v1.model.widget_formula_cell_display_mode_options import WidgetFormulaCellDisplayModeOptions |
| 24 | +from datadog_api_client.v1.model.widget_formula_cell_display_mode_options_trend_type import ( |
| 25 | + WidgetFormulaCellDisplayModeOptionsTrendType, |
| 26 | +) |
| 27 | +from datadog_api_client.v1.model.widget_formula_cell_display_mode_options_y_scale import ( |
| 28 | + WidgetFormulaCellDisplayModeOptionsYScale, |
| 29 | +) |
| 30 | +from datadog_api_client.v1.model.widget_formula_sort import WidgetFormulaSort |
| 31 | +from datadog_api_client.v1.model.widget_layout import WidgetLayout |
| 32 | +from datadog_api_client.v1.model.widget_legacy_live_span import WidgetLegacyLiveSpan |
| 33 | +from datadog_api_client.v1.model.widget_sort import WidgetSort |
| 34 | +from datadog_api_client.v1.model.widget_sort_by import WidgetSortBy |
| 35 | +from datadog_api_client.v1.model.widget_text_align import WidgetTextAlign |
| 36 | + |
| 37 | +body = Dashboard( |
| 38 | + title="Example-Dashboard", |
| 39 | + description="", |
| 40 | + widgets=[ |
| 41 | + Widget( |
| 42 | + layout=WidgetLayout( |
| 43 | + x=0, |
| 44 | + y=0, |
| 45 | + width=54, |
| 46 | + height=32, |
| 47 | + ), |
| 48 | + definition=TableWidgetDefinition( |
| 49 | + title="", |
| 50 | + title_size="16", |
| 51 | + title_align=WidgetTextAlign.LEFT, |
| 52 | + time=WidgetLegacyLiveSpan(), |
| 53 | + type=TableWidgetDefinitionType.QUERY_TABLE, |
| 54 | + requests=[ |
| 55 | + TableWidgetRequest( |
| 56 | + queries=[ |
| 57 | + FormulaAndFunctionMetricQueryDefinition( |
| 58 | + data_source=FormulaAndFunctionMetricDataSource.METRICS, |
| 59 | + name="query1", |
| 60 | + query="avg:system.cpu.user{*} by {host}", |
| 61 | + aggregator=FormulaAndFunctionMetricAggregation.AVG, |
| 62 | + ), |
| 63 | + ], |
| 64 | + formulas=[ |
| 65 | + WidgetFormula( |
| 66 | + formula="query1", |
| 67 | + conditional_formats=[], |
| 68 | + cell_display_mode=TableWidgetCellDisplayMode.TREND, |
| 69 | + cell_display_mode_options=WidgetFormulaCellDisplayModeOptions( |
| 70 | + trend_type=WidgetFormulaCellDisplayModeOptionsTrendType.LINE, |
| 71 | + y_scale=WidgetFormulaCellDisplayModeOptionsYScale.SHARED, |
| 72 | + ), |
| 73 | + ), |
| 74 | + ], |
| 75 | + sort=WidgetSortBy( |
| 76 | + count=500, |
| 77 | + order_by=[ |
| 78 | + WidgetFormulaSort( |
| 79 | + type=FormulaType.FORMULA, |
| 80 | + index=0, |
| 81 | + order=WidgetSort.DESCENDING, |
| 82 | + ), |
| 83 | + ], |
| 84 | + ), |
| 85 | + response_format=FormulaAndFunctionResponseFormat.SCALAR, |
| 86 | + ), |
| 87 | + ], |
| 88 | + has_search_bar=TableWidgetHasSearchBar.AUTO, |
| 89 | + ), |
| 90 | + ), |
| 91 | + ], |
| 92 | + template_variables=[], |
| 93 | + layout_type=DashboardLayoutType.FREE, |
| 94 | + notify_list=[], |
| 95 | +) |
| 96 | + |
| 97 | +configuration = Configuration() |
| 98 | +with ApiClient(configuration) as api_client: |
| 99 | + api_instance = DashboardsApi(api_client) |
| 100 | + response = api_instance.create_dashboard(body=body) |
| 101 | + |
| 102 | + print(response) |
0 commit comments