package accesslogs import ( "encoding/json" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" ) // DNSIngestLog DNS 访问日志单行结构(JSONEachRow). type DNSIngestLog struct { Timestamp int64 `json:"timestamp"` RequestId string `json:"request_id"` NodeId int64 `json:"node_id"` ClusterId int64 `json:"cluster_id"` DomainId int64 `json:"domain_id"` RecordId int64 `json:"record_id"` RemoteAddr string `json:"remote_addr"` QuestionName string `json:"question_name"` QuestionType string `json:"question_type"` RecordName string `json:"record_name"` RecordType string `json:"record_type"` RecordValue string `json:"record_value"` Networking string `json:"networking"` IsRecursive bool `json:"is_recursive"` Error string `json:"error"` NSRouteCodes []string `json:"ns_route_codes,omitempty"` ContentJSON string `json:"content_json,omitempty"` } // FromNSAccessLog 将 pb.NSAccessLog 转为 DNSIngestLog. func FromNSAccessLog(log *pb.NSAccessLog, clusterId int64) *DNSIngestLog { if log == nil { return nil } contentBytes, _ := json.Marshal(log) return &DNSIngestLog{ Timestamp: log.GetTimestamp(), RequestId: log.GetRequestId(), NodeId: log.GetNsNodeId(), ClusterId: clusterId, DomainId: log.GetNsDomainId(), RecordId: log.GetNsRecordId(), RemoteAddr: log.GetRemoteAddr(), QuestionName: log.GetQuestionName(), QuestionType: log.GetQuestionType(), RecordName: log.GetRecordName(), RecordType: log.GetRecordType(), RecordValue: log.GetRecordValue(), Networking: log.GetNetworking(), IsRecursive: log.GetIsRecursive(), Error: log.GetError(), NSRouteCodes: log.GetNsRouteCodes(), ContentJSON: string(contentBytes), } }