Permalink
Browse files

MOD WIP various longstanding TODOs

ADD  cleanuped options
ADD  verbose flag
MOD  assert required options on startup
ADD  debug flag -- not yet hooked in
ADD  emit() to log - switched on verbose flag
NOP  cleanup emits from harvest on harvest start
DONE check harvest file is a regular file
DONE check stat errors on harvest init
NOP  gofmt affted files - TODO rest

TEST ADHOC OK
  • Loading branch information...
Joubin Houshyar
Joubin Houshyar committed Jul 21, 2014
1 parent 2cbd16d commit 2671f421f182b4fbcb46037b3488580683cd2c66
Showing with 732 additions and 636 deletions.
  1. +21 −22 config.go
  2. +179 −159 harvester.go
  3. +96 −15 logstash-forwarder.go
  4. +215 −217 prospector.go
  5. +221 −223 publisher1.go
View
@@ -2,7 +2,6 @@ package main
import (
"encoding/json"
"log"
"os"
"time"
)
@@ -26,52 +25,52 @@ type NetworkConfig struct {
}
type FileConfig struct {
Paths []string `json:paths`
Fields map[string]string `json:fields`
DeadTime string `json:"dead time"`
deadtime time.Duration
Paths []string `json:paths`
Fields map[string]string `json:fields`
DeadTime string `json:"dead time"`
deadtime time.Duration
}
func LoadConfig(path string) (config Config, err error) {
config_file, err := os.Open(path)
if err != nil {
log.Printf("Failed to open config file '%s': %s\n", path, err)
emit("Failed to open config file '%s': %s\n", path, err)
return
}
fi, _ := config_file.Stat()
if fi.Size() > (10 << 20) {
log.Printf("Config file too large? Aborting, just in case. '%s' is %d bytes\n",
emit("Config file too large? Aborting, just in case. '%s' is %d bytes\n",
path, fi)
return
}
buffer := make([]byte, fi.Size())
_, err = config_file.Read(buffer)
log.Printf("%s\n", buffer)
emit("%s\n", buffer)
err = json.Unmarshal(buffer, &config)
if err != nil {
log.Printf("Failed unmarshalling json: %s\n", err)
emit("Failed unmarshalling json: %s\n", err)
return
}
if config.Network.Timeout == 0 {
config.Network.Timeout = default_NetworkConfig_Timeout
}
if config.Network.Timeout == 0 {
config.Network.Timeout = default_NetworkConfig_Timeout
}
config.Network.timeout = time.Duration(config.Network.Timeout) * time.Second
for k, _ := range config.Files {
if config.Files[k].DeadTime == "" {
config.Files[k].DeadTime = default_FileConfig_DeadTime
}
config.Files[k].deadtime, err = time.ParseDuration(config.Files[k].DeadTime)
if err != nil {
log.Printf("Failed to parse dead time duration '%s'. Error was: %s\n", config.Files[k].DeadTime, err)
return
}
}
for k, _ := range config.Files {
if config.Files[k].DeadTime == "" {
config.Files[k].DeadTime = default_FileConfig_DeadTime
}
config.Files[k].deadtime, err = time.ParseDuration(config.Files[k].DeadTime)
if err != nil {
emit("Failed to parse dead time duration '%s'. Error was: %s\n", config.Files[k].DeadTime, err)
return
}
}
return
}
Oops, something went wrong.

0 comments on commit 2671f42

Please sign in to comment.