summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-07-04 23:39:53 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-07-04 23:39:53 +0200
commit87a783a37790caeb75ef1686ff81d2d59e85493f (patch)
tree0e50c87f0cfc385450000f04cd1a57f0dba6a829
parentsrv now uses a config struct it self (diff)
hub uses config structs now
-rw-r--r--src/hub/src/spreadspace.org/sfive-hub/s5hub.go58
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvConf.go60
2 files changed, 97 insertions, 21 deletions
diff --git a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
index 15b1034..f508dd2 100644
--- a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
+++ b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
@@ -45,6 +45,8 @@ import (
var s5hl = log.New(os.Stderr, "[s5hub]\t", log.LstdFlags)
func main() {
+ // ****************** this should be replaced? by a proper config file
+
db := flag.String("db", "/var/lib/sfive/db.bolt", "path to the database file")
readOnly := flag.Bool("read-only", false, "open database in read-only mode")
anonymize := flag.Bool("anonymize", false, "anonymize clients IP addresses using crypto-pan")
@@ -74,7 +76,27 @@ func main() {
return
}
- srv, err := sfive.NewServer(sfive.SrvConfig{sfive.StoreConfig{*db, *readOnly}, sfive.TransformConfig{*anonymize, *anonKeyFile, *geoipDB}})
+ cfg := sfive.SrvConfig{}
+ if *startPipe {
+ cfg.Interfaces.Pipe = sfive.PipeInterfaceConfig{ListenAddr: *pipe}
+ }
+ if *startPipegram {
+ cfg.Interfaces.Pipegram = sfive.PipegramInterfaceConfig{ListenAddr: *pipegram}
+ }
+ if *startWeb {
+ cfg.Interfaces.Web = sfive.WebInterfaceConfig{ListenAddr: *web}
+ }
+ cfg.Store = sfive.StoreConfig{*db, *readOnly}
+ cfg.Transform = sfive.TransformConfig{*anonymize, *anonKeyFile, *geoipDB}
+ cfg.Forwards.SFive = sfive.SFiveForwardConfig{URL: *forward}
+ cfg.Forwards.Elasticsearch = sfive.ESForwardConfig{URL: *forwardES}
+ cfg.Forwards.Graphite = sfive.GraphiteForwardConfig{Host: *forwardGraphite, BasePath: *graphiteBasePath}
+ cfg.Forwards.Piwik = sfive.PiwikForwardConfig{URL: *forwardPiwik, SiteURL: *piwikSiteURL, SiteID: *piwikSiteID}
+ cfg.Forwards.Piwik.AuthConfig = sfive.AuthConfig{Token: *piwikToken}
+
+ // ****************** end config
+
+ srv, err := sfive.NewServer(cfg)
if err != nil {
s5hl.Fatalf(err.Error())
}
@@ -82,72 +104,72 @@ func main() {
var wg sync.WaitGroup
- if *startPipe {
+ if cfg.Interfaces.Pipe.ListenAddr != "" {
wg.Add(1)
go func() {
defer wg.Done()
- s5hl.Printf("start pipe at %v\n", *pipe)
- srv.ServePipe(*pipe)
+ s5hl.Printf("start pipe at %v\n", cfg.Interfaces.Pipe.ListenAddr)
+ srv.ServePipe(cfg.Interfaces.Pipe.ListenAddr)
s5hl.Println("pipe finished")
}()
}
- if *startPipegram {
+ if cfg.Interfaces.Pipegram.ListenAddr != "" {
wg.Add(1)
go func() {
defer wg.Done()
- s5hl.Printf("starting pipegram at %v\n", *pipegram)
- srv.ServePipegram(*pipegram)
+ s5hl.Printf("starting pipegram at %v\n", cfg.Interfaces.Pipegram.ListenAddr)
+ srv.ServePipegram(cfg.Interfaces.Pipegram.ListenAddr)
s5hl.Println("pipegram finished")
}()
}
- if *startWeb {
+ if cfg.Interfaces.Web.ListenAddr != "" {
wg.Add(1)
go func() {
defer wg.Done()
- s5hl.Printf("starting web at %v\n", *web)
- srv.ServeWeb(*web)
+ s5hl.Printf("starting web at %v\n", cfg.Interfaces.Web.ListenAddr)
+ srv.ServeWeb(cfg.Interfaces.Web.ListenAddr)
s5hl.Println("web finished")
}()
}
- if *forward != "" {
+ if cfg.Forwards.SFive.URL != "" {
wg.Add(1)
go func() {
defer wg.Done()
s5hl.Println("starting forward")
- srv.RunForwarding(*forward)
+ srv.RunForwarding(cfg.Forwards.SFive.URL)
s5hl.Println("forward finished")
}()
}
- if *forwardES != "" {
+ if cfg.Forwards.Elasticsearch.URL != "" {
wg.Add(1)
go func() {
defer wg.Done()
s5hl.Println("starting elastic-search forward")
- srv.RunForwardingEs(*forwardES)
+ srv.RunForwardingEs(cfg.Forwards.Elasticsearch.URL)
s5hl.Println("elastic-search forward finished")
}()
}
- if *forwardGraphite != "" {
+ if cfg.Forwards.Graphite.Host != "" {
wg.Add(1)
go func() {
defer wg.Done()
s5hl.Println("starting graphite forward")
- srv.RunForwardingGraphite(*forwardGraphite, *graphiteBasePath)
+ srv.RunForwardingGraphite(cfg.Forwards.Graphite.Host, cfg.Forwards.Graphite.BasePath)
s5hl.Println("graphite forward finished")
}()
}
- if *forwardPiwik != "" {
+ if cfg.Forwards.Piwik.URL != "" {
wg.Add(1)
go func() {
defer wg.Done()
s5hl.Println("starting piwik forward")
- srv.RunForwardingPiwik(*forwardPiwik, *piwikSiteURL, *piwikSiteID, *piwikToken)
+ srv.RunForwardingPiwik(cfg.Forwards.Piwik.URL, cfg.Forwards.Piwik.SiteURL, cfg.Forwards.Piwik.SiteID, cfg.Forwards.Piwik.AuthConfig.Token)
s5hl.Println("piwik forward finished")
}()
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvConf.go b/src/hub/src/spreadspace.org/sfive/s5srvConf.go
index 7f08a73..6826583 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvConf.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvConf.go
@@ -32,14 +32,68 @@
package sfive
+type PipeInterfaceConfig struct {
+ ListenAddr string `json:"listen" yaml:"listen" toml:"listen"`
+}
+
+type PipegramInterfaceConfig struct {
+ ListenAddr string `json:"listen" yaml:"listen" toml:"listen"`
+}
+
+type WebInterfaceConfig struct {
+ ListenAddr string `json:"listen" yaml:"listen" toml:"listen"`
+}
+
+type InterfacesConfig struct {
+ Pipe PipeInterfaceConfig `json:"pipe" yaml:"pipe" toml:"pipe"`
+ Pipegram PipegramInterfaceConfig `json:"pipegram" yaml:"pipegram" toml:"pipegram"`
+ Web WebInterfaceConfig `json:"web" yaml:"web" toml:"web"`
+}
+
type TransformConfig struct {
Anonymize bool `json:"anonymize" yaml:"anonymize" toml:"anonymize"`
AnonKeyfile string `json:"anonymization-key" yaml:"anonymization-key" toml:"anonymization-key"`
GeoipDB string `json:"geo-ip-db" yaml:"geo-ip-db" toml:"geo-ip-db"`
}
+type AuthConfig struct {
+ Token string `json:"token" yaml:"token" toml:"token"`
+ Username string `json:"username" yaml:"username" toml:"username"`
+ Password string `json:"password" yaml:"password" toml:"password"`
+}
+
+type SFiveForwardConfig struct {
+ URL string `json:"url" yaml:"url" toml:"url"`
+ AuthConfig
+}
+
+type ESForwardConfig struct {
+ URL string `json:"url" yaml:"url" toml:"url"`
+ AuthConfig
+}
+
+type GraphiteForwardConfig struct {
+ Host string `json:"host" yaml:"host" toml:"host"`
+ BasePath string `json:"base-path" yaml:"base-path" toml:"base-path"`
+}
+
+type PiwikForwardConfig struct {
+ URL string `json:"url" yaml:"url" toml:"url"`
+ SiteURL string `json:"site-url" yaml:"site-url" toml:"site-url"`
+ SiteID uint `json:"site-id" yaml:"site-id" toml:"site-id"`
+ AuthConfig
+}
+
+type ForwardsConfig struct {
+ SFive SFiveForwardConfig `json:"sfive" yaml:"sfive" toml:"sfive"`
+ Elasticsearch ESForwardConfig `json:"elasticsearch" yaml:"elasticsearch" toml:"elasticsearch"`
+ Graphite GraphiteForwardConfig `json:"graphite" yaml:"graphite" toml:"graphite"`
+ Piwik PiwikForwardConfig `json:"piwik" yaml:"piwik" toml:"piwik"`
+}
+
type SrvConfig struct {
- // ListenAddr string `json:"listen" yaml:"listen" toml:"listen"`
- Store StoreConfig `json:"store" yaml:"store" toml:"store"`
- Transform TransformConfig `json:"transform" yaml:"transform" toml:"transform"`
+ Interfaces InterfacesConfig `json:"interfaces" yaml:"interfaces" toml:"interfaces"`
+ Transform TransformConfig `json:"transform" yaml:"transform" toml:"transform"`
+ Store StoreConfig `json:"store" yaml:"store" toml:"store"`
+ Forwards ForwardsConfig `json:"forwards" yaml:"forwards" toml:"forwards"`
}