Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -69,6 +73,7 @@
from .api import CockpitV1RegionalAPI

__all__ = [
"AnyAlertState",
"DataSourceOrigin",
"DataSourceType",
"GrafanaUserRole",
Expand All @@ -82,6 +87,7 @@
"UsageUnit",
"ContactPointEmail",
"GetConfigResponseRetention",
"AnyAlert",
"ContactPoint",
"DataSource",
"GrafanaProductDashboard",
Expand All @@ -104,6 +110,7 @@
"GlobalApiSelectPlanRequest",
"GlobalApiSyncGrafanaDataSourcesRequest",
"Grafana",
"ListAlertsResponse",
"ListContactPointsResponse",
"ListDataSourcesResponse",
"ListGrafanaProductDashboardsResponse",
Expand All @@ -126,6 +133,7 @@
"RegionalApiGetDataSourceRequest",
"RegionalApiGetTokenRequest",
"RegionalApiGetUsageOverviewRequest",
"RegionalApiListAlertsRequest",
"RegionalApiListContactPointsRequest",
"RegionalApiListDataSourcesRequest",
"RegionalApiListManagedAlertsRequest",
Expand Down
46 changes: 46 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
fetch_all_pages_async,
)
from .types import (
AnyAlertState,
DataSourceOrigin,
DataSourceType,
GrafanaUserRole,
Expand All @@ -35,6 +36,7 @@
Grafana,
GrafanaProductDashboard,
GrafanaUser,
ListAlertsResponse,
ListContactPointsResponse,
ListDataSourcesResponse,
ListGrafanaProductDashboardsResponse,
Expand Down Expand Up @@ -67,6 +69,7 @@
unmarshal_AlertManager,
unmarshal_GetConfigResponse,
unmarshal_Grafana,
unmarshal_ListAlertsResponse,
unmarshal_ListContactPointsResponse,
unmarshal_ListDataSourcesResponse,
unmarshal_ListGrafanaProductDashboardsResponse,
Expand Down Expand Up @@ -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 <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,
*,
Expand Down
62 changes: 62 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
GetConfigResponseRetention,
GetConfigResponse,
Grafana,
AnyAlert,
ListAlertsResponse,
ListContactPointsResponse,
ListDataSourcesResponse,
ListGrafanaProductDashboardsResponse,
Expand Down Expand Up @@ -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(
Expand Down
82 changes: 81 additions & 1 deletion scaleway-async/scaleway_async/cockpit/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
"""
Expand Down
8 changes: 8 additions & 0 deletions scaleway/scaleway/cockpit/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -69,6 +73,7 @@
from .api import CockpitV1RegionalAPI

__all__ = [
"AnyAlertState",
"DataSourceOrigin",
"DataSourceType",
"GrafanaUserRole",
Expand All @@ -82,6 +87,7 @@
"UsageUnit",
"ContactPointEmail",
"GetConfigResponseRetention",
"AnyAlert",
"ContactPoint",
"DataSource",
"GrafanaProductDashboard",
Expand All @@ -104,6 +110,7 @@
"GlobalApiSelectPlanRequest",
"GlobalApiSyncGrafanaDataSourcesRequest",
"Grafana",
"ListAlertsResponse",
"ListContactPointsResponse",
"ListDataSourcesResponse",
"ListGrafanaProductDashboardsResponse",
Expand All @@ -126,6 +133,7 @@
"RegionalApiGetDataSourceRequest",
"RegionalApiGetTokenRequest",
"RegionalApiGetUsageOverviewRequest",
"RegionalApiListAlertsRequest",
"RegionalApiListContactPointsRequest",
"RegionalApiListDataSourcesRequest",
"RegionalApiListManagedAlertsRequest",
Expand Down
Loading