Example #1
0
//Sets any invalid fields to their default value
func PerformDefault(conf Configuration) {
	err := conf.Validate()
	name := reflect.ValueOf(conf).Type()
	if err != nil {
		if errs, ok := err.(validator.ErrorMap); ok {
			for fieldName := range errs {
				if strings.Contains(fieldName, ".") {
					//If field Name contains a '.' than it is a subfield of a current field
					continue
				}
				glog.V(4).Info("Invalid field searching for default ", fieldName)
				if ok, err := defaults.HasDefault(conf, fieldName); ok {
					value, err := defaults.SetDefault(conf, fieldName)
					if err != nil {
						glog.Errorf("Failed to set default of %s on %s", fieldName, name)
					} else {
						glog.Infof("Defaulted %v.%s to '%v'", name, fieldName, value)
					}
				} else {
					glog.V(4).Info("No default found: ", err)
				}
			}
		} else {
			glog.Errorf("Failed to validate %s: %s", name, err)
		}
	}
}
Example #2
0
func main() {
	defer glog.Flush()
	flag.Parse()
	config, err := morgoth.LoadFromFile(*configPath)
	if err != nil {
		glog.Errorf("Error loading config: %v\n", err)
		os.Exit(2)
	}

	app := morgoth.NewApp(config)
	err = app.Run()
	if err != nil {
		glog.Errorf("Error running application: %v\n", err)
		os.Exit(3)
	}
}
Example #3
0
func (self *Manager) RecordAnomalous(w *Window) {
	glog.Infof("Found anomalous window: %s %s %s", w.Name, w.Tags, w.Start)
	err := self.engine.RecordAnomalous(w.Copy())
	if err != nil {
		glog.Errorf("Error recording anomaly: %s", err)
	}
}
Example #4
0
func (self *APIServer) Start() (err error) {
	self.handler = rest.ResourceHandler{
		EnableStatusService: true,
	}
	self.handler.SetRoutes(
		&rest.Route{"GET", "/status", self.status},
		&rest.Route{"GET", "/stats", self.stats},
	)
	self.listener, err = net.Listen("tcp", fmt.Sprintf(":%d", self.port))
	if err != nil {
		glog.Errorf("Error binding APIServer: %s", err)
		return
	}
	go func() {
		err = http.Serve(self.listener, &self.handler)
		if err != nil {
			glog.Errorf("Error while APIServer was running: %s", err)
		}
	}()
	glog.V(1).Info("APIServer running")
	return
}
Example #5
0
func (self *Manager) processQueries() {
	for query := range self.queryQueue {
		glog.V(2).Info("Executing query:", query)
		windows, err := self.engine.GetWindows(query.query)
		if err != nil {
			glog.Errorf("Failed to execute query: '%s' %s", query, err)
			continue
		}
		// Tag windows with query tags
		glog.V(3).Info("Adding query tags: ", query.tags)
		for _, w := range windows {
			for t, v := range query.tags {
				w.Tags[t] = v
			}
		}

		self.ProcessWindows(windows)
	}
}
Example #6
0
func (self *AlertsManager) processQueries() {
	for query := range self.queryQueue {
		glog.V(2).Info("Executing query:", query)
		windows, err := self.engine.GetWindows(query.query)
		if err != nil {
			glog.Errorf("Failed to execute query: '%s' %s", query, err)
			continue
		}
		glog.Info(windows)

		for _, w := range windows {
			sum := 0.0
			for _, point := range w.Data {
				sum += point
			}
			glog.V(1).Info("Alert Query total ", sum)
			if sum > query.threshold {
				for _, n := range query.notifiers {
					n.Notify(query.message, w)
				}
			}
		}
	}
}