Exemple #1
0
func main() {
	// GET
	uri := `snmp://[email protected]//(1.3.6.1.2.1.1.1.0,1.3.6.1.2.1.1.2.0)`

	// WALK:
	// uri := `snmp://[email protected]//1.3.6.1.2.1.*`

	// NEXT:
	// uri := `snmp://[email protected]//1.3.6.1.2.1+`

	results, err := gsnmpgo.Query(uri, gsnmpgo.GNET_SNMP_V2C)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	gsnmpgo.Dump(results)

	for _, result := range results {
		switch result.Value.(type) {
		case gsnmpgo.VBT_OctetString:
			fmt.Printf("result is a an octet string: %s\n", result)
		default:
			fmt.Println("result is some other type")
		}
	}

	for _, result := range results {
		fmt.Printf("OID %s as a number: %d\n", result.Oid, result.Value.Integer())
		fmt.Printf("OID %s as a string: %s\n", result.Oid, result.Value)
	}
}
Exemple #2
0
func main() {
	gsnmpgo.Debug = true

	// GET
	// uri := `snmp://[email protected]//(1.3.6.1.2.1.1.1.0,1.3.6.1.2.1.1.2.0)`

	// WALK:
	// uri := `snmp://[email protected]//1.3.6.1.*`

	// NEXT:
	// uri := `snmp://[email protected]//1.3.6.1.2.1+`

	// Verax GET - string, oid, timeticks
	uri := `snmp://[email protected]:161//(1.3.6.1.2.1.1.1.0,1.3.6.1.2.1.1.2.0,1.3.6.1.2.1.1.3.0)`

	// Verax NEXT:
	// uri := `snmp://[email protected]:161//(1.3.6.1.2.1.1.1.0)+`

	// Verax WALK
	// uri := `snmp://[email protected]:161//1.3.6.1.*`

	params := gsnmpgo.NewDefaultParams(uri)
	results, err := gsnmpgo.Query(params)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	gsnmpgo.Dump(results)
	fmt.Println()

	ch := results.IterAscend()
	for {
		r := <-ch
		if r == nil {
			break
		}
		result := r.(gsnmpgo.QueryResult)
		switch result.Value.(type) {
		case gsnmpgo.VBT_OctetString:
			fmt.Printf("OID %s is an octet string: %s\n", result.Oid, result.Value)
		default:
			fmt.Printf("OID %s is some other type\n", result.Oid)
		}
	}
	fmt.Println()

	ch2 := results.IterAscend()
	for {
		r := <-ch2
		if r == nil {
			break
		}
		result := r.(gsnmpgo.QueryResult)
		fmt.Printf("OID %s type: %T\n", result.Oid, result.Value)
		fmt.Printf("OID %s as a number: %d\n", result.Oid, result.Value.Integer())
		fmt.Printf("OID %s as a string: %s\n\n", result.Oid, result.Value)
	}
}