Пример #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	conn, err := grpc.Dial(*serverAddr, grpc.WithInsecure())
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	defer conn.Close()

	c := lmifeedr.NewLMIFeedrClient(conn)
	{
		stream, err := c.Watch(context.Background(), &lmifeedr.WatchRequest{
			NameMatch: []string{`^SCJ\d+\b`, `-VM\d*\b`},
		})
		if err != nil {
			fmt.Println("Error1: ", err)
		} else {
			defer stream.CloseSend()
			for {
				computer, err := stream.Recv()
				if err == io.EOF {
					log.Println("EOF")
					break
				}
				if err != nil {
					fmt.Println("Error2: ", err)
					break
				} else {
					fmt.Printf("COMPUTER:[%+v]\n", computer)
				}
			}
		}
	}
}
Пример #2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	conn, err := grpc.Dial(*serverAddr, grpc.WithInsecure())
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	defer conn.Close()

	c := lmifeedr.NewLMIFeedrClient(conn)
	{
		computer, err := c.GetComputer(context.Background(), &lmifeedr.ComputerRequest{
			NameMatch: "MUSHROOM",
		})
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("COMPUTER:[%+v]\n", computer)
		}
	}
	{
		computer, err := c.GetComputer(context.Background(), &lmifeedr.ComputerRequest{
			HostID: 1231231234,
		})
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("COMPUTER:[%+v]\n", computer)
		}
	}
	{
		computer, err := c.GetComputer(context.Background(), &lmifeedr.ComputerRequest{
			NameMatch: "FRED",
		})
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("COMPUTER:[%+v]\n", computer)
		}
	}
	{
		computer, err := c.GetComputer(context.Background(), &lmifeedr.ComputerRequest{
			IpMatch: "216.0.0.0/8",
		})
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("COMPUTER:[%+v]\n", computer)
		}
	}
	{
		// this one should fail as malformed.
		computer, err := c.GetComputer(context.Background(), &lmifeedr.ComputerRequest{
			IpMatch: "999/8",
		})
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("COMPUTER:[%+v]\n", computer)
		}
	}
	{
		computer, err := c.GetComputer(context.Background(), &lmifeedr.ComputerRequest{
			IpMatch: "1.2.3.4",
		})
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("COMPUTER:[%+v]\n", computer)
		}
	}
}