v1_dashboards_CreateDashboard_2361531620/
v1_dashboards_CreateDashboard_2361531620.rs

1// Create a new dashboard with list_stream widget with a valid sort parameter DESC
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::ListStreamColumn;
7use datadog_api_client::datadogV1::model::ListStreamColumnWidth;
8use datadog_api_client::datadogV1::model::ListStreamQuery;
9use datadog_api_client::datadogV1::model::ListStreamResponseFormat;
10use datadog_api_client::datadogV1::model::ListStreamSource;
11use datadog_api_client::datadogV1::model::ListStreamWidgetDefinition;
12use datadog_api_client::datadogV1::model::ListStreamWidgetDefinitionType;
13use datadog_api_client::datadogV1::model::ListStreamWidgetRequest;
14use datadog_api_client::datadogV1::model::Widget;
15use datadog_api_client::datadogV1::model::WidgetDefinition;
16use datadog_api_client::datadogV1::model::WidgetEventSize;
17use datadog_api_client::datadogV1::model::WidgetFieldSort;
18use datadog_api_client::datadogV1::model::WidgetSort;
19
20#[tokio::main]
21async fn main() {
22    let body = Dashboard::new(
23        DashboardLayoutType::ORDERED,
24        "Example-Dashboard with list_stream widget".to_string(),
25        vec![Widget::new(WidgetDefinition::ListStreamWidgetDefinition(
26            Box::new(ListStreamWidgetDefinition::new(
27                vec![ListStreamWidgetRequest::new(
28                    vec![ListStreamColumn::new(
29                        "timestamp".to_string(),
30                        ListStreamColumnWidth::AUTO,
31                    )],
32                    ListStreamQuery::new(ListStreamSource::EVENT_STREAM, "".to_string())
33                        .event_size(WidgetEventSize::LARGE)
34                        .sort(WidgetFieldSort::new(
35                            "timestamp".to_string(),
36                            WidgetSort::DESCENDING,
37                        )),
38                    ListStreamResponseFormat::EVENT_LIST,
39                )],
40                ListStreamWidgetDefinitionType::LIST_STREAM,
41            )),
42        ))],
43    );
44    let configuration = datadog::Configuration::new();
45    let api = DashboardsAPI::with_config(configuration);
46    let resp = api.create_dashboard(body).await;
47    if let Ok(value) = resp {
48        println!("{:#?}", value);
49    } else {
50        println!("{:#?}", resp.unwrap_err());
51    }
52}