@@ -21,6 +21,7 @@ import (
21
21
)
22
22
23
23
const maxTagStackDepth = 5
24
+ const layout = "2006-01-02 15:04:05 MST"
24
25
25
26
// Netconf plugin instance
26
27
type NETCONF struct {
@@ -322,6 +323,15 @@ func (c *NETCONF) subscribeNETCONF(ctx context.Context, address string, u string
322
323
// keep string as type in case of error
323
324
v .valueField = value
324
325
}
326
+ case "epoch" :
327
+ t , err := time .Parse (layout , value )
328
+ if err != nil {
329
+ // keep string as type in case of error
330
+ v .valueField = value
331
+ } else {
332
+ v .valueField = t .UnixNano ()
333
+ }
334
+
325
335
default :
326
336
// Keep value as string for all other types
327
337
v .valueField = value
@@ -349,7 +359,7 @@ func (c *NETCONF) subscribeNETCONF(ctx context.Context, address string, u string
349
359
}
350
360
case xml.CharData :
351
361
// extract value
352
- value = strings .ReplaceAll (string (element ), "\n " , "" )
362
+ value = strings .TrimSpace ( strings . ReplaceAll (string (element ), "\n " , "" ) )
353
363
}
354
364
355
365
}
@@ -403,7 +413,7 @@ const sampleConfig = `
403
413
## A list of xpath lite + type to collect / encode
404
414
## Each entry in the list is made of: <xpath>:<type>
405
415
## - xpath lite
406
- ## - a type of encoding (supported types : int, float, string)
416
+ ## - a type of encoding (supported types : int, float, string, epoch )
407
417
##
408
418
## The xpath lite should follow the rpc reply XML document. Optional: you can include btw [] the KEY's name that must use to detect the loop
409
419
fields = ["/interface-information/physical-interface[ifname]/speed:string",
0 commit comments