Forum Discussion

alejandro_contreras's avatar
alejandro_contreras
Copper Contributor
May 13, 2019
Solved

Work Space Register - Query Shutdown-Start-VMs-By-Resource-Group Errors

I need query to show error´s in the Shutdown-Start-VMs-By-Resource-Group   For create an alert in the Work Space, because de runbook is complete but generate error´s and the VM not power on.  
  • CliveWatson's avatar
    May 13, 2019

    alejandro_contreras 

     

    you can check your runbook status with

    AzureDiagnostics
    | where ResourceProvider == "MICROSOFT.AUTOMATION" and Category == "JobLogs" 
    | summarize count() by ResultType 

    You then probably want to alter this to just look at "Failed" and maybe the specific runbook name?

    AzureDiagnostics
    | where ResourceProvider == "MICROSOFT.AUTOMATION" and Category == "JobLogs" 
        and (ResultType == "Failed" or ResultType == "Stopped" or ResultType == "Suspended" or ResultType == "Pending" or ResultType == "Started")
    | project TimeGenerated , RunbookName_s , ResultType , Resource

    So for use in an Azure Monitor Alert it would be something like this:

    AzureDiagnostics
    | where ResourceProvider == "MICROSOFT.AUTOMATION" and Category == "JobLogs" 
        and (ResultType == "Failed")
        // and RunbookName_s == "Shutdown-Start-VMs-By-Resource-Group"
    | summarize count() by ResultType 

    You can force a value to be 0 or 1 by changing the last line to 

     

    AzureDiagnostics
    | where ResourceProvider == "MICROSOFT.AUTOMATION" and Category == "JobLogs" 
        and (ResultType == "Failed")
        // and RunbookName_s == "Shutdown-Start-VMs-By-Resource-Group"
    | summarize count() by ResultType 
    | where count_ > 1             // put in your own threshold here
    | extend AggregatedValue = 1   // set this to One/1 if the threshold is breached

     

Resources