{"record":{"id":"bddbb53507682c6c","repo":"crowdsecurity/crowdsec","slug":"no-machineid-or-bouncername-set","errorCode":null,"errorMessage":"no machineID or bouncerName set","messagePattern":"no machineID or bouncerName set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/controllers/v1/usagemetrics.go","lineNumber":27,"sourceCode":"\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/go-openapi/strfmt\"\n\tlog \"github.com/sirupsen/logrus\"\n\n\t\"github.com/crowdsecurity/crowdsec/pkg/database/ent\"\n\t\"github.com/crowdsecurity/crowdsec/pkg/database/ent/metric\"\n\t\"github.com/crowdsecurity/crowdsec/pkg/models\"\n)\n\n// updateBaseMetrics updates the base metrics for a machine or bouncer\nfunc (c *Controller) updateBaseMetrics(ctx context.Context, machineID string, bouncer *ent.Bouncer, baseMetrics models.BaseMetrics, hubItems models.HubItems, datasources map[string]int64) error {\n\tswitch {\n\tcase machineID != \"\":\n\t\treturn c.DBClient.MachineUpdateBaseMetrics(ctx, machineID, baseMetrics, hubItems, datasources)\n\tcase bouncer != nil:\n\t\treturn c.DBClient.BouncerUpdateBaseMetrics(ctx, bouncer.Name, bouncer.Type, baseMetrics)\n\tdefault:\n\t\treturn errors.New(\"no machineID or bouncerName set\")\n\t}\n}\n\n// UsageMetrics receives metrics from log processors and remediation components\nfunc (c *Controller) UsageMetrics(gctx *gin.Context) {\n\tvar input models.AllMetrics\n\n\tlogger := log.WithField(\"func\", \"UsageMetrics\")\n\n\t// parse the payload\n\n\tif err := gctx.ShouldBindJSON(&input); err != nil {\n\t\tlogger.Errorf(\"Failed to bind json: %s\", err)\n\t\tgctx.JSON(http.StatusBadRequest, gin.H{\"message\": err.Error()})\n\n\t\treturn\n\t}\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/controllers/v1/usagemetrics.go#L9-L45","documentation":"UsageMetrics ingestion must attribute metrics either to a log processor machine or a remediation component (bouncer). updateBaseMetrics dispatches on machineID or the bouncer object; if neither is present in the request/auth context, metrics cannot be attributed and it returns this error.","triggerScenarios":"POST to the usage-metrics endpoint where the payload/metadata contains no machine identifier and no bouncer identity — e.g. an unauthenticated or malformed metrics submission, or a client (old crowdsec/bouncer version) that doesn't send its identity fields.","commonSituations":"Custom scripts hitting the metrics endpoint without identifying headers; outdated bouncers predating usage-metrics identity fields; metrics posted via LAPI tokens that don't resolve to a machine or bouncer record in the DB.","solutions":["Upgrade the sending component (crowdsec agent or bouncer) so it includes its machine/bouncer identity in metrics payloads.","Verify the client authenticates with a machine or bouncer token known to the LAPI (re-register if the DB entry is gone).","Check the metrics request payload includes the identifier fields expected by the endpoint."],"exampleFix":"// before (custom metrics client)\nreq, _ := http.NewRequest(\"POST\", url+\"/usage-metrics\", body) // no auth/identity\n// after\nreq, _ := http.NewRequest(\"POST\", url+\"/usage-metrics\", body)\nreq.Header.Set(\"Authorization\", \"Bearer <machine-or-bouncer-token>\")","handlingStrategy":"validation","validationCode":"if metrics.MachineID == \"\" && metrics.BouncerName == \"\" {\n    return errors.New(\"metrics payload must identify a machine or bouncer\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.Post(ctx, \"/usage-metrics\", payload)\nif err != nil {\n    log.Warnf(\"usage metrics rejected: %v\", err) // non-fatal for the component\n}","preventionTips":["Keep agents and bouncers up to date so identity fields are sent.","Authenticate metrics submissions with valid machine/bouncer tokens.","Skip metrics reporting gracefully — it must never block the main workflow."],"tags":["metrics","lapi","usage-metrics"],"backgroundTag":"missing-required-argument","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}