コード例 #1
0
ファイル: main.go プロジェクト: nanopack/logvac
func startLogvac(ccmd *cobra.Command, args []string) error {
	// initialize logger
	lumber.Level(lumber.LvlInt(config.LogLevel)) // for clients using lumber too
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))

	// initialize logvac
	logvac.Init()

	// setup authenticator
	err := authenticator.Init()
	if err != nil {
		return fmt.Errorf("Authenticator failed to initialize - %v", err)
	}

	// initialize drains
	err = drain.Init()
	if err != nil {
		return fmt.Errorf("Drain failed to initialize - %v", err)
	}

	// initializes collectors
	err = collector.Init()
	if err != nil {
		return fmt.Errorf("Collector failed to initialize - %v", err)
	}

	err = api.Start(collector.CollectHandler)
	if err != nil {
		return fmt.Errorf("Api failed to initialize - %v", err)
	}

	return nil
}
コード例 #2
0
ファイル: commands.go プロジェクト: nanopack/hoarder
func startHoarder(ccmd *cobra.Command, args []string) error {
	// convert the log level
	logLvl := lumber.LvlInt(viper.GetString("log-level"))

	// configure the logger
	lumber.Prefix("[hoader]")
	lumber.Level(logLvl)

	// enable/start garbage collection if age config was changed
	if ccmd.Flag("clean-after").Changed {
		lumber.Debug("Starting garbage collector (data older than %vs)...\n", ccmd.Flag("clean-after").Value)

		// start garbage collector
		go collector.Start()
	}

	// set, and initialize, the backend driver
	if err := backends.Initialize(); err != nil {
		lumber.Error("Failed to initialize backend - %v", err)
		return err
	}

	// start the API
	if err := api.Start(); err != nil {
		lumber.Fatal("Failed to start API: ", err.Error())
		return err
	}

	return nil
}
コード例 #3
0
ファイル: config.go プロジェクト: nanopack/logvac
// AddFlags adds cli flags to logvac
func AddFlags(cmd *cobra.Command) {
	// collectors
	cmd.Flags().StringVarP(&ListenHttp, "listen-http", "a", ListenHttp, "API listen address (same endpoint for http log collection)")
	cmd.Flags().StringVarP(&ListenUdp, "listen-udp", "u", ListenUdp, "UDP log collection endpoint")
	cmd.Flags().StringVarP(&ListenTcp, "listen-tcp", "t", ListenTcp, "TCP log collection endpoint")

	// drains
	cmd.Flags().StringVarP(&PubAddress, "pub-address", "p", PubAddress, "Log publisher (mist) address (\"mist://127.0.0.1:1445\")")
	cmd.Flags().StringVarP(&PubAuth, "pub-auth", "P", PubAuth, "Log publisher (mist) auth token")
	cmd.Flags().StringVarP(&DbAddress, "db-address", "d", DbAddress, "Log storage address")

	// authenticator
	cmd.PersistentFlags().StringVarP(&AuthAddress, "auth-address", "A", AuthAddress, "Address or file location of authentication db. ('boltdb:///var/db/logvac.bolt' or 'postgresql://127.0.0.1')")

	// other
	cmd.Flags().StringVarP(&CorsAllow, "cors-allow", "C", CorsAllow, "Sets the 'Access-Control-Allow-Origin' header")
	cmd.Flags().StringVarP(&LogKeep, "log-keep", "k", LogKeep, "Age or number of logs to keep per type '{\"app\":\"2w\", \"deploy\": 10}' (int or X(m)in, (h)our,  (d)ay, (w)eek, (y)ear)")
	cmd.Flags().StringVarP(&LogLevel, "log-level", "l", LogLevel, "Level at which to log")
	cmd.Flags().StringVarP(&LogType, "log-type", "L", LogType, "Default type to apply to incoming logs (commonly used: app|deploy)")
	cmd.Flags().StringVarP(&Token, "token", "T", Token, "Administrative token to add/remove 'X-USER-TOKEN's used to pub/sub via http")
	cmd.Flags().BoolVarP(&Server, "server", "s", Server, "Run as server")
	cmd.Flags().BoolVarP(&Insecure, "insecure", "i", Insecure, "Don't use TLS (used for testing)")
	cmd.Flags().BoolVarP(&Version, "version", "v", Version, "Print version info and exit")

	Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))
}
コード例 #4
0
ファイル: collector_test.go プロジェクト: nanopack/logvac
// manually configure and start internals
func initialize() {
	config.ListenHttp = "127.0.0.1:4234"
	config.ListenTcp = "127.0.0.1:4235"
	config.ListenUdp = "127.0.0.1:4234"
	config.DbAddress = "boltdb:///tmp/syslogTest/logvac.bolt"
	config.AuthAddress = ""
	config.Insecure = true
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))

	// initialize logvac
	logvac.Init()

	// setup authenticator
	err := authenticator.Init()
	if err != nil {
		config.Log.Fatal("Authenticator failed to initialize - %v", err)
		os.Exit(1)
	}

	// initialize drains
	err = drain.Init()
	if err != nil {
		config.Log.Fatal("Drain failed to initialize - %v", err)
		os.Exit(1)
	}

	// initializes collectors
	err = collector.Init()
	if err != nil {
		config.Log.Fatal("Collector failed to initialize - %v", err)
		os.Exit(1)
	}
}
コード例 #5
0
ファイル: main.go プロジェクト: nanopack/shaman
func startShaman(ccmd *cobra.Command, args []string) error {
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))

	// initialize cache
	err := cache.Initialize()
	if err != nil {
		config.Log.Fatal(err.Error())
		return err
	}

	// make channel for errors
	errors := make(chan error)

	go func() {
		errors <- api.Start()
	}()
	go func() {
		errors <- server.Start()
	}()

	// break if any of them return an error (blocks exit)
	if err := <-errors; err != nil {
		config.Log.Fatal(err.Error())
	}
	return err
}
コード例 #6
0
ファイル: lvs_test.go プロジェクト: nanopack/portal
func initialize() {
	ifIptables, err := exec.Command("iptables", "-S").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run iptables - %s%v\n", ifIptables, err.Error())
		skip = true
	}
	ifIpvsadm, err := exec.Command("ipvsadm", "--version").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run ipvsadm - %s%v\n", ifIpvsadm, err.Error())
		skip = true
	}

	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	if !skip {
		// todo: find more friendly way to clear crufty rules only
		err = exec.Command("iptables", "-F", "portal").Run()
		if err != nil {
			fmt.Printf("Failed to clear iptables - %v\n", err.Error())
			os.Exit(1)
		}
		err = exec.Command("ipvsadm", "-C").Run()
		if err != nil {
			fmt.Printf("Failed to clear ipvsadm - %v\n", err.Error())
			os.Exit(1)
		}

		balance.Init()
	}
}
コード例 #7
0
ファイル: boltdb_test.go プロジェクト: nanopack/logvac
// manually configure and start internals
func initialize() error {
	var err error
	drain.CleanFreq = 1
	config.LogKeep = `{"app": "1s", "deploy":0}`
	config.LogKeep = `{"app": "1s", "deploy":0, "a":"1m", "aa":"1h", "b":"1d", "c":"1w", "d":"1y", "e":"1"}`
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))

	// initialize logvac
	logvac.Init()

	// initialize archiver
	// Doing broke db
	config.DbAddress = "~!@#$%^&*()"
	drain.Init()

	// Doing file db
	config.DbAddress = "file:///tmp/boltdbTest/logvac.bolt"
	drain.Init()
	drain.Archiver.(*drain.BoltArchive).Close()

	// Doing no db
	config.DbAddress = "/tmp/boltdbTest/logvac.bolt"
	drain.Init()
	drain.Archiver.(*drain.BoltArchive).Close()

	// Doing bolt db
	config.DbAddress = "boltdb:///tmp/boltdbTest/logvac.bolt"
	drain.Init()

	return err
}
コード例 #8
0
ファイル: mist_test.go プロジェクト: nanopack/logvac
// manually configure and start internals
func mistInitialize() error {
	var err error
	drain.CleanFreq = 1
	config.LogKeep = `{"app": "1s", "deploy":0}`
	config.LogKeep = `{"app": "1s", "deploy":0, "a":"1m", "aa":"1h", "b":"1d", "c":"1w", "d":"1y", "e":"1"}`
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))
	config.DbAddress = "boltdb:///tmp/boltdbTest/logvac.bolt"

	server.StartTCP(PubAddress, nil)

	// initialize logvac
	logvac.Init()

	// initialize publisher
	// Doing broke publisher
	config.PubAddress = "~!@#$%^&*()"
	drain.Init()
	drain.Archiver.(*drain.BoltArchive).Close()

	// Doing schemeless publisher
	config.PubAddress = "127.0.0.1:2445"
	drain.Init()
	drain.Archiver.(*drain.BoltArchive).Close()
	drain.Publisher.(*drain.Mist).Close()

	// Doing real publisher
	config.PubAddress = "mist://127.0.0.1:2445"
	err = drain.Init()

	return err
}
コード例 #9
0
ファイル: mist_test.go プロジェクト: nanopack/logvac
// Test writing and getting data
func TestPublish(t *testing.T) {
	lumber.Level(lumber.LvlInt("fatal"))
	err := mistInitialize()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// create test messages
	messages := []logvac.Message{
		logvac.Message{
			Time:     time.Now(),
			UTime:    time.Now().UnixNano(),
			Id:       "myhost",
			Tag:      "test[bolt]",
			Type:     "",
			Priority: 4,
			Content:  "This is a test message",
		},
		logvac.Message{
			Time:     time.Now(),
			UTime:    time.Now().UnixNano(),
			Id:       "myhost",
			Tag:      "test[expire]",
			Type:     "deploy",
			Priority: 4,
			Content:  "This is another test message",
		},
	}

	// write test messages
	drain.Publisher.Publish(messages[0])
	drain.Publisher.Publish(messages[1])
}
コード例 #10
0
ファイル: commands_test.go プロジェクト: nanopack/shaman
// manually configure and start internals
func initialize() {
	config.Insecure = true
	config.L2Connect = "none://"
	config.ApiListen = "127.0.0.1:1634"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))
	config.LogLevel = "FATAL"
}
コード例 #11
0
ファイル: scribble_test.go プロジェクト: nanopack/portal
func TestSetService(t *testing.T) {
	config.DatabaseConnection = "scribble:///tmp/scribbleTest"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	// Backend = &database.ScribbleDatabase{}
	database.Init()

	if err := database.SetService(&testService1); err != nil {
		t.Errorf("Failed to SET service - %v", err)
	}

	service, err := ioutil.ReadFile("/tmp/scribbleTest/services/tcp-192_168_0_15-80.json")
	if err != nil {
		t.Error(err)
	}

	jService, err := toJson(testService1)
	if err != nil {
		t.Error(err)
	}

	if string(service) != string(jService) {
		t.Errorf("Read service differs from written service")
	}
}
コード例 #12
0
ファイル: clients_test.go プロジェクト: nanopack/mist
// TestMain
func TestMain(m *testing.M) {
	lumber.Level(lumber.LvlInt("fatal"))

	server.StartTCP(testAddr, nil)

	//
	os.Exit(m.Run())
}
コード例 #13
0
ファイル: config.go プロジェクト: Lanzafame/butter
func Parse(configFile string) {
	c := map[string]string{}

	bytes, err := ioutil.ReadFile(configFile)
	if err != nil {
		Log.Error("unable to read config file: %v\n", err)
	}
	err = yaml.Unmarshal(bytes, &c)
	if err != nil {
		Log.Error("err parsing config file: %v\n", err)
		Log.Error("falling back to default values")
	}

	Log = lumber.NewConsoleLogger(lumber.LvlInt(c["log_level"]))
	if c["ssh_listen_address"] != "" {
		SshListenAddress = c["ssh_listen_address"]
	}
	if c["http_listen_address"] != "" {
		HttpListenAddress = c["http_listen_address"]
	}
	if c["key_path"] != "" {
		KeyPath = c["key_path"]
	}
	if c["repo_type"] != "" {
		RepoType = c["repo_type"]
	}
	if c["repo_location"] != "" {
		RepoLocation = c["repo_location"]
	}
	if c["key_auth_type"] != "" {
		KeyAuthType = c["key_auth_type"]
	}
	if c["key_auth_location"] != "" {
		KeyAuthLocation = c["key_auth_location"]
	}
	if c["repo_type"] != "" {
		RepoType = c["repo_type"]
	}
	if c["repo_location"] != "" {
		RepoLocation = c["repo_location"]
	}
	if c["repo_type"] != "" {
		RepoType = c["repo_type"]
	}
	if c["repo_location"] != "" {
		RepoLocation = c["repo_location"]
	}
	if c["repo_type"] != "" {
		RepoType = c["repo_type"]
	}
	if c["repo_location"] != "" {
		RepoLocation = c["repo_location"]
	}
	if c["token"] != "" {
		Token = c["token"]
	}
}
コード例 #14
0
ファイル: main.go プロジェクト: nanopack/pulse
func startPulse(ccmd *cobra.Command, args []string) error {
	// re-initialize logger
	lumber.Level(lumber.LvlInt(viper.GetString("log-level")))

	plex := plexer.NewPlexer()

	if viper.GetString("mist-address") != "" {
		mist, err := mist.New(viper.GetString("mist-address"), viper.GetString("mist-token"))
		if err != nil {
			return fmt.Errorf("Mist failed to start - %s", err.Error())
		}
		plex.AddObserver("mist", mist.Publish)
		defer mist.Close()
	}

	plex.AddBatcher("influx", influx.Insert)

	err := pulse.Listen(viper.GetString("server-listen-address"), plex.Publish)
	if err != nil {
		return fmt.Errorf("Pulse failed to start - %s", err.Error())
	}
	// begin polling the connected servers
	pollSec := viper.GetInt("poll-interval")
	if pollSec == 0 {
		pollSec = 60
	}
	go pulse.StartPolling(nil, nil, time.Duration(pollSec)*time.Second, nil)

	queries := []string{
		"CREATE DATABASE statistics",
		"CREATE RETENTION POLICY one_day ON statistics DURATION 8h REPLICATION 1 DEFAULT",
		fmt.Sprintf("CREATE RETENTION POLICY one_week ON statistics DURATION %dw REPLICATION 1", viper.GetInt("retention")), // todo: ALTER as well?
	}

	for _, query := range queries {
		_, err := influx.Query(query)
		if err != nil {
			return fmt.Errorf("Failed to query influx - %s", err.Error())
		}
	}

	go influx.KeepContinuousQueriesUpToDate()

	if viper.GetString("kapacitor-address") != "" {
		err := kapacitor.Init()
		if err != nil {
			return fmt.Errorf("Kapacitor failed to start - %s", err.Error())
		}
	}

	err = api.Start()
	if err != nil {
		return fmt.Errorf("Api failed to start - %s", err.Error())
	}

	return nil
}
コード例 #15
0
ファイル: cache_test.go プロジェクト: nanopack/shaman
func TestMain(m *testing.M) {
	// manually configure
	// config.Log = lumber.NewConsoleLogger(lumber.LvlInt("trace"))
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	// run tests
	rtn := m.Run()

	os.Exit(rtn)
}
コード例 #16
0
ファイル: shaman_test.go プロジェクト: nanopack/shaman
func TestMain(m *testing.M) {
	shamanClear()
	// manually configure
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	// run tests
	rtn := m.Run()

	os.Exit(rtn)
}
コード例 #17
0
ファイル: dns_test.go プロジェクト: nanopack/shaman
func TestMain(m *testing.M) {
	// manually configure
	config.DnsListen = "127.0.0.1:8053"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	// start dns server
	go server.Start()
	<-time.After(time.Second)

	// run tests
	rtn := m.Run()

	os.Exit(rtn)
}
コード例 #18
0
ファイル: redis_test.go プロジェクト: nanopack/portal
func initialize() {
	rExec, err := exec.Command("redis-server", "-v").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run redis-server - %s%v\n", rExec, err.Error())
		skip = true
	}

	config.RouteHttp = "0.0.0.0:9082"
	config.RouteTls = "0.0.0.0:9445"
	config.LogLevel = "FATAL"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))

	if !skip {
		config.ClusterConnection = "redis://127.0.0.1:6379"
		config.DatabaseConnection = "scribble:///tmp/clusterTest"

		err = database.Init()
		if err != nil {
			fmt.Printf("database init failed - %v\n", err)
			os.Exit(1)
		}

		balance.Balancer = &database.ScribbleDatabase{}
		err = balance.Balancer.Init()
		if err != nil {
			fmt.Printf("balance init failed - %v\n", err)
			os.Exit(1)
		}

		// initialize proxymgr
		err = proxymgr.Init()
		if err != nil {
			fmt.Printf("Proxymgr init failed - %v\n", err)
			os.Exit(1)
		}

		// initialize vipmgr
		err = vipmgr.Init()
		if err != nil {
			fmt.Printf("Vipmgr init failed - %v\n", err)
			os.Exit(1)
		}

		err = cluster.Init()
		if err != nil {
			fmt.Printf("Cluster init failed - %v\n", err)
			os.Exit(1)
		}
	}
}
コード例 #19
0
ファイル: authenticator_test.go プロジェクト: nanopack/logvac
// manually configure and start internals
func initialize() error {
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	config.ListenHttp = "127.0.0.1:3234"
	config.ListenTcp = "127.0.0.1:3235"
	config.ListenUdp = "127.0.0.1:3234"
	config.DbAddress = "boltdb:///tmp/authTest/logvac.bolt"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))

	// initialize logvac
	logvac.Init()

	// setup authenticator
	config.AuthAddress = ""
	err := authenticator.Init()
	if err != nil {
		return fmt.Errorf("Authenticator failed to initialize - %v", err)
	}
	config.AuthAddress = "file:///tmp/authTest/logvac-auth.bolt"
	err = authenticator.Init()
	if err != nil {
		return fmt.Errorf("Authenticator failed to initialize - %v", err)
	}
	config.AuthAddress = "~!@#$%^&*()_"
	err = authenticator.Init()
	if err == nil {
		return fmt.Errorf("Authenticator failed to initialize - %v", err)
	}
	config.AuthAddress = "boltdb:///tmp/authTest/logvac-auth.bolt"
	err = authenticator.Init()
	if err != nil {
		return fmt.Errorf("Authenticator failed to initialize - %v", err)
	}

	// initialize drains
	err = drain.Init()
	if err != nil {
		return fmt.Errorf("Drain failed to initialize - %v", err)
	}

	// initializes collectors
	err = collector.Init()
	if err != nil {
		return fmt.Errorf("Collector failed to initialize - %v", err)
	}

	return nil
}
コード例 #20
0
ファイル: main.go プロジェクト: nanopack/redundis
// startRedundis reads a specified config file, initializes the logger, and starts
// redundis
func startRedundis(ccmd *cobra.Command, args []string) {
	if err := config.ReadConfigFile(configFile); err != nil {
		config.Log.Fatal("Failed to read config - %v", err)
		os.Exit(1)
	}

	// initialize logger
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))
	config.Log.Prefix("[redundis]")

	// initialize redundis
	err := redundis.Start()
	if err != nil {
		config.Log.Fatal("Failed to listen - %v", err)
		os.Exit(1)
	}
}
コード例 #21
0
ファイル: commands_test.go プロジェクト: nanopack/portal
// manually configure and start internals
func initialize() {
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	config.DatabaseConnection = "scribble:///tmp/cliTest"
	config.ClusterConnection = "none://"
	config.ApiHost = "127.0.0.1"
	config.ApiPort = "8445"
	config.ApiToken = ""
	config.RouteHttp = "0.0.0.0:9081"
	config.RouteTls = "0.0.0.0:9444"
	config.LogLevel = "FATAL"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))
	apiAddr = fmt.Sprintf("%v:%v", config.ApiHost, config.ApiPort)

	// initialize database
	err := database.Init()
	if err != nil {
		fmt.Printf("Database init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize balancer
	balance.Balancer = &database.ScribbleDatabase{}
	err = balance.Balancer.Init()
	if err != nil {
		fmt.Printf("Balancer init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize proxymgr
	err = proxymgr.Init()
	if err != nil {
		fmt.Printf("Proxymgr init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize vipmgr
	err = vipmgr.Init()
	if err != nil {
		fmt.Printf("Vipmgr init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize clusterer
	err = cluster.Init()
	if err != nil {
		fmt.Printf("Clusterer init failed - %v\n", err)
		os.Exit(1)
	}
}
コード例 #22
0
ファイル: proxymgr_test.go プロジェクト: nanopack/portal
// initialize proxymgr
func initialize() {
	config.LogLevel = "FATAL"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))

	// bad initialize proxymgr
	config.RouteHttp = "!@#$%^&*"
	err := proxymgr.Init()
	if err == nil {
		fmt.Printf("Proxymgr init succeeded when it should have failed\n")
		os.Exit(1)
	}

	// initialize proxymgr
	config.RouteHttp = "0.0.0.0:9083"
	config.RouteTls = "0.0.0.0:9446"
	err = proxymgr.Init()
	if err != nil {
		fmt.Printf("Proxymgr init failed - %v\n", err)
		os.Exit(1)
	}
}
コード例 #23
0
ファイル: api_test.go プロジェクト: nanopack/hoarder
func TestMain(m *testing.M) {

	// manually configure
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	viper.Set("backend", "file:///tmp/hoarder_test")
	viper.Set("listen-addr", testAddr)
	viper.Set("token", "secret")
	lumber.Level(lumber.LvlInt("fatal"))

	// empty test dir
	os.RemoveAll("/tmp/hoarder_test")
	backends.Initialize()
	// start api
	go api.Start()
	<-time.After(time.Second)
	rtn := m.Run()

	// empty test dir
	os.RemoveAll("/tmp/hoarder_test")

	os.Exit(rtn)
}
コード例 #24
0
ファイル: postgres_test.go プロジェクト: nanopack/portal
// Requires SetService to be run first (initializes database)
func TestSetServicePg(t *testing.T) {
	config.DatabaseConnection = "postgres://[email protected]?sslmode=disable"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	pgbackend = &database.PostgresDb{}
	err := pgbackend.Init()
	if err != nil {
		fmt.Printf("Failed to connect, skipping - %s\n", err.Error())
		pgskip = true
	}

	if pgskip {
		t.SkipNow()
	}

	if err := pgbackend.SetService(&testService1); err != nil {
		t.Errorf("Failed to SET service - %v", err)
	}

	svc, err := pgbackend.GetService("tcp-192_168_0_15-80")
	if err != nil {
		t.Error(err)
	}

	service, err := toJson(svc)
	if err != nil {
		t.Error(err)
	}

	jService, err := toJson(testService1)
	if err != nil {
		t.Error(err)
	}

	if string(service) != string(jService) {
		t.Errorf("Read service differs from written service")
	}
}
コード例 #25
0
ファイル: nginx_test.go プロジェクト: nanopack/portal
////////////////////////////////////////////////////////////////////////////////
// PRIVS
////////////////////////////////////////////////////////////////////////////////
func nginxPrep() bool {
	nginx, err := exec.Command("which", "nginx").CombinedOutput()
	// nginx, err := exec.Command("nginx", "-v").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run nginx - %s%v\n", nginx, err.Error())
		return false
	}

	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	config.Balancer = "nginx"
	config.WorkDir = "/tmp/portal"

	// todo: write config file for tests to /tmp/portal/portal-nginx.conf

	err = balance.Init()
	// skip tests if failed to init
	if err != nil {
		fmt.Printf("Failed to initialize nginx - %s%v\n", nginx, err.Error())
		return false
	}
	return true
}
コード例 #26
0
ファイル: nanobox.go プロジェクト: nanopack/portal
func (self Nanobox) Init() error {
	// we want to see nanobox-router logs
	lumber.Level(lumber.LvlInt(config.LogLevel))

	// configure upstream cert checks
	router.IgnoreUpstreamCerts = config.ProxyIgnore

	// start http proxy
	err := router.StartHTTP(config.RouteHttp)
	if err != nil {
		return err
	}
	config.Log.Info("Proxy listening at http://%s...", config.RouteHttp)

	// start https proxy
	err = router.StartTLS(config.RouteTls)
	if err != nil {
		return err
	}
	config.Log.Info("Proxy listening at https://%s...", config.RouteTls)

	return nil
}
コード例 #27
0
ファイル: api_test.go プロジェクト: nanopack/logvac
// manually configure and start internals
func initialize() {
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	secureHttp = "127.0.0.1:2236"
	insecureHttp = "127.0.0.1:2234"
	config.Insecure = true
	config.ListenHttp = "127.0.0.1:2234"
	config.ListenTcp = "127.0.0.1:2235"
	config.ListenUdp = "127.0.0.1:2234"
	config.DbAddress = "boltdb:///tmp/apiTest/logvac.bolt"
	config.AuthAddress = ""
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))

	// initialize logvac
	logvac.Init()

	// setup authenticator
	err := authenticator.Init()
	if err != nil {
		config.Log.Fatal("Authenticator failed to initialize - %v", err)
		os.Exit(1)
	}

	// initialize drains
	err = drain.Init()
	if err != nil {
		config.Log.Fatal("Drain failed to initialize - %v", err)
		os.Exit(1)
	}

	// initializes collectors
	err = collector.Init()
	if err != nil {
		config.Log.Fatal("Collector failed to initialize - %v", err)
		os.Exit(1)
	}
}
コード例 #28
0
ファイル: main.go プロジェクト: nanopack/pulse
func init() {
	Pulse.Flags().StringP("http-listen-address", "H", httpAddress, "Http listen address")
	viper.BindPFlag("http-listen-address", Pulse.Flags().Lookup("http-listen-address"))
	Pulse.Flags().StringP("server-listen-address", "S", serverAddress, "Server listen address")
	viper.BindPFlag("server-listen-address", Pulse.Flags().Lookup("server-listen-address"))
	Pulse.Flags().StringP("influx-address", "i", influxAddress, "InfluxDB server address")
	viper.BindPFlag("influx-address", Pulse.Flags().Lookup("influx-address"))
	Pulse.Flags().StringP("kapacitor-address", "k", kapacitorAddress, "Kapacitor server address (http://127.0.0.1:9092)")
	viper.BindPFlag("kapacitor-address", Pulse.Flags().Lookup("kapacitor-address"))
	Pulse.Flags().StringP("mist-address", "m", mistAddress, "Mist server address")
	viper.BindPFlag("mist-address", Pulse.Flags().Lookup("mist-address"))
	Pulse.Flags().StringP("mist-token", "M", mistToken, "Mist server token")
	viper.BindPFlag("mist-token", Pulse.Flags().Lookup("mist-token"))
	Pulse.Flags().StringP("log-level", "l", logLevel, "Level at which to log")
	viper.BindPFlag("log-level", Pulse.Flags().Lookup("log-level"))
	Pulse.Flags().StringP("cors-allow", "C", corsAllow, "Sets the 'Access-Control-Allow-Origin' header")
	viper.BindPFlag("cors-allow", Pulse.Flags().Lookup("cors-allow"))
	Pulse.Flags().BoolP("server", "s", server, "Run as server")
	viper.BindPFlag("server", Pulse.Flags().Lookup("server"))
	Pulse.Flags().BoolP("insecure", "I", insecure, "Run insecure")
	viper.BindPFlag("insecure", Pulse.Flags().Lookup("insecure"))

	Pulse.Flags().StringP("token", "t", token, "Security token (recommend placing in config file)")
	viper.BindPFlag("token", Pulse.Flags().Lookup("token"))
	Pulse.Flags().IntP("poll-interval", "p", pollInterval, "Interval to request stats from clients")
	viper.BindPFlag("poll-interval", Pulse.Flags().Lookup("poll-interval"))
	Pulse.Flags().IntP("aggregate-interval", "a", aggregateInterval, "Interval at which stats are aggregated")
	viper.BindPFlag("aggregate-interval", Pulse.Flags().Lookup("aggregate-interval"))
	Pulse.Flags().IntP("retention", "r", retention, "Number of weeks to store aggregated stats")
	viper.BindPFlag("retention", Pulse.Flags().Lookup("retention"))

	Pulse.Flags().StringVarP(&configFile, "config-file", "c", configFile, "Config file location for server")
	Pulse.Flags().BoolVarP(&version, "version", "v", version, "Print version info and exit")

	lumber.Level(lumber.LvlInt(viper.GetString("log-level")))
}
コード例 #29
0
ファイル: main.go プロジェクト: jshawl/mist
func main() {
	configFile := ""
	if len(os.Args) > 1 && !strings.HasPrefix(os.Args[1], "-") {
		configFile = os.Args[1]
	}

	defaults := map[string]string{
		"tcp_listen_address":  "127.0.0.1:1445",
		"http_listen_address": "127.0.0.1:8080",
		"log_level":           "INFO",
		"multicast_interface": "eth1",
		"pg_user":             "******",
		"pg_database":         "postgres",
		"pg_address":          "127.0.0.1:5432",
	}

	config.Load(defaults, configFile)

	level := lumber.LvlInt(config.Config["log_level"])

	mist := mist.New()
	api.Name = "MIST"
	api.Logger = lumber.NewConsoleLogger(level)
	api.User = mist

	user := config.Config["pg_user"]
	database := config.Config["pg_database"]
	address := config.Config["pg_address"]

	pgAuth, err := authenticate.NewPostgresqlAuthenticator(user, database, address)
	if err != nil {
		api.Logger.Fatal("unable to start postgresql authenticator %v", err)
		os.Exit(1)
	}

	authCommands := handlers.GenerateAdditionalCommands(pgAuth)

	listen := config.Config["tcp_listen_address"]
	server, err := mist.Listen(listen, authCommands)

	if err != nil {
		api.Logger.Fatal("unable to start mist tcp listener %v", err)
		os.Exit(1)
	}
	defer server.Close()

	// start discovering other mist nodes on the network
	discover, err := discovery.NewDiscovery(config.Config["multicast_interface"], "mist", time.Second*2)
	if err != nil {
		panic(err)
	}
	defer discover.Close()

	// advertise this nodes listen address
	discover.Add("mist", listen)

	// enable replication between mist nodes
	replicate := handlers.EnableReplication(mist, discover)
	go replicate.Monitor()

	// start up the authenticated websocket connection
	authenticator := authenticate.NewNoopAuthenticator()
	handlers.LoadWebsocketRoute(authenticator)
	api.Start(config.Config["http_listen_address"])
}
コード例 #30
0
ファイル: api.go プロジェクト: nanopack/logvac
// GenerateArchiveEndpoint generates the endpoint for fetching filtered logs
// note: javascript number precision may cause unexpected results (missing logs within 100 nanosecond window)
func GenerateArchiveEndpoint(archive drain.ArchiverDrain) http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		query := req.URL.Query()

		host := query.Get("id")
		tag := query.Get("tag")

		kind := query.Get("type")
		if kind == "" {
			kind = config.LogType // "app"
		}
		start := query.Get("start")
		if start == "" {
			start = "0"
		}
		end := query.Get("end")
		if end == "" {
			end = "0"
		}
		limit := query.Get("limit")
		if limit == "" {
			limit = "100"
		}
		level := query.Get("level")
		if level == "" {
			level = "TRACE"
		}
		config.Log.Trace("type: %v, start: %v, end: %v, limit: %v, level: %v, id: %v, tag: %v", kind, start, end, limit, level, host, tag)
		logLevel := lumber.LvlInt(level)
		realOffset, err := strconv.ParseInt(start, 0, 64)
		if err != nil {
			res.WriteHeader(500)
			res.Write([]byte("bad start offset"))
			return
		}
		realEnd, err := strconv.ParseInt(end, 0, 64)
		if err != nil {
			res.WriteHeader(500)
			res.Write([]byte("bad end value"))
			return
		}
		realLimit, err := strconv.Atoi(limit)
		if err != nil {
			res.WriteHeader(500)
			res.Write([]byte("bad limit"))
			return
		}
		slices, err := archive.Slice(kind, host, tag, realOffset, realEnd, int64(realLimit), logLevel)
		if err != nil {
			res.WriteHeader(500)
			res.Write([]byte(err.Error()))
			return
		}
		body, err := json.Marshal(slices)
		if err != nil {
			res.WriteHeader(500)
			res.Write([]byte(err.Error()))
			return
		}

		res.WriteHeader(200)
		res.Write(append(body, byte('\n')))
	}
}