Esempio n. 1
0
func InitConfig(t *testing.T, conf string) {
	f, err := ioutil.TempFile("", "skydive_agent")
	if err != nil {
		t.Fatal(err.Error())
	}

	var logLevel string
	if testing.Verbose() {
		logLevel = "DEBUG"
	} else {
		logLevel = "INFO"
	}

	conf += fmt.Sprintf("\nlogging:\n  default: %s", logLevel)
	f.WriteString(conf)
	f.Close()

	err = config.InitConfigFromFile(f.Name())
	if err != nil {
		t.Fatal(err.Error())
	}

	err = logging.InitLogger()
	if err != nil {
		t.Fatal(err)
	}
}
Esempio n. 2
0
func InitConfig(t *testing.T, conf string) {
	f, err := ioutil.TempFile("", "skydive_agent")
	if err != nil {
		t.Fatal(err.Error())
	}

	f.WriteString(conf)
	f.Close()

	err = config.InitConfigFromFile(f.Name())
	if err != nil {
		t.Fatal(err.Error())
	}

	err = logging.InitLogger()
	if err != nil {
		t.Fatal(err)
	}
}
Esempio n. 3
0
func InitConfig(t *testing.T, conf string) {
	f, err := ioutil.TempFile("", "skydive_agent")
	if err != nil {
		t.Fatal(err.Error())
	}

	param := struct {
		AnalyzerPort int
		LogLevel     string
	}{
		AnalyzerPort: rand.Intn(400) + 64500,
	}

	if testing.Verbose() {
		param.LogLevel = "DEBUG"
	} else {
		param.LogLevel = "INFO"
	}

	tmpl, err := template.New("config").Parse(conf)
	if err != nil {
		t.Fatal(err.Error())
	}
	buff := bytes.NewBufferString("")
	tmpl.Execute(buff, param)

	f.Write(buff.Bytes())
	f.Close()

	t.Logf("Configuration: %s", buff.String())

	err = config.InitConfigFromFile(f.Name())
	if err != nil {
		t.Fatal(err.Error())
	}

	err = logging.InitLogger()
	if err != nil {
		t.Fatal(err)
	}
}
Esempio n. 4
0
func main() {
	filename := flag.String("conf", "/etc/skydive/skydive.ini",
		"Config file with all the skydive parameter.")
	flag.CommandLine.Usage = usage
	flag.Parse()

	err := config.InitConfigFromFile(*filename)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}

	logging.GetLogger().Notice("Skydive Analyzer starting...")

	router := mux.NewRouter().StrictSlash(true)

	server, err := analyzer.NewServerFromConfig(router)
	if err != nil {
		logging.GetLogger().Fatalf("Can't start Analyzer : %v", err)
	}

	storage, err := elasticseach.New()
	if err != nil {
		logging.GetLogger().Fatalf("Can't connect to ElasticSearch server : %v", err)
	}
	server.SetStorage(storage)

	logging.GetLogger().Notice("Skydive Analyzer started !")
	go server.ListenAndServe()

	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
	<-ch

	server.Stop()

	logging.GetLogger().Notice("Skydive Analyzer stopped.")
}
Esempio n. 5
0
func main() {
	filename := flag.String("conf", "/etc/skydive/skydive.ini",
		"Config file with all the skydive parameter.")
	flag.CommandLine.Usage = usage
	flag.Parse()

	err := config.InitConfigFromFile(*filename)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}

	logging.GetLogger().Notice("Skydive Agent starting...")
	agent := agent.NewAgent()
	agent.Start()

	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
	<-ch

	agent.Stop()

	logging.GetLogger().Notice("Skydive Agent stopped.")
}
Esempio n. 6
0
	"github.com/redhat-cip/skydive/config"
	"github.com/redhat-cip/skydive/version"

	"github.com/spf13/cobra"
)

var showVersion bool
var cfgFile string

var rootCmd = &cobra.Command{
	Use:          "skydive [sub]",
	Short:        "Skydive",
	SilenceUsage: true,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		if cfgFile != "" {
			err := config.InitConfigFromFile(cfgFile)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%v\n", err)
				os.Exit(1)
			}
		}
	},
}

var versionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version number of Skydive",
	Run: func(cmd *cobra.Command, args []string) {
		version.PrintVersion()
	},
}