Skip to content

Commit

Permalink
feat: handled review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Dec 18, 2024
1 parent b6b90e7 commit b67d9c0
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 64 deletions.
21 changes: 13 additions & 8 deletions cmd/collectors/rest/plugins/snapshotpolicy/snapshotpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/util"
"github.com/netapp/harvest/v2/third_party/tidwall/gjson"
"strconv"
"strings"
)
Expand All @@ -25,15 +26,19 @@ func (m *SnapshotPolicy) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri
data := dataMap[m.Object]

for _, instance := range data.GetInstances() {
copies := strings.Split(instance.GetLabel("copies"), ",")
if len(copies) > 1 {
var copiesValue int
for _, c := range copies {
val, _ := strconv.Atoi(c)
copiesValue += val
}
instance.SetLabel("copies", strconv.Itoa(copiesValue))
copies := instance.GetLabel("copies")
copiesJSON := gjson.Result{Type: gjson.JSON, Raw: "[" + copies + "]"}
var scheduleVal string
var copiesValue int
for _, copiesData := range copiesJSON.Array() {
count := copiesData.Get("count").String()
countVal, _ := strconv.Atoi(count)
schedule := copiesData.Get("schedule.name").ClonedString()
scheduleVal = scheduleVal + schedule + ":" + count + ","
copiesValue += countVal
}
instance.SetLabel("schedules", strings.TrimSuffix(scheduleVal, ","))
instance.SetLabel("copies", strconv.Itoa(copiesValue))
}

return nil, nil, nil
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 @@ -15,6 +15,7 @@ import (
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/security"
"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/snapshotpolicy"
"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"
Expand Down Expand Up @@ -148,6 +149,8 @@ func (z *Zapi) LoadPlugin(kind string, abc *plugin.AbstractPlugin) plugin.Plugin
switch kind {
case "Snapmirror":
return snapmirror.New(abc)
case "SnapshotPolicy":
return snapshotpolicy.New(abc)
case "Shelf":
return shelf.New(abc)
case "Qtree":
Expand Down
46 changes: 46 additions & 0 deletions cmd/collectors/zapi/plugins/snapshotpolicy/snapshotpolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright NetApp Inc, 2024 All rights reserved
*/

package snapshotpolicy

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

type SnapshotPolicy struct {
*plugin.AbstractPlugin
}

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

func (m *SnapshotPolicy) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) {
// Purge and reset data
data := dataMap[m.Object]

for _, instance := range data.GetInstances() {
copies := strings.Split(instance.GetLabel("copies"), ",")
schedules := strings.Split(instance.GetLabel("schedules"), ",")

var scheduleVal string
var copiesValue int
if len(copies) > 1 {
for index, copiesData := range copies {
countVal, _ := strconv.Atoi(copiesData)
schedule := schedules[index]
scheduleVal = scheduleVal + schedule + ":" + copiesData + ","
copiesValue += countVal
}
instance.SetLabel("schedules", strings.TrimSuffix(scheduleVal, ","))
instance.SetLabel("copies", strconv.Itoa(copiesValue))
}
}

return nil, nil, nil
}
3 changes: 0 additions & 3 deletions cmd/tools/generate/counter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,6 @@ counters:
- Name: snapmirror_update_successful_count
Description: Number of Successful Updates

- Name: snapshot_policy_total_schedules
Description: Total Number of Schedules in this Policy

- Name: svm_nfs_read_throughput
APIs:
- API: REST
Expand Down
3 changes: 1 addition & 2 deletions conf/rest/9.12.0/snapshotpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ object: snapshot_policy
counters:
- ^^uuid => uuid
- ^comment => comment
- ^copies.#.count => copies
- ^copies => copies
- ^enabled => status
- ^name => snapshot_policy
- ^schedules => schedules
- ^scope => scope
- ^svm.name => svm

Expand Down
27 changes: 21 additions & 6 deletions conf/zapi/cdot/9.8.0/snapshotpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@ name: SnapshotPolicy
query: snapshot-policy-get-iter
object: snapshot_policy


counters:
snapshot-policy-info:
- ^^policy => snapshot_policy
- ^^vserver-name => svm
- ^comment => comment
- total-schedules => total_schedules
- ^^policy => snapshot_policy
- ^^vserver-name => svm
- ^comment => comment
- ^enabled => status
- ^policy-owner => policy_owner
- snapshot-policy-schedules:
- snapshot-schedule-info:
- ^count => copies
- ^schedule => schedules

plugins:
- LabelAgent:
split:
- policy_owner `-admin` scope,
- SnapshotPolicy

export_options:
instance_keys:
- comment
- snapshot_policy
instance_labels:
- comment
- copies
- schedules
- scope
- status
- svm


10 changes: 0 additions & 10 deletions docs/ontap-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -11503,16 +11503,6 @@ Number of Successful Updates
| ZAPI | `snapmirror-get-iter` | `snapmirror-info.update-successful-count` | conf/zapi/cdot/9.8.0/snapmirror.yaml |


### snapshot_policy_total_schedules

Total Number of Schedules in this Policy

| API | Endpoint | Metric | Template |
|--------|----------|--------|---------|
| REST | `api/private/cli/volume/snapshot/policy` | `total_schedules` | conf/rest/9.12.0/snapshotpolicy.yaml |
| ZAPI | `snapshot-policy-get-iter` | `snapshot-policy-info.total-schedules` | conf/zapi/cdot/9.8.0/snapshotpolicy.yaml |


### svm_cifs_connections

Number of connections
Expand Down
2 changes: 1 addition & 1 deletion docs/prepare-cdot-clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ security login rest-role create -role harvest2-rest-role -access readonly -api /
security login rest-role create -role harvest-rest-role -access readonly -api /api/storage/qos/workloads
security login rest-role create -role harvest-rest-role -access readonly -api /api/storage/quota/reports
security login rest-role create -role harvest-rest-role -access readonly -api /api/storage/shelves
security login rest-role create -role harvest-rest-role -access readonly -api /api/storage/snapshot-policies
security login rest-role create -role harvest-rest-role -access readonly -api /api/storage/volumes
security login rest-role create -role harvest-rest-role -access readonly -api /api/support/auto-update
security login rest-role create -role harvest-rest-role -access readonly -api /api/support/autosupport
Expand Down Expand Up @@ -235,7 +236,6 @@ security login rest-role create -role harvest2-rest-role -access readonly -api /
security login rest-role create -role harvest-rest-role -access readonly -api /api/private/cli/qos/workload
security login rest-role create -role harvest-rest-role -access readonly -api /api/private/cli/qtree
security login rest-role create -role harvest-rest-role -access readonly -api /api/private/cli/snapmirror
security login rest-role create -role harvest-rest-role -access readonly -api /api/private/cli/volume/snapshot/policy
security login rest-role create -role harvest-rest-role -access readonly -api /api/private/cli/storage/failover
security login rest-role create -role harvest-rest-role -access readonly -api /api/private/cli/storage/shelf
security login rest-role create -role harvest-rest-role -access readonly -api /api/private/cli/system/chassis/fru
Expand Down
Loading

0 comments on commit b67d9c0

Please sign in to comment.