sometimes answer can be empty, therefore question could be lost -- pass both to querylog
This commit is contained in:
parent
606bed9d20
commit
e122d9138b
@ -19,7 +19,8 @@ import (
|
|||||||
var logBuffer = ring.Ring{}
|
var logBuffer = ring.Ring{}
|
||||||
|
|
||||||
type logEntry struct {
|
type logEntry struct {
|
||||||
R *dns.Msg
|
Question *dns.Msg
|
||||||
|
Answer *dns.Msg
|
||||||
Result dnsfilter.Result
|
Result dnsfilter.Result
|
||||||
Time time.Time
|
Time time.Time
|
||||||
Elapsed time.Duration
|
Elapsed time.Duration
|
||||||
@ -30,9 +31,10 @@ func init() {
|
|||||||
logBuffer.SetCapacity(1000)
|
logBuffer.SetCapacity(1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logRequest(r *dns.Msg, result dnsfilter.Result, elapsed time.Duration, ip string) {
|
func logRequest(question *dns.Msg, answer *dns.Msg, result dnsfilter.Result, elapsed time.Duration, ip string) {
|
||||||
entry := logEntry{
|
entry := logEntry{
|
||||||
R: r,
|
Question: question,
|
||||||
|
Answer: answer,
|
||||||
Result: result,
|
Result: result,
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
Elapsed: elapsed,
|
Elapsed: elapsed,
|
||||||
@ -57,21 +59,21 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
"client": entry.IP,
|
"client": entry.IP,
|
||||||
}
|
}
|
||||||
question := map[string]interface{}{
|
question := map[string]interface{}{
|
||||||
"host": strings.ToLower(strings.TrimSuffix(entry.R.Question[0].Name, ".")),
|
"host": strings.ToLower(strings.TrimSuffix(entry.Question.Question[0].Name, ".")),
|
||||||
"type": dns.Type(entry.R.Question[0].Qtype).String(),
|
"type": dns.Type(entry.Question.Question[0].Qtype).String(),
|
||||||
"class": dns.Class(entry.R.Question[0].Qclass).String(),
|
"class": dns.Class(entry.Question.Question[0].Qclass).String(),
|
||||||
}
|
}
|
||||||
jsonentry["question"] = question
|
jsonentry["question"] = question
|
||||||
|
|
||||||
status, _ := response.Typify(entry.R, time.Now().UTC())
|
status, _ := response.Typify(entry.Answer, time.Now().UTC())
|
||||||
jsonentry["status"] = status.String()
|
jsonentry["status"] = status.String()
|
||||||
if len(entry.Result.Rule) > 0 {
|
if len(entry.Result.Rule) > 0 {
|
||||||
jsonentry["rule"] = entry.Result.Rule
|
jsonentry["rule"] = entry.Result.Rule
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(entry.R.Answer) > 0 {
|
if entry.Answer != nil && len(entry.Answer.Answer) > 0 {
|
||||||
var answers = []map[string]interface{}{}
|
var answers = []map[string]interface{}{}
|
||||||
for _, k := range entry.R.Answer {
|
for _, k := range entry.Answer.Answer {
|
||||||
header := k.Header()
|
header := k.Header()
|
||||||
answer := map[string]interface{}{
|
answer := map[string]interface{}{
|
||||||
"type": dns.TypeToString[header.Rrtype],
|
"type": dns.TypeToString[header.Rrtype],
|
||||||
|
Loading…
Reference in New Issue
Block a user