2017-09-15 6 views
1

Ich definiere eine Alarmregel in meinem template.json mit benutzerdefinierten eMails, die im Falle eines Fehlers alarmiert werden sollen. So sieht das JSON-Schnipsel wie folgt aus:Azure ARM Vorlage - mit Array-Variable

"resources": [ 
    { 
     "type": "microsoft.insights/alertrules", 
     "properties": { 
      "action": { 
       "customEmails": [ 
        "[email protected]", 
        "[email protected]" 
       ] 
      } 
     } 
    } 
] 

Nun möchte Ich mag diese E-Mails als Array-Variablen speichern, etwa so:

"variables": { 
    "alertEmails": [ 
     "[email protected]", 
     "[email protected]" 
    ] 
}, 
"resources": [ 
    { 
     "type": "microsoft.insights/alertrules", 
     "properties": { 
      "action": { 
       "customEmails": "[variables('alertEmails')]" 
      } 
     } 
    } 
] 

dies nicht funktioniert, aber ich didn habe nicht herausgefunden, was die richtige Syntax ist. Kann mir das jemand sagen?

+0

haben Bitte versuchen Sie die [azur Dokument] zu folgen (https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-enable-alerts-using-template) um "" customEmails "zu verwenden:" [split (Parameter ('customEmailAddresses') , ',')] "', "customEmailAddresses": "Durch Kommas begrenzte E-Mail-Adressen, an die auch die Benachrichtigungen gesendet werden" –

Antwort

1

Das funktioniert nicht, aber ich habe nicht herausgefunden, was die richtige Syntax ist. Kann mir das jemand sagen?

Ich teste es mit Ihrem mitgelieferten Code, es funktioniert richtig auf meiner Seite. Folgendes ist meine verwendete Vorlage. Bitte versuchen Sie es mit dem folgenden Democode.

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
    "serverFarmName": { 
     "type": "string", 
     "defaultValue": "serviceplan" 
    }, 
    "resourceId": { 
     "type": "string", 
     "defaultValue": "/subscriptions/{subscriptionId}/resourceGroups/{resourceName}/providers/Microsoft.Web/sites/websiteName", 
     "metadata": { 
     "description": "Resource ID of the resource emitting the metric that will be used for the comparison." 
     } 
    }, 
    "metricName": { 
     "type": "string", 
     "defaultValue": "BytesReceived", 
     "metadata": { 
     "description": "Name of the metric used in the comparison to activate the alert." 
     } 
    }, 
    "operator": { 
     "type": "string", 
     "defaultValue": "GreaterThan", 
     "allowedValues": [ 
     "GreaterThan", 
     "GreaterThanOrEqual", 
     "LessThan", 
     "LessThanOrEqual" 
     ], 
     "metadata": { 
     "description": "Operator comparing the current value with the threshold value." 
     } 
    }, 
    "threshold": { 
     "type": "string", 
     "defaultValue": "1", 
     "metadata": { 
     "description": "The threshold value at which the alert is activated." 
     } 
    }, 
    "aggregation": { 
     "type": "string", 
     "defaultValue": "Average", 
     "allowedValues": [ 
     "Average", 
     "Last", 
     "Maximum", 
     "Minimum", 
     "Total" 
     ], 
     "metadata": { 
     "description": "How the data that is collected should be combined over time." 
     } 
    }, 
    "windowSize": { 
     "type": "string", 
     "defaultValue": "PT5M", 
     "metadata": { 
     "description": "Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one day. ISO 8601 duration format." 
     } 
    }, 
    "sendToServiceOwners": { 
     "type": "bool", 
     "defaultValue": true, 
     "metadata": { 
     "description": "Specifies whether alerts are sent to service owners" 
     } 
    }, 
    "webhookUrl": { 
     "type": "string", 
     "defaultValue": "", 
     "metadata": { 
     "description": "URL of a webhook that will receive an HTTP POST when the alert activates." 
     } 
    }, 
    "serverFarmResourceGroup": { 
     "type": "string", 
     "defaultValue": "resourceGroup" 
    } 
    }, 
    "variables": { 
    "alertEmails": [ 
     "[email protected]", 
     "[email protected]" 
    ], 


    "TomARMtestName": "[concat('TomARMtest', uniqueString(resourceGroup().id))]" 
    }, 
    "resources": [ 
    { 
     "type": "Microsoft.Insights/alertRules", 
     "name": "newalert", 
     "location": "[resourceGroup().location]", 
     "apiVersion": "2016-03-01", 
     "properties": { 
     "name": "newalert", 
     "description": "newalert", 
     "isEnabled": true, 
     "condition": { 
      "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition", 
      "dataSource": { 
      "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource", 
      "resourceUri": "[parameters('resourceId')]", 
      "metricName": "[parameters('metricName')]" 
      }, 
      "operator": "[parameters('operator')]", 
      "threshold": "[parameters('threshold')]", 
      "windowSize": "[parameters('windowSize')]", 
      "timeAggregation": "[parameters('aggregation')]" 
     }, 
     "actions": [ 
      { 
      "customEmails": "[variables('alertEmails')]" 
      } 
     ] 
     } 
    } 
    ] 
    , 
    "outputs": { 
    "out": { 
     "type": "array", 
     "value": "[variables('alertEmails')]" 
    } 
    } 
} 

Und ich folge der azure documentcustomEmails": "[split(parameters('customEmailAddresses'), ',')]" Code zu verwenden, es funktioniert auch korrekt auf meiner Seite.

+0

Hmm, es funktioniert wirklich. Ich weiß nicht, was ich falsch gemacht habe ... – Munchkin

+0

Wenn es nützlich ist, bitte markieren Sie es als eine Antwort, die mehr Gemeinden helfen wird. –

1

Wenn Sie Array verwenden möchten, können wir vielleicht json wie folgt verwenden:

"parameters": {  
"customEmailAddresses": { 
       "type": "array", 
       "defaultValue": ["[email protected]", 
        "[email protected]", 
        "[email protected]"] 

    } 
}, 

und in Aktion, wie folgt aus:

"customEmails": "[array(parameters('customEmailAddresses'))]" 
Verwandte Themen