v1_dashboards_CreateDashboard_1024858348/
v1_dashboards_CreateDashboard_1024858348.rs

1// Create a new dashboard with a formulas and functions treemap widget
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI;
4use datadog_api_client::datadogV1::model::Dashboard;
5use datadog_api_client::datadogV1::model::DashboardLayoutType;
6use datadog_api_client::datadogV1::model::FormulaAndFunctionEventAggregation;
7use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinition;
8use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionCompute;
9use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionSearch;
10use datadog_api_client::datadogV1::model::FormulaAndFunctionEventsDataSource;
11use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
12use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
13use datadog_api_client::datadogV1::model::TreeMapWidgetDefinition;
14use datadog_api_client::datadogV1::model::TreeMapWidgetDefinitionType;
15use datadog_api_client::datadogV1::model::TreeMapWidgetRequest;
16use datadog_api_client::datadogV1::model::Widget;
17use datadog_api_client::datadogV1::model::WidgetDefinition;
18use datadog_api_client::datadogV1::model::WidgetFormula;
19use datadog_api_client::datadogV1::model::WidgetLayout;
20
21#[tokio::main]
22async fn main() {
23    let body =
24        Dashboard::new(
25            DashboardLayoutType::ORDERED,
26            "Example-Dashboard".to_string(),
27            vec![
28                Widget::new(
29                    WidgetDefinition::TreeMapWidgetDefinition(
30                        Box::new(
31                            TreeMapWidgetDefinition::new(
32                                vec![
33                                    TreeMapWidgetRequest::new()
34                                        .formulas(
35                                            vec![
36                                                WidgetFormula::new("hour_before(query1)".to_string()),
37                                                WidgetFormula::new("query1".to_string())
38                                            ],
39                                        )
40                                        .queries(
41                                            vec![
42                                                FormulaAndFunctionQueryDefinition
43                                                ::FormulaAndFunctionEventQueryDefinition(
44                                                    Box::new(
45                                                        FormulaAndFunctionEventQueryDefinition::new(
46                                                            FormulaAndFunctionEventQueryDefinitionCompute::new(
47                                                                FormulaAndFunctionEventAggregation::COUNT,
48                                                            ),
49                                                            FormulaAndFunctionEventsDataSource::LOGS,
50                                                            "query1".to_string(),
51                                                        )
52                                                            .group_by(vec![])
53                                                            .indexes(vec!["*".to_string()])
54                                                            .search(
55                                                                FormulaAndFunctionEventQueryDefinitionSearch::new(
56                                                                    "".to_string(),
57                                                                ),
58                                                            ),
59                                                    ),
60                                                )
61                                            ],
62                                        )
63                                        .response_format(FormulaAndFunctionResponseFormat::SCALAR)
64                                ],
65                                TreeMapWidgetDefinitionType::TREEMAP,
66                            ).title("".to_string()),
67                        ),
68                    ),
69                ).layout(WidgetLayout::new(4, 4, 0, 0))
70            ],
71        );
72    let configuration = datadog::Configuration::new();
73    let api = DashboardsAPI::with_config(configuration);
74    let resp = api.create_dashboard(body).await;
75    if let Ok(value) = resp {
76        println!("{:#?}", value);
77    } else {
78        println!("{:#?}", resp.unwrap_err());
79    }
80}