Skip to content

Commit ad644cc

Browse files
authored
Merge pull request #6 from door7302/2-add-epoch-time-netconf
add epoch code
2 parents f53d836 + 4c5baed commit ad644cc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

plugins/inputs/netconf_junos/netcong.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
)
2222

2323
const maxTagStackDepth = 5
24+
const layout = "2006-01-02 15:04:05 MST"
2425

2526
// Netconf plugin instance
2627
type NETCONF struct {
@@ -322,6 +323,15 @@ func (c *NETCONF) subscribeNETCONF(ctx context.Context, address string, u string
322323
// keep string as type in case of error
323324
v.valueField = value
324325
}
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+
325335
default:
326336
// Keep value as string for all other types
327337
v.valueField = value
@@ -349,7 +359,7 @@ func (c *NETCONF) subscribeNETCONF(ctx context.Context, address string, u string
349359
}
350360
case xml.CharData:
351361
// extract value
352-
value = strings.ReplaceAll(string(element), "\n", "")
362+
value = strings.TrimSpace(strings.ReplaceAll(string(element), "\n", ""))
353363
}
354364

355365
}
@@ -403,7 +413,7 @@ const sampleConfig = `
403413
## A list of xpath lite + type to collect / encode
404414
## Each entry in the list is made of: <xpath>:<type>
405415
## - xpath lite
406-
## - a type of encoding (supported types : int, float, string)
416+
## - a type of encoding (supported types : int, float, string, epoch)
407417
##
408418
## 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
409419
fields = ["/interface-information/physical-interface[ifname]/speed:string",

telegraf.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.0.2

0 commit comments

Comments
 (0)