|
| 1 | +// Create a geomap widget with conditional formats and text formats |
| 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::FormulaType; |
| 15 | +use datadog_api_client::datadogV1::model::GeomapWidgetDefinition; |
| 16 | +use datadog_api_client::datadogV1::model::GeomapWidgetDefinitionStyle; |
| 17 | +use datadog_api_client::datadogV1::model::GeomapWidgetDefinitionType; |
| 18 | +use datadog_api_client::datadogV1::model::GeomapWidgetDefinitionView; |
| 19 | +use datadog_api_client::datadogV1::model::GeomapWidgetRequest; |
| 20 | +use datadog_api_client::datadogV1::model::GeomapWidgetRequestStyle; |
| 21 | +use datadog_api_client::datadogV1::model::ListStreamColumn; |
| 22 | +use datadog_api_client::datadogV1::model::ListStreamColumnWidth; |
| 23 | +use datadog_api_client::datadogV1::model::ListStreamQuery; |
| 24 | +use datadog_api_client::datadogV1::model::ListStreamSource; |
| 25 | +use datadog_api_client::datadogV1::model::TableWidgetTextFormatMatch; |
| 26 | +use datadog_api_client::datadogV1::model::TableWidgetTextFormatMatchType; |
| 27 | +use datadog_api_client::datadogV1::model::TableWidgetTextFormatPalette; |
| 28 | +use datadog_api_client::datadogV1::model::TableWidgetTextFormatRule; |
| 29 | +use datadog_api_client::datadogV1::model::Widget; |
| 30 | +use datadog_api_client::datadogV1::model::WidgetComparator; |
| 31 | +use datadog_api_client::datadogV1::model::WidgetConditionalFormat; |
| 32 | +use datadog_api_client::datadogV1::model::WidgetDefinition; |
| 33 | +use datadog_api_client::datadogV1::model::WidgetFormula; |
| 34 | +use datadog_api_client::datadogV1::model::WidgetFormulaSort; |
| 35 | +use datadog_api_client::datadogV1::model::WidgetLayout; |
| 36 | +use datadog_api_client::datadogV1::model::WidgetPalette; |
| 37 | +use datadog_api_client::datadogV1::model::WidgetSort; |
| 38 | +use datadog_api_client::datadogV1::model::WidgetSortBy; |
| 39 | +use datadog_api_client::datadogV1::model::WidgetSortOrderBy; |
| 40 | + |
| 41 | +#[tokio::main] |
| 42 | +async fn main() { |
| 43 | + let body = |
| 44 | + Dashboard::new( |
| 45 | + DashboardLayoutType::ORDERED, |
| 46 | + "Example-Dashboard".to_string(), |
| 47 | + vec![ |
| 48 | + Widget::new( |
| 49 | + WidgetDefinition::GeomapWidgetDefinition( |
| 50 | + Box::new( |
| 51 | + GeomapWidgetDefinition::new( |
| 52 | + vec![ |
| 53 | + GeomapWidgetRequest::new() |
| 54 | + .conditional_formats( |
| 55 | + vec![ |
| 56 | + WidgetConditionalFormat::new( |
| 57 | + WidgetComparator::GREATER_THAN, |
| 58 | + WidgetPalette::WHITE_ON_GREEN, |
| 59 | + 1000.0, |
| 60 | + ) |
| 61 | + ], |
| 62 | + ) |
| 63 | + .formulas(vec![WidgetFormula::new("query1".to_string())]) |
| 64 | + .queries( |
| 65 | + vec![ |
| 66 | + FormulaAndFunctionQueryDefinition |
| 67 | + ::FormulaAndFunctionEventQueryDefinition( |
| 68 | + Box::new( |
| 69 | + FormulaAndFunctionEventQueryDefinition::new( |
| 70 | + FormulaAndFunctionEventQueryDefinitionCompute::new( |
| 71 | + FormulaAndFunctionEventAggregation::COUNT, |
| 72 | + ), |
| 73 | + FormulaAndFunctionEventsDataSource::RUM, |
| 74 | + "query1".to_string(), |
| 75 | + ) |
| 76 | + .group_by(vec![]) |
| 77 | + .indexes(vec!["*".to_string()]) |
| 78 | + .search( |
| 79 | + FormulaAndFunctionEventQueryDefinitionSearch::new( |
| 80 | + "@type:session".to_string(), |
| 81 | + ), |
| 82 | + ), |
| 83 | + ), |
| 84 | + ) |
| 85 | + ], |
| 86 | + ) |
| 87 | + .response_format(FormulaAndFunctionResponseFormat::SCALAR) |
| 88 | + .sort( |
| 89 | + WidgetSortBy::new() |
| 90 | + .count(250) |
| 91 | + .order_by( |
| 92 | + vec![ |
| 93 | + WidgetSortOrderBy::WidgetFormulaSort( |
| 94 | + Box::new( |
| 95 | + WidgetFormulaSort::new( |
| 96 | + 0, |
| 97 | + WidgetSort::DESCENDING, |
| 98 | + FormulaType::FORMULA, |
| 99 | + ), |
| 100 | + ), |
| 101 | + ) |
| 102 | + ], |
| 103 | + ), |
| 104 | + ), |
| 105 | + GeomapWidgetRequest::new() |
| 106 | + .columns( |
| 107 | + vec![ |
| 108 | + ListStreamColumn::new( |
| 109 | + "@network.client.geoip.location.latitude".to_string(), |
| 110 | + ListStreamColumnWidth::AUTO, |
| 111 | + ), |
| 112 | + ListStreamColumn::new( |
| 113 | + "@network.client.geoip.location.longitude".to_string(), |
| 114 | + ListStreamColumnWidth::AUTO, |
| 115 | + ), |
| 116 | + ListStreamColumn::new( |
| 117 | + "@network.client.geoip.country.iso_code".to_string(), |
| 118 | + ListStreamColumnWidth::AUTO, |
| 119 | + ), |
| 120 | + ListStreamColumn::new( |
| 121 | + "@network.client.geoip.subdivision.name".to_string(), |
| 122 | + ListStreamColumnWidth::AUTO, |
| 123 | + ) |
| 124 | + ], |
| 125 | + ) |
| 126 | + .query( |
| 127 | + ListStreamQuery::new(ListStreamSource::LOGS_STREAM, "".to_string()) |
| 128 | + .indexes(vec![]) |
| 129 | + .storage("hot".to_string()), |
| 130 | + ) |
| 131 | + .response_format(FormulaAndFunctionResponseFormat::EVENT_LIST) |
| 132 | + .style(GeomapWidgetRequestStyle::new("status".to_string())) |
| 133 | + .text_formats( |
| 134 | + vec![ |
| 135 | + TableWidgetTextFormatRule::new( |
| 136 | + TableWidgetTextFormatMatch::new( |
| 137 | + TableWidgetTextFormatMatchType::IS, |
| 138 | + "error".to_string(), |
| 139 | + ), |
| 140 | + ).palette(TableWidgetTextFormatPalette::WHITE_ON_RED) |
| 141 | + ], |
| 142 | + ) |
| 143 | + ], |
| 144 | + GeomapWidgetDefinitionStyle::new("hostmap_blues".to_string(), false), |
| 145 | + GeomapWidgetDefinitionType::GEOMAP, |
| 146 | + GeomapWidgetDefinitionView::new("NORTH_AMERICA".to_string()), |
| 147 | + ).title("Log Count by Service and Source".to_string()), |
| 148 | + ), |
| 149 | + ), |
| 150 | + ).layout(WidgetLayout::new(6, 12, 0, 0)) |
| 151 | + ], |
| 152 | + ) |
| 153 | + .description(Some("Example-Dashboard".to_string())) |
| 154 | + .notify_list(Some(vec![])) |
| 155 | + .reflow_type(DashboardReflowType::FIXED) |
| 156 | + .tags(Some(vec![])) |
| 157 | + .template_variables(Some(vec![])); |
| 158 | + let configuration = datadog::Configuration::new(); |
| 159 | + let api = DashboardsAPI::with_config(configuration); |
| 160 | + let resp = api.create_dashboard(body).await; |
| 161 | + if let Ok(value) = resp { |
| 162 | + println!("{:#?}", value); |
| 163 | + } else { |
| 164 | + println!("{:#?}", resp.unwrap_err()); |
| 165 | + } |
| 166 | +} |
0 commit comments