Exemple #1
0
func init() {
	printDevices := flag.Bool("devices", false, "Print the list of devices and exit")

	beat.AddFlagsCallback(func(_ *beat.Beat) error {
		if *printDevices == false {
			return nil
		}

		devs, err := sniffer.ListDeviceNames(true)
		if err != nil {
			return fmt.Errorf("Error getting devices list: %v\n", err)
		}
		if len(devs) == 0 {
			fmt.Printf("No devices found.")
			if runtime.GOOS != "windows" {
				fmt.Printf(" You might need sudo?\n")
			} else {
				fmt.Printf("\n")
			}
		}

		for i, dev := range devs {
			fmt.Printf("%d: %s\n", i, dev)
		}
		return beat.GracefulExit
	})
}
Exemple #2
0
// Handle custom command line flags
func (pb *Packetbeat) HandleFlags(b *beat.Beat) {
	// -devices CLI flag
	if *pb.CmdLineArgs.PrintDevices {
		devs, err := sniffer.ListDeviceNames(true)
		if err != nil {
			fmt.Printf("Error getting devices list: %v\n", err)
			os.Exit(1)
		}
		if len(devs) == 0 {
			fmt.Printf("No devices found.")
			if runtime.GOOS != "windows" {
				fmt.Printf(" You might need sudo?\n")
			} else {
				fmt.Printf("\n")
			}
		}
		for i, dev := range devs {
			fmt.Printf("%d: %s\n", i, dev)
		}
		os.Exit(0)
	}
}