Forum Discussion

Racheal2k's avatar
Racheal2k
Copper Contributor
Jun 28, 2021
Solved

Loop through the KQL query result

Hi ,   I need to trigger an alert if windows service is stopped in one of the node. There are 2 nodes and service will be running in both nodes or at one node . Only If service is not running in ...
  • CliveWatson's avatar
    CliveWatson
    Jun 29, 2021

    Racheal2k I think you tried this before? 

    let status =
    Event
    | where TimeGenerated > ago (1d)
    | where EventLog == 'System' and EventID == 7036 and Source == 'Service Control Manager'  and RenderedDescription has 'WMI Performance Adapter' //"Apache tomcat"
    | parse kind=relaxed EventData with * '<Data Name="param1">' Windows_Service_Name '</Data><Data Name="param2">' Windows_Service_State '</Data>' *
    | summarize count(), (TimeGenerated, winstatus) = arg_max(TimeGenerated, Windows_Service_State) by Windows_Service_Name, Computer;
    status
    | extend winstatus = iif(winstatus == 'running',1,0)
    | summarize sumif(winstatus, winstatus > 0), ComputersOK = make_set_if(Computer, winstatus > 0), ComputerNotOk = make_set_if(Computer, winstatus == 0)
    | extend ServiceStatus = iif(sumif_winstatus > 0, "The service is running"," The Service is not runnimg")

     

     

Resources