Skip to content

Commit

Permalink
Adding Deploy to Azure Button for Alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBarnes committed Jun 4, 2024
1 parent 200bf33 commit 707abd5
Show file tree
Hide file tree
Showing 20 changed files with 2,170 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.hugo_build.lock
public
services/amba-alerts*
artifacts/*/**
3 changes: 3 additions & 0 deletions artifacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# WARNING

The files in this directory are generated thru automation. Any direct changes will be overwritten.
4 changes: 4 additions & 0 deletions config/_default/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ enableRobotsTXT = true
source = 'services'
target = 'static'
includeFiles = ['amba-alerts.*']
[[module.mounts]]
source = 'artifacts'
target = 'content/artifacts'
includeFiles = ['**/*.json', '**/*.bicep']

[markup]
[markup.goldmark.renderer]
Expand Down
52 changes: 16 additions & 36 deletions docs/layouts/partials/templates/template-tabs.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{ $category := .category }}
{{ $type := .type }}
{{ $filename := printf "%s.json" .alert.guid | printf "%s"}}
{{ $file := path.Join "artifacts/templates" $category $type $filename }}
<div class="gdoc-tabs">
<input
type="radio"
Expand All @@ -6,9 +10,13 @@
id="{{ anchorize .alert.name }}-0"
checked="checked"
/>
<label for="{{ anchorize .alert.name }}-0" class="gdoc-tabs__label"></label>
<label for="{{ anchorize .alert.name }}-0" class="gdoc-tabs__label">Deploy</label>
<div class="gdoc-markdown--nested gdoc-tabs__content">
<p><b>Click a tab to view the template</b></p>
<p>
<a href="https://portal.azure.com/#create/Microsoft.Template/uri/{{ absURL $file }}" target="_blank">
<img src="https://aka.ms/deploytoazurebutton"/>
</a>
</p>
</div>
<input
type="radio"
Expand All @@ -20,23 +28,8 @@
ARM
</label>
<div class="gdoc-markdown--nested gdoc-tabs__content">
{{ if eq .alert.type "Metric" }}
{{ if eq .alert.properties.criterionType "StaticThresholdCriterion" }}
{{ highlight (partial "templates/arm/metric-static.html" .alert) "json" }}
{{ else }}
{{ highlight (partial "templates/arm/metric-dynamic.html" .alert) "json" }}
{{ end }}
{{ else if eq .alert.type "Log" }}
{{ highlight (partial "templates/arm/log.html" .alert) "json" }}
{{ else if eq .alert.type "ActivityLog" }}
{{ if eq .alert.properties.category "Administrative" }}
{{ highlight (partial "templates/arm/activity-administrative.html" .alert) "json" }}
{{ else if eq .alert.properties.category "ServiceHealth" }}
{{ highlight (partial "templates/arm/activity-servicehealth.html" .alert) "json" }}
{{ else if eq .alert.properties.category "ResourceHealth" }}
{{ highlight (partial "templates/arm/activity-resourcehealth.html" .alert) "json" }}
{{ end}}
{{ end }}
{{ $data := readFile $file }}
{{ highlight $data "json" }}
</div>
<input
type="radio"
Expand All @@ -48,23 +41,10 @@
Bicep
</label>
<div class="gdoc-markdown--nested gdoc-tabs__content">
{{ if eq .alert.type "Metric" }}
{{ if eq .alert.properties.criterionType "StaticThresholdCriterion" }}
{{ highlight (partial "templates/bicep/metric-static.html" .alert) "bicep" }}
{{ else }}
{{ highlight (partial "templates/bicep/metric-dynamic.html" .alert) "bicep" }}
{{ end }}
{{ else if eq .alert.type "Log" }}
{{ highlight (partial "templates/bicep/log.html" .alert) "bicep" }}
{{ else if eq .alert.type "ActivityLog" }}
{{ if eq .alert.properties.category "Administrative" }}
{{ highlight (partial "templates/bicep/activity-administrative.html" .alert) "bicep" }}
{{ else if eq .alert.properties.category "ServiceHealth" }}
{{ highlight (partial "templates/bicep/activity-servicehealth.html" .alert) "bicep" }}
{{ else if eq .alert.properties.category "ResourceHealth" }}
{{ highlight (partial "templates/bicep/activity-resourcehealth.html" .alert) "bicep" }}
{{ end}}
{{ end }}
{{ $filename := printf "%s.bicep" .alert.guid | printf "%s"}}
{{ $file := path.Join "artifacts/templates" $category $type $filename }}
{{ $data := readFile $file }}
{{ highlight $data "bicep" }}
</div>
{{ $name := .alert.name }}
{{ $category := .category }}
Expand Down
1 change: 1 addition & 0 deletions services/Network/loadBalancers/alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
windowSize: PT5M
evaluationFrequency: PT1M
timeAggregation: Total
criterionType: StaticThresholdCriterion
autoMitigate: false
guid: d766dc3e-42cc-42a7-ba4f-3c1d7fa295c5
- name: AllocatedSnartPorts
Expand Down
20 changes: 20 additions & 0 deletions tooling/generate-templates/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Local python packages
.python_packages/

# Python Environments
.env
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Visual Studio Code
.vscode

95 changes: 95 additions & 0 deletions tooling/generate-templates/arm/activity-administrative.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"type": "string",
"metadata": {
"description": "Unique name (within the Resource Group) for the Activity log alert."
}
},
"alertDescription": {
"type": "string",
"defaultValue": "##DESCRIPTION##",
"metadata": {
"description": "Description of alert"
}
},
"isEnabled": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Indicates whether or not the alert is enabled."
}
},
"currentDateTimeUtcNow": {
"type": "string",
"defaultValue": "[utcNow()]",
"metadata": {
"description": "The current date and time using the utcNow function. Used for deployment name uniqueness"
}
},
"telemetryOptOut": {
"type": "string",
"defaultValue": "No",
"allowedValues": [
"Yes",
"No"
],
"metadata": {
"description": "The customer usage identifier used for telemetry purposes. The default value of False enables telemetry. The value of True disables telemetry."
}
}
},
"variables": {
"pidDeploymentName": "[take(concat('##TELEMETRY_PID##-', uniqueString(resourceGroup().id, parameters('alertName'), parameters('currentDateTimeUtcNow'))), 64)]"
},
"resources": [
{
"type": "Microsoft.Insights/activityLogAlerts",
"apiVersion": "2017-04-01",
"name": "[parameters('alertName')]",
"location": "Global",
"tags": {
"_deployed_by_amba": true
},
"properties": {
"description": "[parameters('alertDescription')]",
"scopes": [
"[subscription().id]"
],
"enabled": "[parameters('isEnabled')]",
"condition": {
"allOf": [
{
"field": "category",
"equals": "Administrative"
},
{
"field": "operationName",
"equals": "##OPERATION_NAME##"
},
{
"field": "status",
"containsAny": ##STATUS##
}
]
}
}
},
{
"condition": "[equals(parameters('telemetryOptOut'), 'No')]",
"apiVersion": "2020-06-01",
"name": "[variables('pidDeploymentName')]",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": []
}
}
}
]
}
95 changes: 95 additions & 0 deletions tooling/generate-templates/arm/activity-resourcehealth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"type": "string",
"metadata": {
"description": "Unique name (within the Resource Group) for the Activity log alert."
}
},
"alertDescription": {
"type": "string",
"defaultValue": "##DESCRIPTION##",
"metadata": {
"description": "Description of alert"
}
},
"isEnabled": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Indicates whether or not the alert is enabled."
}
},
"currentDateTimeUtcNow": {
"type": "string",
"defaultValue": "[utcNow()]",
"metadata": {
"description": "The current date and time using the utcNow function. Used for deployment name uniqueness"
}
},
"telemetryOptOut": {
"type": "string",
"defaultValue": "No",
"allowedValues": [
"Yes",
"No"
],
"metadata": {
"description": "The customer usage identifier used for telemetry purposes. The default value of False enables telemetry. The value of True disables telemetry."
}
}
},
"variables": {
"pidDeploymentName": "[take(concat('##TELEMETRY_PID##-', uniqueString(resourceGroup().id, parameters('alertName'), parameters('currentDateTimeUtcNow'))), 64)]"
},
"resources": [
{
"type": "Microsoft.Insights/activityLogAlerts",
"apiVersion": "2017-04-01",
"name": "[parameters('alertName')]",
"location": "Global",
"tags": {
"_deployed_by_amba": true
},
"properties": {
"description": "[parameters('alertDescription')]",
"scopes": [
"[subscription().id]"
],
"enabled": "[parameters('isEnabled')]",
"condition": {
"allOf": [
{
"field": "category",
"equals": "ResourceHealth"
},
{
"anyOf": [##CAUSES##
]
},
{
"anyOf": [##CURRENT_HEALTH_STATUS##
]
}
]
}
}
},
{
"condition": "[equals(parameters('telemetryOptOut'), 'No')]",
"apiVersion": "2020-06-01",
"name": "[variables('pidDeploymentName')]",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": []
}
}
}
]
}
Loading

0 comments on commit 707abd5

Please sign in to comment.