-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checkups for installation troubleshooting + general Windows troub…
…leshooting (#1288)
- Loading branch information
1 parent
54d1849
commit 9b0172a
Showing
6 changed files
with
496 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package checkups | ||
|
||
import ( | ||
"archive/zip" | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"runtime" | ||
) | ||
|
||
type installCheckup struct { | ||
} | ||
|
||
func (i *installCheckup) Name() string { | ||
return "Package Install Logs" | ||
} | ||
|
||
func (i *installCheckup) Run(ctx context.Context, extraWriter io.Writer) error { | ||
extraZip := zip.NewWriter(extraWriter) | ||
defer extraZip.Close() | ||
|
||
if err := gatherInstallationLogs(extraZip); err != nil { | ||
return fmt.Errorf("gathering installation logs: %w", err) | ||
} | ||
|
||
return nil | ||
|
||
} | ||
|
||
func (i *installCheckup) ExtraFileName() string { | ||
return "install.zip" | ||
} | ||
|
||
func (i *installCheckup) Status() Status { | ||
return Informational | ||
} | ||
|
||
func (i *installCheckup) Summary() string { | ||
return "N/A" | ||
} | ||
|
||
func (i *installCheckup) Data() any { | ||
return nil | ||
} | ||
|
||
func gatherInstallationLogs(z *zip.Writer) error { | ||
if runtime.GOOS == "windows" || runtime.GOOS == "linux" { | ||
return nil | ||
} | ||
|
||
out, err := z.Create("macos-var-log-install.log") | ||
if err != nil { | ||
return fmt.Errorf("creating macos-var-log-install.log in zip: %w", err) | ||
} | ||
|
||
installLog, err := os.Open("/var/log/install.log") | ||
if err != nil { | ||
return fmt.Errorf("opening /var/log/install.log: %w", err) | ||
} | ||
defer installLog.Close() | ||
|
||
if _, err := io.Copy(out, installLog); err != nil { | ||
return fmt.Errorf("writing /var/log/install.log contents to zip: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package checkups | ||
|
||
import ( | ||
"context" | ||
"io" | ||
) | ||
|
||
type powerCheckup struct{} | ||
|
||
func (p *powerCheckup) Name() string { | ||
return "" | ||
} | ||
|
||
func (p *powerCheckup) Run(ctx context.Context, extraWriter io.Writer) error { | ||
return nil | ||
} | ||
|
||
func (p *powerCheckup) ExtraFileName() string { | ||
return "" | ||
} | ||
|
||
func (p *powerCheckup) Status() Status { | ||
return Informational | ||
} | ||
|
||
func (p *powerCheckup) Summary() string { | ||
return "" | ||
} | ||
|
||
func (p *powerCheckup) Data() any { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package checkups | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
|
||
"github.com/kolide/launcher/pkg/agent" | ||
) | ||
|
||
type powerCheckup struct{} | ||
|
||
func (p *powerCheckup) Name() string { | ||
return "Power Report" | ||
} | ||
|
||
func (p *powerCheckup) Run(ctx context.Context, extraWriter io.Writer) error { | ||
// Create a temporary file for powercfg to write its output to | ||
tmpFilePath := agent.TempPath("launcher-checkup-spr.html") | ||
defer os.Remove(tmpFilePath) | ||
|
||
// See: https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options#option_systempowerreport | ||
powerCfgCmd := exec.CommandContext(ctx, "powercfg.exe", "/systempowerreport", "/output", tmpFilePath) | ||
powerCfgCmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // prevents spawning window | ||
if out, err := powerCfgCmd.CombinedOutput(); err != nil { | ||
return fmt.Errorf("running powercfg.exe: error %w, output %s", err, string(out)) | ||
} | ||
|
||
sprHandle, err := os.Open(tmpFilePath) | ||
if err != nil { | ||
return fmt.Errorf("opening system power report: %w", err) | ||
} | ||
defer sprHandle.Close() | ||
|
||
if _, err := io.Copy(extraWriter, sprHandle); err != nil { | ||
return fmt.Errorf("copying system power report: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (p *powerCheckup) ExtraFileName() string { | ||
return "power.html" | ||
} | ||
|
||
func (p *powerCheckup) Status() Status { | ||
return Informational | ||
} | ||
|
||
func (p *powerCheckup) Summary() string { | ||
return "" | ||
} | ||
|
||
func (p *powerCheckup) Data() any { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package checkups | ||
|
||
import ( | ||
"context" | ||
"io" | ||
) | ||
|
||
type servicesCheckup struct { | ||
} | ||
|
||
func (s *servicesCheckup) Name() string { | ||
return "" | ||
} | ||
|
||
func (s *servicesCheckup) Run(ctx context.Context, extraWriter io.Writer) error { | ||
return nil | ||
} | ||
|
||
func (s *servicesCheckup) ExtraFileName() string { | ||
return "" | ||
} | ||
|
||
func (s *servicesCheckup) Status() Status { | ||
return Informational | ||
} | ||
|
||
func (s *servicesCheckup) Summary() string { | ||
return "" | ||
} | ||
|
||
func (s *servicesCheckup) Data() any { | ||
return nil | ||
} |
Oops, something went wrong.