v1_dashboards_CreateDashboard_2843286292/
v1_dashboards_CreateDashboard_2843286292.rs

1// Create a new dashboard with logs_transaction_stream list_stream 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::ListStreamColumn;
7use datadog_api_client::datadogV1::model::ListStreamColumnWidth;
8use datadog_api_client::datadogV1::model::ListStreamComputeAggregation;
9use datadog_api_client::datadogV1::model::ListStreamComputeItems;
10use datadog_api_client::datadogV1::model::ListStreamGroupByItems;
11use datadog_api_client::datadogV1::model::ListStreamQuery;
12use datadog_api_client::datadogV1::model::ListStreamResponseFormat;
13use datadog_api_client::datadogV1::model::ListStreamSource;
14use datadog_api_client::datadogV1::model::ListStreamWidgetDefinition;
15use datadog_api_client::datadogV1::model::ListStreamWidgetDefinitionType;
16use datadog_api_client::datadogV1::model::ListStreamWidgetRequest;
17use datadog_api_client::datadogV1::model::Widget;
18use datadog_api_client::datadogV1::model::WidgetDefinition;
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::LOGS_TRANSACTION_STREAM, "".to_string())
33                        .compute(vec![ListStreamComputeItems::new(
34                            ListStreamComputeAggregation::COUNT,
35                        )
36                        .facet("service".to_string())])
37                        .group_by(vec![ListStreamGroupByItems::new("service".to_string())]),
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}