예제 #1
0
func main() {
	var err error
	if len(os.Args) >= 2 {
		Output, err = os.Create(os.Args[1])
		if err != nil {
			panic(err)
		}
		log.Printf("output to %s", os.Args[1])
	} else {
		Output = os.Stdout
	}
	err = zabbix.RunTrapper("127.0.0.1:10051", handler)
	if err != nil {
		panic(err)
	}
}
예제 #2
0
func TestTrapper(t *testing.T) {
	done = make(chan bool)
	go zabbix.RunTrapper("localhost", func(req zabbix.TrapperRequest) (res zabbix.TrapperResponse, err error) {
		switch req.Request {
		case "timeout":
			log.Println("request timeout sleeping...")
			time.Sleep(timeout + time.Second)
			log.Println("wake up")
		case "shutdown":
			done <- true
		}
		for _, data := range req.Data {
			log.Println(data)
		}
		res.Proceeded = len(req.Data)
		return res, nil
	})
	time.Sleep(1 * time.Second)
}