diff --git a/server/datastore/mysql/scripts.go b/server/datastore/mysql/scripts.go index e6cfa5b9924..ae3a8ed40ef 100644 --- a/server/datastore/mysql/scripts.go +++ b/server/datastore/mysql/scripts.go @@ -1526,17 +1526,23 @@ func (ds *Datastore) GetHostLockWipeStatus(ctx context.Context, host *fleet.Host // lock and unlock references are scripts if mdmActions.LockRef != nil { hsr, err := ds.getHostScriptExecutionResultDB(ctx, ds.reader(ctx), *mdmActions.LockRef, scriptExecutionSearchOpts{IncludeCanceled: true}) - if err != nil { + if err != nil && !fleet.IsNotFound(err) { return nil, ctxerr.Wrap(ctx, err, "get lock reference script result") } + if fleet.IsNotFound(err) { + level.Error(ds.logger).Log("msg", "orphan lock script execution reference", "host_id", host.ID, "execution_id", *mdmActions.LockRef) + } status.LockScript = hsr } if mdmActions.UnlockRef != nil { hsr, err := ds.getHostScriptExecutionResultDB(ctx, ds.reader(ctx), *mdmActions.UnlockRef, scriptExecutionSearchOpts{IncludeCanceled: true}) - if err != nil { + if err != nil && !fleet.IsNotFound(err) { return nil, ctxerr.Wrap(ctx, err, "get unlock reference script result") } + if fleet.IsNotFound(err) { + level.Error(ds.logger).Log("msg", "orphan unlock script execution reference", "host_id", host.ID, "execution_id", *mdmActions.UnlockRef) + } status.UnlockScript = hsr } @@ -1551,9 +1557,12 @@ func (ds *Datastore) GetHostLockWipeStatus(ctx context.Context, host *fleet.Host status.WipeMDMCommandResult = cmdRes } else { hsr, err := ds.getHostScriptExecutionResultDB(ctx, ds.reader(ctx), *mdmActions.WipeRef, scriptExecutionSearchOpts{IncludeCanceled: true}) - if err != nil { + if err != nil && !fleet.IsNotFound(err) { return nil, ctxerr.Wrap(ctx, err, "get wipe reference script result") } + if fleet.IsNotFound(err) { + level.Error(ds.logger).Log("msg", "orphan wipe script execution reference", "host_id", host.ID, "execution_id", *mdmActions.WipeRef) + } status.WipeScript = hsr } }