crowdsecurity/crowdsec · error

machine not found

Error message

machine not found

What it means

ValidateMachine marks an alert-parsing/decision machine as validated in the local DB. It first runs an ent update filtered by machine_id; if the update succeeds but affects 0 rows, no machine with that ID exists, so it returns 'machine not found'. Note the earlier branch wraps DB errors in UpdateFail, this one is purely a zero-rows condition.

Source

Thrown at pkg/database/machines.go:146

}

func (c *Client) ListMachines(ctx context.Context) ([]*ent.Machine, error) {
	machines, err := c.Ent.Machine.Query().All(ctx)
	if err != nil {
		return nil, fmt.Errorf("listing machines: %w: %w", err, QueryFail)
	}

	return machines, nil
}

func (c *Client) ValidateMachine(ctx context.Context, machineID string) error {
	rets, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetIsValidated(true).Save(ctx)
	if err != nil {
		return fmt.Errorf("validating machine: %w: %w", err, UpdateFail)
	}

	if rets == 0 {
		return errors.New("machine not found")
	}

	return nil
}

func (c *Client) QueryPendingMachine(ctx context.Context) ([]*ent.Machine, error) {
	machines, err := c.Ent.Machine.Query().Where(machine.IsValidatedEQ(false)).All(ctx)
	if err != nil {
		c.Log.Warningf("QueryPendingMachine : %s", err)
		return nil, fmt.Errorf("querying pending machines: %w: %w", err, QueryFail)
	}

	return machines, nil
}

func (c *Client) DeleteWatcher(ctx context.Context, name string) error {
	nbDeleted, err := c.Ent.Machine.
		Delete().

View on GitHub (pinned to 909b515798)

Solutions

  1. Query the machine list (cscli machines list or LAPI) and use an exact existing machine_id
  2. Check for typos/case in the machine identifier
  3. Re-register the machine with cscli if it was deleted
Defensive patterns

Strategy: validation

Validate before calling

machines, err := client.QueryMachine(ctx, machineID)
if err != nil || len(machines) == 0 {
    return fmt.Errorf("machine %q does not exist", machineID)
}
_ = client.ValidateMachine(ctx, machineID)

Prevention

When it happens

Trigger: Calling ValidateMachine(ctx, machineID) with a machine_id that has no row in the machines table, e.g. via LAPI /machines/validate with a wrong or stale machine name.

Common situations: Bouncer/enrollment API called with a machine identifier that was deleted, typo in machine name, validating on the wrong LAPI instance, machine purged by db_flush.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/2a8c42969305e2ff. Report an issue: GitHub.