Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into hl_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Nov 12, 2024
2 parents f3dd31f + e19d978 commit 04a303f
Show file tree
Hide file tree
Showing 116 changed files with 1,320 additions and 416 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linters:
- gosec
- gosimple
- govet
- iface
- ineffassign
- intrange
- makezero
Expand All @@ -32,6 +33,7 @@ linters:
- perfsprint
- prealloc
- reassign
- recvcheck
- revive
- sloglint
- staticcheck
Expand Down
2 changes: 1 addition & 1 deletion cmd/collectors/ems/ems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewEms() *Ems {
opts.HomePath = homePath
opts.IsTest = true

ac := collector.New("Ems", "Ems", opts, emsParams(emsConfigPath), nil)
ac := collector.New("Ems", "Ems", opts, emsParams(emsConfigPath), nil, conf.Remote{})
e := &Ems{}
if err := e.Init(ac); err != nil {
slog.Error("", slogx.Err(err))
Expand Down
2 changes: 0 additions & 2 deletions cmd/collectors/keyperf/keyperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func (kp *KeyPerf) Init(a *collector.AbstractCollector) error {
return err
}

kp.Remote = kp.Client.Remote()

if kp.Prop.TemplatePath, err = kp.LoadTemplate(); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/collectors/keyperf/keyperf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func newKeyPerf(object string, path string) *KeyPerf {
opts.HomePath = "testdata"
opts.IsTest = true

ac := collector.New("KeyPerf", object, opts, params(object, path), nil)
ac := collector.New("KeyPerf", object, opts, params(object, path), nil, conf.Remote{})
kp := KeyPerf{}
err = kp.Init(ac)
if err != nil {
Expand Down
103 changes: 103 additions & 0 deletions cmd/collectors/ontap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package collectors

import (
"errors"
"github.com/netapp/harvest/v2/cmd/tools/rest"
"github.com/netapp/harvest/v2/pkg/api/ontapi/zapi"
"github.com/netapp/harvest/v2/pkg/auth"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/errs"
"net/http"
"time"
)

func GatherClusterInfo(pollerName string, cred *auth.Credentials) (conf.Remote, error) {

var (
err error
)

remoteZapi, err := checkZapi(pollerName, cred)
if err != nil {
return conf.Remote{}, err
}

remoteRest, err := checkRest(pollerName, cred)
if err != nil {
return remoteZapi, err
}

remoteRest.ZAPIsExist = remoteZapi.ZAPIsExist

return remoteRest, nil
}

func checkRest(pollerName string, cred *auth.Credentials) (conf.Remote, error) {

var (
poller *conf.Poller
client *rest.Client
err error
)

// connect to the cluster
if poller, err = conf.PollerNamed(pollerName); err != nil {
return conf.Remote{}, err
}

timeout, _ := time.ParseDuration(rest.DefaultTimeout)
client, err = rest.New(poller, timeout, cred)
if err != nil {
return conf.Remote{}, err
}

if err := client.Init(5, conf.Remote{}); err != nil {
return conf.Remote{}, err
}

return client.Remote(), nil
}

func checkZapi(pollerName string, cred *auth.Credentials) (conf.Remote, error) {

var (
poller *conf.Poller
client *zapi.Client
err error
zapisExist bool
)

// connect to the cluster and retrieve the system version
if poller, err = conf.PollerNamed(pollerName); err != nil {
return conf.Remote{}, err
}
if client, err = zapi.New(poller, cred); err != nil {
return conf.Remote{}, err
}

zapisExist = true
err = client.Init(2, conf.Remote{})

if err != nil {

returnErr := true

var he errs.HarvestError
if errors.As(err, &he) {
switch {
case he.ErrNum == errs.ErrNumZAPISuspended, he.StatusCode == http.StatusBadRequest:
zapisExist = false
returnErr = false
}
}

if returnErr {
return conf.Remote{}, err
}
}

remote := client.Remote()
remote.ZAPIsExist = zapisExist

return remote, nil
}
4 changes: 2 additions & 2 deletions cmd/collectors/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ type Sensor struct {
hasREST bool
}

func (s *Sensor) Init() error {
func (s *Sensor) Init(remote conf.Remote) error {

var err error
if err := s.InitAbc(); err != nil {
Expand All @@ -455,7 +455,7 @@ func (s *Sensor) Init() error {

s.hasREST = true

if err := s.client.Init(5); err != nil {
if err := s.client.Init(5, remote); err != nil {
var re *errs.RestError
if errors.As(err, &re) && re.StatusCode == http.StatusNotFound {
s.SLogger.Warn("Cluster does not support REST. Power plugin disabled")
Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/plugins/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &Aggregate{AbstractPlugin: p}
}

func (a *Aggregate) Init() error {
func (a *Aggregate) Init(remote conf.Remote) error {
if err := a.InitAbc(); err != nil {
return fmt.Errorf("failed to initialize AbstractPlugin: %w", err)
}
Expand All @@ -48,7 +48,7 @@ func (a *Aggregate) Init() error {
}
a.client = client

if err := a.client.Init(5); err != nil {
if err := a.client.Init(5, remote); err != nil {
return fmt.Errorf("failed to initialize REST client: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/plugins/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &Certificate{AbstractPlugin: p}
}

func (c *Certificate) Init() error {
func (c *Certificate) Init(remote conf.Remote) error {

var err error

Expand All @@ -44,7 +44,7 @@ func (c *Certificate) Init() error {
return err
}

if err := c.client.Init(5); err != nil {
if err := c.client.Init(5, remote); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/plugins/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var metrics = []string{
"alerts",
}

func (h *Health) Init() error {
func (h *Health) Init(remote conf.Remote) error {

var err error

Expand Down Expand Up @@ -89,7 +89,7 @@ func (h *Health) Init() error {
return err
}

return h.client.Init(5)
return h.client.Init(5, remote)
}

func (h *Health) InitAllMatrix() error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metroclustercheck

import (
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/slogx"
"github.com/netapp/harvest/v2/pkg/tree/node"
Expand All @@ -19,7 +20,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &MetroclusterCheck{AbstractPlugin: p}
}

func (m *MetroclusterCheck) Init() error {
func (m *MetroclusterCheck) Init(conf.Remote) error {

pluginMetrics := []string{"cluster_status", "node_status", "aggr_status", "volume_status"}
pluginLabels := []string{"result", "name", "node", "aggregate", "volume"}
Expand Down
3 changes: 2 additions & 1 deletion cmd/collectors/rest/plugins/netroute/netroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package netroute

import (
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/slogx"
"github.com/netapp/harvest/v2/pkg/tree/node"
Expand Down Expand Up @@ -35,7 +36,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &NetRoute{AbstractPlugin: p}
}

func (n *NetRoute) Init() error {
func (n *NetRoute) Init(conf.Remote) error {

if err := n.InitAbc(); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &OntapS3Service{AbstractPlugin: p}
}

func (o *OntapS3Service) Init() error {
func (o *OntapS3Service) Init(remote conf.Remote) error {
var err error

if err := o.InitAbc(); err != nil {
Expand All @@ -49,7 +49,7 @@ func (o *OntapS3Service) Init() error {
return err
}

if err := o.client.Init(5); err != nil {
if err := o.client.Init(5, remote); err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/collectors/rest/plugins/quota/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package quota

import (
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/slogx"
"github.com/netapp/harvest/v2/pkg/util"
Expand All @@ -17,7 +18,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &Quota{AbstractPlugin: p}
}

func (q *Quota) Init() error {
func (q *Quota) Init(conf.Remote) error {
if err := q.InitAbc(); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &SecurityAccount{AbstractPlugin: p}
}

func (s *SecurityAccount) Init() error {
func (s *SecurityAccount) Init(remote conf.Remote) error {
var err error

if err := s.InitAbc(); err != nil {
Expand All @@ -47,7 +47,7 @@ func (s *SecurityAccount) Init() error {
return fmt.Errorf("failed to connect err=%w", err)
}

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

Expand Down
3 changes: 2 additions & 1 deletion cmd/collectors/rest/plugins/shelf/shelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package shelf
import (
"github.com/netapp/harvest/v2/cmd/collectors"
"github.com/netapp/harvest/v2/cmd/poller/plugin"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/util"
)
Expand All @@ -16,7 +17,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &Shelf{AbstractPlugin: p}
}

func (my *Shelf) Init() error {
func (my *Shelf) Init(conf.Remote) error {
return my.InitAbc()
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/plugins/snapmirror/snapmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &SnapMirror{AbstractPlugin: p}
}

func (m *SnapMirror) Init() error {
func (m *SnapMirror) Init(remote conf.Remote) error {

var err error

Expand All @@ -54,7 +54,7 @@ func (m *SnapMirror) Init() error {
return err
}

if err := m.client.Init(5); err != nil {
if err := m.client.Init(5, remote); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/plugins/svm/svm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func New(p *plugin.AbstractPlugin) plugin.Plugin {
return &SVM{AbstractPlugin: p}
}

func (s *SVM) Init() error {
func (s *SVM) Init(remote conf.Remote) error {

var err error

Expand All @@ -62,7 +62,7 @@ func (s *SVM) Init() error {
return err
}

if err := s.client.Init(5); err != nil {
if err := s.client.Init(5, remote); err != nil {
return err
}
s.nsswitchInfo = make(map[string]Nsswitch)
Expand Down
Loading

0 comments on commit 04a303f

Please sign in to comment.