Skip to content

Commit

Permalink
Updated azure-mgmt-monitor to 0.7.0 and added new action-group featur…
Browse files Browse the repository at this point in the history
…es (Azure#11051)
  • Loading branch information
ritwik8119 authored and mmyyrroonn committed Nov 8, 2019
1 parent 7d25cde commit 85ad0a4
Show file tree
Hide file tree
Showing 23 changed files with 310 additions and 70 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,3 @@ pip.log
.tox/

az_command_coverage.txt

30 changes: 28 additions & 2 deletions src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods
MGMT_RESOURCE_POLICY = ('azure.mgmt.resource.policy', 'PolicyClient')
MGMT_RESOURCE_RESOURCES = ('azure.mgmt.resource.resources', 'ResourceManagementClient')
MGMT_RESOURCE_SUBSCRIPTIONS = ('azure.mgmt.resource.subscriptions', 'SubscriptionClient')
MGMT_MONITOR = ('azure.mgmt.monitor', 'MonitorManagementClient')
DATA_KEYVAULT = ('azure.keyvault', 'KeyVaultClient')
MGMT_EVENTHUB = ('azure.mgmt.eventhub', 'EventHubManagementClient')
# the "None" below will stay till a command module fills in the type so "get_mgmt_service_client"
Expand Down Expand Up @@ -76,7 +77,6 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods
MGMT_IOTCENTRAL = ('azure.mgmt.iotcentral', None)
MGMT_DEVTESTLABS = ('azure.mgmt.devtestlabs', None)
MGMT_MAPS = ('azure.mgmt.maps', None)
MGMT_MONITOR = ('azure.mgmt.monitor', None)
MGMT_POLICYINSIGHTS = ('azure.mgmt.policyinsights', None)
MGMT_RDBMS = ('azure.mgmt.rdbms', None)
MGMT_REDIS = ('azure.mgmt.redis', None)
Expand Down Expand Up @@ -148,7 +148,33 @@ def default_api_version(self):
ResourceType.DATA_KEYVAULT: '7.0',
ResourceType.DATA_STORAGE: '2018-11-09',
ResourceType.DATA_COSMOS_TABLE: '2017-04-17',
ResourceType.MGMT_EVENTHUB: '2017-04-01'
ResourceType.MGMT_EVENTHUB: '2017-04-01',
ResourceType.MGMT_MONITOR: SDKProfile('2019-06-01', {
'activity_log_alerts': '2017-04-01',
'activity_logs': '2015-04-01',
'alert_rule_incidents': '2016-03-01',
'alert_rules': '2016-03-01',
'autoscale_settings': '2015-04-01',
'baseline': '2018-09-01',
'baselines': '2019-03-01',
'diagnostic_settings': '2017-05-01-preview',
'diagnostic_settings_category': '2017-05-01-preview',
'event_categories': '2015-04-01',
'guest_diagnostics_settings': '2018-06-01-preview',
'guest_diagnostics_settings_association': '2018-06-01-preview',
'log_profiles': '2016-03-01',
'metric_alerts': '2018-03-01',
'metric_alerts_status': '2018-03-01',
'metric_baseline': '2018-09-01',
'metric_definitions': '2018-01-01',
'metric_namespaces': '2017-12-01-preview',
'metrics': '2018-01-01',
'operations': '2015-04-01',
'scheduled_query_rules': '2018-04-16',
'service_diagnostic_settings': '2016-09-01',
'tenant_activity_logs': '2015-04-01',
'vm_insights': '2018-11-27-preview'
})
},
'2019-03-01-hybrid': {
ResourceType.MGMT_STORAGE: '2017-10-01',
Expand Down
7 changes: 7 additions & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ Release History
* Fix #9352: Unexpected error when certificate file does not exist
* Fix #7048: `az keyvault recover/purge` not working

**Monitor**

* Updated azure-mgmt-monitor to 0.7.0
* az monitor action-group create/update: Added suport for following new receivers: Arm role, Azure app push, ITSM, automation runbook, voice, logic app and Azure function
* Included parameter usecommonalertschema for supported receivers
* Included parameter useaadwebhook for webhook receiver

**NetAppFiles**

* Upgrade azure-mgmt-netapp to 0.6.0 to use API version 2019-07-01. This new API version includes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@


def monitor_exception_handler(ex):
from azure.mgmt.monitor.models import ErrorResponseException
from azure.mgmt.monitor.v2015_04_01.models import ErrorResponseException as ErrorResponseException_v2015_04_01
from azure.mgmt.monitor.v2016_03_01.models import ErrorResponseException as ErrorResponseException_v2016_03_01
from azure.mgmt.monitor.v2017_04_01.models import ErrorResponseException as ErrorResponseException_v2017_04_01
from azure.mgmt.monitor.v2017_05_01_preview.models import \
ErrorResponseException as ErrorResponseException_v2017_05_01
from azure.mgmt.monitor.v2018_01_01.models import ErrorResponseException as ErrorResponseException_v2018_01_01
from azure.mgmt.monitor.v2018_03_01.models import ErrorResponseException as ErrorResponseException_v2018_03_01
from azure.mgmt.monitor.v2019_06_01.models import ErrorResponseException as ErrorResponseException_v2019_06_01

from knack.util import CLIError

if isinstance(ex, ErrorResponseException):
if isinstance(ex, (ErrorResponseException_v2015_04_01,
ErrorResponseException_v2016_03_01,
ErrorResponseException_v2017_04_01,
ErrorResponseException_v2017_05_01,
ErrorResponseException_v2018_01_01,
ErrorResponseException_v2018_03_01,
ErrorResponseException_v2019_06_01
)):
# work around for issue: https://github.com/Azure/azure-sdk-for-python/issues/1556
try:
error_payload = ex.response.json()
Expand Down
72 changes: 65 additions & 7 deletions src/azure-cli/azure/cli/command_modules/monitor/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,39 @@
short-summary: Add receivers to the action group during the creation
long-summary: |
Usage: --action TYPE NAME [ARG ...]
Email: --action email bob bob@contoso.com
SMS: --action sms charli 1 5551234567
Webhook: --action webhook alert_hook https://www.contoso.com/alert
Multiple actions can be specified by using more than one `--action` argument.
Email:
Format: --action email NAME EMAIL_ADDRESS [usecommonalertschema]
Example: --action email bob bob@contoso.com
SMS:
Format: --action sms NAME COUNTRY_CODE PHONE_NUMBER
Example: --action sms charli 1 5551234567
Webhook:
Format: --action webhook NAME URI [useaadauth OBJECT_ID IDENTIFIER URI] [usecommonalertschema]
Example: --action webhook alert_hook https://www.contoso.com/alert useaadauth testobj http://identifier usecommonalertschema
Arm Role:
Format: --action armrole NAME ROLE_ID [usecommonalertschema]
Example: --action armole owner_role 8e3af657-a8ff-443c-a75c-2fe8c4bcb635
Azure App Push:
Format: --action azureapppush NAME EMAIL_ADDRESS
Example: --action azureapppush test_apppush bob@contoso.com
ITSM:
Format: --action itsm NAME WORKSPACE_ID CONNECTION_ID TICKET_CONFIGURATION REGION
Example: --action itsm test_itsm test_workspace test_conn ticket_blob useast
Automation runbook:
Format: --action automationrunbook NAME AUTOMATION_ACCOUNT_ID RUNBOOK_NAME WEBHOOK_RESOURCE_ID SERVICE_URI [isglobalrunbook] [usecommonalertschema]
Example: --action automationrunbook test_runbook test_acc test_book test_webhook test_rsrc http://example.com isglobalrunbook usecommonalertschema
Voice:
Format: --action voice NAME COUNTRY_CODE PHONE_NUMBER
Example: --action voice charli 1 4441234567
Logic App:
Format: --action logicapp NAME RESOURCE_ID CALLBACK_URL [usecommonalertschema]
Example: --action logicapp test_logicapp test_rsrc http://callback
Azure Function:
Format: --action azurefunction NAME FUNCTION_APP_RESOURCE_ID FUNCTION_NAME HTTP_TRIGGER_URL [usecommonalertschema]
Example: --action azurefunction test_function test_rsrc test_func http://trigger usecommonalertschema
Multiple actions can be specified by using more than one `--add-action` argument.
'useaadauth', 'isglobalrunbook' and 'usecommonalertschema' are optional arguements that only need to be passed to set the respective parameter to True.
If the 'useaadauth' argument is passed, then the OBJECT_ID and IDENTIFIER_URI values are required as well.
- name: --short-name
short-summary: The short name of the action group
examples:
Expand Down Expand Up @@ -67,10 +96,39 @@
short-summary: Add receivers to the action group
long-summary: |
Usage: --add-action TYPE NAME [ARG ...]
Email: --add-action email bob bob@contoso.com
SMS: --add-action sms charli 1 5551234567
Webhook: --add-action https://www.contoso.com/alert
Email:
Format: --add-action email NAME EMAIL_ADDRESS [usecommonalertschema]
Example: --add-action email bob bob@contoso.com
SMS:
Format: --add-action sms NAME COUNTRY_CODE PHONE_NUMBER
Example: --add-action sms charli 1 5551234567
Webhook:
Format: --add-action webhook NAME URI [useaadauth OBJECT_ID IDENTIFIER URI] [usecommonalertschema]
Example: --add-action https://www.contoso.com/alert useaadauth testobj http://identifier usecommonalertschema
Arm Role:
Format: --add-action armrole NAME ROLE_ID [usecommonalertschema]
Example: --add-action armole owner_role 8e3af657-a8ff-443c-a75c-2fe8c4bcb635
Azure App Push:
Format: --add-action azureapppush NAME EMAIL_ADDRESS
Example: --add-action azureapppush test_apppush bob@contoso.com
ITSM:
Format: --add-action itsm NAME WORKSPACE_ID CONNECTION_ID TICKET_CONFIGURATION REGION
Example: --add-action itsm test_itsm test_workspace test_conn ticket_blob useast
Automation runbook:
Format: --add-action automationrunbook NAME AUTOMATION_ACCOUNT_ID RUNBOOK_NAME WEBHOOK_RESOURCE_ID SERVICE_URI [isglobalrunbook] [usecommonalertschema]
Example: --add-action automationrunbook test_runbook test_acc test_book test_webhook test_rsrc http://example.com isglobalrunbook usecommonalertschema
Voice:
Format: --add-action voice NAME COUNTRY_CODE PHONE_NUMBER
Example: --add-action voice charli 1 4441234567
Logic App:
Format: --add-action logicapp NAME RESOURCE_ID CALLBACK_URL [usecommonalertschema]
Example: --add-action logicapp test_logicapp test_rsrc http://callback
Azure Function:
Format: --add-action azurefunction NAME FUNCTION_APP_RESOURCE_ID FUNCTION_NAME HTTP_TRIGGER_URL [usecommonalertschema]
Example: --add-action azurefunction test_function test_rsrc test_func http://trigger usecommonalertschema
Multiple actions can be specified by using more than one `--add-action` argument.
'useaadauth', 'isglobalrunbook' and 'usecommonalertschema' are optional arguements that only need to be passed to set the respective parameter to True.
If the 'useaadauth' argument is passed, then the OBJECT_ID and IDENTIFIER_URI values are required as well.
- name: --remove-action -r
short-summary: Remove receivers from the action group. Accept space-separated list of receiver names.
examples:
Expand Down
91 changes: 72 additions & 19 deletions src/azure-cli/azure/cli/command_modules/monitor/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,26 +315,79 @@ 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

if type_name == 'email':
try:
return EmailReceiver(name=type_properties[0], email_address=type_properties[1])
except IndexError:
raise CLIError('usage error: --action email NAME EMAIL_ADDRESS')
elif type_name == 'sms':
try:
return SmsReceiver(
from azure.mgmt.monitor.models import EmailReceiver, SmsReceiver, WebhookReceiver, \
ArmRoleReceiver, AzureAppPushReceiver, ItsmReceiver, AutomationRunbookReceiver, \
VoiceReceiver, LogicAppReceiver, AzureFunctionReceiver
syntax = {
'email': 'NAME EMAIL_ADDRESS [usecommonalertschema]',
'sms': 'NAME COUNTRY_CODE PHONE_NUMBER',
'webhook': 'NAME URI [useaadauth OBJECT_ID IDENTIFIER URI] [usecommonalertschema]',
'armrole': 'NAME ROLE_ID [usecommonalertschema]',
'azureapppush': 'NAME EMAIL_ADDRESS',
'itsm': 'NAME WORKSPACE_ID CONNECTION_ID TICKET_CONFIG REGION',
'automationrunbook': 'NAME AUTOMATION_ACCOUNT_ID RUNBOOK_NAME WEBHOOK_RESOURCE_ID '
'SERVICE_URI [isglobalrunbook] [usecommonalertschema]',
'voice': 'NAME COUNTRY_CODE PHONE_NUMBER',
'logicapp': 'NAME RESOURCE_ID CALLBACK_URL [usecommonalertschema]',
'azurefunction': 'NAME FUNCTION_APP_RESOURCE_ID '
'FUNCTION_NAME HTTP_TRIGGER_URL [usecommonalertschema]'
}

receiver = None
useCommonAlertSchema = 'usecommonalertschema' in (property.lower() for property in type_properties)
try:
if type_name == 'email':
receiver = EmailReceiver(name=type_properties[0], email_address=type_properties[1],
use_common_alert_schema=useCommonAlertSchema)
elif type_name == 'sms':
receiver = SmsReceiver(
name=type_properties[0],
country_code=type_properties[1],
phone_number=type_properties[2]
)
except IndexError:
raise CLIError('usage error: --action sms NAME COUNTRY_CODE PHONE_NUMBER')
elif type_name == 'webhook':
try:
return WebhookReceiver(name=type_properties[0], service_uri=type_properties[1])
except IndexError:
raise CLIError('usage error: --action webhook NAME URI')
else:
raise ValueError('usage error: the type "{}" is not recognizable.'.format(type_name))
elif type_name == 'webhook':
useAadAuth = len(type_properties) >= 3 and type_properties[2] == 'useaadauth'
object_id = type_properties[3] if useAadAuth else None
identifier_uri = type_properties[4] if useAadAuth else None
receiver = WebhookReceiver(name=type_properties[0], service_uri=type_properties[1],
use_common_alert_schema=useCommonAlertSchema,
use_aad_auth=useAadAuth, object_id=object_id,
identifier_uri=identifier_uri)
elif type_name == 'armrole':
receiver = ArmRoleReceiver(name=type_properties[0], role_id=type_properties[1],
use_common_alert_schema=useCommonAlertSchema)
elif type_name == 'azureapppush':
receiver = AzureAppPushReceiver(name=type_properties[0], email_address=type_properties[1])
elif type_name == 'itsm':
receiver = ItsmReceiver(name=type_properties[0], workspace_id=type_properties[1],
connection_id=type_properties[2], ticket_configuration=type_properties[3],
region=type_properties[4])
elif type_name == 'automationrunbook':
isGlobalRunbook = 'isglobalrunbook' in (property.lower() for property in type_properties)
receiver = AutomationRunbookReceiver(name=type_properties[0], automation_account_id=type_properties[1],
runbook_name=type_properties[2],
webhook_resource_id=type_properties[3],
service_uri=type_properties[4],
is_global_runbook=isGlobalRunbook,
use_common_alert_schema=useCommonAlertSchema)
elif type_name == 'voice':
receiver = VoiceReceiver(
name=type_properties[0],
country_code=type_properties[1],
phone_number=type_properties[2]
)
elif type_name == 'logicapp':
receiver = LogicAppReceiver(name=type_properties[0], resource_id=type_properties[1],
callback_url=type_properties[2],
use_common_alert_schema=useCommonAlertSchema)
elif type_name == 'azurefunction':
receiver = AzureFunctionReceiver(name=type_properties[0], function_app_resource_id=type_properties[1],
function_name=type_properties[2],
http_trigger_url=type_properties[3],
use_common_alert_schema=useCommonAlertSchema)
else:
raise ValueError('usage error: the type "{}" is not recognizable.'.format(type_name))

except IndexError:
raise CLIError('usage error: --action {}'.format(syntax[type_name]))
return receiver
Loading

0 comments on commit 85ad0a4

Please sign in to comment.