-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (39 loc) · 976 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"context"
"fmt"
"github.com/aristanetworks/glog"
"github.com/aristanetworks/goarista/gnmi"
pb "github.com/openconfig/gnmi/proto/gnmi"
)
var cfg = &gnmi.Config{
Addr: "192.168.100.172:5901",
Username: "admin",
Password: "admin",
}
func main() {
paths := []string{"/interfaces/interface[name=Ethernet2]/state"}
var origin = "openconfig"
//var origin = "eos_native"
ctx := gnmi.NewContext(context.Background(), cfg)
client, err := gnmi.Dial(cfg)
if err != nil {
glog.Fatal(err)
}
req, err := gnmi.NewGetRequest(gnmi.SplitPaths(paths), origin)
if err != nil {
glog.Fatal(err)
}
if cfg.Addr != "" {
if req.Prefix == nil {
req.Prefix = &pb.Path{}
}
req.Prefix.Target = cfg.Addr
}
fmt.Println(req)
err = gnmi.GetWithRequest(ctx, client, req)
if err != nil {
glog.Fatal(err)
fmt.Println(err)
}
}