-
Notifications
You must be signed in to change notification settings - Fork 99
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 database reset history to uninstall and add uninstall history checkup #1639
Changes from 2 commits
ed7c8c8
fc778ab
383141f
00bffdd
8a16675
3f545c4
ea98edb
921fff1
eb53ed4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package checkups | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"io" | ||
"time" | ||
|
||
"github.com/kolide/launcher/ee/agent" | ||
"github.com/kolide/launcher/ee/agent/types" | ||
) | ||
|
||
type ( | ||
uninstallHistoryCheckup struct { | ||
k types.Knapsack | ||
status Status | ||
summary string | ||
data map[string]any | ||
} | ||
) | ||
|
||
func (hc *uninstallHistoryCheckup) Data() any { return hc.data } | ||
func (hc *uninstallHistoryCheckup) ExtraFileName() string { return "" } | ||
func (hc *uninstallHistoryCheckup) Name() string { return "Uninstall History" } | ||
func (hc *uninstallHistoryCheckup) Status() Status { return hc.status } | ||
func (hc *uninstallHistoryCheckup) Summary() string { return hc.summary } | ||
|
||
func (hc *uninstallHistoryCheckup) Run(ctx context.Context, extraFH io.Writer) error { | ||
hc.data = make(map[string]any) | ||
if hc.k.PersistentHostDataStore() == nil { | ||
hc.status = Informational | ||
hc.summary = "Unable to access uninstall history" | ||
return nil | ||
} | ||
|
||
resetRecordsRaw, err := hc.k.PersistentHostDataStore().Get(agent.HostDataKeyResetRecords) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider moving this to something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will go ahead and do that, it should clean this all up a bit. thank you! |
||
if err != nil { | ||
hc.status = Erroring | ||
hc.summary = "Unable to gather previous host data from store" | ||
hc.data["error"] = err.Error() | ||
return nil | ||
} | ||
|
||
var resetRecords []agent.DBResetRecord | ||
if len(resetRecordsRaw) == 0 { | ||
hc.status = Informational | ||
hc.summary = "No installation history exists for this device" | ||
return nil | ||
} | ||
|
||
if err := json.Unmarshal(resetRecordsRaw, &resetRecords); err != nil { | ||
hc.status = Erroring | ||
hc.summary = "Unable to unmarshal previous host data from store" | ||
hc.data["error"] = err.Error() | ||
return nil | ||
} | ||
|
||
for _, uninstallRecord := range resetRecords { | ||
resetTimeKey := time.Unix(uninstallRecord.ResetTimestamp, 0) | ||
hc.data[resetTimeKey.Format(time.RFC3339)] = map[string]any{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, but feels like a bit of overkill. The time sorted array was probably fine |
||
"serial": uninstallRecord.Serial, | ||
"hardware_uuid": uninstallRecord.HardwareUUID, | ||
"munemo": uninstallRecord.Munemo, | ||
"device_id": uninstallRecord.DeviceID, | ||
"remote_ip": uninstallRecord.RemoteIP, | ||
"tombstone_id": uninstallRecord.TombstoneID, | ||
"reset_timestamp": resetTimeKey, | ||
"reset_reason": uninstallRecord.ResetReason, | ||
} | ||
} | ||
|
||
hc.status = Passing | ||
zackattack01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hc.summary = "Successfully collected uninstallation history" | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally sure why this is exported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I might be able to un-export this one too after moving to using
agent.GetResetRecords
, will give that a try