Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure ApplicationInsights资源的SamplingPercentage属性的策略允许值_Azure_Azure Policy - Fatal编程技术网

Azure ApplicationInsights资源的SamplingPercentage属性的策略允许值

Azure ApplicationInsights资源的SamplingPercentage属性的策略允许值,azure,azure-policy,Azure,Azure Policy,我正在尝试构建一个Azure策略,该策略将审核Azure租户中SamplingPercentage值大于参数化值的ApplicationInsights资源。目前,该参数被设置为类型“Float”(因为您可以指定33.3,12.5,8.3): 但是,当通过Azure门户设置SamplingPercentage时,您会看到一个有效选项列表。我想在最大值参数的允许值属性中包含这些值 第一个想法是使用strongType(我假设它将提示Azure门户根据该类型注入允许的值)。。。我一直找不到这样的价值

我正在尝试构建一个Azure策略,该策略将审核Azure租户中SamplingPercentage值大于参数化值的ApplicationInsights资源。目前,该参数被设置为类型“Float”(因为您可以指定
33.3
12.5
8.3
):

但是,当通过Azure门户设置SamplingPercentage时,您会看到一个有效选项列表。我想在
最大值
参数的
允许值
属性中包含这些值

第一个想法是使用strongType(我假设它将提示Azure门户根据该类型注入允许的值)。。。我一直找不到这样的价值。第二次尝试失败,因为似乎无法创建整数的
数组。第三次尝试失败,当时我将
最大值
参数的
类型
更改为
字符串
,并声明参数如下:

"parameters": {
   "Maximum": {
     "type": "Array",
     "metadata": {
       "displayName": "Maximum",
       "description": "Sets the maximum allowed sampling percentage."
     },
     "allowedValues": [ "100", "50", "33.3", "25", "12.5", "8.3", "4", "2", "1" ]
   }
 }
以及

{
   "value": "SamplingPercentage",
   "greater": "[float(parameters('Maximum'))]"
}
导致此错误的原因:

使用无效的参数调用了内部异常“模板语言函数”float。无法将该值转换为目标类型。'


我做错了什么?

以下策略规则将审核采样率大于参数化值的ApplicationInsights资源:

"policyRule": {
  "if": {
    "allOf": [
      {
        "field": "type",
        "equals": "Microsoft.Insights/components"
      },
      {
        "value": "[float(field('Microsoft.Insights/components/SamplingPercentage'))]",
        "greater": "[float(parameters('Maximum'))]"
      }
    ]
  },
  "then": {
    "effect": "audit"
  }
},
"parameters": {
  "Maximum": {
    "type": "String",
    "metadata": {
      "displayName": "Maximum",
      "description": "Sets the maximum allowed sampling percentage."
    },
    "allowedValues": [
      "100",
      "50",
      "33.3",
      "25",
      "12.5",
      "8.3",
      "4",
      "2",
      "1"
    ]
  }
}
以下是您的政策出了什么问题:

  • 参数最大值的类型应为字符串,而不是数组
    • allowedValues始终是一个数组。参数的类型是将被指定的类型
  • 无法直接访问属性(如SamplingType)。您必须使用(Microsoft.Insights/components/SamplingPercentage)
  • 在a中,
    “value”
    将计算文字值。使用
    “field”
    (或函数)评估请求负载中的属性
  • "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Insights/components"
          },
          {
            "value": "[float(field('Microsoft.Insights/components/SamplingPercentage'))]",
            "greater": "[float(parameters('Maximum'))]"
          }
        ]
      },
      "then": {
        "effect": "audit"
      }
    },
    "parameters": {
      "Maximum": {
        "type": "String",
        "metadata": {
          "displayName": "Maximum",
          "description": "Sets the maximum allowed sampling percentage."
        },
        "allowedValues": [
          "100",
          "50",
          "33.3",
          "25",
          "12.5",
          "8.3",
          "4",
          "2",
          "1"
        ]
      }
    }