Skip to content

Commit

Permalink
collect power events for windows flares (#1916)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackattack01 authored Oct 25, 2024
1 parent e79e130 commit e03767c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ee/debug/checkups/power_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ func (p *powerCheckup) Run(ctx context.Context, extraWriter io.Writer) error {
return fmt.Errorf("writing available sleep states output file: %w", err)
}

eventFilter := `Get-Winevent -FilterHashtable @{LogName='System'; ProviderName='Microsoft-Windows-Power-Troubleshooter','Microsoft-Windows-Kernel-Power'} -MaxEvents 500 | Select-Object @{name='Time'; expression={$_.TimeCreated.ToString("O")}},Id,LogName,ProviderName,Message,TimeCreated | ConvertTo-Json`
getWinEventCmd, err := allowedcmd.Powershell(ctx, eventFilter)
if err != nil {
return fmt.Errorf("creating powershell get-winevent command: %w", err)
}

powerEventFile, err := extraZip.Create("windows_power_events.json")
if err != nil {
return fmt.Errorf("creating windows_power_events.json: %w", err)
}

powerEventsOut, err := getWinEventCmd.CombinedOutput()
if err != nil {
return fmt.Errorf("running get-winevent command: %w, output %s", err, string(powerEventsOut))
}

if _, err := powerEventFile.Write(powerEventsOut); err != nil {
return fmt.Errorf("writing power events to output file: %w", err)
}

return nil
}

Expand Down

0 comments on commit e03767c

Please sign in to comment.