|
| 1 | +// Clients deserialize a dashboard with a empty time object |
| 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::FormulaAndFunctionCloudCostDataSource; |
| 7 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionCloudCostQueryDefinition; |
| 8 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition; |
| 9 | +use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat; |
| 10 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinition; |
| 11 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinitionType; |
| 12 | +use datadog_api_client::datadogV1::model::TimeseriesWidgetRequest; |
| 13 | +use datadog_api_client::datadogV1::model::Widget; |
| 14 | +use datadog_api_client::datadogV1::model::WidgetDefinition; |
| 15 | +use datadog_api_client::datadogV1::model::WidgetDisplayType; |
| 16 | +use datadog_api_client::datadogV1::model::WidgetFormula; |
| 17 | +use datadog_api_client::datadogV1::model::WidgetLegacyLiveSpan; |
| 18 | +use datadog_api_client::datadogV1::model::WidgetLineType; |
| 19 | +use datadog_api_client::datadogV1::model::WidgetLineWidth; |
| 20 | +use datadog_api_client::datadogV1::model::WidgetRequestStyle; |
| 21 | +use datadog_api_client::datadogV1::model::WidgetTextAlign; |
| 22 | +use datadog_api_client::datadogV1::model::WidgetTime; |
| 23 | + |
| 24 | +#[tokio::main] |
| 25 | +async fn main() { |
| 26 | + let body = |
| 27 | + Dashboard::new( |
| 28 | + DashboardLayoutType::ORDERED, |
| 29 | + "Example-Dashboard".to_string(), |
| 30 | + vec![ |
| 31 | + Widget::new( |
| 32 | + WidgetDefinition::TimeseriesWidgetDefinition( |
| 33 | + Box::new( |
| 34 | + TimeseriesWidgetDefinition::new( |
| 35 | + vec![ |
| 36 | + TimeseriesWidgetRequest::new() |
| 37 | + .display_type(WidgetDisplayType::BARS) |
| 38 | + .formulas(vec![WidgetFormula::new("query1".to_string())]) |
| 39 | + .queries( |
| 40 | + vec![ |
| 41 | + FormulaAndFunctionQueryDefinition |
| 42 | + ::FormulaAndFunctionCloudCostQueryDefinition( |
| 43 | + Box::new( |
| 44 | + FormulaAndFunctionCloudCostQueryDefinition::new( |
| 45 | + FormulaAndFunctionCloudCostDataSource::CLOUD_COST, |
| 46 | + "query1".to_string(), |
| 47 | + "sum:aws.cost.amortized{*} by {aws_product}.rollup(sum, monthly)".to_string(), |
| 48 | + ), |
| 49 | + ), |
| 50 | + ) |
| 51 | + ], |
| 52 | + ) |
| 53 | + .response_format(FormulaAndFunctionResponseFormat::TIMESERIES) |
| 54 | + .style( |
| 55 | + WidgetRequestStyle::new() |
| 56 | + .line_type(WidgetLineType::SOLID) |
| 57 | + .line_width(WidgetLineWidth::NORMAL) |
| 58 | + .palette("dog_classic".to_string()), |
| 59 | + ) |
| 60 | + ], |
| 61 | + TimeseriesWidgetDefinitionType::TIMESERIES, |
| 62 | + ) |
| 63 | + .time(WidgetTime::WidgetLegacyLiveSpan(Box::new(WidgetLegacyLiveSpan::new()))) |
| 64 | + .title("Example Cloud Cost Query".to_string()) |
| 65 | + .title_align(WidgetTextAlign::LEFT) |
| 66 | + .title_size("16".to_string()), |
| 67 | + ), |
| 68 | + ), |
| 69 | + ) |
| 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 | +} |
0 commit comments