示例#1
0
文件: testing.go 项目: soniah/gsnmpgo
func CompareVerax(t *testing.T, gresults, vresults *llrb.Tree) {
	ch := gresults.IterAscend()
	for {
		gr := <-ch
		if gr == nil {
			break
		}
		goresult := gr.(QueryResult)
		vstruct := QueryResult{Oid: goresult.Oid}
		vr := vresults.Get(vstruct)
		if vr == nil {
			continue
		}
		vresult := vr.(QueryResult)

		vstring := vresult.Value.String()
		gostring := goresult.Value.String()
		fmt.Printf("verax  : %s\ngsnmpgo: %s\n\n", vstring, gostring)
		if gostring != vstring {
			// fmt.Printf("OK oid: %s type: %T value: %s\n", goresult.Oid, goresult.Value, gostring)
			if len(gostring) > 4 && gostring[0:5] == "07 DA" {
				// skip - weird Verax stuff
			} else if len(vstring) > 4 && vstring[0:5] == "4E:85" {
				// skip - weird Verax stuff
			} else if len(vstring) > 17 && vstring[0:18] == "Cisco IOS Software" {
				// skip - \n's have been stripped - ignore
			} else {
				t.Errorf("compare fail: oid: %s type: %T\ngostring: |%s|\nvstring : |%s|",
					goresult.Oid, goresult.Value, gostring, vstring)
			}
		}
	}
}
示例#2
0
文件: gsnmpgo.go 项目: soniah/gsnmpgo
// Dump is a convenience function for printing the results of a Query.
func Dump(results *llrb.Tree) {
	if results == nil {
		fmt.Println("Dump: results are NIL")
		return
	}
	fmt.Println("Dump:")
	ch := results.IterAscend()
	for {
		r := <-ch
		if r == nil {
			break
		}
		result := r.(QueryResult)
		fmt.Printf("oid, type: %s, %T\n", result.Oid, result.Value)
		fmt.Printf("INTEGER: %d\n", result.Value.Integer())
		fmt.Printf("STRING : %s\n", result.Value)
		fmt.Println()
	}
}
示例#3
0
func TestQueryGets(t *testing.T) {
	for i, test := range veraxDevices {
		var err error

		var vresults *llrb.Tree
		if vresults, err = ReadVeraxResults(test.path); err != nil {
			t.Errorf("#%d, %s: ReadVeraxResults error: %s", i, test.path, err)
		}

		var counter int
		var uri, oids string
		gresults := llrb.New(LessOID)
		ch := vresults.IterAscend()
		for {
			r := <-ch
			if r == nil {
				break
			}
			counter += 1
			if counter <= 3 { // TODO random number of oids, not hardcoded n
				oid := r.(QueryResult)
				oids += "," + oid.Oid
			} else {
				uri = `snmp://[email protected]:` + strconv.Itoa(test.port) + "//(" + oids[1:] + ")"
				counter = 0 // reset
				oids = ""   // reset

				params := &QueryParams{
					Uri:     uri,
					Version: GNET_SNMP_V2C,
					Timeout: 200,
					Retries: 5,
					Tree:    gresults,
				}
				if _, err := Query(params); err != nil {
					t.Errorf("Query error: %s. Uri: %s", err, uri)
				}
			}
		}
		CompareVerax(t, gresults, vresults)
	}
}