{"record":{"id":"154b9b927e1585d2","repo":"hashicorp/nomad","slug":"service-name-must-include-nomad","errorCode":null,"errorMessage":"service name must include 'nomad","messagePattern":"service name must include 'nomad","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/monitor/export_monitor.go","lineNumber":132,"sourceCode":"\t\tlogCh:        make(chan []byte, bufSize),\n\t\tbufSize:      bufSize,\n\t\tExportReader: exportReader,\n\t}\n\n\treturn &sw, nil\n}\n\n// ScanServiceName checks that the length, prefix and suffix conform to\n// systemd conventions and ensures the service name includes the word 'nomad'\nfunc ScanServiceName(input string) error {\n\tprefix := \"\"\n\t// invalid if prefix and suffix together are > 255 char\n\tif len(input) > 255 {\n\t\treturn errors.New(\"service name too long\")\n\t}\n\n\tif isNomad := strings.Contains(input, \"nomad\"); !isNomad {\n\t\treturn errors.New(`service name must include 'nomad`)\n\t}\n\n\t// if there is a suffix, check against list of valid suffixes\n\t// and set prefix to exclude suffix index, else set prefix\n\tsplitInput := strings.Split(input, \".\")\n\tif len(splitInput) < 2 {\n\t\tprefix = input\n\t} else {\n\t\tsuffix := splitInput[len(splitInput)-1]\n\t\tvalidSuffix := []string{\n\t\t\t\"service\",\n\t\t\t\"socket\",\n\t\t\t\"device\",\n\t\t\t\"mount\",\n\t\t\t\"automount\",\n\t\t\t\"swap\",\n\t\t\t\"target\",\n\t\t\t\"path\",","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/monitor/export_monitor.go#L114-L150","documentation":"ScanServiceName requires every validated service name to contain the substring 'nomad', ensuring exported journald units are identifiable as Nomad-managed. If strings.Contains(input, \"nomad\") is false, it returns this error (note the missing closing quote in the message is a literal quirk). This prevents users from monitoring arbitrary non-Nomad systemd units through this endpoint.","triggerScenarios":"Passing a systemd service name without the word 'nomad' anywhere in it to AgentMonitorExport or the CLI reader — e.g. `\"docker.service\"`, `\"consul.service\"`, or `\"myapp.service\"`.","commonSituations":"Users trying to export logs of non-Nomad services; typos like `nomd-client.service`; custom unit naming that drops the nomad prefix; misunderstanding that the API is Nomad-log-only.","solutions":["Rename or select the correct unit name so it includes 'nomad', e.g. `nomad-client.service` or `nomad-job-xyz.service`.","Check the actual unit exists with `systemctl list-units 'nomad*'` and pass that exact name.","If you intend to monitor non-Nomad services, use journalctl/systemd tooling instead of Nomad's export monitor.","Fix typos in configured service names in the monitoring request or agent config."],"exampleFix":"// before\nScanServiceName(\"client.service\")\n// after\nScanServiceName(\"nomad-client.service\")","handlingStrategy":"validation","validationCode":"if !strings.Contains(serviceName, \"nomad\") {\n    return errors.New(\"service name must include 'nomad'; use e.g. nomad-client.service\")\n}","typeGuard":null,"tryCatchPattern":"if err := monitor.ScanServiceName(name); err != nil {\n    if strings.Contains(err.Error(), \"must include 'nomad\") {\n        return fmt.Errorf(\"%q is not a Nomad-managed unit; check `systemctl list-units 'nomad*'`\", name)\n    }\n    return err\n}","preventionTips":["Only monitor units Nomad creates (they always contain 'nomad').","Double-check spelling of unit names from config.","Use `systemctl list-units 'nomad*'` to copy exact names."],"tags":["systemd","validation","naming","journald"],"backgroundTag":"invalid-service-name","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}