I have initialize a variable of type array but I am always getting output value as null.
I have used the JSON payload :Log alert with monitoringService = Application Insights from below link:
https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-payload-samples
Here's my array expression :
createArray(triggerBody()?['data']?['essentials']?['alertContext']?['condition']?['allof']?[0]?['dimensions']?[0]?['value'])
How do I get the actual required output?
The http Output Body schema from which I added the expressions:
"body": {
"schemaId": "azureMonitorCommonAlertSchema",
"data": {
"essentials": {
"alertId": "",
"alertRule": "",
"severity": "Sev1",
"signalType": "Log",
"monitorCondition": "Fired",
"monitoringService": "Log Alerts V2",
"alertTargetIDs": [
"/subscriptions/"
],
"configurationItems": [
"/subscriptions/"
],
"originAlertId": "bb88b50d-3cec-452c-a5d4-xxxxx”,
"firedDateTime": "2023-XX-XXT",
"description": “xxxx”,
"essentialsVersion": "1.0",
"alertContextVersion": "1.0"
},
"alertContext": {
"properties": {},
"conditionType": "LogQueryCriteria",
"condition": {
"windowSize": "PT15M",
"allOf": [
{
"searchQuery": " exceptions \n| where assembly has \”__XXXX\”\n| where timestamp >= ago(1h)\n| summarize errorCount = count() by outerMessage\n| where errorCount >= 1\n| where outerMessage contains \”XXXX\”\n\n”,
"metricMeasureColumn": "errorCount",
"targetResourceTypes": "['microsoft.insights/components']",
"operator": "GreaterThanOrEqual",
"threshold": "1",
"timeAggregation": "Total",
"dimensions": [
{
"name": "outerMessage",
"value": "Error Found in XXXX”
}
],
"metricValue": 12,
"failingPeriods": {
"numberOfEvaluationPeriods": 1,
"minFailingPeriodsToAlert": 1
},
"linkToSearchResultsUI": "https://portal.azure.comXXX”,
"linkToFilteredSearchResultsUI": "https://portal.azure.comXXXX”,
"linkToSearchResultsAPI": "https://api.applicationinsights.io/v1/apps/XXX”,
"linkToFilteredSearchResultsAPI": "https://api.applicationinsights.io/v1/apps/XXXx”
}
],
"windowStartTime": "2023XXXX”,
"windowEndTime": "2023XXXX”
}
},
"customProperties": {}
}
}
You'll kick yourself when you see it but you specified essentials
when you didn't need to. It and alertContext
are on the same level.
So change your expression to this ...
createArray(triggerBody()?['data']?['alertContext']?['condition']?['allof']?[0]?['dimensions']?[0]?['value'])