@@ -235,6 +235,7 @@ def create_alert_definition(
235235 description : Optional [str ] = None ,
236236 scope : Optional [Union [AlertScope , str ]] = None ,
237237 regions : Optional [list [str ]] = None ,
238+ group_by : Optional [list [str ]] = None ,
238239 ) -> AlertDefinition :
239240 """
240241 Create a new alert definition for a given service type.
@@ -270,6 +271,8 @@ def create_alert_definition(
270271 :type scope: Optional[Union[AlertScope, str]]
271272 :param regions: (Optional) Regions to monitor.
272273 :type regions: Optional[list[str]]
274+ :param group_by: (Optional) Aggregates metric data by dimension so that alert conditions are evaluated independently for each dimension value.
275+ :type group_by: Optional[list[str]]
273276
274277 :returns: The newly created :class:`AlertDefinition`.
275278 :rtype: AlertDefinition
@@ -294,6 +297,8 @@ def create_alert_definition(
294297 params ["scope" ] = scope
295298 if regions is not None :
296299 params ["regions" ] = regions
300+ if group_by is not None :
301+ params ["group_by" ] = group_by
297302
298303 # API will validate service_type and return an error if missing
299304 result = self .client .post (
@@ -308,6 +313,96 @@ def create_alert_definition(
308313
309314 return AlertDefinition (self .client , result ["id" ], service_type , result )
310315
316+ def clone_alert_definition (
317+ self ,
318+ service_type : str ,
319+ id : int ,
320+ label : str ,
321+ description : Optional [str ] = None ,
322+ scope : Optional [Union [AlertScope , str ]] = None ,
323+ regions : Optional [list [str ]] = None ,
324+ entity_ids : Optional [list [str ]] = None ,
325+ severity : Optional [int ] = None ,
326+ rule_criteria : Optional [dict ] = None ,
327+ trigger_conditions : Optional [dict ] = None ,
328+ channel_ids : Optional [list [int ]] = None ,
329+ group_by : Optional [list [str ]] = None ,
330+ ) -> AlertDefinition :
331+ """
332+ Clone an existing alert definition for a given service type.
333+ The clone request creates a new alert definition based on the source
334+ definition identified by ``id``.
335+
336+ API URL: POST /monitor/services/{service_type}/alert-definitions/{id}/clone
337+ API Documentation: TODO
338+
339+ :param service_type: Service type for the source alert definition
340+ (e.g. ``"dbaas"``).
341+ :type service_type: str
342+ :param id: Source alert definition identifier.
343+ :type id: int (Alert identifier)
344+ :param label: Human-readable label for the cloned alert definition.
345+ This value is mandatory and must be unique.
346+ :type label: str
347+ :param description: (Optional) Longer description for the cloned alert definition.
348+ :type description: Optional[str]
349+ :param scope: (Optional) Alert scope provided in the clone request.
350+ Scope is inherited from the source alert and is immutable.
351+ :type scope: Optional[Union[AlertScope, str]]
352+ :param regions: (Optional) Regions to monitor.
353+ :type regions: Optional[list[str]]
354+ :param entity_ids: (Optional) Restrict the alert to a subset of entity IDs.
355+ :type entity_ids: Optional[list[str]]
356+ :param severity: (Optional) Severity level for the alert.
357+ :type severity: Optional[int]
358+ :param rule_criteria: (Optional) Rule criteria used to evaluate the alert.
359+ :type rule_criteria: Optional[dict]
360+ :param trigger_conditions: (Optional) Trigger conditions for alert state transitions.
361+ :type trigger_conditions: Optional[dict]
362+ :param channel_ids: (Optional) List of alert channel IDs to notify.
363+ :type channel_ids: Optional[list[int]]
364+ :param group_by: (Optional) Aggregates metric data by dimension so that alert conditions are evaluated independently for each dimension value.
365+ :type group_by: Optional[list[str]]
366+
367+ :returns: The newly created cloned :class:`AlertDefinition`.
368+ :rtype: AlertDefinition
369+ """
370+ params = {
371+ "label" : label ,
372+ }
373+
374+ if description is not None :
375+ params ["description" ] = description
376+ if scope is not None :
377+ params ["scope" ] = scope
378+ if regions is not None :
379+ params ["regions" ] = regions
380+ if entity_ids is not None :
381+ params ["entity_ids" ] = entity_ids
382+ if severity is not None :
383+ params ["severity" ] = severity
384+ if rule_criteria is not None :
385+ params ["rule_criteria" ] = rule_criteria
386+ if trigger_conditions is not None :
387+ params ["trigger_conditions" ] = trigger_conditions
388+ if channel_ids is not None :
389+ params ["channel_ids" ] = channel_ids
390+ if group_by is not None :
391+ params ["group_by" ] = group_by
392+
393+ result = self .client .post (
394+ f"/monitor/services/{ service_type } /alert-definitions/{ id } /clone" ,
395+ data = params ,
396+ )
397+
398+ if "id" not in result :
399+ raise UnexpectedResponseError (
400+ "Unexpected response when cloning alert definition!" ,
401+ json = result ,
402+ )
403+
404+ return AlertDefinition (self .client , result ["id" ], service_type , result )
405+
311406 def alert_definition_entities (
312407 self ,
313408 service_type : str ,
0 commit comments