diff --git a/scaleway-async/scaleway_async/cockpit/v1/__init__.py b/scaleway-async/scaleway_async/cockpit/v1/__init__.py index a648fc794..5137711f8 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/__init__.py +++ b/scaleway-async/scaleway_async/cockpit/v1/__init__.py @@ -1,5 +1,6 @@ # This file was automatically generated. DO NOT EDIT. # If you have any remark or suggestion do not hesitate to open an issue. +from .types import AnyAlertState from .types import DataSourceOrigin from .types import DataSourceType from .types import GrafanaUserRole @@ -13,6 +14,7 @@ from .types import UsageUnit from .types import ContactPointEmail from .types import GetConfigResponseRetention +from .types import AnyAlert from .types import ContactPoint from .types import DataSource from .types import GrafanaProductDashboard @@ -35,6 +37,7 @@ from .types import GlobalApiSelectPlanRequest from .types import GlobalApiSyncGrafanaDataSourcesRequest from .types import Grafana +from .types import ListAlertsResponse from .types import ListContactPointsResponse from .types import ListDataSourcesResponse from .types import ListGrafanaProductDashboardsResponse @@ -57,6 +60,7 @@ from .types import RegionalApiGetDataSourceRequest from .types import RegionalApiGetTokenRequest from .types import RegionalApiGetUsageOverviewRequest +from .types import RegionalApiListAlertsRequest from .types import RegionalApiListContactPointsRequest from .types import RegionalApiListDataSourcesRequest from .types import RegionalApiListManagedAlertsRequest @@ -69,6 +73,7 @@ from .api import CockpitV1RegionalAPI __all__ = [ + "AnyAlertState", "DataSourceOrigin", "DataSourceType", "GrafanaUserRole", @@ -82,6 +87,7 @@ "UsageUnit", "ContactPointEmail", "GetConfigResponseRetention", + "AnyAlert", "ContactPoint", "DataSource", "GrafanaProductDashboard", @@ -104,6 +110,7 @@ "GlobalApiSelectPlanRequest", "GlobalApiSyncGrafanaDataSourcesRequest", "Grafana", + "ListAlertsResponse", "ListContactPointsResponse", "ListDataSourcesResponse", "ListGrafanaProductDashboardsResponse", @@ -126,6 +133,7 @@ "RegionalApiGetDataSourceRequest", "RegionalApiGetTokenRequest", "RegionalApiGetUsageOverviewRequest", + "RegionalApiListAlertsRequest", "RegionalApiListContactPointsRequest", "RegionalApiListDataSourcesRequest", "RegionalApiListManagedAlertsRequest", diff --git a/scaleway-async/scaleway_async/cockpit/v1/api.py b/scaleway-async/scaleway_async/cockpit/v1/api.py index 6833fdbf3..1d234dd48 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/api.py +++ b/scaleway-async/scaleway_async/cockpit/v1/api.py @@ -12,6 +12,7 @@ fetch_all_pages_async, ) from .types import ( + AnyAlertState, DataSourceOrigin, DataSourceType, GrafanaUserRole, @@ -35,6 +36,7 @@ Grafana, GrafanaProductDashboard, GrafanaUser, + ListAlertsResponse, ListContactPointsResponse, ListDataSourcesResponse, ListGrafanaProductDashboardsResponse, @@ -67,6 +69,7 @@ unmarshal_AlertManager, unmarshal_GetConfigResponse, unmarshal_Grafana, + unmarshal_ListAlertsResponse, unmarshal_ListContactPointsResponse, unmarshal_ListDataSourcesResponse, unmarshal_ListGrafanaProductDashboardsResponse, @@ -1512,6 +1515,49 @@ async def list_managed_alerts_all( }, ) + async def list_alerts( + self, + *, + region: Optional[ScwRegion] = None, + project_id: Optional[str] = None, + is_enabled: Optional[bool] = None, + is_preconfigured: Optional[bool] = None, + state: Optional[AnyAlertState] = None, + ) -> ListAlertsResponse: + """ + List alerts. + List preconfigured and/or custom alerts for the specified Project. + :param region: Region to target. If none is passed will use default region from the config. + :param project_id: Project ID to filter for, only alerts from this Project will be returned. + :param is_enabled: True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply. + :param is_preconfigured: True returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply. + :param state: Valid values to filter on are `disabled`, `enabled`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply. + :return: :class:`ListAlertsResponse ` + + Usage: + :: + + result = await api.list_alerts() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/cockpit/v1/regions/{param_region}/alerts", + params={ + "is_enabled": is_enabled, + "is_preconfigured": is_preconfigured, + "project_id": project_id or self.client.default_project_id, + "state": state, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListAlertsResponse(res.json()) + async def enable_managed_alerts( self, *, diff --git a/scaleway-async/scaleway_async/cockpit/v1/marshalling.py b/scaleway-async/scaleway_async/cockpit/v1/marshalling.py index 6739977d0..03b6090ff 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/marshalling.py +++ b/scaleway-async/scaleway_async/cockpit/v1/marshalling.py @@ -22,6 +22,8 @@ GetConfigResponseRetention, GetConfigResponse, Grafana, + AnyAlert, + ListAlertsResponse, ListContactPointsResponse, ListDataSourcesResponse, ListGrafanaProductDashboardsResponse, @@ -415,6 +417,66 @@ def unmarshal_Grafana(data: Any) -> Grafana: return Grafana(**args) +def unmarshal_AnyAlert(data: Any) -> AnyAlert: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'AnyAlert' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("region", None) + if field is not None: + args["region"] = field + + field = data.get("preconfigured", None) + if field is not None: + args["preconfigured"] = field + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("rule", None) + if field is not None: + args["rule"] = field + + field = data.get("duration", None) + if field is not None: + args["duration"] = field + + field = data.get("state", None) + if field is not None: + args["state"] = field + + field = data.get("annotations", None) + if field is not None: + args["annotations"] = field + + return AnyAlert(**args) + + +def unmarshal_ListAlertsResponse(data: Any) -> ListAlertsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAlertsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + field = data.get("alerts", None) + if field is not None: + args["alerts"] = ( + [unmarshal_AnyAlert(v) for v in field] if field is not None else None + ) + + return ListAlertsResponse(**args) + + def unmarshal_ListContactPointsResponse(data: Any) -> ListContactPointsResponse: if not isinstance(data, dict): raise TypeError( diff --git a/scaleway-async/scaleway_async/cockpit/v1/types.py b/scaleway-async/scaleway_async/cockpit/v1/types.py index d7363a866..7f50e6629 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/types.py +++ b/scaleway-async/scaleway_async/cockpit/v1/types.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from datetime import datetime from enum import Enum -from typing import List, Optional +from typing import Dict, List, Optional from scaleway_core.bridge import ( Region as ScwRegion, @@ -15,6 +15,17 @@ ) +class AnyAlertState(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATE = "unknown_state" + DISABLED = "disabled" + ENABLED = "enabled" + PENDING = "pending" + FIRING = "firing" + + def __str__(self) -> str: + return str(self.value) + + class DataSourceOrigin(str, Enum, metaclass=StrEnumMeta): UNKNOWN_ORIGIN = "unknown_origin" SCALEWAY = "scaleway" @@ -143,6 +154,26 @@ class GetConfigResponseRetention: default_days: int +@dataclass +class AnyAlert: + region: ScwRegion + """ + Region to target. If none is passed will use default region from the config. + """ + + preconfigured: bool + + name: str + + rule: str + + duration: str + + state: AnyAlertState + + annotations: Dict[str, str] + + @dataclass class ContactPoint: """ @@ -707,6 +738,23 @@ class Grafana: """ +@dataclass +class ListAlertsResponse: + """ + Retrieve a list of alerts matching the request. + """ + + total_count: int + """ + Total count of alerts matching the request. + """ + + alerts: List[AnyAlert] + """ + List of alerts matching the applied filters. + """ + + @dataclass class ListContactPointsResponse: """ @@ -1115,6 +1163,38 @@ class RegionalApiGetUsageOverviewRequest: interval: Optional[str] +@dataclass +class RegionalApiListAlertsRequest: + """ + Retrieve a list of alerts. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + project_id: Optional[str] + """ + Project ID to filter for, only alerts from this Project will be returned. + """ + + is_enabled: Optional[bool] + """ + True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply. + """ + + is_preconfigured: Optional[bool] + """ + True returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply. + """ + + state: Optional[AnyAlertState] + """ + Valid values to filter on are `disabled`, `enabled`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply. + """ + + @dataclass class RegionalApiListContactPointsRequest: """ diff --git a/scaleway/scaleway/cockpit/v1/__init__.py b/scaleway/scaleway/cockpit/v1/__init__.py index a648fc794..5137711f8 100644 --- a/scaleway/scaleway/cockpit/v1/__init__.py +++ b/scaleway/scaleway/cockpit/v1/__init__.py @@ -1,5 +1,6 @@ # This file was automatically generated. DO NOT EDIT. # If you have any remark or suggestion do not hesitate to open an issue. +from .types import AnyAlertState from .types import DataSourceOrigin from .types import DataSourceType from .types import GrafanaUserRole @@ -13,6 +14,7 @@ from .types import UsageUnit from .types import ContactPointEmail from .types import GetConfigResponseRetention +from .types import AnyAlert from .types import ContactPoint from .types import DataSource from .types import GrafanaProductDashboard @@ -35,6 +37,7 @@ from .types import GlobalApiSelectPlanRequest from .types import GlobalApiSyncGrafanaDataSourcesRequest from .types import Grafana +from .types import ListAlertsResponse from .types import ListContactPointsResponse from .types import ListDataSourcesResponse from .types import ListGrafanaProductDashboardsResponse @@ -57,6 +60,7 @@ from .types import RegionalApiGetDataSourceRequest from .types import RegionalApiGetTokenRequest from .types import RegionalApiGetUsageOverviewRequest +from .types import RegionalApiListAlertsRequest from .types import RegionalApiListContactPointsRequest from .types import RegionalApiListDataSourcesRequest from .types import RegionalApiListManagedAlertsRequest @@ -69,6 +73,7 @@ from .api import CockpitV1RegionalAPI __all__ = [ + "AnyAlertState", "DataSourceOrigin", "DataSourceType", "GrafanaUserRole", @@ -82,6 +87,7 @@ "UsageUnit", "ContactPointEmail", "GetConfigResponseRetention", + "AnyAlert", "ContactPoint", "DataSource", "GrafanaProductDashboard", @@ -104,6 +110,7 @@ "GlobalApiSelectPlanRequest", "GlobalApiSyncGrafanaDataSourcesRequest", "Grafana", + "ListAlertsResponse", "ListContactPointsResponse", "ListDataSourcesResponse", "ListGrafanaProductDashboardsResponse", @@ -126,6 +133,7 @@ "RegionalApiGetDataSourceRequest", "RegionalApiGetTokenRequest", "RegionalApiGetUsageOverviewRequest", + "RegionalApiListAlertsRequest", "RegionalApiListContactPointsRequest", "RegionalApiListDataSourcesRequest", "RegionalApiListManagedAlertsRequest", diff --git a/scaleway/scaleway/cockpit/v1/api.py b/scaleway/scaleway/cockpit/v1/api.py index 0be7b2ca2..9f19a0c7a 100644 --- a/scaleway/scaleway/cockpit/v1/api.py +++ b/scaleway/scaleway/cockpit/v1/api.py @@ -12,6 +12,7 @@ fetch_all_pages, ) from .types import ( + AnyAlertState, DataSourceOrigin, DataSourceType, GrafanaUserRole, @@ -35,6 +36,7 @@ Grafana, GrafanaProductDashboard, GrafanaUser, + ListAlertsResponse, ListContactPointsResponse, ListDataSourcesResponse, ListGrafanaProductDashboardsResponse, @@ -67,6 +69,7 @@ unmarshal_AlertManager, unmarshal_GetConfigResponse, unmarshal_Grafana, + unmarshal_ListAlertsResponse, unmarshal_ListContactPointsResponse, unmarshal_ListDataSourcesResponse, unmarshal_ListGrafanaProductDashboardsResponse, @@ -1512,6 +1515,49 @@ def list_managed_alerts_all( }, ) + def list_alerts( + self, + *, + region: Optional[ScwRegion] = None, + project_id: Optional[str] = None, + is_enabled: Optional[bool] = None, + is_preconfigured: Optional[bool] = None, + state: Optional[AnyAlertState] = None, + ) -> ListAlertsResponse: + """ + List alerts. + List preconfigured and/or custom alerts for the specified Project. + :param region: Region to target. If none is passed will use default region from the config. + :param project_id: Project ID to filter for, only alerts from this Project will be returned. + :param is_enabled: True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply. + :param is_preconfigured: True returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply. + :param state: Valid values to filter on are `disabled`, `enabled`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply. + :return: :class:`ListAlertsResponse ` + + Usage: + :: + + result = api.list_alerts() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/cockpit/v1/regions/{param_region}/alerts", + params={ + "is_enabled": is_enabled, + "is_preconfigured": is_preconfigured, + "project_id": project_id or self.client.default_project_id, + "state": state, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListAlertsResponse(res.json()) + def enable_managed_alerts( self, *, diff --git a/scaleway/scaleway/cockpit/v1/marshalling.py b/scaleway/scaleway/cockpit/v1/marshalling.py index 6739977d0..03b6090ff 100644 --- a/scaleway/scaleway/cockpit/v1/marshalling.py +++ b/scaleway/scaleway/cockpit/v1/marshalling.py @@ -22,6 +22,8 @@ GetConfigResponseRetention, GetConfigResponse, Grafana, + AnyAlert, + ListAlertsResponse, ListContactPointsResponse, ListDataSourcesResponse, ListGrafanaProductDashboardsResponse, @@ -415,6 +417,66 @@ def unmarshal_Grafana(data: Any) -> Grafana: return Grafana(**args) +def unmarshal_AnyAlert(data: Any) -> AnyAlert: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'AnyAlert' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("region", None) + if field is not None: + args["region"] = field + + field = data.get("preconfigured", None) + if field is not None: + args["preconfigured"] = field + + field = data.get("name", None) + if field is not None: + args["name"] = field + + field = data.get("rule", None) + if field is not None: + args["rule"] = field + + field = data.get("duration", None) + if field is not None: + args["duration"] = field + + field = data.get("state", None) + if field is not None: + args["state"] = field + + field = data.get("annotations", None) + if field is not None: + args["annotations"] = field + + return AnyAlert(**args) + + +def unmarshal_ListAlertsResponse(data: Any) -> ListAlertsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAlertsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + field = data.get("alerts", None) + if field is not None: + args["alerts"] = ( + [unmarshal_AnyAlert(v) for v in field] if field is not None else None + ) + + return ListAlertsResponse(**args) + + def unmarshal_ListContactPointsResponse(data: Any) -> ListContactPointsResponse: if not isinstance(data, dict): raise TypeError( diff --git a/scaleway/scaleway/cockpit/v1/types.py b/scaleway/scaleway/cockpit/v1/types.py index d7363a866..7f50e6629 100644 --- a/scaleway/scaleway/cockpit/v1/types.py +++ b/scaleway/scaleway/cockpit/v1/types.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from datetime import datetime from enum import Enum -from typing import List, Optional +from typing import Dict, List, Optional from scaleway_core.bridge import ( Region as ScwRegion, @@ -15,6 +15,17 @@ ) +class AnyAlertState(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_STATE = "unknown_state" + DISABLED = "disabled" + ENABLED = "enabled" + PENDING = "pending" + FIRING = "firing" + + def __str__(self) -> str: + return str(self.value) + + class DataSourceOrigin(str, Enum, metaclass=StrEnumMeta): UNKNOWN_ORIGIN = "unknown_origin" SCALEWAY = "scaleway" @@ -143,6 +154,26 @@ class GetConfigResponseRetention: default_days: int +@dataclass +class AnyAlert: + region: ScwRegion + """ + Region to target. If none is passed will use default region from the config. + """ + + preconfigured: bool + + name: str + + rule: str + + duration: str + + state: AnyAlertState + + annotations: Dict[str, str] + + @dataclass class ContactPoint: """ @@ -707,6 +738,23 @@ class Grafana: """ +@dataclass +class ListAlertsResponse: + """ + Retrieve a list of alerts matching the request. + """ + + total_count: int + """ + Total count of alerts matching the request. + """ + + alerts: List[AnyAlert] + """ + List of alerts matching the applied filters. + """ + + @dataclass class ListContactPointsResponse: """ @@ -1115,6 +1163,38 @@ class RegionalApiGetUsageOverviewRequest: interval: Optional[str] +@dataclass +class RegionalApiListAlertsRequest: + """ + Retrieve a list of alerts. + """ + + region: Optional[ScwRegion] + """ + Region to target. If none is passed will use default region from the config. + """ + + project_id: Optional[str] + """ + Project ID to filter for, only alerts from this Project will be returned. + """ + + is_enabled: Optional[bool] + """ + True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply. + """ + + is_preconfigured: Optional[bool] + """ + True returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply. + """ + + state: Optional[AnyAlertState] + """ + Valid values to filter on are `disabled`, `enabled`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply. + """ + + @dataclass class RegionalApiListContactPointsRequest: """