Exemplo n.º 1
0
// WebServer starts the web server and serves GET & POST requests
func (u *Uchiwa) WebServer(publicPath *string, auth auth.Config) {
	// Private endpoints
	http.Handle("/aggregates", auth.Authenticate(http.HandlerFunc(u.aggregatesHandler)))
	http.Handle("/aggregates/", auth.Authenticate(http.HandlerFunc(u.aggregatesHandler)))
	http.Handle("/checks", auth.Authenticate(http.HandlerFunc(u.checksHandler)))
	http.Handle("/clients", auth.Authenticate(http.HandlerFunc(u.clientsHandler)))
	http.Handle("/clients/", auth.Authenticate(http.HandlerFunc(u.clientsHandler)))
	http.Handle("/config", auth.Authenticate(http.HandlerFunc(u.configHandler)))
	http.Handle("/datacenters", auth.Authenticate(http.HandlerFunc(u.datacentersHandler)))
	http.Handle("/events", auth.Authenticate(http.HandlerFunc(u.eventsHandler)))
	http.Handle("/events/", auth.Authenticate(http.HandlerFunc(u.eventsHandler)))
	http.Handle("/request", auth.Authenticate(http.HandlerFunc(u.requestHandler)))
	http.Handle("/results/", auth.Authenticate(http.HandlerFunc(u.resultsHandler)))
	http.Handle("/stashes", auth.Authenticate(http.HandlerFunc(u.stashesHandler)))
	http.Handle("/stashes/", auth.Authenticate(http.HandlerFunc(u.stashesHandler)))
	http.Handle("/subscriptions", auth.Authenticate(http.HandlerFunc(u.subscriptionsHandler)))
	if u.Config.Uchiwa.Enterprise == false {
		http.Handle("/metrics", auth.Authenticate(http.HandlerFunc(u.metricsHandler)))
	}

	// Static files
	http.Handle("/", http.FileServer(http.Dir(*publicPath)))

	// Public endpoints
	http.Handle("/config/", http.HandlerFunc(u.configHandler))
	http.Handle("/health", http.HandlerFunc(u.healthHandler))
	http.Handle("/health/", http.HandlerFunc(u.healthHandler))
	http.Handle("/login", auth.GetIdentification())

	listen := fmt.Sprintf("%s:%d", u.Config.Uchiwa.Host, u.Config.Uchiwa.Port)
	logger.Warningf("Uchiwa is now listening on %s", listen)
	logger.Fatal(http.ListenAndServe(listen, nil))
}
Exemplo n.º 2
0
// WebServer starts the web server and serves GET & POST requests
func (u *Uchiwa) WebServer(publicPath *string, auth auth.Config) {

	// private endpoints
	http.Handle("/aggregates", auth.Authenticate(http.HandlerFunc(u.aggregatesHandler)))
	http.Handle("/checks", auth.Authenticate(http.HandlerFunc(u.checksHandler)))
	http.Handle("/clients", auth.Authenticate(http.HandlerFunc(u.clientsHandler)))
	http.Handle("/datacenters", auth.Authenticate(http.HandlerFunc(u.datacentersHandler)))
	http.Handle("/events", auth.Authenticate(http.HandlerFunc(u.eventsHandler)))
	http.Handle("/results", auth.Authenticate(http.HandlerFunc(u.resultsHandler)))
	http.Handle("/stashes", auth.Authenticate(http.HandlerFunc(u.stashesHandler)))
	http.Handle("/stashes/delete", auth.Authenticate(http.HandlerFunc(u.stashDeleteHandler)))
	http.Handle("/subscriptions", auth.Authenticate(http.HandlerFunc(u.subscriptionsHandler)))

	http.Handle("/delete_client", auth.Authenticate(http.HandlerFunc(u.deleteClientHandler)))
	http.Handle("/get_aggregate", auth.Authenticate(http.HandlerFunc(u.getAggregateHandler)))
	http.Handle("/get_aggregate_by_issued", auth.Authenticate(http.HandlerFunc(u.getAggregateByIssuedHandler)))
	http.Handle("/get_client", auth.Authenticate(http.HandlerFunc(u.getClientHandler)))
	http.Handle("/get_config", auth.Authenticate(http.HandlerFunc(u.getConfigHandler)))
	http.Handle("/get_sensu", auth.Authenticate(http.HandlerFunc(u.getSensuHandler)))
	http.Handle("/post_event", auth.Authenticate(http.HandlerFunc(u.postEventHandler)))

	// static files
	http.Handle("/", http.FileServer(http.Dir(*publicPath)))

	// public endpoints
	http.Handle("/config/auth", http.HandlerFunc(u.configAuthHandler))
	http.Handle("/health", http.HandlerFunc(u.healthHandler))
	http.Handle("/health/", http.HandlerFunc(u.healthHandler))
	http.Handle("/login", auth.GetIdentification())

	listen := fmt.Sprintf("%s:%d", u.Config.Uchiwa.Host, u.Config.Uchiwa.Port)
	logger.Infof("Uchiwa is now listening on %s", listen)
	logger.Fatal(http.ListenAndServe(listen, nil))
}
Exemplo n.º 3
0
// Load retrieves a specified configuration file and return a Config struct
func Load(file, directories string) *Config {
	// Load the configuration file
	conf, err := loadFile(file)
	if err != nil {
		logger.Fatal(err)
	}

	// Apply default configs to the configuration file
	if err := mergo.Merge(conf, defaultConfig); err != nil {
		logger.Fatal(err)
	}
	for i := range conf.Sensu {
		if err := mergo.Merge(&conf.Sensu[i], defaultSensuConfig); err != nil {
			logger.Fatal(err)
		}
	}

	if directories != "" {
		configDir := loadDirectories(directories)
		// Overwrite the file config with the configs from the directories
		if err := mergo.MergeWithOverwrite(conf, configDir); err != nil {
			logger.Fatal(err)
		}
	}

	conf.Sensu = initSensu(conf.Sensu)

	// Support the dashboard attribute
	if conf.Dashboard != nil {
		conf.Uchiwa = *conf.Dashboard
		// Apply the default config to the dashboard attribute
		if err := mergo.Merge(conf, defaultConfig); err != nil {
			logger.Fatal(err)
		}
	}

	conf.Uchiwa = initUchiwa(conf.Uchiwa)
	return conf
}
Exemplo n.º 4
0
// loadDirectories loads a Config struct from one or multiple directories of configuration
func loadDirectories(path string) *Config {
	conf := new(Config)
	var configFiles []string
	directories := strings.Split(strings.ToLower(path), ",")

	for _, directory := range directories {
		// Find all JSON files in the specified directories
		files, err := filepath.Glob(filepath.Join(directory, "*.json"))
		if err != nil {
			logger.Warning(err)
			continue
		}

		// Add the files found to a slice of configuration files to open
		for _, file := range files {
			configFiles = append(configFiles, file)
		}
	}

	// Load every configuration files and merge them together bit by bit
	for _, file := range configFiles {
		// Load the config from the file
		c, err := loadFile(file)
		if err != nil {
			logger.Warning(err)
			continue
		}

		// Apply this configuration to the existing one
		if err := mergo.MergeWithOverwrite(conf, c); err != nil {
			logger.Warning(err)
			continue
		}
	}

	// Apply the default config to the Sensu APIs
	for i := range conf.Sensu {
		if err := mergo.Merge(&conf.Sensu[i], defaultSensuConfig); err != nil {
			logger.Fatal(err)
		}
	}

	return conf
}
Exemplo n.º 5
0
func main() {
	configFile := flag.String("c", "./config.json", "Full or relative path to the configuration file")
	publicPath := flag.String("p", "public", "Full or relative path to the public directory")
	flag.Parse()

	config, err := config.Load(*configFile)
	if err != nil {
		logger.Fatal(err)
	}

	logger.Debug("Debug mode enabled")

	u := uchiwa.Init(config)

	authentication := auth.New(config.Uchiwa.Auth)
	if config.Uchiwa.Auth.Driver == "simple" {
		authentication.Simple(config.Uchiwa.Users)
	} else {
		authentication.None()
	}

	// Audit
	audit.Log = audit.LogMock

	// filters
	uchiwa.FilterAggregates = filters.FilterAggregates
	uchiwa.FilterChecks = filters.FilterChecks
	uchiwa.FilterClients = filters.FilterClients
	uchiwa.FilterDatacenters = filters.FilterDatacenters
	uchiwa.FilterEvents = filters.FilterEvents
	uchiwa.FilterStashes = filters.FilterStashes
	uchiwa.FilterSubscriptions = filters.FilterSubscriptions

	uchiwa.FilterGetRequest = filters.GetRequest
	uchiwa.FilterPostRequest = filters.PostRequest
	uchiwa.FilterSensuData = filters.SensuData

	u.WebServer(publicPath, authentication)
}