|
| 1 | +// Create a new timeseries widget with incident_analytics data source |
| 2 | +use datadog_api_client::datadog; |
| 3 | +use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI; |
| 4 | +use datadog_api_client::datadogV1::model::Dashboard; |
| 5 | +use datadog_api_client::datadogV1::model::DashboardLayoutType; |
| 6 | +use datadog_api_client::datadogV1::model::DashboardReflowType; |
| 7 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionEventAggregation; |
| 8 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinition; |
| 9 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionCompute; |
| 10 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionSearch; |
| 11 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionEventsDataSource; |
| 12 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition; |
| 13 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat; |
| 14 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinition; |
| 15 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinitionType; |
| 16 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetLegendColumn; |
| 17 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetLegendLayout; |
| 18 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetRequest; |
| 19 | +use datadog_api_client::datadogV1::model::Widget; |
| 20 | +use datadog_api_client::datadogV1::model::WidgetDefinition; |
| 21 | +use datadog_api_client::datadogV1::model::WidgetDisplayType; |
| 22 | +use datadog_api_client::datadogV1::model::WidgetFormula; |
| 23 | +use datadog_api_client::datadogV1::model::WidgetLineType; |
| 24 | +use datadog_api_client::datadogV1::model::WidgetLineWidth; |
| 25 | +use datadog_api_client::datadogV1::model::WidgetRequestStyle; |
| 26 | +use datadog_api_client::datadogV1::model::WidgetTime; |
| 27 | + |
| 28 | +#[tokio::main] |
| 29 | +async fn main() { |
| 30 | + let body = |
| 31 | + Dashboard::new( |
| 32 | + DashboardLayoutType::ORDERED, |
| 33 | + "Example-Dashboard with incident_analytics datasource".to_string(), |
| 34 | + vec![ |
| 35 | + Widget::new( |
| 36 | + WidgetDefinition::TimeseriesWidgetDefinition( |
| 37 | + Box::new( |
| 38 | + TimeseriesWidgetDefinition::new( |
| 39 | + vec![ |
| 40 | + TimeseriesWidgetRequest::new() |
| 41 | + .display_type(WidgetDisplayType::LINE) |
| 42 | + .formulas(vec![WidgetFormula::new("query1".to_string())]) |
| 43 | + .queries( |
| 44 | + vec![ |
| 45 | + FormulaAndFunctionQueryDefinition |
| 46 | + ::FormulaAndFunctionEventQueryDefinition( |
| 47 | + Box::new( |
| 48 | + FormulaAndFunctionEventQueryDefinition::new( |
| 49 | + FormulaAndFunctionEventQueryDefinitionCompute::new( |
| 50 | + FormulaAndFunctionEventAggregation::COUNT, |
| 51 | + ), |
| 52 | + FormulaAndFunctionEventsDataSource::INCIDENT_ANALYTICS, |
| 53 | + "query1".to_string(), |
| 54 | + ) |
| 55 | + .group_by(vec![]) |
| 56 | + .indexes(vec!["*".to_string()]) |
| 57 | + .search( |
| 58 | + FormulaAndFunctionEventQueryDefinitionSearch::new( |
| 59 | + "test_level:test".to_string(), |
| 60 | + ), |
| 61 | + ), |
| 62 | + ), |
| 63 | + ) |
| 64 | + ], |
| 65 | + ) |
| 66 | + .response_format(FormulaAndFunctionResponseFormat::TIMESERIES) |
| 67 | + .style( |
| 68 | + WidgetRequestStyle::new() |
| 69 | + .line_type(WidgetLineType::SOLID) |
| 70 | + .line_width(WidgetLineWidth::NORMAL) |
| 71 | + .palette("dog_classic".to_string()), |
| 72 | + ) |
| 73 | + ], |
| 74 | + TimeseriesWidgetDefinitionType::TIMESERIES, |
| 75 | + ) |
| 76 | + .legend_columns( |
| 77 | + vec![ |
| 78 | + TimeseriesWidgetLegendColumn::AVG, |
| 79 | + TimeseriesWidgetLegendColumn::MIN, |
| 80 | + TimeseriesWidgetLegendColumn::MAX, |
| 81 | + TimeseriesWidgetLegendColumn::VALUE, |
| 82 | + TimeseriesWidgetLegendColumn::SUM |
| 83 | + ], |
| 84 | + ) |
| 85 | + .legend_layout(TimeseriesWidgetLegendLayout::AUTO) |
| 86 | + .show_legend(true) |
| 87 | + .time(WidgetTime::new()) |
| 88 | + .title("".to_string()), |
| 89 | + ), |
| 90 | + ), |
| 91 | + ) |
| 92 | + ], |
| 93 | + ).reflow_type(DashboardReflowType::AUTO); |
| 94 | + let configuration = datadog::Configuration::new(); |
| 95 | + let api = DashboardsAPI::with_config(configuration); |
| 96 | + let resp = api.create_dashboard(body).await; |
| 97 | + if let Ok(value) = resp { |
| 98 | + println!("{:#?}", value); |
| 99 | + } else { |
| 100 | + println!("{:#?}", resp.unwrap_err()); |
| 101 | + } |
| 102 | +} |
0 commit comments