mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-22 11:54:54 +00:00
pt-galera-log-explainer: add custom regexes parameter
That way anybody can handle non-galera specific logs in a single view tests/expected/operator_auto_ambiguous_ips_list_all_no_color has been updated, it was out-of-sync due to 2 previous pull requests that were made in parallel
This commit is contained in:
43
src/go/pt-galera-log-explainer/regex/custom.go
Normal file
43
src/go/pt-galera-log-explainer/regex/custom.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package regex
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/types"
|
||||
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/utils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var CustomMap = types.RegexMap{}
|
||||
|
||||
func AddCustomRegexes(regexes map[string]string) error {
|
||||
for regexstring, output := range regexes {
|
||||
r, err := regexp.Compile(regexstring)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to add custom regex")
|
||||
}
|
||||
|
||||
lr := &types.LogRegex{Regex: r, Type: types.CustomRegexType}
|
||||
|
||||
if output == "" {
|
||||
// capture and print everything that matched, instead of a static message
|
||||
lr.InternalRegex, err = regexp.Compile("(?P<all>" + regexstring + ")")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to add custom regex: failed to generate dynamic output")
|
||||
}
|
||||
|
||||
lr.Handler = func(submatch map[string]string, ctx types.LogCtx, _ string, _ time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
return ctx, types.SimpleDisplayer(utils.Paint(utils.MagentaText, submatch["all"]))
|
||||
}
|
||||
|
||||
} else {
|
||||
lr.Handler = func(_ map[string]string, ctx types.LogCtx, _ string, _ time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
return ctx, types.SimpleDisplayer(utils.Paint(utils.MagentaText, output))
|
||||
}
|
||||
}
|
||||
|
||||
CustomMap[regexstring] = lr
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -34,7 +34,7 @@ func SetVerbosity(verbosity types.Verbosity, regexes types.RegexMap) {
|
||||
}
|
||||
|
||||
func AllRegexes() types.RegexMap {
|
||||
IdentsMap.Merge(ViewsMap).Merge(SSTMap).Merge(EventsMap).Merge(StatesMap).Merge(ApplicativeMap)
|
||||
IdentsMap.Merge(ViewsMap).Merge(SSTMap).Merge(EventsMap).Merge(StatesMap).Merge(ApplicativeMap).Merge(CustomMap)
|
||||
return IdentsMap
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user