Ver código fonte

Add option to configure 'loggers'

Ask Bjørn Hansen 12 anos atrás
pai
commit
461dd402e9
4 arquivos alterados com 27 adições e 2 exclusões
  1. 3 0
      dns/test.example.com.json
  2. 7 2
      zone.go
  3. 14 0
      zones.go
  4. 3 0
      zones_test.go

+ 3 - 0
dns/test.example.com.json

@@ -1,6 +1,9 @@
 { "serial": 3,
   "ttl":    600,
   "max_hosts": 2,
+  "logging": {
+    "stathat": true
+  },
   "contact": "support.bitnames.com",
   "data" : {
     "":  {

+ 7 - 2
zone.go

@@ -8,13 +8,17 @@ import (
 	"time"
 )
 
-type Options struct {
+type ZoneOptions struct {
 	Serial   int
 	Ttl      int
 	MaxHosts int
 	Contact  string
 }
 
+type ZoneLogging struct {
+	StatHat bool
+}
+
 type Record struct {
 	RR     dns.RR
 	Weight int
@@ -48,7 +52,8 @@ type Zone struct {
 	Origin    string
 	Labels    labels
 	LenLabels int
-	Options   Options
+	Options   ZoneOptions
+	Logging   *ZoneLogging
 	LastRead  time.Time
 	Metrics   ZoneMetrics
 }

+ 14 - 0
zones.go

@@ -178,6 +178,20 @@ func readZoneFile(zoneName, fileName string) (zone *Zone, zerr error) {
 			case "max_hosts":
 				zone.Options.MaxHosts = valueToInt(v)
 			}
+		case "logging":
+			{
+				logging := new(ZoneLogging)
+				for logger, enabled := range v.(map[string]interface{}) {
+					switch logger {
+					case "stathat":
+						logging.StatHat = enabled.(bool)
+					default:
+						log.Println("Unknown logger", logger)
+					}
+				}
+				zone.Logging = logging
+				// log.Printf("logging options: %#v", logging)
+			}
 			continue
 
 		case "data":

+ 3 - 0
zones_test.go

@@ -38,6 +38,9 @@ func (s *ConfigSuite) TestReadConfigs(c *C) {
 	c.Check(tz.Options.MaxHosts, Equals, 2)
 	c.Check(tz.Options.Contact, Equals, "support.bitnames.com")
 
+	// Got logging option
+	c.Check(tz.Logging.StatHat, Equals, true)
+
 	c.Check(tz.Labels["weight"].MaxHosts, Equals, 1)
 
 	/* test different cname targets */