@@ -225,6 +225,7 @@ def create_alert_definition(
225225 description : Optional [str ] = None ,
226226 scope : Optional [Union [AlertScope , str ]] = None ,
227227 regions : Optional [list [str ]] = None ,
228+ group_by : Optional [list [str ]] = None ,
228229 ) -> AlertDefinition :
229230 """
230231 Create a new alert definition for a given service type.
@@ -258,6 +259,8 @@ def create_alert_definition(
258259 :type scope: Optional[Union[AlertScope, str]]
259260 :param regions: (Optional) Regions to monitor.
260261 :type regions: Optional[list[str]]
262+ :param group_by: (Optional) Aggregates metric data by dimension so that alert conditions are evaluated independently for each dimension value.
263+ :type group_by: Optional[list[str]]
261264
262265 :returns: The newly created :class:`AlertDefinition`.
263266 :rtype: AlertDefinition
@@ -282,6 +285,8 @@ def create_alert_definition(
282285 params ["scope" ] = scope
283286 if regions is not None :
284287 params ["regions" ] = regions
288+ if group_by is not None :
289+ params ["group_by" ] = group_by
285290
286291 # API will validate service_type and return an error if missing
287292 result = self .client .post (
@@ -296,6 +301,95 @@ def create_alert_definition(
296301
297302 return AlertDefinition (self .client , result ["id" ], service_type , result )
298303
304+ def clone_alert_definition (
305+ self ,
306+ service_type : str ,
307+ id : int ,
308+ label : str ,
309+ description : Optional [str ] = None ,
310+ scope : Optional [Union [AlertScope , str ]] = None ,
311+ regions : Optional [list [str ]] = None ,
312+ entity_ids : Optional [list [str ]] = None ,
313+ severity : Optional [int ] = None ,
314+ rule_criteria : Optional [dict ] = None ,
315+ trigger_conditions : Optional [dict ] = None ,
316+ channel_ids : Optional [list [int ]] = None ,
317+ group_by : Optional [list [str ]] = None ,
318+ ) -> AlertDefinition :
319+ """
320+ Clone an existing alert definition for a given service type.
321+ The clone request creates a new alert definition based on the source
322+ definition identified by ``id``.
323+
324+ API Documentation: TODO
325+
326+ :param service_type: Service type for the source alert definition
327+ (e.g. ``"dbaas"``).
328+ :type service_type: str
329+ :param id: Source alert definition identifier.
330+ :type id: int (Alert identifier)
331+ :param label: Human-readable label for the cloned alert definition.
332+ This value is mandatory and must be unique.
333+ :type label: str
334+ :param description: (Optional) Longer description for the cloned alert definition.
335+ :type description: Optional[str]
336+ :param scope: (Optional) Alert scope provided in the clone request.
337+ Scope is inherited from the source alert and is immutable.
338+ :type scope: Optional[Union[AlertScope, str]]
339+ :param regions: (Optional) Regions to monitor.
340+ :type regions: Optional[list[str]]
341+ :param entity_ids: (Optional) Restrict the alert to a subset of entity IDs.
342+ :type entity_ids: Optional[list[str]]
343+ :param severity: (Optional) Severity level for the alert.
344+ :type severity: Optional[int]
345+ :param rule_criteria: (Optional) Rule criteria used to evaluate the alert.
346+ :type rule_criteria: Optional[dict]
347+ :param trigger_conditions: (Optional) Trigger conditions for alert state transitions.
348+ :type trigger_conditions: Optional[dict]
349+ :param channel_ids: (Optional) List of alert channel IDs to notify.
350+ :type channel_ids: Optional[list[int]]
351+ :param group_by: (Optional) Aggregates metric data by dimension so that alert conditions are evaluated independently for each dimension value.
352+ :type group_by: Optional[list[str]]
353+
354+ :returns: The newly created cloned :class:`AlertDefinition`.
355+ :rtype: AlertDefinition
356+ """
357+ params = {
358+ "label" : label ,
359+ }
360+
361+ if description is not None :
362+ params ["description" ] = description
363+ if scope is not None :
364+ params ["scope" ] = scope
365+ if regions is not None :
366+ params ["regions" ] = regions
367+ if entity_ids is not None :
368+ params ["entity_ids" ] = entity_ids
369+ if severity is not None :
370+ params ["severity" ] = severity
371+ if rule_criteria is not None :
372+ params ["rule_criteria" ] = rule_criteria
373+ if trigger_conditions is not None :
374+ params ["trigger_conditions" ] = trigger_conditions
375+ if channel_ids is not None :
376+ params ["channel_ids" ] = channel_ids
377+ if group_by is not None :
378+ params ["group_by" ] = group_by
379+
380+ result = self .client .post (
381+ f"/monitor/services/{ service_type } /alert-definitions/{ id } /clone" ,
382+ data = params ,
383+ )
384+
385+ if "id" not in result :
386+ raise UnexpectedResponseError (
387+ "Unexpected response when cloning alert definition!" ,
388+ json = result ,
389+ )
390+
391+ return AlertDefinition (self .client , result ["id" ], service_type , result )
392+
299393 def alert_definition_entities (
300394 self ,
301395 service_type : str ,
0 commit comments