Example #1
0
func main() {
	rb := snmp.Connect("10.0.1.250", "public")
	iface, err := rb.FindInterfaceByName("UPSTREAM")
	if err != nil {
		log.Fatalf("ERROR: %v", err)
	}
	sampleChannel := iface.MonitorBandwidth(time.Second * 5)
	for sample := range sampleChannel {
		log.Printf("%s tx/rx %s/%s",
			iface.FullName(),
			sample.TX().BitsString(),
			sample.RX().BitsString(),
		)
	}
}
Example #2
0
// Reads the configuration, inits objects, and returns the AppConfig
func parseConfig() *AppConfig {
	var (
		host, community string
	)
	cfg := new(AppConfig)

	var isVersion bool = false

	cfg.action = monitorBandwidth
	flag.StringVar(&host, "h", "127.0.0.7", "Mikrotik IP")
	flag.StringVar(&community, "c", "public", "SNMP Community Name")

	flag.DurationVar(&cfg.SampleInterval, "s", time.Second, "Sample Interval")
	flag.StringVar(&cfg.InterfaceName, "i", "ether1", "Mikrotik Interface Name")

	// Non operational flags
	flag.BoolVar(&cfg.dumpInterfaces, "list", false, "Lists all known interfaces and exits")
	flag.BoolVar(&isVersion, "v", false, "Report version and exit")
	flag.Parse()

	if isVersion {
		cfg.action = printVersion
		return cfg
	}

	cfg.Routerboard = snmp.Connect(host, community)

	// Print RB banner (so it is on all output)
	banner, err := cfg.Routerboard.GetSystemBanner()
	if err != nil {
		log.Fatalf("ERROR: %v", err)
	}
	log.Println("Connected to", banner)

	// Now check non-operational status

	if cfg.dumpInterfaces {
		cfg.action = printInterfaces
	}

	return cfg
}