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 the bucket and policy rest template to the data protecti… #3414

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions cmd/collectors/rest/plugins/clusterschedule/clusterschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,10 @@ func (c *ClusterScheule) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri
cron := instance.GetLabel("cron")
updateDetailsJSON := gjson.Result{Type: gjson.JSON, Raw: cron}
var cronVal, minStr, hourStr, weekDayStr string
if minutes := updateDetailsJSON.Get("minutes"); minutes.Exists() {
for _, m := range minutes.Array() {
minStr = minStr + m.String() + ", "
}
minStr = strings.TrimSuffix(minStr, ", ")
}
if hours := updateDetailsJSON.Get("hours"); hours.Exists() {
for _, h := range hours.Array() {
hourStr = hourStr + h.String() + ", "
}
hourStr = strings.TrimSuffix(hourStr, ", ")
}
if weekdays := updateDetailsJSON.Get("weekdays"); weekdays.Exists() {
for _, w := range weekdays.Array() {
weekDayStr = weekDayStr + w.String() + ", "
}
weekDayStr = strings.TrimSuffix(weekDayStr, ", ")
}

minStr = list(updateDetailsJSON.Get("minutes"))
hourStr = list(updateDetailsJSON.Get("hours"))
weekDayStr = list(updateDetailsJSON.Get("weekdays"))

if minStr != "" {
cronVal = cronVal + "minutes: " + "[" + minStr + "] "
Expand All @@ -54,7 +40,19 @@ func (c *ClusterScheule) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri
if weekDayStr != "" {
cronVal = cronVal + "weekdays: " + "[" + weekDayStr + "]"
}
instance.SetLabel("cron", cronVal)
instance.SetLabel("cron", strings.TrimSpace(cronVal))
}
return nil, nil, nil
}

func list(get gjson.Result) string {
if !get.IsArray() {
return ""
}
array := get.Array()
items := make([]string, 0, len(array))
for _, e := range array {
items = append(items, e.ClonedString())
}
return strings.Join(items, ", ")
}
12 changes: 8 additions & 4 deletions cmd/collectors/rest/plugins/snapshotpolicy/snapshotpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/util"
"github.com/netapp/harvest/v2/third_party/tidwall/gjson"
"slices"
"strconv"
"strings"
)
Expand All @@ -28,16 +29,19 @@ func (m *SnapshotPolicy) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri
for _, instance := range data.GetInstances() {
copies := instance.GetLabel("copies")
copiesJSON := gjson.Result{Type: gjson.JSON, Raw: "[" + copies + "]"}
var scheduleVal string
var copiesValue int
var schedules []string
for _, copiesData := range copiesJSON.Array() {
count := copiesData.Get("count").String()
count := copiesData.Get("count").ClonedString()
countVal, _ := strconv.Atoi(count)
schedule := copiesData.Get("schedule.name").ClonedString()
scheduleVal = scheduleVal + schedule + ":" + count + ","
schedules = append(schedules, schedule+":"+count)
copiesValue += countVal
}
instance.SetLabel("schedules", strings.TrimSuffix(scheduleVal, ","))

slices.Sort(schedules)

instance.SetLabel("schedules", strings.Join(schedules, ","))
instance.SetLabel("copies", strconv.Itoa(copiesValue))
}

Expand Down
11 changes: 8 additions & 3 deletions cmd/collectors/zapi/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"
"slices"
"strconv"
"strings"
)
Expand All @@ -27,17 +28,21 @@ func (m *SnapshotPolicy) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri
for _, instance := range data.GetInstances() {
copies := strings.Split(instance.GetLabel("copies"), ",")
schedules := strings.Split(instance.GetLabel("schedules"), ",")
var schedulesS []string

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 + ","
schedulesS = append(schedulesS, schedule+":"+copiesData)

copiesValue += countVal
}
instance.SetLabel("schedules", strings.TrimSuffix(scheduleVal, ","))

slices.Sort(schedulesS)

instance.SetLabel("schedules", strings.Join(schedulesS, ","))
instance.SetLabel("copies", strconv.Itoa(copiesValue))
}
}
Expand Down
Loading