Bylaw

Gallery › Monitoring › Azure built-in policies

[Deprecated]: Virtual machines should have the Log Analytics extension installed

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.1.0-deprecated Deprecated

This policy definition is deprecated because of limited performance uplift possible and the usage of a legacy authentication model. While there is not a specific replacement policy, we have various policies available based on the VM setup that can be found under Azure Monitor Agent/DCRA Linux. Learn more about policy definition deprecation at aka.ms/policydefdeprecation

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONVirtualMachines_LogAnalyticsAgent_AINE.json · 70 lines
{
  "properties": {
    "displayName": "[Deprecated]: Virtual machines should have the Log Analytics extension installed",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy definition is deprecated because of limited performance uplift possible and the usage of a legacy authentication model. While there is not a specific replacement policy, we have various policies available based on the VM setup that can be found under Azure Monitor Agent/DCRA Linux. Learn more about policy definition deprecation at aka.ms/policydefdeprecation",
    "metadata": {
      "version": "1.1.0-deprecated",
      "category": "Monitoring",
      "deprecated": true
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Disabled",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy",
          "deprecated": true
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Compute/virtualMachines"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Compute/virtualMachines/extensions",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/publisher",
                "equals": "Microsoft.EnterpriseCloud.Monitoring"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/type",
                "in": [
                  "MicrosoftMonitoringAgent",
                  "OmsAgentForLinux"
                ]
              },
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/provisioningState",
                "equals": "Succeeded"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/settings.workspaceId",
                "exists": "true"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.1.0",
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/a70ca396-0a34-413a-88e1-b956c1e683be",
  "name": "a70ca396-0a34-413a-88e1-b956c1e683be"
}
Bylawa70ca396-0a34-413a-88e1-b956c1e683be.bylaw.ps1 · 33 lines
# Converted from VirtualMachines_LogAnalyticsAgent_AINE.json by ConvertTo-Bylaw.
Policy 'a70ca396-0a34-413a-88e1-b956c1e683be' {

    Properties @{
        DisplayName   = '[Deprecated]: Virtual machines should have the Log Analytics extension installed'
        Description   = 'This policy definition is deprecated because of limited performance uplift possible and the usage of a legacy authentication model. While there is not a specific replacement policy, we have various policies available based on the VM setup that can be found under Azure Monitor Agent/DCRA Linux. Learn more about policy definition deprecation at aka.ms/policydefdeprecation'
        Version       = '1.1.0-deprecated'
        Category      = 'Monitoring'
        Deprecated    = $true
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'Disabled'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
        Metadata      = [ordered]@{ deprecated = $true }
    }

    Resource 'Microsoft.Compute/virtualMachines'

    AuditIfNotExists 'Microsoft.Compute/virtualMachines/extensions' -Effect (Param Effect) {
        Require 'publisher, type, provisioningState and 1 more are as required' {
            Field publisher | Must -Be 'Microsoft.EnterpriseCloud.Monitoring'
            Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -BeIn @('MicrosoftMonitoringAgent', 'OmsAgentForLinux')
            Field provisioningState | Must -Be 'Succeeded'
            Field settings.workspaceId | Must -Exist
        }
    }
}

Source: built-in-policies/policyDefinitions/Monitoring/VirtualMachines_LogAnalyticsAgent_AINE.json in Azure/azure-policy, under the MIT licence.