@@ -21,28 +21,28 @@ var sysInfoPaths = []*gnmi.Path{
2121 {Name : "host-name" },
2222 },
2323 },
24- {
25- Elem : []* gnmi.PathElem {
26- {Name : "interface" ,
27- Key : map [string ]string {"name" : "mgmt0" },
28- },
29- {Name : "subinterface" },
30- {Name : "ipv4" },
31- {Name : "address" },
32- {Name : "status" },
33- },
34- },
35- {
36- Elem : []* gnmi.PathElem {
37- {Name : "interface" ,
38- Key : map [string ]string {"name" : "mgmt0" },
39- },
40- {Name : "subinterface" },
41- {Name : "ipv6" },
42- {Name : "address" },
43- {Name : "status" },
44- },
45- },
24+ // {
25+ // Elem: []*gnmi.PathElem{
26+ // {Name: "interface",
27+ // Key: map[string]string{"name": "mgmt0"},
28+ // },
29+ // {Name: "subinterface"},
30+ // {Name: "ipv4"},
31+ // {Name: "address"},
32+ // {Name: "status"},
33+ // },
34+ // },
35+ // {
36+ // Elem: []*gnmi.PathElem{
37+ // {Name: "interface",
38+ // Key: map[string]string{"name": "mgmt0"},
39+ // },
40+ // {Name: "subinterface"},
41+ // {Name: "ipv6"},
42+ // {Name: "address"},
43+ // {Name: "status"},
44+ // },
45+ // },
4646 {
4747 Elem : []* gnmi.PathElem {
4848 {Name : "system" },
@@ -61,14 +61,11 @@ var sysInfoPaths = []*gnmi.Path{
6161type systemInfo struct {
6262 Name string
6363 Version string
64- ChassisType string
65- ChassisMacAddress string
66- ChassisCLEICode string
67- ChassisPartNumber string
68- ChassisSerialNumber string
69- //NetworkInstance string
70- IPAddrV4 string
71- IPAddrV6 string
64+ ChassisType string `json:"type,omitempty"`
65+ ChassisMacAddress string `json:"hw-mac-address,omitempty"`
66+ ChassisCLEICode string `json:"clei-code,omitempty"`
67+ ChassisPartNumber string `json:"part-number,omitempty"`
68+ ChassisSerialNumber string `json:"serial-number,omitempty"`
7269}
7370
7471func createGNMIClient (ctx context.Context ) (gnmi.GNMIClient , error ) {
@@ -84,7 +81,10 @@ func createGNMIClient(ctx context.Context) (gnmi.GNMIClient, error) {
8481}
8582
8683func (a * app ) getSystemInfo (ctx context.Context ) (* systemInfo , error ) {
87- ctx = metadata .AppendToOutgoingContext (ctx , "username" , a .config .username , "password" , a .config .password )
84+ ctx = metadata .AppendToOutgoingContext (ctx ,
85+ "username" , a .config .username ,
86+ "password" , a .config .password ,
87+ )
8888 sctx , cancel := context .WithCancel (ctx )
8989 defer cancel ()
9090START:
9494 default :
9595 gnmiClient , err := createGNMIClient (sctx )
9696 if err != nil {
97- log .Infof ("failed to create a gnmi connection to %q: %v" , gnmiServerUnixSocket , err )
97+ log .Errorf ("failed to create a gnmi connection to %q: %v" , gnmiServerUnixSocket , err )
9898 time .Sleep (retryInterval )
9999 goto START
100100 }
@@ -115,16 +115,6 @@ START:
115115 for _ , n := range rsp .GetNotification () {
116116 for _ , u := range n .GetUpdate () {
117117 path := utils .GnmiPathToXPath (u .GetPath (), true )
118- if strings .HasPrefix (path , "interface" ) {
119- if strings .Contains (path , "/ipv4/address/status" ) {
120- ip := getPathKeyVal (u .GetPath (), "address" , "ip-prefix" )
121- sysInfo .IPAddrV4 = strings .Split (ip , "/" )[0 ]
122- }
123- if strings .Contains (path , "/ipv6/address/status" ) {
124- ip := getPathKeyVal (u .GetPath (), "address" , "ip-prefix" )
125- sysInfo .IPAddrV6 = strings .Split (ip , "/" )[0 ]
126- }
127- }
128118 if strings .Contains (path , "system/name" ) {
129119 sysInfo .Name = u .GetVal ().GetStringVal ()
130120 }
@@ -152,12 +142,3 @@ START:
152142 return sysInfo , nil
153143 }
154144}
155-
156- func getPathKeyVal (p * gnmi.Path , elem , key string ) string {
157- for _ , e := range p .GetElem () {
158- if e .Name == elem {
159- return e .Key [key ]
160- }
161- }
162- return ""
163- }
0 commit comments