-
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 osquery restart history to checkups (#1633)
- Loading branch information
1 parent
5117ee4
commit 0c783a3
Showing
2 changed files
with
63 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,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 | ||
} |