turbot/steampipe-mod-azure-compliance

Control: Audit Windows machines on which the Log Analytics agent is not connected as expected

Description

Requires that prerequisites are deployed to the policy assignment scope. Machines are non-compliant if the agent is not installed, or if it is installed but the COM object AgentConfigManager.MgmtSvcCfg returns that it is registered to a workspace other than the ID specified in the policy parameter.

Usage

Run the control in your terminal:

powerpipe control run azure_compliance.control.compute_vm_log_analytics_agent_installed_windows

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run azure_compliance.control.compute_vm_log_analytics_agent_installed_windows --share

SQL

This control uses a named query:

with agent_installed_vm as (
select
distinct a.vm_id
from
azure_compute_virtual_machine as a,
jsonb_array_elements(extensions) as b
where
b ->> 'Publisher' = 'Microsoft.EnterpriseCloud.Monitoring'
and b ->> 'ExtensionType' = any(ARRAY ['MicrosoftMonitoringAgent', 'OmsAgentForLinux'])
and b ->> 'ProvisioningState' = 'Succeeded'
and b -> 'Settings' ->> 'workspaceId' is not null
)
select
a.vm_id as resource,
case
when a.os_type <> 'Windows' then 'skip'
when b.vm_id is not null then 'ok'
else 'alarm'
end as status,
case
when a.os_type <> 'Windows' then a.title || ' is of ' || a.os_type || ' operating syetem.'
when b.vm_id is not null then a.title || ' have log analytics agent installed.'
else a.title || ' log analytics agent not installed.'
end as reason
, a.resource_group as resource_group
, sub.display_name as subscription
from
azure_compute_virtual_machine as a
left join agent_installed_vm as b on a.vm_id = b.vm_id,
azure_subscription as sub
where
sub.subscription_id = a.subscription_id;

Tags