Advertisement
Guest User

Untitled

a guest
Jul 10th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 11.62 KB | None | 0 0
  1. {
  2.   "$schema": "https://raw.githubusercontent.com/Azure/enterprise-azure-policy-as-code/main/Schemas/policy-definition-schema.json",
  3.   "name": "Deploy_WSF_MemoryPercentage_Alert",
  4.   "properties": {
  5.     "displayName": "AMBA - Deploy App Service Plan Memory Percentage Alert",
  6.     "description": "Policy to audit/deploy App Service Plan Memory Percentage  Alert",
  7.     "mode": "All",
  8.     "metadata": {
  9.       "version": "1.1.0",
  10.       "source": "https://github.com/Azure/azure-monitor-baseline-alerts/",
  11.       "Category": "Web Services",
  12.       "_deployed_by_amba": "True"
  13.     },
  14.     "parameters": {
  15.       "evaluationFrequency": {
  16.         "allowedValues": [
  17.           "PT1M",
  18.           "PT5M",
  19.           "PT15M",
  20.           "PT30M",
  21.           "PT1H"
  22.         ],
  23.         "defaultValue": "PT5M",
  24.         "metadata": {
  25.           "description": "Evaluation frequency for the alert",
  26.           "displayName": "Evaluation Frequency"
  27.         },
  28.         "type": "String"
  29.       },
  30.       "autoMitigate": {
  31.         "allowedValues": [
  32.           "true",
  33.           "false"
  34.         ],
  35.         "defaultValue": "true",
  36.         "metadata": {
  37.           "description": "Auto Mitigate for the alert",
  38.           "displayName": "Auto Mitigate"
  39.         },
  40.         "type": "String"
  41.       },
  42.       "windowSize": {
  43.         "allowedValues": [
  44.           "PT1M",
  45.           "PT5M",
  46.           "PT15M",
  47.           "PT30M",
  48.           "PT1H",
  49.           "PT6H",
  50.           "PT12H",
  51.           "P1D"
  52.         ],
  53.         "defaultValue": "PT5M",
  54.         "metadata": {
  55.           "description": "Window size for the alert",
  56.           "displayName": "Window Size"
  57.         },
  58.         "type": "String"
  59.       },
  60.       "enabled": {
  61.         "allowedValues": [
  62.           "true",
  63.           "false"
  64.         ],
  65.         "defaultValue": "true",
  66.         "metadata": {
  67.           "description": "Alert state for the alert",
  68.           "displayName": "Alert State"
  69.         },
  70.         "type": "String"
  71.       },
  72.       "severity": {
  73.         "allowedValues": [
  74.           "0",
  75.           "1",
  76.           "2",
  77.           "3",
  78.           "4"
  79.         ],
  80.         "defaultValue": "2",
  81.         "metadata": {
  82.           "description": "Severity of the Alert",
  83.           "displayName": "Severity"
  84.         },
  85.         "type": "String"
  86.       },
  87.       "threshold": {
  88.         "defaultValue": "85",
  89.         "metadata": {
  90.           "description": "Threshold for the alert",
  91.           "displayName": "Threshold"
  92.         },
  93.         "type": "String"
  94.       },
  95.       "monitorDisable": {
  96.         "defaultValue": "MonitorDisable",
  97.         "metadata": {
  98.           "description": "Tag name to disable monitoring resource. Set to true if monitoring should be disabled",
  99.           "displayName": "Effect"
  100.         },
  101.         "type": "String"
  102.       },
  103.       "effect": {
  104.         "allowedValues": [
  105.           "deployIfNotExists",
  106.           "disabled"
  107.         ],
  108.         "defaultValue": "deployIfNotExists",
  109.         "metadata": {
  110.           "description": "Effect of the policy",
  111.           "displayName": "Effect"
  112.         },
  113.         "type": "String"
  114.       }
  115.     },
  116.     "policyRule": {
  117.       "if": {
  118.         "allOf": [
  119.           {
  120.             "equals": "Microsoft.Web/serverfarms",
  121.             "field": "type"
  122.           },
  123.           {
  124.             "field": "[concat('tags[', parameters('MonitorDisable'), ']')]",
  125.             "notEquals": "true"
  126.           }
  127.         ]
  128.       },
  129.       "then": {
  130.         "effect": "[parameters('effect')]",
  131.         "details": {
  132.           "type": "Microsoft.Insights/metricAlerts",
  133.           "roleDefinitionIds": [
  134.             "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
  135.           ],
  136.           "existenceCondition": {
  137.             "allOf": [
  138.               {
  139.                 "equals": "Microsoft.Web/serverfarms",
  140.                 "field": "Microsoft.Insights/metricAlerts/criteria.Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria.allOf[*].metricNamespace"
  141.               },
  142.               {
  143.                 "equals": "MemoryPercentage",
  144.                 "field": "Microsoft.Insights/metricAlerts/criteria.Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria.allOf[*].metricName"
  145.               },
  146.               {
  147.                 "equals": "[concat(subscription().id, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/serverfarms/', field('fullName'))]",
  148.                 "field": "Microsoft.Insights/metricalerts/scopes[*]"
  149.               },
  150.               {
  151.                 "equals": "[parameters('enabled')]",
  152.                 "field": "Microsoft.Insights/metricAlerts/enabled"
  153.               },
  154.               {
  155.                 "equals": "[parameters('evaluationFrequency')]",
  156.                 "field": "Microsoft.Insights/metricAlerts/evaluationFrequency"
  157.               },
  158.               {
  159.                 "equals": "[parameters('windowSize')]",
  160.                 "field": "Microsoft.Insights/metricAlerts/windowSize"
  161.               },
  162.               {
  163.                 "equals": "[parameters('severity')]",
  164.                 "field": "Microsoft.Insights/metricalerts/severity"
  165.               },
  166.               {
  167.                 "equals": "[parameters('autoMitigate')]",
  168.                 "field": "Microsoft.Insights/metricAlerts/autoMitigate"
  169.               },
  170.               {
  171.                 "equals": "Average",
  172.                 "field": "Microsoft.Insights/metricAlerts/criteria.Microsoft-Azure-Monitor-SingleResourceMultipleMetricCriteria.allOf[*].timeAggregation"
  173.               },
  174.               {
  175.                 "equals": "GreaterThan",
  176.                 "field": "Microsoft.Insights/metricAlerts/criteria.Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria.allOf[*].StaticThresholdCriterion.operator"
  177.               },
  178. //              {
  179. //                "equals": "[parameters('threshold')]",
  180. //                "field": "Microsoft.Insights/metricAlerts/criteria.Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria.allOf[*].StaticThresholdCriterion.threshold"
  181. //              },
  182.               {
  183.                 "equals": "[if(contains(field('tags'), 'Custom_Alert_Memory_Threshold'), field('tags.Custom_Alert_Memory_Threshold'), parameters('threshold'))]",
  184.                 "field": "Microsoft.Insights/metricAlerts/criteria.Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria.allOf[*].StaticThresholdCriterion.threshold"
  185.               }
  186.             ]
  187.           },
  188.           "deployment": {
  189.             "properties": {
  190.               "parameters": {
  191.                 "resourceId": {
  192.                   "value": "[field('id')]"
  193.                 },
  194.                 "evaluationFrequency": {
  195.                   "value": "[parameters('evaluationFrequency')]"
  196.                 },
  197.                 "autoMitigate": {
  198.                   "value": "[parameters('autoMitigate')]"
  199.                 },
  200.                 "windowSize": {
  201.                   "value": "[parameters('windowSize')]"
  202.                 },
  203.                 "enabled": {
  204.                   "value": "[parameters('enabled')]"
  205.                 },
  206.                 "severity": {
  207.                   "value": "[parameters('severity')]"
  208.                 },
  209.                 "threshold": {
  210.                   "value": "[if(contains(field('tags'), 'Custom_Alert_Memory_Threshold'), field('tags.Custom_Alert_Memory_Threshold'), parameters('threshold'))]"
  211.                 },
  212.                 "resourceName": {
  213.                   "value": "[field('name')]"
  214.                 }
  215.               },
  216.               "template": {
  217.                 "parameters": {
  218.                   "resourceId": {
  219.                     "metadata": {
  220.                       "description": "Resource ID of the resource emitting the metric that will be used for the comparison",
  221.                       "displayName": "resourceId"
  222.                     },
  223.                     "type": "String"
  224.                   },
  225.                   "evaluationFrequency": {
  226.                     "type": "String"
  227.                   },
  228.                   "autoMitigate": {
  229.                     "type": "String"
  230.                   },
  231.                   "windowSize": {
  232.                     "type": "String"
  233.                   },
  234.                   "enabled": {
  235.                     "type": "String"
  236.                   },
  237.                   "severity": {
  238.                     "type": "String"
  239.                   },
  240.                   "threshold": {
  241.                     "type": "String"
  242.                   },
  243.                   "resourceName": {
  244.                     "metadata": {
  245.                       "description": "Name of the resource",
  246.                       "displayName": "resourceName"
  247.                     },
  248.                     "type": "String"
  249.                   }
  250.                 },
  251.                 "contentVersion": "1.0.0.0",
  252.                 "resources": [
  253.                   {
  254.                     "type": "Microsoft.Insights/metricAlerts",
  255.                     "properties": {
  256.                       "description": "Metric Alert for App Service Plan Memory Percentage",
  257.                       "evaluationFrequency": "[parameters('evaluationFrequency')]",
  258.                       "autoMitigate": "[parameters('autoMitigate')]",
  259.                       "parameters": {
  260.                         "evaluationFrequency": {
  261.                           "value": "[parameters('evaluationFrequency')]"
  262.                         },
  263.                         "autoMitigate": {
  264.                           "value": "[parameters('autoMitigate')]"
  265.                         },
  266.                         "windowSize": {
  267.                           "value": "[parameters('windowSize')]"
  268.                         },
  269.                         "enabled": {
  270.                           "value": "[parameters('enabled')]"
  271.                         },
  272.                         "severity": {
  273.                           "value": "[parameters('severity')]"
  274.                         },
  275.                         "threshold": {
  276.                           "value": "[parameters('threshold')]"
  277.                         }
  278.                       },
  279.                       "windowSize": "[parameters('windowSize')]",
  280.                       "enabled": "[parameters('enabled')]",
  281.                       "severity": "[parameters('severity')]",
  282.                       "criteria": {
  283.                         "allOf": [
  284.                           {
  285.                             "threshold": "[parameters('threshold')]",
  286.                             "timeAggregation": "Average",
  287.                             "name": "MemoryPercentage",
  288.                             "operator": "GreaterThan",
  289.                             "metricNamespace": "Microsoft.Web/serverfarms",
  290.                             "criterionType": "StaticThresholdCriterion",
  291.                             "metricName": "MemoryPercentage"
  292.                           }
  293.                         ],
  294.                         "odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
  295.                       },
  296.                       "scopes": [
  297.                         "[parameters('resourceId')]"
  298.                       ]
  299.                     },
  300.                     "apiVersion": "2018-03-01",
  301.                     "location": "global",
  302.                     "name": "[concat('AMBA-', parameters('resourceName'), '-MemoryPercentage')]",
  303.                     "tags": {
  304.                       "_deployed_by_amba": true
  305.                     }
  306.                   }
  307.                 ],
  308.                 "variables": {},
  309.                 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
  310.               },
  311.               "mode": "incremental"
  312.             }
  313.           }
  314.         }
  315.       }
  316.     }
  317.   }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement