{"record":{"id":"8ae2123697d8b75d","repo":"louislam/uptime-kuma","slug":"hostname-is-required","errorCode":null,"errorMessage":"Hostname is required","messagePattern":"Hostname is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/monitor-types/ntp.js","lineNumber":21,"sourceCode":"const dayjs = require(\"dayjs\");\nconst dgram = require(\"dgram\");\nconst dns = require(\"dns\");\n\n/**\n * NTP Monitor Type\n * Monitors NTP servers for availability, time accuracy, and quality metrics\n */\nclass NTPMonitorType extends MonitorType {\n    name = \"ntp\";\n\n    /**\n     * @inheritdoc\n     */\n    async check(monitor, heartbeat, _server) {\n        const startTime = dayjs().valueOf();\n\n        if (!monitor.hostname) {\n            throw new Error(\"Hostname is required\");\n        }\n\n        const port = monitor.port || 123;\n        const timeout = (monitor.timeout || 10) * 1000;\n\n        const ntpResult = await this.queryNTP(monitor.hostname, port, timeout);\n\n        heartbeat.ping = dayjs().valueOf() - startTime;\n\n        const { stratum, offset, rootDispersion, refid, roundTripDelay } = ntpResult;\n\n        heartbeat.msg = `Stratum: ${stratum}, RefID: ${refid}, Offset: ${offset.toFixed(3)}ms, Delay: ${roundTripDelay.toFixed(3)}ms, Dispersion: ${rootDispersion.toFixed(3)}ms`;\n\n        if (stratum === 16) {\n            throw new Error(\"NTP server is unsynchronized (stratum 16)\");\n        }\n\n        const stratumThreshold = monitor.ntp_stratum_threshold || 5;","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/monitor-types/ntp.js#L3-L39","documentation":"Thrown at the top of NTPMonitorType.check when monitor.hostname is falsy. The NTP monitor needs a target host to resolve and query over UDP/123, so a missing hostname is a configuration defect, not a runtime/network problem.","triggerScenarios":"check() invoked with a monitor object whose hostname is undefined, null, '' or 0. Occurs when a monitor was created without the hostname field, the field was cleared via the API, or a provisioning script omitted it.","commonSituations":"Provisioning/import script that did not set hostname; frontend allowed saving with empty hostname due to a bug; monitor cloned without setting the new target.","solutions":["Set monitor.hostname to the NTP server hostname or IP (e.g. 'pool.ntp.org').","Add UI/API-level validation requiring hostname before persistence for the 'ntp' type.","If importing monitors, validate each row has a non-empty hostname."],"exampleFix":"// before: monitor.hostname = ''\n// after:  monitor.hostname = 'pool.ntp.org'","handlingStrategy":"validation","validationCode":"function requireNtpHostname(monitor) {\n  if (!monitor.hostname || typeof monitor.hostname !== 'string' || !monitor.hostname.trim())\n    throw new Error('NTP monitor requires a hostname');\n}","typeGuard":"function hasNtpHostname(m) { return typeof m?.hostname === 'string' && m.hostname.trim().length > 0; }","tryCatchPattern":null,"preventionTips":["Validate hostname at the API/UI before persisting an NTP monitor.","When importing monitors, assert each 'ntp' row has a non-empty hostname.","Treat a missing hostname as a config error, not a runtime retry."],"tags":["ntp","validation","config","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}