Skip to content

Commit af527e8

Browse files
authored
[Monitor] BREAKING CHANGE: az monitor activity-log alert create: Change default value from resourceGroupId to subscriptionId for parameter --scope (#27126)
* migrate activity-logs to codegenV2
1 parent f796bae commit af527e8

25 files changed

+4071
-1226
lines changed

src/azure-cli/azure/cli/command_modules/monitor/_help.py

Lines changed: 0 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -32,111 +32,6 @@
3232
short-summary: Manage activity log alert rules.
3333
"""
3434

35-
helps['monitor activity-log alert action-group'] = """
36-
type: group
37-
short-summary: Manage action groups for activity log alert rules.
38-
"""
39-
40-
helps['monitor activity-log alert action-group add'] = """
41-
type: command
42-
short-summary: Add action groups to this activity log alert rule. It can also be used to overwrite existing webhook properties of particular action groups.
43-
parameters:
44-
- name: --name -n
45-
short-summary: Name of the activity log alert rule.
46-
- name: --action-group -a
47-
short-summary: The names or the resource ids of the action groups to be added.
48-
- name: --reset
49-
short-summary: Remove all the existing action groups before add new conditions.
50-
- name: --webhook-properties -w
51-
short-summary: >
52-
Space-separated webhook properties in 'key[=value]' format. These properties will be associated with
53-
the action groups added in this command.
54-
long-summary: >
55-
For any webhook receiver in these action group, these data are appended to the webhook payload.
56-
To attach different webhook properties to different action groups, add the action groups in separate update-action commands.
57-
- name: --strict
58-
short-summary: Fails the command if an action group to be added will change existing webhook properties.
59-
examples:
60-
- name: Add an action group and specify webhook properties.
61-
text: |
62-
az monitor activity-log alert action-group add -n {AlertName} -g {ResourceGroup} \\
63-
--action /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/microsoft.insights/actionGroups/{ActionGroup} \\
64-
--webhook-properties usage=test owner=jane
65-
- name: Overwite an existing action group's webhook properties.
66-
text: |
67-
az monitor activity-log alert action-group add -n {AlertName} -g {ResourceGroup} \\
68-
-a /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/microsoft.insights/actionGroups/{ActionGroup} \\
69-
--webhook-properties usage=test owner=john
70-
- name: Remove webhook properties from an existing action group.
71-
text: |
72-
az monitor activity-log alert action-group add -n {AlertName} -g {ResourceGroup} \\
73-
-a /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/microsoft.insights/actionGroups/{ActionGroup}
74-
- name: Add new action groups but prevent the command from accidently overwrite existing webhook properties
75-
text: |
76-
az monitor activity-log alert action-group add -n {AlertName} -g {ResourceGroup} --strict \\
77-
--action-group {ResourceIDList}
78-
"""
79-
80-
helps['monitor activity-log alert action-group remove'] = """
81-
type: command
82-
short-summary: Remove action groups from this activity log alert rule.
83-
parameters:
84-
- name: --name -n
85-
short-summary: Name of the activity log alert rule.
86-
- name: --action-group -a
87-
short-summary: The names or the resource ids of the action groups to be removed.
88-
"""
89-
90-
helps['monitor activity-log alert create'] = """
91-
type: command
92-
short-summary: Create a default activity log alert rule.
93-
long-summary: This command will create a default activity log with one condition which compares if the activities logs 'category' field equals to 'ServiceHealth'. The newly created activity log alert does not have any action groups attached to it.
94-
parameters:
95-
- name: --name -n
96-
short-summary: Name of the activity log alert rule.
97-
- name: --scope -s
98-
short-summary: A list of strings that will be used as prefixes.
99-
long-summary: >
100-
The alert rule will only apply to activity logs with resourceIDs that fall under one of these prefixes.
101-
If not provided, the path to the resource group will be used.
102-
- name: --disable
103-
short-summary: Disable the activity log alert rule after it is created.
104-
- name: --description
105-
short-summary: A description of this activity log alert rule.
106-
- name: --condition -c
107-
short-summary: The condition that will cause the alert rule to activate. The format is FIELD=VALUE[ and FIELD=VALUE...].
108-
long-summary: >
109-
The possible values for the field are 'resourceId', 'category', 'caller', 'level', 'operationName', 'resourceGroup',
110-
'resourceProvider', 'status', 'subStatus', 'resourceType', or anything beginning with 'properties.'.
111-
- name: --action-group -a
112-
short-summary: >
113-
Add an action group. Accepts space-separated action group identifiers. The identifier can be the action group's name
114-
or its resource ID.
115-
- name: --webhook-properties -w
116-
short-summary: >
117-
Space-separated webhook properties in 'key[=value]' format. These properties are associated with the action groups
118-
added in this command.
119-
long-summary: >
120-
For any webhook receiver in these action group, this data is appended to the webhook payload. To attach different webhook
121-
properties to different action groups, add the action groups in separate update-action commands.
122-
examples:
123-
- name: Create an alert rule with default settings.
124-
text: >
125-
az monitor activity-log alert create -n {AlertName} -g {ResourceGroup}
126-
- name: Create an alert rule with condition about error level service health log.
127-
text: >
128-
az monitor activity-log alert create -n {AlertName} -g {ResourceGroup} \\
129-
--condition category=ServiceHealth and level=Error
130-
- name: Create an alert rule with an action group and specify webhook properties.
131-
text: >
132-
az monitor activity-log alert create -n {AlertName} -g {ResourceGroup} \\
133-
-a /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/microsoft.insights/actionGroups/{ActionGroup} \\
134-
-w usage=test owner=jane
135-
- name: Create an alert rule which is initially disabled.
136-
text: >
137-
az monitor activity-log alert create -n {AlertName} -g {ResourceGroup} --disable
138-
"""
139-
14035
helps['monitor activity-log alert list'] = """
14136
type: command
14237
short-summary: List activity log alert rules under a resource group or the current subscription.
@@ -145,67 +40,6 @@
14540
short-summary: Name of the resource group under which the activity log alert rules are being listed. If it is omitted, all the activity log alert rules under the current subscription are listed.
14641
"""
14742

148-
helps['monitor activity-log alert scope'] = """
149-
type: group
150-
short-summary: Manage scopes for activity log alert rules.
151-
"""
152-
153-
helps['monitor activity-log alert scope add'] = """
154-
type: command
155-
short-summary: Add scopes to this activity log alert rule.
156-
parameters:
157-
- name: --name -n
158-
short-summary: Name of the activity log alert rule.
159-
- name: --scope -s
160-
short-summary: List of scopes to add. Each scope could be a resource ID, a resource group ID or a subscription ID.
161-
- name: --reset
162-
short-summary: Remove all the existing scopes before add new scopes.
163-
examples:
164-
- name: Add scopes to this activity log alert rule. (autogenerated)
165-
text: |
166-
az monitor activity-log alert scope add --name MyActivityLogAlerts --resource-group MyResourceGroup --scope /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myRG /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myRG/Microsoft.KeyVault/vaults/mykey
167-
crafted: true
168-
"""
169-
170-
helps['monitor activity-log alert scope remove'] = """
171-
type: command
172-
short-summary: Removes scopes from this activity log alert rule.
173-
parameters:
174-
- name: --name -n
175-
short-summary: Name of the activity log alert rule.
176-
- name: --scope -s
177-
short-summary: The scopes to remove
178-
"""
179-
180-
helps['monitor activity-log alert update'] = """
181-
type: command
182-
short-summary: Update the details of this activity log alert rule.
183-
parameters:
184-
- name: --description
185-
short-summary: A description of this activity log alert rule.
186-
- name: --condition -c
187-
short-summary: The conditional expression that will cause the alert rule to activate. The format is FIELD=VALUE[ and FIELD=VALUE...].
188-
long-summary: >
189-
The possible values for the field are 'resourceId', 'category', 'caller', 'level', 'operationName', 'resourceGroup',
190-
'resourceProvider', 'status', 'subStatus', 'resourceType', or anything beginning with 'properties.'.
191-
examples:
192-
- name: Update the condition
193-
text: >
194-
az monitor activity-log alert update -n {AlertName} -g {ResourceGroup} \\
195-
--condition category=ServiceHealth and level=Error
196-
- name: Disable an alert rule.
197-
text: >
198-
az monitor activity-log alert update -n {AlertName} -g {ResourceGroup} --enable false
199-
- name: Update the details of this activity log alert rule. (autogenerated)
200-
text: |
201-
az monitor activity-log alert update --enabled true --name MyActivityLogAlerts --resource-group MyResourceGroup --subscription MySubscription
202-
crafted: true
203-
- name: Update the details of this activity log alert. (autogenerated)
204-
text: |
205-
az monitor activity-log alert update --name MyActivityLogAlerts --resource-group MyResourceGroup --tags key=value
206-
crafted: true
207-
"""
208-
20943
helps['monitor activity-log list'] = """
21044
type: command
21145
short-summary: List and query activity log events.
@@ -242,11 +76,6 @@
24276
text: az monitor activity-log list -g {ResourceGroup} --offset 1h
24377
"""
24478

245-
helps['monitor activity-log list-categories'] = """
246-
type: command
247-
short-summary: List the event categories of activity logs.
248-
"""
249-
25079
helps['monitor autoscale'] = """
25180
type: group
25281
short-summary: Manage autoscale settings.

src/azure-cli/azure/cli/command_modules/monitor/_params.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
timezone_offset_type, timezone_name_type, MetricAlertConditionAction, MetricAlertAddAction)
1616
from azure.cli.command_modules.monitor.util import get_operator_map, get_aggregation_map
1717
from azure.cli.command_modules.monitor.validators import (
18-
process_webhook_prop, validate_autoscale_recurrence, validate_autoscale_timegrain, get_action_group_validator,
18+
validate_autoscale_recurrence, validate_autoscale_timegrain, get_action_group_validator,
1919
get_action_group_id_validator, validate_metric_dimension, validate_storage_accounts_name_or_id)
2020

2121
from knack.arguments import CLIArgumentType
@@ -26,7 +26,6 @@ def load_arguments(self, _):
2626
from azure.mgmt.monitor.models import ConditionOperator, TimeAggregationOperator, EventData, PredictiveAutoscalePolicyScaleMode
2727
from .grammar.metric_alert.MetricAlertConditionValidator import dim_op_conversion, agg_conversion, op_conversion, sens_conversion
2828
name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')
29-
webhook_prop_type = CLIArgumentType(validator=process_webhook_prop, nargs='*')
3029

3130
autoscale_name_type = CLIArgumentType(options_list=['--autoscale-name'], help='Name of the autoscale settings.', id_part='name')
3231
autoscale_profile_name_type = CLIArgumentType(options_list=['--profile-name'], help='Name of the autoscale profile.')
@@ -299,39 +298,6 @@ def load_arguments(self, _):
299298
# region ActivityLog Alerts
300299
with self.argument_context('monitor activity-log alert') as c:
301300
c.argument('activity_log_alert_name', options_list=['--name', '-n'], id_part='name')
302-
303-
with self.argument_context('monitor activity-log alert create') as c:
304-
from .operations.activity_log_alerts import process_condition_parameter
305-
c.argument('disable', action='store_true')
306-
c.argument('scopes', options_list=['--scope', '-s'], nargs='+')
307-
c.argument('condition', options_list=['--condition', '-c'], nargs='+', validator=process_condition_parameter)
308-
c.argument('action_groups', options_list=['--action-group', '-a'], nargs='+')
309-
c.argument('webhook_properties', options_list=['--webhook-properties', '-w'], arg_type=webhook_prop_type)
310-
311-
with self.argument_context('monitor activity-log alert update-condition') as c:
312-
c.argument('reset', action='store_true')
313-
c.argument('add_conditions', options_list=['--add-condition', '-a'], nargs='+')
314-
c.argument('remove_conditions', options_list=['--remove-condition', '-r'], nargs='+')
315-
316-
with self.argument_context('monitor activity-log alert update') as c:
317-
from .operations.activity_log_alerts import process_condition_parameter
318-
c.argument('condition', options_list=['--condition', '-c'], nargs='+', validator=process_condition_parameter)
319-
c.argument('enabled', arg_type=get_three_state_flag())
320-
321-
with self.argument_context('monitor activity-log alert action-group add') as c:
322-
c.argument('reset', action='store_true')
323-
c.argument('action_group_ids', options_list=['--action-group', '-a'], nargs='+')
324-
c.argument('webhook_properties', options_list=['--webhook-properties', '-w'], arg_type=webhook_prop_type)
325-
326-
with self.argument_context('monitor activity-log alert action-group remove') as c:
327-
c.argument('action_group_ids', options_list=['--action-group', '-a'], nargs='+')
328-
329-
with self.argument_context('monitor activity-log alert scope add') as c:
330-
c.argument('scopes', options_list=['--scope', '-s'], nargs='+')
331-
c.argument('reset', action='store_true')
332-
333-
with self.argument_context('monitor activity-log alert scope remove') as c:
334-
c.argument('scopes', options_list=['--scope', '-s'], nargs='+')
335301
# endregion
336302

337303
# region Log Analytics Workspace
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"monitor activity-log",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage activity logs.
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
12+
from ._list import *
13+
from ._list_categories import *

0 commit comments

Comments
 (0)