Skip to content

Commit

Permalink
add osquery restart history to checkups (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackattack01 committed Mar 1, 2024
1 parent 5117ee4 commit 0c783a3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions ee/debug/checkups/checkups.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func checkupsFor(k types.Knapsack, target targetBits) []checkupInt {
{&osqConfigConflictCheckup{}, doctorSupported | flareSupported},
{&serverDataCheckup{k: k}, doctorSupported | flareSupported | logSupported},
{&osqDataCollector{k: k}, doctorSupported | flareSupported},
{&osqRestartCheckup{k: k}, doctorSupported | flareSupported},
}

checkupsToRun := make([]checkupInt, 0)
Expand Down
62 changes: 62 additions & 0 deletions ee/debug/checkups/osquery_restarts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package checkups

import (
"context"
"errors"
"io"

"github.com/kolide/launcher/ee/agent/types"
"github.com/kolide/launcher/pkg/osquery/runtime/history"
)

type (
osqRestartCheckup struct {
k types.Knapsack
status Status
summary string
data map[string]any
}
)

func (orc *osqRestartCheckup) Data() any { return orc.data }
func (orc *osqRestartCheckup) ExtraFileName() string { return "" }
func (orc *osqRestartCheckup) Name() string { return "Osquery Restarts" }
func (orc *osqRestartCheckup) Status() Status { return orc.status }
func (orc *osqRestartCheckup) Summary() string { return orc.summary }

func (orc *osqRestartCheckup) Run(ctx context.Context, extraFH io.Writer) error {
orc.data = make(map[string]any)

restartHistory, err := history.GetHistory()
if err != nil && errors.Is(err, history.NoInstancesError{}) {
orc.status = Informational
orc.summary = "No osquery restart history instances available"
return nil
}

if err != nil {
orc.status = Erroring
orc.summary = "Unable to collect osquery restart history"
orc.data["error"] = err.Error()
return nil
}

results := make([]map[string]string, len(restartHistory))

for idx, instance := range restartHistory {
results[idx] = map[string]string{
"start_time": instance.StartTime,
"connect_time": instance.ConnectTime,
"exit_time": instance.ExitTime,
"instance_id": instance.InstanceId,
"version": instance.Version,
"errors": instance.Error,
}
}

orc.status = Passing
orc.data["history"] = results
orc.summary = "Successfully collected osquery restart history"

return nil
}

0 comments on commit 0c783a3

Please sign in to comment.