Skip to content

Commit

Permalink
Add checkups for installation troubleshooting + general Windows troub…
Browse files Browse the repository at this point in the history
…leshooting (#1288)
  • Loading branch information
RebeccaMahany authored Aug 10, 2023
1 parent 54d1849 commit 9b0172a
Show file tree
Hide file tree
Showing 6 changed files with 496 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/debug/checkups/checkups.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func checkupsFor(k types.Knapsack, target targetBits) []checkupInt {
{&enrollSecretCheckup{}, doctorSupported | flareSupported},
{&bboltdbCheckup{k: k}, flareSupported},
{&networkCheckup{}, doctorSupported | flareSupported},
{&installCheckup{}, flareSupported},
{&servicesCheckup{}, doctorSupported | flareSupported},
{&powerCheckup{}, flareSupported},
}

checkupsToRun := make([]checkupInt, 0)
Expand Down
68 changes: 68 additions & 0 deletions pkg/debug/checkups/install.go
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
}
35 changes: 35 additions & 0 deletions pkg/debug/checkups/power_other.go
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
}
62 changes: 62 additions & 0 deletions pkg/debug/checkups/power_windows.go
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
}
36 changes: 36 additions & 0 deletions pkg/debug/checkups/services_other.go
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
}
Loading

0 comments on commit 9b0172a

Please sign in to comment.