Exemplo n.º 1
0
func main() {
	var useUDP bool
	var port int
	flag.BoolVar(&useUDP, "u", false, "use UDP instead of TCP")
	flag.IntVar(&port, "p", 9090, "port number to bind to")
	flag.Parse()

	var srv *lineserver.LineServer
	var err error
	addr := fmt.Sprintf(":%d", port)
	proto := "tcp"
	if useUDP {
		proto = "udp"
	}

	if useUDP {
		srv, err = lineserver.NewLineServerUDP(addr)
	} else {
		srv, err = lineserver.NewLineServerTCP(addr)
	}

	if err != nil {
		log.Fatal(err)
	}

	log.Infof("Server running as %s://%s", proto, addr)
	go srv.Start()

	for line := range srv.Ch {
		fmt.Println(line)
	}
}
Exemplo n.º 2
0
func createLogyardConfig() {
	g, err := server.NewConfig("logyard", logyardConfig{})
	if err != nil {
		log.Fatalf("Unable to load logyard config; %v", err)
	}
	config = g
	if config.GetConfig().(*logyardConfig).Drains == nil {
		log.Fatal("Logyard configuration is missing")
	}
}
Exemplo n.º 3
0
func (cmd *recv) Run(args []string) (string, error) {
	if cmd.json {
		return "", fmt.Errorf("--json not supported by this subcommand")
	}
	sub := logyard.Broker.Subscribe(cmd.filter)
	for msg := range sub.Ch {
		if cmd.hideprefix {
			fmt.Println(msg.Value)
		} else {
			fmt.Println(msg.Key, msg.Value)
		}
	}
	err := sub.Wait()
	if err != nil {
		log.Fatal(err)
	}
	return "", nil
}
Exemplo n.º 4
0
func main() {
	major, minor, patch := gozmq.Version()
	log.Infof("Starting logyard (Go %s; ZeroMQ %d.%d.%d)",
		runtime.Version(), major, minor, patch)

	m := drain.NewDrainManager()
	log.Info("Starting drain manager")
	go m.Run()
	// SIGTERM handle for stopping running drains.
	go func() {
		sigchan := make(chan os.Signal)
		signal.Notify(sigchan, syscall.SIGTERM)
		<-sigchan
		log.Info("Stopping all drains before exiting")
		m.Stop()
		log.Info("Exiting now.")
		os.Exit(0)
	}()

	server.MarkRunning("logyard")

	log.Info("Running pubsub broker")
	log.Fatal(logyard.Broker.Run())
}
Exemplo n.º 5
0
func (cmd *stream) Run(args []string) (string, error) {
	ipaddr, err := server.LocalIP()
	if err != nil {
		return "", err
	}

	rand.Seed(time.Now().UnixNano())
	port := 7000 + rand.Intn(1000)
	addr := fmt.Sprintf("%s:%d", ipaddr, port)

	srv, err := lineserver.NewLineServer(CLI_STREAM_PROTO, addr)
	if err != nil {
		return "", err
	}
	go srv.Start()

	// Debug mode allows one to debug just the logyard related logs,
	// without any magical stripping.
	debugMode := false
	if len(args) == 1 && args[0] == "debug" {
		debugMode = true
		args = []string{
			"systail.logyard",
			"systail.apptail",
			"systail.logyard_sieve",
			"systail.systail",
		}
	}

	name := fmt.Sprintf("tmp.logyard-cli.%s-%d", ipaddr, port)

	uri, err := drain.ConstructDrainURI(
		name,
		fmt.Sprintf("%s://%s", CLI_STREAM_PROTO, addr),
		args,
		map[string]string{"format": "raw"})
	if err != nil {
		return "", err
	}
	if err = logyard.AddDrain(name, uri); err != nil {
		return "", err
	}
	log.Infof("Added drain %s", uri)

	deleteDrain := func() {
		if err := logyard.DeleteDrain(name); err != nil {
			log.Fatal(err)
		}
		fmt.Println("")
		log.Infof("Deleted drain %s", name)
	}
	defer deleteDrain()

	handleKeyboardInterrupt(func() {
		deleteDrain()
		os.Exit(1)
	})

	cli_stream.Stream(srv.Ch, cli_stream.MessagePrinterOptions{
		cmd.raw, cmd.raw || debugMode, cmd.time, cmd.nocolor, cmd.nodeid, cmd.json})

	return "", nil
}
Exemplo n.º 6
0
func main() {
	srv := subcommand_server.Server{
		commands.GetAll()}
	server.MarkRunning("logyard_remote")
	log.Fatal(srv.Start("127.0.0.1:8891"))
}