Skip to content

Commit

Permalink
feat(powerdns): add support for deviceID, deviceName and RequestorId (#…
Browse files Browse the repository at this point in the history
…909)

* feat(powerdns): add support for deviceID, deviceName and RequestorId
  • Loading branch information
dmachard authored Dec 20, 2024
1 parent db16141 commit 6c1ecca
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 3 deletions.
3 changes: 3 additions & 0 deletions dnsutils/dnsmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type PowerDNS struct {
HTTPVersion string `json:"http-version"`
MessageID string `json:"message-id"`
InitialRequestorID string `json:"initial-requestor-id"`
RequestorID string `json:"requestor-id"`
DeviceName string `json:"device-name"`
DeviceID string `json:"device-id"`
}

type TransformDNSGeo struct {
Expand Down
5 changes: 5 additions & 0 deletions dnsutils/dnsmessage_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func (dm *DNSMessage) Flatten() (map[string]interface{}, error) {
dnsFields["powerdns.metadata."+mk] = mv
}
dnsFields["powerdns.http-version"] = dm.PowerDNS.HTTPVersion
dnsFields["powerdns.message-id"] = dm.PowerDNS.MessageID
dnsFields["powerdns.requestor-id"] = dm.PowerDNS.RequestorID
dnsFields["powerdns.device-id"] = dm.PowerDNS.DeviceID
dnsFields["powerdns.device-name"] = dm.PowerDNS.DeviceName
dnsFields["powerdns.initial-requestor-id"] = dm.PowerDNS.InitialRequestorID
}

// relabeling ?
Expand Down
8 changes: 7 additions & 1 deletion dnsutils/dnsmessage_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func TestDnsMessage_Json_Collectors_Reference(t *testing.T) {
HTTPVersion: "http3",
MessageID: "27c3e94ad6284eec9a50cfc5bd7384d6",
InitialRequestorID: "5e006236c8a74f7eafc6af126e6d0689",
RequestorID: "f7c3e94ad6284eec9a50cfc5bd7384d6",
DeviceID: "ffffffffffffffffeaaeaeae",
DeviceName: "foobar",
}},

jsonRef: `{
Expand All @@ -129,7 +132,10 @@ func TestDnsMessage_Json_Collectors_Reference(t *testing.T) {
},
"http-version": "http3",
"message-id": "27c3e94ad6284eec9a50cfc5bd7384d6",
"initial-requestor-id": "5e006236c8a74f7eafc6af126e6d0689"
"initial-requestor-id": "5e006236c8a74f7eafc6af126e6d0689",
"requestor-id": "f7c3e94ad6284eec9a50cfc5bd7384d6",
"device-id": "ffffffffffffffffeaaeaeae",
"device-name": "foobar"
}
}`,
},
Expand Down
18 changes: 18 additions & 0 deletions dnsutils/dnsmessage_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ func (dm *DNSMessage) handlePdnsDirectives(directive string, s *strings.Builder)
} else {
s.WriteString("-")
}
case directive == "powerdns-requestor-id":
if len(dm.PowerDNS.RequestorID) > 0 {
s.WriteString(dm.PowerDNS.RequestorID)
} else {
s.WriteString("-")
}
case directive == "powerdns-device-id":
if len(dm.PowerDNS.DeviceID) > 0 {
s.WriteString(dm.PowerDNS.DeviceID)
} else {
s.WriteString("-")
}
case directive == "powerdns-device-name":
if len(dm.PowerDNS.DeviceName) > 0 {
s.WriteString(dm.PowerDNS.DeviceName)
} else {
s.WriteString("-")
}
case directive == "powerdns-message-id":
if len(dm.PowerDNS.MessageID) > 0 {
s.WriteString(dm.PowerDNS.MessageID)
Expand Down
12 changes: 12 additions & 0 deletions dnsutils/dnsmessage_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,18 @@ func TestDnsMessage_TextFormat_Directives_Pdns(t *testing.T) {
dm: DNSMessage{PowerDNS: &PowerDNS{InitialRequestorID: "5e006236c8a74f7eafc6af126e6d0689"}},
expected: "5e006236c8a74f7eafc6af126e6d0689",
},
{
name: "requestor_id",
format: "powerdns-requestor-id",
dm: DNSMessage{PowerDNS: &PowerDNS{RequestorID: "5e006236c8a74f7eafc6af126e6d0689"}},
expected: "5e006236c8a74f7eafc6af126e6d0689",
},
{
name: "device_id_name",
format: "powerdns-device-id powerdns-device-name",
dm: DNSMessage{PowerDNS: &PowerDNS{DeviceID: "5e006236c8a74f7eafc6af126e6d0689", DeviceName: "test"}},
expected: "5e006236c8a74f7eafc6af126e6d0689 test",
},
}

for _, tc := range testcases {
Expand Down
8 changes: 7 additions & 1 deletion docs/collectors/collector_powerdns.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ If you logs your DNS traffic in basic text format, you can use the specific dire
* `powerdns-http-version`: http version used with DoH queries
* `powerdns-message-id`: message id
* `powerdns-initial-requestor-id`: initial requestor id
* `powerdns-requestor-id`: requestor id
* `powerdns-device-id`: device id
* `powerdns-device-name`: device name

Configuration example:

Expand Down Expand Up @@ -100,7 +103,10 @@ If you logs your DNS traffic in JSON output, the following part will be added in
},
"http-version": "HTTP3",
"message-id": "27c3e94ad6284eec9a50cfc5bd7384d6",
"initial-requestor-id": "5e006236c8a74f7eafc6af126e6d0689"
"initial-requestor-id": "5e006236c8a74f7eafc6af126e6d0689",
"requestor-id": "f7c3e94ad6284eec9a50cfc5bd7384d6",
"device-id": "ffffffffffffffffeaaeaeae",
"device-name": "foobar"
}
```

Expand Down
5 changes: 4 additions & 1 deletion workers/powerdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,12 @@ func (w *PdnsProcessor) StartCollect() {
pdns.HTTPVersion = pbdm.GetHttpVersion().String()
}

// get id
// get some string
pdns.MessageID = hex.EncodeToString(pbdm.MessageId)
pdns.InitialRequestorID = hex.EncodeToString(pbdm.InitialRequestId)
pdns.RequestorID = pbdm.GetRequestorId()
pdns.DeviceName = pbdm.GetDeviceName()
pdns.DeviceID = hex.EncodeToString(pbdm.DeviceId)

// finally set pdns to dns message
dm.PowerDNS = &pdns
Expand Down

0 comments on commit 6c1ecca

Please sign in to comment.