Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add osquery restart history to checkups #1633

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading