-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
skip_datasets
for monitor
rules
Every item can be configured to skip some datasets from the check, like: ```yaml - prefix: "zrepl_monthly_" skip_datasets: - pattern: "zdisk/video" warning: 13 critical: 14 ``` In this example it checks number of snapshots with prefix `zrepl_monthly_` for every dataset, configured in `datasets`, except `zdisk/video`. `skip_datasets` has the same syntax, like `datasets`.
- Loading branch information
Showing
4 changed files
with
180 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package monitor | ||
|
||
import ( | ||
"github.com/dsh2dsh/zrepl/internal/config" | ||
"github.com/dsh2dsh/zrepl/internal/daemon/filters" | ||
"github.com/dsh2dsh/zrepl/internal/zfs" | ||
) | ||
|
||
func CountRulesFromConfig(in []config.MonitorCount) ([]*CountRule, error) { | ||
rules := make([]*CountRule, len(in)) | ||
for i := range in { | ||
r, err := NewCountRule(&in[i]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
rules[i] = r | ||
} | ||
return rules, nil | ||
} | ||
|
||
func NewCountRule(m *config.MonitorCount) (*CountRule, error) { | ||
r := &CountRule{MonitorCount: m} | ||
return r.init() | ||
} | ||
|
||
type CountRule struct { | ||
*config.MonitorCount | ||
|
||
skip *filters.DatasetFilter | ||
} | ||
|
||
func (self *CountRule) init() (*CountRule, error) { | ||
if length := len(self.SkipDatasets); length != 0 { | ||
skip := filters.New(length) | ||
if err := skip.AddList(self.SkipDatasets); err != nil { | ||
return nil, err | ||
} | ||
self.skip = skip | ||
} | ||
return self, nil | ||
} | ||
|
||
func (self *CountRule) Skip(path *zfs.DatasetPath) (bool, error) { | ||
if self.skip != nil { | ||
return self.skip.Filter(path) | ||
} | ||
return false, nil | ||
} | ||
|
||
// -------------------------------------------------- | ||
|
||
func AgeRulesFromConfig(in []config.MonitorCreation) ([]*AgeRule, error) { | ||
rules := make([]*AgeRule, len(in)) | ||
for i := range in { | ||
r, err := NewAgeRule(&in[i]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
rules[i] = r | ||
} | ||
return rules, nil | ||
} | ||
|
||
func NewAgeRule(m *config.MonitorCreation) (*AgeRule, error) { | ||
r := &AgeRule{MonitorCreation: m} | ||
return r.init() | ||
} | ||
|
||
type AgeRule struct { | ||
*config.MonitorCreation | ||
|
||
skip *filters.DatasetFilter | ||
} | ||
|
||
func (self *AgeRule) init() (*AgeRule, error) { | ||
if length := len(self.SkipDatasets); length != 0 { | ||
skip := filters.New(length) | ||
if err := skip.AddList(self.SkipDatasets); err != nil { | ||
return nil, err | ||
} | ||
self.skip = skip | ||
} | ||
return self, nil | ||
} | ||
|
||
func (self *AgeRule) Skip(path *zfs.DatasetPath) (bool, error) { | ||
if self.skip != nil { | ||
return self.skip.Filter(path) | ||
} | ||
return false, nil | ||
} |
Oops, something went wrong.