Exemple #1
0
    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(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))
Exemple #2
0
 def deserialize_object(self, type_name, type_properties):
     from azure.mgmt.monitor.models import EmailReceiver, SmsReceiver, WebhookReceiver
     if type_name == 'email':
         return EmailReceiver(name=type_properties[0],
                              email_address=type_properties[1])
     elif type_name == 'sms':
         return SmsReceiver(name=type_properties[0],
                            country_code=type_properties[1],
                            phone_number=type_properties[2])
     elif type_name == 'webhook':
         return WebhookReceiver(name=type_properties[0],
                                service_uri=type_properties[1])
     else:
         raise ValueError(
             'usage error: the type "{}" is not recognizable.'.format(
                 type_name))
Exemple #3
0
    def deserialize_object(self, type_name, type_properties):
        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])
            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