From 5e085287ce7c8efaedf05c2ac96e1021ff130dd4 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Wed, 24 Aug 2022 14:20:27 +0530 Subject: [PATCH] feat: Network Port templates Fixes #472 --- cmd/collectors/rest/rest.go | 10 +++++++++- conf/rest/9.12.0/netPort.yaml | 27 +++++++++++++++++++++++++++ conf/rest/default.yaml | 1 + conf/zapi/cdot/9.8.0/netPort.yaml | 28 ++++++++++++++++++++++++++++ conf/zapi/default.yaml | 1 + 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 conf/rest/9.12.0/netPort.yaml create mode 100644 conf/zapi/cdot/9.8.0/netPort.yaml diff --git a/cmd/collectors/rest/rest.go b/cmd/collectors/rest/rest.go index ca3e6196c..ca1daadc7 100644 --- a/cmd/collectors/rest/rest.go +++ b/cmd/collectors/rest/rest.go @@ -17,6 +17,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/tree/node" + "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "os" "sort" @@ -25,6 +26,11 @@ import ( "time" ) +var ( + //ignore missing label warning in log. In Rest, some fields are not present in response when not applicable. + ignoreLabelMissingWarning = []string{"NetPort"} +) + type Rest struct { *collector.AbstractCollector Client *rest.Client @@ -443,7 +449,9 @@ func (r *Rest) HandleResults(result []gjson.Result, prop *prop, allowInstanceCre } count++ } else { - r.Logger.Warn().Str("Instance key", instanceKey).Str("label", label).Msg("Missing label value") + if !util.Contains(ignoreLabelMissingWarning, r.GetObject()) { + r.Logger.Warn().Str("Instance key", instanceKey).Str("label", label).Msg("Missing label value") + } } } diff --git a/conf/rest/9.12.0/netPort.yaml b/conf/rest/9.12.0/netPort.yaml new file mode 100644 index 000000000..3e689af5a --- /dev/null +++ b/conf/rest/9.12.0/netPort.yaml @@ -0,0 +1,27 @@ +name: NetPort +query: api/network/ethernet/ports +object: net_port + +counters: + - ^^name => port + - ^^node.name => node + - ^broadcast_domain.name => broadcast + - ^lag.distribution_policy => lag_distribution_policy + - ^lag.mode => lag_mode + - ^lag.active_ports.name => lag_port + - ^broadcast_domain.ipspace.name => ipspace + - ^enabled => admin_up + - ^state => status + - ^vlan.tag => vlan_id + - ^vlan.base_port.node.name => vlan_node + - ^vlan.base_port.name => vlan_port + - mtu => mtu + - operational-speed => op_speed + +plugins: + LabelAgent: + value_to_num: + - status status up up `0` + +export_options: + include_all_labels: true \ No newline at end of file diff --git a/conf/rest/default.yaml b/conf/rest/default.yaml index 42432e407..785499484 100644 --- a/conf/rest/default.yaml +++ b/conf/rest/default.yaml @@ -13,6 +13,7 @@ objects: # ClusterPeer: clusterpeer.yaml # Disk: disk.yaml # Lun: lun.yaml +# NetPort: netPort.yaml # Node: node.yaml # NtpServer: ntpserver.yaml # Port: port.yaml diff --git a/conf/zapi/cdot/9.8.0/netPort.yaml b/conf/zapi/cdot/9.8.0/netPort.yaml new file mode 100644 index 000000000..94c7945c1 --- /dev/null +++ b/conf/zapi/cdot/9.8.0/netPort.yaml @@ -0,0 +1,28 @@ +name: NetPort +query: net-port-get-iter +object: net_port + +counters: + net-port-info: + - ^^port => port + - ^^node => node + - ^broadcast-domain => broadcast + - ^ifgrp-distribution-function => lag_distribution_policy + - ^ifgrp-mode => lag_mode + - ^ifgrp-port => lag_port + - ^ipspace => ipspace + - ^is-administrative-up => admin_up + - ^link-status => status + - ^vlan-id => vlan_id + - ^vlan-node => vlan_node + - ^vlan-port => vlan_port + - mtu => mtu + - operational-speed => op_speed + +plugins: + LabelAgent: + value_to_num: + - status status up up `0` + +export_options: + include_all_labels: true \ No newline at end of file diff --git a/conf/zapi/default.yaml b/conf/zapi/default.yaml index 0b588c44e..df0577136 100644 --- a/conf/zapi/default.yaml +++ b/conf/zapi/default.yaml @@ -12,6 +12,7 @@ objects: ClusterPeer: clusterpeer.yaml Disk: disk.yaml Lun: lun.yaml +# NetPort: netPort.yaml Node: node.yaml NtpServer: ntpserver.yaml Qtree: qtree.yaml