-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding the bucket and policy rest template (#3374)
* feat: add the bucket and policy rest template to the data protection dashboard (#3414) --------- Co-authored-by: Chris Grindstaff <[email protected]>
- Loading branch information
Showing
23 changed files
with
3,803 additions
and
1,867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
cmd/collectors/rest/plugins/clusterschedule/clusterschedule.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package clusterschedule | ||
|
||
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" | ||
"strings" | ||
) | ||
|
||
type ClusterScheule struct { | ||
*plugin.AbstractPlugin | ||
} | ||
|
||
func New(p *plugin.AbstractPlugin) plugin.Plugin { | ||
return &ClusterScheule{AbstractPlugin: p} | ||
} | ||
|
||
func (c *ClusterScheule) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Metadata, error) { | ||
for _, instance := range dataMap[c.Object].GetInstances() { | ||
if cron := instance.GetLabel("cron"); cron != "" { | ||
updateDetailsJSON := gjson.Result{Type: gjson.JSON, Raw: cron} | ||
var minStr, hourStr, dayStr, monthStr, weekDayStr string | ||
var cronVal []string | ||
|
||
minStr = list(updateDetailsJSON.Get("minutes")) | ||
hourStr = list(updateDetailsJSON.Get("hours")) | ||
dayStr = list(updateDetailsJSON.Get("days")) | ||
monthStr = list(updateDetailsJSON.Get("months")) | ||
weekDayStr = list(updateDetailsJSON.Get("weekdays")) | ||
cronVal = append(cronVal, minStr, hourStr, dayStr, monthStr, weekDayStr) | ||
cronData := strings.Join(cronVal, " ") | ||
instance.SetLabel("cron", cronData) | ||
instance.SetLabel("schedule", cronData) | ||
} | ||
if interval := instance.GetLabel("interval"); interval != "" { | ||
instance.SetLabel("schedule", interval) | ||
} | ||
} | ||
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, ",") | ||
} |
49 changes: 49 additions & 0 deletions
49
cmd/collectors/rest/plugins/snapshotpolicy/snapshotpolicy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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" | ||
"github.com/netapp/harvest/v2/third_party/tidwall/gjson" | ||
"slices" | ||
"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 := instance.GetLabel("copies") | ||
copiesJSON := gjson.Result{Type: gjson.JSON, Raw: "[" + copies + "]"} | ||
var copiesValue int | ||
var schedules []string | ||
for _, copiesData := range copiesJSON.Array() { | ||
count := copiesData.Get("count").ClonedString() | ||
countVal, _ := strconv.Atoi(count) | ||
schedule := copiesData.Get("schedule.name").ClonedString() | ||
schedules = append(schedules, schedule+":"+count) | ||
copiesValue += countVal | ||
} | ||
|
||
slices.Sort(schedules) | ||
|
||
instance.SetLabel("schedules", strings.Join(schedules, ",")) | ||
instance.SetLabel("copies", strconv.Itoa(copiesValue)) | ||
} | ||
|
||
return nil, nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.