|
| 1 | +""" |
| 2 | +Create backfilled degradation returns "Created" response |
| 3 | +""" |
| 4 | + |
| 5 | +from datetime import datetime |
| 6 | +from dateutil.relativedelta import relativedelta |
| 7 | +from os import environ |
| 8 | +from datadog_api_client import ApiClient, Configuration |
| 9 | +from datadog_api_client.v2.api.status_pages_api import StatusPagesApi |
| 10 | +from datadog_api_client.v2.model.create_backfilled_degradation_request import CreateBackfilledDegradationRequest |
| 11 | +from datadog_api_client.v2.model.create_backfilled_degradation_request_data import ( |
| 12 | + CreateBackfilledDegradationRequestData, |
| 13 | +) |
| 14 | +from datadog_api_client.v2.model.create_backfilled_degradation_request_data_attributes import ( |
| 15 | + CreateBackfilledDegradationRequestDataAttributes, |
| 16 | +) |
| 17 | +from datadog_api_client.v2.model.create_backfilled_degradation_request_data_attributes_updates_items import ( |
| 18 | + CreateBackfilledDegradationRequestDataAttributesUpdatesItems, |
| 19 | +) |
| 20 | +from datadog_api_client.v2.model.create_degradation_request_data_attributes_components_affected_items import ( |
| 21 | + CreateDegradationRequestDataAttributesComponentsAffectedItems, |
| 22 | +) |
| 23 | +from datadog_api_client.v2.model.create_degradation_request_data_attributes_status import ( |
| 24 | + CreateDegradationRequestDataAttributesStatus, |
| 25 | +) |
| 26 | +from datadog_api_client.v2.model.patch_degradation_request_data_type import PatchDegradationRequestDataType |
| 27 | +from datadog_api_client.v2.model.status_pages_component_data_attributes_status import ( |
| 28 | + StatusPagesComponentDataAttributesStatus, |
| 29 | +) |
| 30 | + |
| 31 | +# there is a valid "status_page" in the system |
| 32 | +STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID = environ[ |
| 33 | + "STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID" |
| 34 | +] |
| 35 | +STATUS_PAGE_DATA_ID = environ["STATUS_PAGE_DATA_ID"] |
| 36 | + |
| 37 | +body = CreateBackfilledDegradationRequest( |
| 38 | + data=CreateBackfilledDegradationRequestData( |
| 39 | + attributes=CreateBackfilledDegradationRequestDataAttributes( |
| 40 | + title="Past API Outage", |
| 41 | + updates=[ |
| 42 | + CreateBackfilledDegradationRequestDataAttributesUpdatesItems( |
| 43 | + components_affected=[ |
| 44 | + CreateDegradationRequestDataAttributesComponentsAffectedItems( |
| 45 | + id=STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID, |
| 46 | + status=StatusPagesComponentDataAttributesStatus.DEGRADED, |
| 47 | + ), |
| 48 | + ], |
| 49 | + description="We detected elevated error rates in the API.", |
| 50 | + started_at=(datetime.now() + relativedelta(hours=-1)), |
| 51 | + status=CreateDegradationRequestDataAttributesStatus.INVESTIGATING, |
| 52 | + ), |
| 53 | + CreateBackfilledDegradationRequestDataAttributesUpdatesItems( |
| 54 | + components_affected=[ |
| 55 | + CreateDegradationRequestDataAttributesComponentsAffectedItems( |
| 56 | + id=STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID, |
| 57 | + status=StatusPagesComponentDataAttributesStatus.DEGRADED, |
| 58 | + ), |
| 59 | + ], |
| 60 | + description="Root cause identified as a misconfigured deployment.", |
| 61 | + started_at=(datetime.now() + relativedelta(minutes=-30)), |
| 62 | + status=CreateDegradationRequestDataAttributesStatus.IDENTIFIED, |
| 63 | + ), |
| 64 | + CreateBackfilledDegradationRequestDataAttributesUpdatesItems( |
| 65 | + components_affected=[ |
| 66 | + CreateDegradationRequestDataAttributesComponentsAffectedItems( |
| 67 | + id=STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID, |
| 68 | + status=StatusPagesComponentDataAttributesStatus.OPERATIONAL, |
| 69 | + ), |
| 70 | + ], |
| 71 | + description="The issue has been resolved and API is operating normally.", |
| 72 | + started_at=datetime.now(), |
| 73 | + status=CreateDegradationRequestDataAttributesStatus.RESOLVED, |
| 74 | + ), |
| 75 | + ], |
| 76 | + ), |
| 77 | + type=PatchDegradationRequestDataType.DEGRADATIONS, |
| 78 | + ), |
| 79 | +) |
| 80 | + |
| 81 | +configuration = Configuration() |
| 82 | +with ApiClient(configuration) as api_client: |
| 83 | + api_instance = StatusPagesApi(api_client) |
| 84 | + response = api_instance.create_backfilled_degradation(page_id=STATUS_PAGE_DATA_ID, body=body) |
| 85 | + |
| 86 | + print(response) |
0 commit comments