Permalink
Browse files

query logging wip

  • Loading branch information...
abh committed Jul 12, 2016
1 parent dc6fbb8 commit 0aab8e63800ea5f227791c1cf21665a5041ea57c
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -4,6 +4,9 @@ all: templates.go
templates.go: templates/*.html monitor.go
go generate
test:
go test -race $(go list ./... | grep -v /vendor/)
devel:
go build -tags devel
View
@@ -251,3 +251,14 @@ var CountryContinent = map[string]string{
"zm": "africa",
"zw": "africa",
}
var ContinentCountries = map[string][]string{}
func init() {
for cc, co := range CountryContinent {
if _, ok := ContinentCountries[co]; !ok {
ContinentCountries[co] = []string{}
}
ContinentCountries[co] = append(ContinentCountries[co], cc)
}
}
View
@@ -4,72 +4,80 @@ import (
"log"
)
func CountryRegionGroup(country, region string) string {
var RegionGroups = map[string]string{
"us-ak": "us-west",
"us-az": "us-west",
"us-ca": "us-west",
"us-co": "us-west",
"us-hi": "us-west",
"us-id": "us-west",
"us-mt": "us-west",
"us-nm": "us-west",
"us-nv": "us-west",
"us-or": "us-west",
"us-ut": "us-west",
"us-wa": "us-west",
"us-wy": "us-west",
if country != "us" {
return ""
}
"us-ar": "us-central",
"us-ia": "us-central",
"us-il": "us-central",
"us-in": "us-central",
"us-ks": "us-central",
"us-la": "us-central",
"us-mn": "us-central",
"us-mo": "us-central",
"us-nd": "us-central",
"us-ne": "us-central",
"us-ok": "us-central",
"us-sd": "us-central",
"us-tx": "us-central",
"us-wi": "us-central",
"us-al": "us-east",
"us-ct": "us-east",
"us-dc": "us-east",
"us-de": "us-east",
"us-fl": "us-east",
"us-ga": "us-east",
"us-ky": "us-east",
"us-ma": "us-east",
"us-md": "us-east",
"us-me": "us-east",
"us-mi": "us-east",
"us-ms": "us-east",
"us-nc": "us-east",
"us-nh": "us-east",
"us-nj": "us-east",
"us-ny": "us-east",
"us-oh": "us-east",
"us-pa": "us-east",
"us-ri": "us-east",
"us-sc": "us-east",
"us-tn": "us-east",
"us-va": "us-east",
"us-vt": "us-east",
"us-wv": "us-east",
}
regions := map[string]string{
"us-ak": "us-west",
"us-az": "us-west",
"us-ca": "us-west",
"us-co": "us-west",
"us-hi": "us-west",
"us-id": "us-west",
"us-mt": "us-west",
"us-nm": "us-west",
"us-nv": "us-west",
"us-or": "us-west",
"us-ut": "us-west",
"us-wa": "us-west",
"us-wy": "us-west",
var RegionGroupRegions = map[string][]string{}
"us-ar": "us-central",
"us-ia": "us-central",
"us-il": "us-central",
"us-in": "us-central",
"us-ks": "us-central",
"us-la": "us-central",
"us-mn": "us-central",
"us-mo": "us-central",
"us-nd": "us-central",
"us-ne": "us-central",
"us-ok": "us-central",
"us-sd": "us-central",
"us-tx": "us-central",
"us-wi": "us-central",
func CountryRegionGroup(country, region string) string {
"us-al": "us-east",
"us-ct": "us-east",
"us-dc": "us-east",
"us-de": "us-east",
"us-fl": "us-east",
"us-ga": "us-east",
"us-ky": "us-east",
"us-ma": "us-east",
"us-md": "us-east",
"us-me": "us-east",
"us-mi": "us-east",
"us-ms": "us-east",
"us-nc": "us-east",
"us-nh": "us-east",
"us-nj": "us-east",
"us-ny": "us-east",
"us-oh": "us-east",
"us-pa": "us-east",
"us-ri": "us-east",
"us-sc": "us-east",
"us-tn": "us-east",
"us-va": "us-east",
"us-vt": "us-east",
"us-wv": "us-east",
if country != "us" {
return ""
}
if group, ok := regions[region]; ok {
if group, ok := RegionGroups[region]; ok {
return group
}
log.Printf("Did not find a region group for '%s'/'%s'", country, region)
return ""
}
func init() {
for ccrc, rg := range RegionGroups {
RegionGroupRegions[rg] = append(RegionGroupRegions[rg], ccrc)
}
}
View
@@ -33,7 +33,7 @@ import (
)
// VERSION is the current version of GeoDNS
var VERSION string = "2.6.0"
var VERSION string = "2.7.0"
var buildTime string
var gitVersion string
@@ -95,6 +95,7 @@ func main() {
}
srv := Server{}
srv.SetQueryLogger("log/queries.log")
if len(*flagLogFile) > 0 {
logToFileOpen(*flagLogFile)
View
@@ -0,0 +1,51 @@
package querylog
import (
"encoding/json"
"gopkg.in/natefinch/lumberjack.v2"
)
type QueryLogger interface {
Write(*Entry) error
}
// easyjson:json
type Entry struct {
Time int64
Origin string
Name string
Qtype uint16
Rcode int
Answers int
Targets []string
LabelName string
RemoteAddr string
ClientAddr string
HasECS bool
}
type FileLogger struct {
logger lumberjack.Logger
}
func NewFileLogger(filename string) (*FileLogger, error) {
fl := &FileLogger{}
fl.logger = lumberjack.Logger{
Filename: filename,
MaxSize: 500, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
}
return fl, nil
}
func (l *FileLogger) Write(e *Entry) error {
js, err := json.Marshal(e)
if err != nil {
return err
}
js = append(js, []byte("\n")...)
_, err = l.logger.Write(js)
return err
}
Oops, something went wrong.

0 comments on commit 0aab8e6

Please sign in to comment.