From b6925593563249321742190e13bd2f98ae150971 Mon Sep 17 00:00:00 2001 From: hardikl Date: Thu, 28 Sep 2023 13:43:27 +0530 Subject: [PATCH] feat: handled dependent labels in plugin --- .../rest/plugins/netroute/netroute.go | 17 ++++++++++------- conf/rest/9.12.0/netroute.yaml | 5 ++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/collectors/rest/plugins/netroute/netroute.go b/cmd/collectors/rest/plugins/netroute/netroute.go index 791f601b4..e5380b237 100644 --- a/cmd/collectors/rest/plugins/netroute/netroute.go +++ b/cmd/collectors/rest/plugins/netroute/netroute.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/tree/node" + "github.com/tidwall/gjson" "strconv" "strings" ) @@ -69,11 +70,13 @@ func (n *NetRoute) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, err for key, instance := range data.GetInstances() { cluster := data.GetGlobalLabels().Get("cluster") routeID := instance.GetLabel("uuid") - interfaceName := instance.GetLabel("interface_name") - interfaceAddress := instance.GetLabel("interface_address") - if interfaceName != "" && interfaceAddress != "" { - names := strings.Split(interfaceName, ",") - address := strings.Split(interfaceAddress, ",") + interfaces := instance.GetLabel("interfaces") + + interfacesList := gjson.Result{Type: gjson.JSON, Raw: interfaces} + names := interfacesList.Get("..#.name").Array() + address := interfacesList.Get("..#.ip.address").Array() + + if names != nil && address != nil { if len(names) == len(address) { for i, name := range names { index := strings.Join([]string{cluster, strconv.Itoa(count)}, "_") @@ -87,8 +90,8 @@ func (n *NetRoute) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, err interfaceInstance.SetLabel(l, instance.GetLabel(l)) } interfaceInstance.SetLabel("index", index) - interfaceInstance.SetLabel("address", address[i]) - interfaceInstance.SetLabel("name", name) + interfaceInstance.SetLabel("address", address[i].String()) + interfaceInstance.SetLabel("name", name.String()) interfaceInstance.SetLabel("route_uuid", routeID) count++ } diff --git a/conf/rest/9.12.0/netroute.yaml b/conf/rest/9.12.0/netroute.yaml index d33f6c22e..8bb02d7bd 100644 --- a/conf/rest/9.12.0/netroute.yaml +++ b/conf/rest/9.12.0/netroute.yaml @@ -8,8 +8,7 @@ counters: - ^destination.family => family - ^destination.netmask => netmask_length - ^gateway => gateway - - ^interfaces.#.ip.address => interface_address # Added in Ontap 9.9 - - ^interfaces.#.name => interface_name # Added in Ontap 9.9 + - ^interfaces => interfaces # Added in Ontap 9.9 - ^ipspace.name => ipspace - ^scope => scope - ^svm.name => svm @@ -17,7 +16,7 @@ counters: - interfaces plugins: - - NetRoute #Creates net_route_interface_labels from interface_name and interface_address metrics collected above + - NetRoute #Creates net_route_interface_labels from interfaces metrics collected above export_options: instance_keys: