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
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
99 changes: 99 additions & 0 deletions cmd/collectors/zapi/plugins/systemnode/systemnode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package systemnode

import (
"errors"
"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/errs"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
)

type SystemNode struct {
*plugin.AbstractPlugin
client *zapi.Client
partnerNameMap map[string]string // node-name -> partner name map
}

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

func (a *SystemNode) Init() error {

var err error

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

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

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

a.partnerNameMap = make(map[string]string)
return nil
}

func (a *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) {
data := dataMap[a.Object]

// invoke system-get-node-info-iter zapi and populate node info
if err := a.getPartnerNodeInfo(); err != nil {
if errors.Is(err, errs.ErrNoInstance) {
a.Logger.Debug().Err(err).Msg("Failed to collect cloud store data")
}
}

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

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

func (a *SystemNode) getPartnerNodeInfo() error {
var (
result []*node.Node
err error
)

// system-get-node-info-iter zapi
a.partnerNameMap = 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 = a.client.InvokeZapiCall(request); err != nil {
return err
}

if len(result) == 0 || result == nil {
return errs.New(errs.ErrNoInstance, "no records found")
}

for _, objectStore := range result {
partnerName := objectStore.GetChildContentS("partner-system-name")
nodeName := objectStore.GetChildContentS("system-name")
a.partnerNameMap[nodeName] = partnerName
}
return nil
}
2 changes: 2 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 Down Expand Up @@ -40,6 +41,7 @@ plugins:

export_options:
instance_keys:
- ha_partner
- node
- serial
instance_labels:
Expand Down
2 changes: 2 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 Down
Loading