Skip to main content
Skip table of contents

Azure Generation Rule Examples

Below is an example of how to configure Generation Rules and templates for Azure resources—in this case, Azure App Services. The final result automatically generates an SLX, SLI, and Runbook for each matched App Service.

Example Directory Layout

CODE
azure-appservice-triage
└── .runwhen
    ├── generation-rules
    │   └── azure-appservice-triage.yaml
    └── templates
        ├── azure-appservice-triage-slx.yaml
        ├── azure-appservice-triage-sli.yaml
        └── azure-appservice-triage-taskset.yaml

Generation Rule

CODE
apiVersion: runwhen.com/v1
kind: GenerationRules
spec:
  platform: azure
  generationRules:
    - resourceTypes:
        - azure_appservice_web_apps
      matchRules:
        - type: pattern
          pattern: ".+"
          properties: [ name ]
          mode: substring
      slxs:
        - baseName: az-appsvc-triage
          qualifiers: [ "resource", "resource_group" ]
          baseTemplateName: azure-appservice-triage
          levelOfDetail: basic
          outputItems:
            - type: slx
            - type: sli
            - type: runbook
              templateName: azure-appservice-triage-taskset.yaml

Explanation

  1. resourceTypes: Targets Azure App Service Web Apps (azure_appservice_web_apps).

  2. matchRules: Matches any App Service name containing at least one character.

  3. slxs: Generates an SLX, an SLI, and a Runbook for every matched resource. The templates are all prefixed by azure-appservice-triage.


SLX Template Example

CODE
apiVersion: runwhen.com/v1
kind: ServiceLevelX
metadata:
  name: {{slx_name}}
  labels:
    {% include "common-labels.yaml" %}
  annotations:
    {% include "common-annotations.yaml" %}
spec:
  imageURL: https://storage.googleapis.com/runwhen-nonprod-shared-images/icons/azure/app%20services/10035-icon-service-App-Services.svg
  alias: Azure App Service Health for {{match_resource.resource.name}} in resource group {{resource_group.name}}
  asMeasuredBy: An aggregate score that is evaluated from configuration, metric, event or log issues.
  configProvided:
  - name: AZ_RESOURCE_GROUP
    value: {{resource_group.name}}
  - name: APP_SERVICE_NAME
    value: {{match_resource.resource.name}}
  owners:
  - {{workspace.owner_email}}
  statement: >-
    App Service {{match_resource.resource.name}} in resource group {{resource_group.name}} be available and healthy.
  additionalContext:
    name: "{{match_resource.resource.name}}"

Explanation

  • alias: Provides a more descriptive name for your SLX.

  • configProvided: Passes relevant Azure info (Resource Group and App Service name) to be used by your code or robots.

  • statement: Summarizes the primary objective.


SLI Template Example

CODE
apiVersion: runwhen.com/v1
kind: ServiceLevelIndicator
metadata:
  name: {{slx_name}}
  labels:
    {% include "common-labels.yaml" %}
  annotations:
    {% include "common-annotations.yaml" %}
spec:
  displayUnitsLong: OK
  displayUnitsShort: ok
  locations:
    - {{default_location}}
  description: Measures the health of Azure App Service {{match_resource.resource.name}} in resource group {{resource_group.name}}
  codeBundle:
    {% if repo_url %}
    repoUrl: {{repo_url}}
    {% else %}
    repoUrl: https://github.com/runwhen-contrib/rw-cli-codecollection.git
    {% endif %}
    {% if ref %}
    ref: {{ref}}
    {% else %}
    ref: main
    {% endif %}
    pathToRobot: codebundles/azure-appservice-triage/sli.robot
  intervalStrategy: intermezzo
  intervalSeconds: 600
  configProvided:
    - name: AZ_RESOURCE_GROUP
      value: {{resource_group.name}}
    - name: APP_SERVICE_NAME
      value: {{match_resource.resource.name}}
    - name: TIME_PERIOD_MINUTES
      value: "10"
  secretsProvided:
  {% if wb_version %}
    {% include "azure-auth.yaml" ignore missing %}
  {% else %}
    - name: azure_credentials
      workspaceKey: AUTH DETAILS NOT FOUND
  {% endif %}
  alerts:
    warning:
      operator: <
      threshold: '1'
      for: '20m'
    ticket:
      operator: <
      threshold: '1'
      for: '30m'
    page:
      operator: '=='
      threshold: '0'
      for: ''

Explanation

  • intervalSeconds: Runs every 600 seconds (10 minutes).

  • configProvided: Passes the Resource Group name and App Service name into the SLI code.

  • secretsProvided: Provides Azure credentials.

  • alerts: Defines thresholds for warning, ticket, and page alerts.


Runbook Template Example

CODE
apiVersion: runwhen.com/v1
kind: Runbook
metadata:
  name: {{slx_name}}
  labels:
    {% include "common-labels.yaml" %}
  annotations:
    {% include "common-annotations.yaml" %}
spec:
  location: {{default_location}}
  description: Generates a report for Azure App Service {{match_resource.resource.name}} in resource group {{resource_group.name}}
  codeBundle:
    {% if repo_url %}
    repoUrl: {{repo_url}}
    {% else %}
    repoUrl: https://github.com/runwhen-contrib/rw-cli-codecollection.git
    {% endif %}
    {% if ref %}
    ref: {{ref}}
    {% else %}
    ref: main
    {% endif %}
    pathToRobot: codebundles/azure-appservice-triage/runbook.robot
  configProvided:
    - name: AZ_RESOURCE_GROUP
      value: {{resource_group.name}}
    - name: APP_SERVICE_NAME
      value: {{match_resource.resource.name}}
    - name: TIME_PERIOD_MINUTES
      value: "10"
  secretsProvided:
  {% if wb_version %}
    {% include "azure-auth.yaml" ignore missing %}
  {% else %}
    - name: azure_credentials
      workspaceKey: AUTH DETAILS NOT FOUND
  {% endif %}

Explanation

  • pathToRobot: Points to the location of your runbook code in the CodeBundle.

  • configProvided: The Azure resource group and App Service name again.

  • location: Usually inherited from your workspace default location.


Summary

With these configurations:

  1. A single Generation Rule matches Azure App Service Web Apps.

  2. It emits an SLX, SLI, and Runbook for each matched App Service.

  3. The templates reference relevant Azure metadata (e.g., Resource Group, App Service name) for triaging or health checks.

This approach can be extended to other Azure resource types by adjusting resourceTypes, matchRules, and the code bundles used in your templates.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.