Skip to content

Commit 5534653

Browse files
committed
Quote DHCP hostname
Some DHCP clients register wild hostnames no matter what RFC 1035 says. That causes errors as Prometheus accepts only valid UTF-8. Fix nshttpd#116
1 parent dc93f93 commit 5534653

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

collector/dhcp_lease_collector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func (c *dhcpLeaseCollector) collectMetric(ctx *collectorContext, re *proto.Sent
7676
server := re.Map["server"]
7777
status := re.Map["status"]
7878
activeaddress := re.Map["active-address"]
79-
hostname := re.Map["host-name"]
79+
// QuoteToASCII because of broken DHCP clients
80+
hostname := strconv.QuoteToASCII(re.Map["host-name"])
8081

8182
metric, err := prometheus.NewConstMetric(c.descriptions, prometheus.GaugeValue, v, ctx.device.Name, ctx.device.Address, activemacaddress, server, status, strconv.FormatFloat(f, 'f', 0, 64), activeaddress, hostname)
8283
if err != nil {

0 commit comments

Comments
 (0)