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
4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-monitor/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.2.6
+++++
* `monitor metrics alert create/update`: `--condition` now supports metric names which include characters forward-slash (/) and period (.).

0.2.5
+++++
* `monitor activity-log list`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@
helps['monitor diagnostic-settings create'] = """
type: command
short-summary: Create diagnostic settings for the specified resource.
long-summary: >
For more information, visit: https://docs.microsoft.com/en-us/rest/api/monitor/diagnosticsettings/createorupdate#metricsettings
parameters:
- name: --name -n
short-summary: The name of the diagnostic settings.
Expand All @@ -351,6 +353,31 @@
Name or ID an event hub. If none is specified, the default event hub will be selected.
- name: --event-hub-rule
short-summary: Name or ID of the event hub authorization rule.
examples:
- name: Create diagnostic settings with EventHub.
text: |
az monitor diagnostic-settings create --resource {ID} -n {name}
--event-hub-rule {eventHubRuleID} --storage-account {storageAccount}
--logs '[
{
"category": "WorkflowRuntime",
"enabled": true,
"retentionPolicy": {
"enabled": false,
"days": 0
}
}
]'
--metrics '[
{
"category": "WorkflowRuntime",
"enabled": true,
"retentionPolicy": {
"enabled": false,
"days": 0
}
}
]'
"""
helps['monitor diagnostic-settings update'] = """
type: command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# --------------------------------------------------------------------------------------------

import argparse

import antlr4
from knack.util import CLIError

from azure.cli.command_modules.monitor.util import (
get_aggregation_map, get_operator_map, get_autoscale_operator_map,
Expand All @@ -16,7 +16,6 @@ def timezone_name_type(value):
from azure.cli.command_modules.monitor._autoscale_util import AUTOSCALE_TIMEZONES
zone = next((x['name'] for x in AUTOSCALE_TIMEZONES if x['name'].lower() == value.lower()), None)
if not zone:
from knack.util import CLIError
raise CLIError(
"Invalid time zone: '{}'. Run 'az monitor autoscale profile list-timezones' for values.".format(value))
return zone
Expand All @@ -33,7 +32,6 @@ def timezone_offset_type(value):
hour = int(hour)

if hour > 14 or hour < -12:
from knack.util import CLIError
raise CLIError('Offset out of range: -12 to +14')

if hour >= 0 and hour < 10:
Expand Down Expand Up @@ -96,17 +94,27 @@ def __call__(self, parser, namespace, values, option_string=None):
from azure.cli.command_modules.monitor.grammar import (
MetricAlertConditionLexer, MetricAlertConditionParser, MetricAlertConditionValidator)

usage = 'usage error: --condition {avg,min,max,total} [NAMESPACE.]METRIC {=,!=,>,>=,<,<=} THRESHOLD\n' \
' [where DIMENSION {includes,excludes} VALUE [or VALUE ...]\n' \
' [and DIMENSION {includes,excludes} VALUE [or VALUE ...] ...]]'

string_val = ' '.join(values)

lexer = MetricAlertConditionLexer(antlr4.InputStream(string_val))
stream = antlr4.CommonTokenStream(lexer)
parser = MetricAlertConditionParser(stream)
tree = parser.expression()

validator = MetricAlertConditionValidator()
walker = antlr4.ParseTreeWalker()
walker.walk(validator, tree)
metric_condition = validator.result()
try:
validator = MetricAlertConditionValidator()
walker = antlr4.ParseTreeWalker()
walker.walk(validator, tree)
metric_condition = validator.result()
for item in ['time_aggregation', 'metric_name', 'threshold', 'operator']:
if not getattr(metric_condition, item, None):
raise CLIError(usage)
except (AttributeError, TypeError, KeyError):
raise CLIError(usage)
super(MetricAlertConditionAction, self).__call__(parser, namespace, metric_condition, option_string)


Expand Down Expand Up @@ -136,7 +144,6 @@ def __call__(self, parser, namespace, values, option_string=None):
# specified as a quoted expression
values = values[0].split(' ')
if len(values) < 5:
from knack.util import CLIError
raise CLIError('usage error: --condition METRIC {>,>=,<,<=} THRESHOLD {avg,min,max,total,last} DURATION')
metric_name = ' '.join(values[:-4])
operator = get_operator_map()[values[-4]]
Expand All @@ -157,7 +164,6 @@ def __call__(self, parser, namespace, values, option_string=None):
super(AlertAddAction, self).__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
from knack.util import CLIError
_type = values[0].lower()
if _type == 'email':
from azure.mgmt.monitor.models import RuleEmailAction
Expand All @@ -182,7 +188,6 @@ def __call__(self, parser, namespace, values, option_string=None):
def get_action(self, values, option_string): # pylint: disable=no-self-use
# TYPE is artificially enforced to create consistency with the --add-action argument
# but it could be enhanced to do additional validation in the future.
from knack.util import CLIError
_type = values[0].lower()
if _type not in ['email', 'webhook']:
raise CLIError('usage error: {} TYPE KEY [KEY ...]'.format(option_string))
Expand All @@ -196,7 +201,6 @@ def __call__(self, parser, namespace, values, option_string=None):
super(AutoscaleAddAction, self).__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
from knack.util import CLIError
_type = values[0].lower()
if _type == 'email':
from azure.mgmt.monitor.models import EmailNotification
Expand All @@ -221,7 +225,6 @@ def __call__(self, parser, namespace, values, option_string=None):
def get_action(self, values, option_string): # pylint: disable=no-self-use
# TYPE is artificially enforced to create consistency with the --add-action argument
# but it could be enhanced to do additional validation in the future.
from knack.util import CLIError
_type = values[0].lower()
if _type not in ['email', 'webhook']:
raise CLIError('usage error: {} TYPE KEY [KEY ...]'.format(option_string))
Expand All @@ -243,7 +246,6 @@ def __call__(self, parser, namespace, values, option_string=None):
aggregation = get_autoscale_aggregation_map()[values[-2].lower()]
window = get_period_type()(values[-1])
except (IndexError, KeyError):
from knack.util import CLIError
raise CLIError('usage error: --condition METRIC {==,!=,>,>=,<,<=} '
'THRESHOLD {avg,min,max,total,count} PERIOD')
condition = MetricTrigger(
Expand All @@ -267,7 +269,6 @@ def __call__(self, parser, namespace, values, option_string=None):
# specified as a quoted expression
values = values[0].split(' ')
if len(values) != 2:
from knack.util import CLIError
raise CLIError('usage error: --scale {in,out,to} VALUE[%]')
dir_val = values[0]
amt_val = values[1]
Expand Down Expand Up @@ -316,7 +317,6 @@ def deserialize_object(self, type_name, type_properties):
class ActionGroupReceiverParameterAction(MultiObjectsDeserializeAction):
def deserialize_object(self, type_name, type_properties):
from azure.mgmt.monitor.models import EmailReceiver, SmsReceiver, WebhookReceiver
from knack.util import CLIError

if type_name == 'email':
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ aggregation : WORD WHITESPACE ;

namespace : WORD ;

metric : (WORD | WHITESPACE)+;
metric : (WORD | WHITESPACE | '.' | '/')+;

operator : OPERATOR WHITESPACE ;

Expand Down Expand Up @@ -69,3 +69,4 @@ QUOTE : ('\'' | '"') ;
WHITESPACE : (' ' | '\t')+ ;
NEWLINE : ('\r'? '\n' | '\r')+ ;
WORD : (LOWERCASE | UPPERCASE | DIGIT | '_')+ ;

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
T__0=1
T__1=2
WHERE=3
AND=4
IN=5
IS=6
OR=7
OPERATOR=8
NUMBER=9
QUOTE=10
WHITESPACE=11
NEWLINE=12
WORD=13
T__2=3
WHERE=4
AND=5
INCLUDES=6
EXCLUDES=7
OR=8
OPERATOR=9
NUMBER=10
QUOTE=11
WHITESPACE=12
NEWLINE=13
WORD=14
'.'=1
','=2
'/'=2
','=3
Loading