Azure警报未触发Azure WebJobs的WebHook

时间:2017-12-08 08:34:23

标签: azure templates alert webhooks insight

我试图找到我的Azure Alert模板部署中的错误。我想发送电子邮件并使用基本身份验证在Azure WebJobs中触发WebHook。

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {

  },
  "variables": {
  },
  "resources": [
    {
      "type": "Microsoft.Insights/alertRules",
      "name": "tesTalert",
      "location": "westeurope",
      "apiVersion": "2014-04-01",
      "properties": {
        "name": "test",
        "isEnabled": true,
      "condition": {
          "odata.type": "Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition",
          "dataSource": {
              "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource",
              "operationName": "RunFinished",
              "status": "Failed",
              "subStatus": "FailedExecution"
          }
        },
        "action": {
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleWebhookAction",
        "serviceUri": "https://$myUserName:MyPassWord@MyWebsite.scm.azurewebsites.net/api/triggeredwebjobs/WebJobName/run",
        "properties": {}
        }
      }
    }
  ]
}

我也尝试使用这个模板与电子邮件,它的工作,但不是为webhook。也许问题来自api版本,所以我尝试不同的版本。什么都没发生。

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": { },
    "resources": [
        {
            "type": "microsoft.insights/alertrules",
            "name": "ADFAlertsSlice",
            "apiVersion": "2015-01-01",
            "location": "westeurope",
            "properties": {
                "name": "ADFAlertsSlice",
                "description": "One or more of the data slices for the Azure Data Factory has failed processing.",
                "isEnabled": true,
                "condition": {
                    "odata.type": "Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition",
                    "dataSource": {
                        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource",
                        "operationName": "RunFinished",
                        "status": "Failed",
                        "subStatus": "FailedExecution"
                    }

                },
                "actions": [        
                       {
                        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleWebhookAction",
                         "serviceUri": "https://$myUserName:MyPassWord@MyWebsite.scm.azurewebsites.net/api/triggeredwebjobs/WebJobName/run",
                        "properties": {}
                    },
                    {
                        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
                        "customEmails": [
                         "MyEmail@email.com"
                        ]
                    }
                ]
            }
        }
    ]
}

我无法找到问题所在。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

根据Microsoft文档,来自指标警报规则的webhooks只能使用令牌身份验证。

验证webhook webhook可以使用基于令牌的授权进行身份验证。 webhook URI与令牌ID一起保存,例如。

https://mysamplealert/webcallback?tokenid=sometokenid&someparameter=somevalue

https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts 如果您向下滚动评论其他问题与他们相同,他们甚至开始向MS提出功能请求。 https://feedback.azure.com/forums/602299-azure-alert-management/suggestions/19711606-enable-user-password-authentication-to-webhooks