Monitor Security Score using KQL/ Kusto using Log Analytics Workspace

Rahul 296 Reputation points
2023-04-17T15:46:58.77+00:00

Hello Team,

The security Score in my Azure Subscription fluctuates every time. I'm trying to configure an Azure Monitor Alert using Log Analytics Workspace. I enabled Continuous Export features from Microsoft Defender for the cloud under my subscription to export security score logs in Log Analytics Workspace.
SecurityScores and SecurityScoreControls both tables provide info for current Secure Score in Log Analytics Workspace

I'm trying to Jon both the Tables using the below KQL Query that shows me an error.   SecureScores
//| where CurrentScore < 60
| extend Percent=PercentageScore100
| summarize avg(Percent) by bin(TimeGenerated,1d), SubscriptionId=_SubscriptionId
| where avg_Percent < 80
| join kind=leftouter (
SecureScoreControls
| extend Percent=PercentageScore
100
| summarize avg(Percent) by bin(TimeGenerated,1d), SubscriptionId=_SubscriptionId
)
on $left.CurrentScore == $right.CurrentScore
//on $left.AssessedResourceId == $right.AssessedResourceId and $left.SecureScoresSubscriptionId== $right.SecureScoresSubscriptionId
Does anyone have any input on this?
Thanks In advance

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
Microsoft Security | Microsoft Defender | Microsoft Defender for Cloud
{count} votes

Answer accepted by question author
  1. Clive Watson 7,946 Reputation points MVP Volunteer Moderator
    2023-04-18T12:07:56.62+00:00

    This will fix the KQL error, use had a error in the extend() lines and also hadn't mapped Current Score in the summarize commands, so the join wasn't possible.

    SecureScores
    | extend Percent=PercentageScore
    | summarize avg(Percent) by bin(TimeGenerated,1d), SubscriptionId=_SubscriptionId, CurrentScore
    | where avg_Percent < 80
    | join kind=leftouter (
    SecureScoreControls
    | extend Percent=PercentageScore
    | summarize avg(Percent) by bin(TimeGenerated,1d), SubscriptionId=_SubscriptionId, CurrentScore
    )
    on $left.CurrentScore == $right.CurrentScore
    
    
    // Question, wouldn't you be better to join on something other than the Score % unless you are 100% sure they are // for the same resource?   Maybe try this instead?
    
    
    SecureScores
    | extend Percent=PercentageScore
    | summarize avg(Percent) by bin(TimeGenerated,1d), SubscriptionId=_SubscriptionId, AssessedResourceId
    | join 
    (
        SecureScoreControls
        | where AssessedResourceId has "ascScore"
        | parse AssessedResourceId with AssessedResourceId '/secureScoreControl' *
        | extend Percent=PercentageScore
        | summarize avg(Percent) by bin(TimeGenerated,1d), SubscriptionId=_SubscriptionId, CurrentScore, AssessedResourceId
    ) on AssessedResourceId
    
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.