Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding ha_partner info in node #2723

Merged
merged 9 commits into from
Mar 15, 2024
31 changes: 31 additions & 0 deletions cmd/collectors/rest/plugins/systemnode/systemnode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package systemnode

import (
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/util"
)

type SystemNode struct {
*plugin.AbstractPlugin
}

func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &SystemNode{AbstractPlugin: p}
}

func (s *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
data := dataMap[s.Object]
nodeStateMap := make(map[string]string)

for _, node := range data.GetInstanceKeys() {
nodeStateMap[node] = data.GetInstance(node).GetLabel("healthy")
}

// update node instance with partner_healthy info
for _, node := range data.GetInstances() {
node.SetLabel("partner_healthy", nodeStateMap[node.GetLabel("ha_partner")])
}

return nil, nil, nil
}
3 changes: 3 additions & 0 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/shelf"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/snapmirror"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/svm"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/systemnode"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/volume"
"github.com/netapp/harvest/v2/cmd/collectors/rest/plugins/volumeanalytics"
"github.com/netapp/harvest/v2/cmd/poller/collector"
Expand Down Expand Up @@ -445,6 +446,8 @@ func (r *Rest) LoadPlugin(kind string, abc *plugin.AbstractPlugin) plugin.Plugin
return ontaps3service.New(abc)
case "MetroclusterCheck":
return metroclustercheck.New(abc)
case "SystemNode":
return systemnode.New(abc)
default:
r.Logger.Warn().Str("kind", kind).Msg("no rest plugin found ")
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/collectors/zapi/collector/zapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/shelf"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/snapmirror"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/svm"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/systemnode"
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/volume"
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/conf"
Expand Down Expand Up @@ -171,6 +172,8 @@ func (z *Zapi) LoadPlugin(kind string, abc *plugin.AbstractPlugin) plugin.Plugin
return qospolicyadaptive.New(abc)
case "Aggregate":
return aggregate.New(abc)
case "SystemNode":
return systemnode.New(abc)
default:
z.Logger.Info().Msgf("no zapi plugin found for %s", kind)
}
Expand Down
104 changes: 104 additions & 0 deletions cmd/collectors/zapi/plugins/systemnode/systemnode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package systemnode
Hardikl marked this conversation as resolved.
Show resolved Hide resolved

import (
"github.com/netapp/harvest/v2/cmd/collectors"
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/api/ontapi/zapi"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
"github.com/netapp/harvest/v2/pkg/util"
)

type SystemNode struct {
*plugin.AbstractPlugin
client *zapi.Client
}

func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &SystemNode{AbstractPlugin: p}
}

func (s *SystemNode) Init() error {

var err error

if err = s.InitAbc(); err != nil {
return err
}

if s.client, err = zapi.New(conf.ZapiPoller(s.ParentParams), s.Auth); err != nil {
s.Logger.Error().Stack().Err(err).Msg("connecting")
return err
}

if err = s.client.Init(5); err != nil {
return err
}

return nil
}

func (s *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
data := dataMap[s.Object]
s.client.Metadata.Reset()
nodeStateMap := make(map[string]string)

// invoke system-get-node-info-iter zapi and populate node info
partnerNameMap, err := s.getPartnerNodeInfo()
if err != nil {
s.Logger.Error().Err(err).Msg("Failed to collect partner node detail")
}

for _, node := range data.GetInstanceKeys() {
nodeStateMap[node] = data.GetInstance(node).GetLabel("healthy")
}

// update node instance with partner and partner_healthy info
for nodeName, node := range data.GetInstances() {
node.SetLabel("ha_partner", partnerNameMap[nodeName])
node.SetLabel("partner_healthy", nodeStateMap[node.GetLabel("ha_partner")])
}

// update node metrics with partner info
for _, metric := range data.GetMetrics() {
metric.SetLabel("ha_partner", partnerNameMap[metric.GetLabel("node")])
}
return nil, s.client.Metadata, nil
}

func (s *SystemNode) getPartnerNodeInfo() (map[string]string, error) {
var (
result []*node.Node
nodePartnerNodeMap map[string]string // node-name -> partner-node-name map
err error
)

// system-get-node-info-iter zapi
nodePartnerNodeMap = make(map[string]string)
request := node.NewXMLS("system-get-node-info-iter")
request.NewChildS("max-records", collectors.DefaultBatchSize)

desired := node.NewXMLS("desired-attributes")
systemInfo := node.NewXMLS("system-info")
systemInfo.NewChildS("partner-system-name", "")
systemInfo.NewChildS("system-name", "")
desired.AddChild(systemInfo)
request.AddChild(desired)

if result, err = s.client.InvokeZapiCall(request); err != nil {
return nil, err
}

if len(result) == 0 || result == nil {
s.Logger.Debug().Err(err).Msg("no records found")
return nodePartnerNodeMap, nil
}

for _, objectStore := range result {
partnerName := objectStore.GetChildContentS("partner-system-name")
nodeName := objectStore.GetChildContentS("system-name")
nodePartnerNodeMap[nodeName] = partnerName
}
return nodePartnerNodeMap, nil
}
4 changes: 4 additions & 0 deletions conf/rest/9.12.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ counters:
- ^controller.failed_fan.message.message => failed_fan_message
- ^controller.failed_power_supply.message.message => failed_power_message
- ^controller.over_temperature => over_temperature
- ^ha.partners.0.name => ha_partner
- ^location
- ^model
- ^serial_number => serial
Expand All @@ -31,6 +32,7 @@ endpoints:
- cpu_busy_time => cpu_busytime

plugins:
- SystemNode
- LabelAgent:
value_to_num:
- new_status healthy true up `0`
Expand All @@ -40,6 +42,7 @@ plugins:

export_options:
instance_keys:
- ha_partner
- node
- serial
instance_labels:
Expand All @@ -50,6 +53,7 @@ export_options:
- max_vol_num
- max_vol_size
- model
- partner_healthy
- state
- uptime
- vendor
Expand Down
3 changes: 3 additions & 0 deletions conf/zapi/cdot/9.8.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ counters:
# - sas2-sas3-mixed-stack-support

plugins:
- SystemNode
- LabelAgent:
# metric label zapi_value rest_value `default_value`
value_to_num:
Expand All @@ -51,6 +52,7 @@ plugins:

export_options:
instance_keys:
- ha_partner
- node
- serial
instance_labels:
Expand All @@ -61,6 +63,7 @@ export_options:
- max_vol_num
- max_vol_size
- model
- partner_healthy
- uptime
- vendor
- version
Expand Down
Loading