Skip to content

Commit 49b8bb1

Browse files
feat(cockpit): add support for RegionalApiListAlertsRequest (#857)
Co-authored-by: Rémy Léone <rleone@scaleway.com>
1 parent 3dba7b8 commit 49b8bb1

File tree

8 files changed

+394
-2
lines changed

8 files changed

+394
-2
lines changed

scaleway-async/scaleway_async/cockpit/v1/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This file was automatically generated. DO NOT EDIT.
22
# If you have any remark or suggestion do not hesitate to open an issue.
3+
from .types import AnyAlertState
34
from .types import DataSourceOrigin
45
from .types import DataSourceType
56
from .types import GrafanaUserRole
@@ -13,6 +14,7 @@
1314
from .types import UsageUnit
1415
from .types import ContactPointEmail
1516
from .types import GetConfigResponseRetention
17+
from .types import AnyAlert
1618
from .types import ContactPoint
1719
from .types import DataSource
1820
from .types import GrafanaProductDashboard
@@ -35,6 +37,7 @@
3537
from .types import GlobalApiSelectPlanRequest
3638
from .types import GlobalApiSyncGrafanaDataSourcesRequest
3739
from .types import Grafana
40+
from .types import ListAlertsResponse
3841
from .types import ListContactPointsResponse
3942
from .types import ListDataSourcesResponse
4043
from .types import ListGrafanaProductDashboardsResponse
@@ -57,6 +60,7 @@
5760
from .types import RegionalApiGetDataSourceRequest
5861
from .types import RegionalApiGetTokenRequest
5962
from .types import RegionalApiGetUsageOverviewRequest
63+
from .types import RegionalApiListAlertsRequest
6064
from .types import RegionalApiListContactPointsRequest
6165
from .types import RegionalApiListDataSourcesRequest
6266
from .types import RegionalApiListManagedAlertsRequest
@@ -69,6 +73,7 @@
6973
from .api import CockpitV1RegionalAPI
7074

7175
__all__ = [
76+
"AnyAlertState",
7277
"DataSourceOrigin",
7378
"DataSourceType",
7479
"GrafanaUserRole",
@@ -82,6 +87,7 @@
8287
"UsageUnit",
8388
"ContactPointEmail",
8489
"GetConfigResponseRetention",
90+
"AnyAlert",
8591
"ContactPoint",
8692
"DataSource",
8793
"GrafanaProductDashboard",
@@ -104,6 +110,7 @@
104110
"GlobalApiSelectPlanRequest",
105111
"GlobalApiSyncGrafanaDataSourcesRequest",
106112
"Grafana",
113+
"ListAlertsResponse",
107114
"ListContactPointsResponse",
108115
"ListDataSourcesResponse",
109116
"ListGrafanaProductDashboardsResponse",
@@ -126,6 +133,7 @@
126133
"RegionalApiGetDataSourceRequest",
127134
"RegionalApiGetTokenRequest",
128135
"RegionalApiGetUsageOverviewRequest",
136+
"RegionalApiListAlertsRequest",
129137
"RegionalApiListContactPointsRequest",
130138
"RegionalApiListDataSourcesRequest",
131139
"RegionalApiListManagedAlertsRequest",

scaleway-async/scaleway_async/cockpit/v1/api.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
fetch_all_pages_async,
1313
)
1414
from .types import (
15+
AnyAlertState,
1516
DataSourceOrigin,
1617
DataSourceType,
1718
GrafanaUserRole,
@@ -35,6 +36,7 @@
3536
Grafana,
3637
GrafanaProductDashboard,
3738
GrafanaUser,
39+
ListAlertsResponse,
3840
ListContactPointsResponse,
3941
ListDataSourcesResponse,
4042
ListGrafanaProductDashboardsResponse,
@@ -67,6 +69,7 @@
6769
unmarshal_AlertManager,
6870
unmarshal_GetConfigResponse,
6971
unmarshal_Grafana,
72+
unmarshal_ListAlertsResponse,
7073
unmarshal_ListContactPointsResponse,
7174
unmarshal_ListDataSourcesResponse,
7275
unmarshal_ListGrafanaProductDashboardsResponse,
@@ -1512,6 +1515,49 @@ async def list_managed_alerts_all(
15121515
},
15131516
)
15141517

1518+
async def list_alerts(
1519+
self,
1520+
*,
1521+
region: Optional[ScwRegion] = None,
1522+
project_id: Optional[str] = None,
1523+
is_enabled: Optional[bool] = None,
1524+
is_preconfigured: Optional[bool] = None,
1525+
state: Optional[AnyAlertState] = None,
1526+
) -> ListAlertsResponse:
1527+
"""
1528+
List alerts.
1529+
List preconfigured and/or custom alerts for the specified Project.
1530+
:param region: Region to target. If none is passed will use default region from the config.
1531+
:param project_id: Project ID to filter for, only alerts from this Project will be returned.
1532+
: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.
1533+
: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.
1534+
: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.
1535+
:return: :class:`ListAlertsResponse <ListAlertsResponse>`
1536+
1537+
Usage:
1538+
::
1539+
1540+
result = await api.list_alerts()
1541+
"""
1542+
1543+
param_region = validate_path_param(
1544+
"region", region or self.client.default_region
1545+
)
1546+
1547+
res = self._request(
1548+
"GET",
1549+
f"/cockpit/v1/regions/{param_region}/alerts",
1550+
params={
1551+
"is_enabled": is_enabled,
1552+
"is_preconfigured": is_preconfigured,
1553+
"project_id": project_id or self.client.default_project_id,
1554+
"state": state,
1555+
},
1556+
)
1557+
1558+
self._throw_on_error(res)
1559+
return unmarshal_ListAlertsResponse(res.json())
1560+
15151561
async def enable_managed_alerts(
15161562
self,
15171563
*,

scaleway-async/scaleway_async/cockpit/v1/marshalling.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
GetConfigResponseRetention,
2323
GetConfigResponse,
2424
Grafana,
25+
AnyAlert,
26+
ListAlertsResponse,
2527
ListContactPointsResponse,
2628
ListDataSourcesResponse,
2729
ListGrafanaProductDashboardsResponse,
@@ -415,6 +417,66 @@ def unmarshal_Grafana(data: Any) -> Grafana:
415417
return Grafana(**args)
416418

417419

420+
def unmarshal_AnyAlert(data: Any) -> AnyAlert:
421+
if not isinstance(data, dict):
422+
raise TypeError(
423+
"Unmarshalling the type 'AnyAlert' failed as data isn't a dictionary."
424+
)
425+
426+
args: Dict[str, Any] = {}
427+
428+
field = data.get("region", None)
429+
if field is not None:
430+
args["region"] = field
431+
432+
field = data.get("preconfigured", None)
433+
if field is not None:
434+
args["preconfigured"] = field
435+
436+
field = data.get("name", None)
437+
if field is not None:
438+
args["name"] = field
439+
440+
field = data.get("rule", None)
441+
if field is not None:
442+
args["rule"] = field
443+
444+
field = data.get("duration", None)
445+
if field is not None:
446+
args["duration"] = field
447+
448+
field = data.get("state", None)
449+
if field is not None:
450+
args["state"] = field
451+
452+
field = data.get("annotations", None)
453+
if field is not None:
454+
args["annotations"] = field
455+
456+
return AnyAlert(**args)
457+
458+
459+
def unmarshal_ListAlertsResponse(data: Any) -> ListAlertsResponse:
460+
if not isinstance(data, dict):
461+
raise TypeError(
462+
"Unmarshalling the type 'ListAlertsResponse' failed as data isn't a dictionary."
463+
)
464+
465+
args: Dict[str, Any] = {}
466+
467+
field = data.get("total_count", None)
468+
if field is not None:
469+
args["total_count"] = field
470+
471+
field = data.get("alerts", None)
472+
if field is not None:
473+
args["alerts"] = (
474+
[unmarshal_AnyAlert(v) for v in field] if field is not None else None
475+
)
476+
477+
return ListAlertsResponse(**args)
478+
479+
418480
def unmarshal_ListContactPointsResponse(data: Any) -> ListContactPointsResponse:
419481
if not isinstance(data, dict):
420482
raise TypeError(

scaleway-async/scaleway_async/cockpit/v1/types.py

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dataclasses import dataclass
66
from datetime import datetime
77
from enum import Enum
8-
from typing import List, Optional
8+
from typing import Dict, List, Optional
99

1010
from scaleway_core.bridge import (
1111
Region as ScwRegion,
@@ -15,6 +15,17 @@
1515
)
1616

1717

18+
class AnyAlertState(str, Enum, metaclass=StrEnumMeta):
19+
UNKNOWN_STATE = "unknown_state"
20+
DISABLED = "disabled"
21+
ENABLED = "enabled"
22+
PENDING = "pending"
23+
FIRING = "firing"
24+
25+
def __str__(self) -> str:
26+
return str(self.value)
27+
28+
1829
class DataSourceOrigin(str, Enum, metaclass=StrEnumMeta):
1930
UNKNOWN_ORIGIN = "unknown_origin"
2031
SCALEWAY = "scaleway"
@@ -143,6 +154,26 @@ class GetConfigResponseRetention:
143154
default_days: int
144155

145156

157+
@dataclass
158+
class AnyAlert:
159+
region: ScwRegion
160+
"""
161+
Region to target. If none is passed will use default region from the config.
162+
"""
163+
164+
preconfigured: bool
165+
166+
name: str
167+
168+
rule: str
169+
170+
duration: str
171+
172+
state: AnyAlertState
173+
174+
annotations: Dict[str, str]
175+
176+
146177
@dataclass
147178
class ContactPoint:
148179
"""
@@ -707,6 +738,23 @@ class Grafana:
707738
"""
708739

709740

741+
@dataclass
742+
class ListAlertsResponse:
743+
"""
744+
Retrieve a list of alerts matching the request.
745+
"""
746+
747+
total_count: int
748+
"""
749+
Total count of alerts matching the request.
750+
"""
751+
752+
alerts: List[AnyAlert]
753+
"""
754+
List of alerts matching the applied filters.
755+
"""
756+
757+
710758
@dataclass
711759
class ListContactPointsResponse:
712760
"""
@@ -1115,6 +1163,38 @@ class RegionalApiGetUsageOverviewRequest:
11151163
interval: Optional[str]
11161164

11171165

1166+
@dataclass
1167+
class RegionalApiListAlertsRequest:
1168+
"""
1169+
Retrieve a list of alerts.
1170+
"""
1171+
1172+
region: Optional[ScwRegion]
1173+
"""
1174+
Region to target. If none is passed will use default region from the config.
1175+
"""
1176+
1177+
project_id: Optional[str]
1178+
"""
1179+
Project ID to filter for, only alerts from this Project will be returned.
1180+
"""
1181+
1182+
is_enabled: Optional[bool]
1183+
"""
1184+
True returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply.
1185+
"""
1186+
1187+
is_preconfigured: Optional[bool]
1188+
"""
1189+
True returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply.
1190+
"""
1191+
1192+
state: Optional[AnyAlertState]
1193+
"""
1194+
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.
1195+
"""
1196+
1197+
11181198
@dataclass
11191199
class RegionalApiListContactPointsRequest:
11201200
"""

scaleway/scaleway/cockpit/v1/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This file was automatically generated. DO NOT EDIT.
22
# If you have any remark or suggestion do not hesitate to open an issue.
3+
from .types import AnyAlertState
34
from .types import DataSourceOrigin
45
from .types import DataSourceType
56
from .types import GrafanaUserRole
@@ -13,6 +14,7 @@
1314
from .types import UsageUnit
1415
from .types import ContactPointEmail
1516
from .types import GetConfigResponseRetention
17+
from .types import AnyAlert
1618
from .types import ContactPoint
1719
from .types import DataSource
1820
from .types import GrafanaProductDashboard
@@ -35,6 +37,7 @@
3537
from .types import GlobalApiSelectPlanRequest
3638
from .types import GlobalApiSyncGrafanaDataSourcesRequest
3739
from .types import Grafana
40+
from .types import ListAlertsResponse
3841
from .types import ListContactPointsResponse
3942
from .types import ListDataSourcesResponse
4043
from .types import ListGrafanaProductDashboardsResponse
@@ -57,6 +60,7 @@
5760
from .types import RegionalApiGetDataSourceRequest
5861
from .types import RegionalApiGetTokenRequest
5962
from .types import RegionalApiGetUsageOverviewRequest
63+
from .types import RegionalApiListAlertsRequest
6064
from .types import RegionalApiListContactPointsRequest
6165
from .types import RegionalApiListDataSourcesRequest
6266
from .types import RegionalApiListManagedAlertsRequest
@@ -69,6 +73,7 @@
6973
from .api import CockpitV1RegionalAPI
7074

7175
__all__ = [
76+
"AnyAlertState",
7277
"DataSourceOrigin",
7378
"DataSourceType",
7479
"GrafanaUserRole",
@@ -82,6 +87,7 @@
8287
"UsageUnit",
8388
"ContactPointEmail",
8489
"GetConfigResponseRetention",
90+
"AnyAlert",
8591
"ContactPoint",
8692
"DataSource",
8793
"GrafanaProductDashboard",
@@ -104,6 +110,7 @@
104110
"GlobalApiSelectPlanRequest",
105111
"GlobalApiSyncGrafanaDataSourcesRequest",
106112
"Grafana",
113+
"ListAlertsResponse",
107114
"ListContactPointsResponse",
108115
"ListDataSourcesResponse",
109116
"ListGrafanaProductDashboardsResponse",
@@ -126,6 +133,7 @@
126133
"RegionalApiGetDataSourceRequest",
127134
"RegionalApiGetTokenRequest",
128135
"RegionalApiGetUsageOverviewRequest",
136+
"RegionalApiListAlertsRequest",
129137
"RegionalApiListContactPointsRequest",
130138
"RegionalApiListDataSourcesRequest",
131139
"RegionalApiListManagedAlertsRequest",

0 commit comments

Comments
 (0)