mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-01-09 23:47:23 +03:00
querylog: imp code
This commit is contained in:
parent
66d9ea7cca
commit
c591e46254
2 changed files with 9 additions and 6 deletions
|
@ -9,9 +9,11 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// csvRow is an alias type for csv rows.
|
||||
type csvRow = [18]string
|
||||
|
||||
// csvHeaderRow is a slice of strings with column names for CSV header row.
|
||||
// This slice should correspond with [logEntry.toCSV] func.
|
||||
var csvHeaderRow = []string{
|
||||
var csvHeaderRow = csvRow{
|
||||
"ans_dnssec",
|
||||
"ans_rcode",
|
||||
"ans_type",
|
||||
|
@ -34,7 +36,7 @@ var csvHeaderRow = []string{
|
|||
|
||||
// toCSV returns a slice of strings with entry fields according to the
|
||||
// csvHeaderRow slice.
|
||||
func (e *logEntry) toCSV() (out []string) {
|
||||
func (e *logEntry) toCSV() (out csvRow) {
|
||||
var filterID, filterRule string
|
||||
|
||||
if e.Result.IsFiltered && len(e.Result.Rules) > 0 {
|
||||
|
@ -45,7 +47,7 @@ func (e *logEntry) toCSV() (out []string) {
|
|||
|
||||
aData := ansData(e)
|
||||
|
||||
return []string{
|
||||
return csvRow{
|
||||
strconv.FormatBool(e.AuthenticatedData),
|
||||
aData.rCode,
|
||||
aData.typ,
|
||||
|
|
|
@ -125,7 +125,7 @@ func (l *queryLog) handleQueryLogExport(w http.ResponseWriter, r *http.Request)
|
|||
csvWriter := csv.NewWriter(w)
|
||||
|
||||
// Write header.
|
||||
if err = csvWriter.Write(csvHeaderRow); err != nil {
|
||||
if err = csvWriter.Write(csvHeaderRow[:]); err != nil {
|
||||
http.Error(w, "writing csv header", http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
|
@ -148,7 +148,8 @@ func (l *queryLog) handleQueryLogExport(w http.ResponseWriter, r *http.Request)
|
|||
params.offset += params.limit
|
||||
|
||||
for _, entry := range entries {
|
||||
if err = csvWriter.Write(entry.toCSV()); err != nil {
|
||||
row := entry.toCSV()
|
||||
if err = csvWriter.Write(row[:]); err != nil {
|
||||
// TODO(a.garipov): Set Trailer X-Error header.
|
||||
log.Error("%s %s %s: %s", r.Method, r.Host, r.URL, "writing csv record")
|
||||
|
||||
|
|
Loading…
Reference in a new issue