|
| 1 | +// Create backfilled degradation returns "Created" response |
| 2 | +use chrono::{DateTime, Utc}; |
| 3 | +use datadog_api_client::datadog; |
| 4 | +use datadog_api_client::datadogV2::api_status_pages::CreateBackfilledDegradationOptionalParams; |
| 5 | +use datadog_api_client::datadogV2::api_status_pages::StatusPagesAPI; |
| 6 | +use datadog_api_client::datadogV2::model::CreateBackfilledDegradationRequest; |
| 7 | +use datadog_api_client::datadogV2::model::CreateBackfilledDegradationRequestData; |
| 8 | +use datadog_api_client::datadogV2::model::CreateBackfilledDegradationRequestDataAttributes; |
| 9 | +use datadog_api_client::datadogV2::model::CreateBackfilledDegradationRequestDataAttributesUpdatesItems; |
| 10 | +use datadog_api_client::datadogV2::model::CreateDegradationRequestDataAttributesComponentsAffectedItems; |
| 11 | +use datadog_api_client::datadogV2::model::CreateDegradationRequestDataAttributesStatus; |
| 12 | +use datadog_api_client::datadogV2::model::PatchDegradationRequestDataType; |
| 13 | +use datadog_api_client::datadogV2::model::StatusPagesComponentDataAttributesStatus; |
| 14 | + |
| 15 | +#[tokio::main] |
| 16 | +async fn main() { |
| 17 | + // there is a valid "status_page" in the system |
| 18 | + let status_page_data_attributes_components_0_components_0_id = uuid::Uuid::parse_str( |
| 19 | + &std::env::var("STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID").unwrap(), |
| 20 | + ) |
| 21 | + .expect("Invalid UUID"); |
| 22 | + let status_page_data_id = uuid::Uuid::parse_str(&std::env::var("STATUS_PAGE_DATA_ID").unwrap()) |
| 23 | + .expect("Invalid UUID"); |
| 24 | + let body = CreateBackfilledDegradationRequest::new().data( |
| 25 | + CreateBackfilledDegradationRequestData::new(PatchDegradationRequestDataType::DEGRADATIONS) |
| 26 | + .attributes(CreateBackfilledDegradationRequestDataAttributes::new( |
| 27 | + "Past API Outage".to_string(), |
| 28 | + vec![ |
| 29 | + CreateBackfilledDegradationRequestDataAttributesUpdatesItems::new( |
| 30 | + DateTime::parse_from_rfc3339("2021-11-11T10:11:11+00:00") |
| 31 | + .expect("Failed to parse datetime") |
| 32 | + .with_timezone(&Utc), |
| 33 | + CreateDegradationRequestDataAttributesStatus::INVESTIGATING, |
| 34 | + ) |
| 35 | + .components_affected(vec![ |
| 36 | + CreateDegradationRequestDataAttributesComponentsAffectedItems::new( |
| 37 | + status_page_data_attributes_components_0_components_0_id.clone(), |
| 38 | + StatusPagesComponentDataAttributesStatus::DEGRADED, |
| 39 | + ), |
| 40 | + ]) |
| 41 | + .description("We detected elevated error rates in the API.".to_string()), |
| 42 | + CreateBackfilledDegradationRequestDataAttributesUpdatesItems::new( |
| 43 | + DateTime::parse_from_rfc3339("2021-11-11T10:41:11+00:00") |
| 44 | + .expect("Failed to parse datetime") |
| 45 | + .with_timezone(&Utc), |
| 46 | + CreateDegradationRequestDataAttributesStatus::IDENTIFIED, |
| 47 | + ) |
| 48 | + .components_affected(vec![ |
| 49 | + CreateDegradationRequestDataAttributesComponentsAffectedItems::new( |
| 50 | + status_page_data_attributes_components_0_components_0_id.clone(), |
| 51 | + StatusPagesComponentDataAttributesStatus::DEGRADED, |
| 52 | + ), |
| 53 | + ]) |
| 54 | + .description( |
| 55 | + "Root cause identified as a misconfigured deployment.".to_string(), |
| 56 | + ), |
| 57 | + CreateBackfilledDegradationRequestDataAttributesUpdatesItems::new( |
| 58 | + DateTime::parse_from_rfc3339("2021-11-11T11:11:11+00:00") |
| 59 | + .expect("Failed to parse datetime") |
| 60 | + .with_timezone(&Utc), |
| 61 | + CreateDegradationRequestDataAttributesStatus::RESOLVED, |
| 62 | + ) |
| 63 | + .components_affected(vec![ |
| 64 | + CreateDegradationRequestDataAttributesComponentsAffectedItems::new( |
| 65 | + status_page_data_attributes_components_0_components_0_id.clone(), |
| 66 | + StatusPagesComponentDataAttributesStatus::OPERATIONAL, |
| 67 | + ), |
| 68 | + ]) |
| 69 | + .description( |
| 70 | + "The issue has been resolved and API is operating normally.".to_string(), |
| 71 | + ), |
| 72 | + ], |
| 73 | + )), |
| 74 | + ); |
| 75 | + let configuration = datadog::Configuration::new(); |
| 76 | + let api = StatusPagesAPI::with_config(configuration); |
| 77 | + let resp = api |
| 78 | + .create_backfilled_degradation( |
| 79 | + status_page_data_id.clone(), |
| 80 | + body, |
| 81 | + CreateBackfilledDegradationOptionalParams::default(), |
| 82 | + ) |
| 83 | + .await; |
| 84 | + if let Ok(value) = resp { |
| 85 | + println!("{:#?}", value); |
| 86 | + } else { |
| 87 | + println!("{:#?}", resp.unwrap_err()); |
| 88 | + } |
| 89 | +} |
0 commit comments