diff --git a/pkg/bkmonitorbeat/VERSION b/pkg/bkmonitorbeat/VERSION index 6a5b169b1..ddc61f6f8 100644 --- a/pkg/bkmonitorbeat/VERSION +++ b/pkg/bkmonitorbeat/VERSION @@ -1 +1 @@ -v3.29.x +v3.30.x diff --git a/pkg/bkmonitorbeat/configs/exceptionbeat.go b/pkg/bkmonitorbeat/configs/exceptionbeat.go index 1276dac48..60824041f 100644 --- a/pkg/bkmonitorbeat/configs/exceptionbeat.go +++ b/pkg/bkmonitorbeat/configs/exceptionbeat.go @@ -38,6 +38,7 @@ type ExceptionBeatConfig struct { DiskRoBlackList []string `config:"disk_ro_black_list"` CoreFileReportGap time.Duration `config:"corefile_report_gap"` CoreFilePattern string `config:"corefile_pattern"` + CoreFileMatchRegex string `config:"corefile_match_regex"` } var DefaultExceptionBeatConfig = ExceptionBeatConfig{ diff --git a/pkg/bkmonitorbeat/script/generate_support_files/write_project_yaml.sh b/pkg/bkmonitorbeat/script/generate_support_files/write_project_yaml.sh index 5a62a3ce8..304975eb0 100644 --- a/pkg/bkmonitorbeat/script/generate_support_files/write_project_yaml.sh +++ b/pkg/bkmonitorbeat/script/generate_support_files/write_project_yaml.sh @@ -59,8 +59,11 @@ config_templates: items: title: interface type: string - corefile_pattern_path: - title: corefile_pattern_path + corefile_pattern: + title: corefile_pattern + type: string + corefile_match_regex: + title: corefile_match_regex type: string - plugin_version: "*" name: bkmonitorbeat_prometheus.conf diff --git a/pkg/bkmonitorbeat/script/generate_support_files/write_root_conf_tpl.sh b/pkg/bkmonitorbeat/script/generate_support_files/write_root_conf_tpl.sh index ae322e811..a687632d8 100644 --- a/pkg/bkmonitorbeat/script/generate_support_files/write_root_conf_tpl.sh +++ b/pkg/bkmonitorbeat/script/generate_support_files/write_root_conf_tpl.sh @@ -204,8 +204,11 @@ EOF check_oom_interval: 10 used_max_disk_space_percent: 95 free_min_disk_space: 10 -{%- if extra_vars is defined and extra_vars.corefile_pattern_path is defined %} - corefile_pattern: {{ extra_vars.corefile_pattern_path or '' }} +{%- if extra_vars is defined and extra_vars.corefile_pattern is defined %} + corefile_pattern: {{ extra_vars.corefile_pattern or '' }} +{%- endif %} +{%- if extra_vars is defined and extra_vars.corefile_match_regex is defined %} + corefile_match_regex: {{ extra_vars.corefile_match_regex or '' }} {%- endif %} EOF cat <> "$path" diff --git a/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/etc/bkmonitorbeat.conf.tpl b/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/etc/bkmonitorbeat.conf.tpl index 72ab605e5..0dc6d5e23 100644 --- a/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/etc/bkmonitorbeat.conf.tpl +++ b/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/etc/bkmonitorbeat.conf.tpl @@ -129,8 +129,11 @@ bkmonitorbeat: check_oom_interval: 10 used_max_disk_space_percent: 95 free_min_disk_space: 10 -{%- if extra_vars is defined and extra_vars.corefile_pattern_path is defined %} - corefile_pattern: {{ extra_vars.corefile_pattern_path or '' }} +{%- if extra_vars is defined and extra_vars.corefile_pattern is defined %} + corefile_pattern: {{ extra_vars.corefile_pattern or '' }} +{%- endif %} +{%- if extra_vars is defined and extra_vars.corefile_match_regex is defined %} + corefile_match_regex: {{ extra_vars.corefile_match_regex or '' }} {%- endif %} # 进程采集:同步 CMDB 进程配置文件到 bkmonitorbeat 子任务文件夹下 procconf_task: diff --git a/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/project.yaml b/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/project.yaml index 6dbf8d673..66cb77637 100644 --- a/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/project.yaml +++ b/pkg/bkmonitorbeat/support-files/templates/freebsd/x86_64/project.yaml @@ -31,8 +31,11 @@ config_templates: items: title: interface type: string - corefile_pattern_path: - title: corefile_pattern_path + corefile_pattern: + title: corefile_pattern + type: string + corefile_match_regex: + title: corefile_match_regex type: string - plugin_version: "*" name: bkmonitorbeat_prometheus.conf diff --git a/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/etc/bkmonitorbeat.conf.tpl b/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/etc/bkmonitorbeat.conf.tpl index 72ab605e5..0dc6d5e23 100644 --- a/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/etc/bkmonitorbeat.conf.tpl +++ b/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/etc/bkmonitorbeat.conf.tpl @@ -129,8 +129,11 @@ bkmonitorbeat: check_oom_interval: 10 used_max_disk_space_percent: 95 free_min_disk_space: 10 -{%- if extra_vars is defined and extra_vars.corefile_pattern_path is defined %} - corefile_pattern: {{ extra_vars.corefile_pattern_path or '' }} +{%- if extra_vars is defined and extra_vars.corefile_pattern is defined %} + corefile_pattern: {{ extra_vars.corefile_pattern or '' }} +{%- endif %} +{%- if extra_vars is defined and extra_vars.corefile_match_regex is defined %} + corefile_match_regex: {{ extra_vars.corefile_match_regex or '' }} {%- endif %} # 进程采集:同步 CMDB 进程配置文件到 bkmonitorbeat 子任务文件夹下 procconf_task: diff --git a/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/project.yaml b/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/project.yaml index 6dbf8d673..66cb77637 100644 --- a/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/project.yaml +++ b/pkg/bkmonitorbeat/support-files/templates/linux/aarch64/project.yaml @@ -31,8 +31,11 @@ config_templates: items: title: interface type: string - corefile_pattern_path: - title: corefile_pattern_path + corefile_pattern: + title: corefile_pattern + type: string + corefile_match_regex: + title: corefile_match_regex type: string - plugin_version: "*" name: bkmonitorbeat_prometheus.conf diff --git a/pkg/bkmonitorbeat/support-files/templates/linux/x86/etc/bkmonitorbeat.conf.tpl b/pkg/bkmonitorbeat/support-files/templates/linux/x86/etc/bkmonitorbeat.conf.tpl index 72ab605e5..0dc6d5e23 100644 --- a/pkg/bkmonitorbeat/support-files/templates/linux/x86/etc/bkmonitorbeat.conf.tpl +++ b/pkg/bkmonitorbeat/support-files/templates/linux/x86/etc/bkmonitorbeat.conf.tpl @@ -129,8 +129,11 @@ bkmonitorbeat: check_oom_interval: 10 used_max_disk_space_percent: 95 free_min_disk_space: 10 -{%- if extra_vars is defined and extra_vars.corefile_pattern_path is defined %} - corefile_pattern: {{ extra_vars.corefile_pattern_path or '' }} +{%- if extra_vars is defined and extra_vars.corefile_pattern is defined %} + corefile_pattern: {{ extra_vars.corefile_pattern or '' }} +{%- endif %} +{%- if extra_vars is defined and extra_vars.corefile_match_regex is defined %} + corefile_match_regex: {{ extra_vars.corefile_match_regex or '' }} {%- endif %} # 进程采集:同步 CMDB 进程配置文件到 bkmonitorbeat 子任务文件夹下 procconf_task: diff --git a/pkg/bkmonitorbeat/support-files/templates/linux/x86/project.yaml b/pkg/bkmonitorbeat/support-files/templates/linux/x86/project.yaml index 6dbf8d673..66cb77637 100644 --- a/pkg/bkmonitorbeat/support-files/templates/linux/x86/project.yaml +++ b/pkg/bkmonitorbeat/support-files/templates/linux/x86/project.yaml @@ -31,8 +31,11 @@ config_templates: items: title: interface type: string - corefile_pattern_path: - title: corefile_pattern_path + corefile_pattern: + title: corefile_pattern + type: string + corefile_match_regex: + title: corefile_match_regex type: string - plugin_version: "*" name: bkmonitorbeat_prometheus.conf diff --git a/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/etc/bkmonitorbeat.conf.tpl b/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/etc/bkmonitorbeat.conf.tpl index 72ab605e5..0dc6d5e23 100644 --- a/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/etc/bkmonitorbeat.conf.tpl +++ b/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/etc/bkmonitorbeat.conf.tpl @@ -129,8 +129,11 @@ bkmonitorbeat: check_oom_interval: 10 used_max_disk_space_percent: 95 free_min_disk_space: 10 -{%- if extra_vars is defined and extra_vars.corefile_pattern_path is defined %} - corefile_pattern: {{ extra_vars.corefile_pattern_path or '' }} +{%- if extra_vars is defined and extra_vars.corefile_pattern is defined %} + corefile_pattern: {{ extra_vars.corefile_pattern or '' }} +{%- endif %} +{%- if extra_vars is defined and extra_vars.corefile_match_regex is defined %} + corefile_match_regex: {{ extra_vars.corefile_match_regex or '' }} {%- endif %} # 进程采集:同步 CMDB 进程配置文件到 bkmonitorbeat 子任务文件夹下 procconf_task: diff --git a/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/project.yaml b/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/project.yaml index 6dbf8d673..66cb77637 100644 --- a/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/project.yaml +++ b/pkg/bkmonitorbeat/support-files/templates/linux/x86_64/project.yaml @@ -31,8 +31,11 @@ config_templates: items: title: interface type: string - corefile_pattern_path: - title: corefile_pattern_path + corefile_pattern: + title: corefile_pattern + type: string + corefile_match_regex: + title: corefile_match_regex type: string - plugin_version: "*" name: bkmonitorbeat_prometheus.conf diff --git a/pkg/bkmonitorbeat/support-files/templates/windows/x86/etc/bkmonitorbeat.conf.tpl b/pkg/bkmonitorbeat/support-files/templates/windows/x86/etc/bkmonitorbeat.conf.tpl index 9710091ba..3feb3f27b 100644 --- a/pkg/bkmonitorbeat/support-files/templates/windows/x86/etc/bkmonitorbeat.conf.tpl +++ b/pkg/bkmonitorbeat/support-files/templates/windows/x86/etc/bkmonitorbeat.conf.tpl @@ -129,8 +129,11 @@ bkmonitorbeat: check_oom_interval: 10 used_max_disk_space_percent: 95 free_min_disk_space: 10 -{%- if extra_vars is defined and extra_vars.corefile_pattern_path is defined %} - corefile_pattern: {{ extra_vars.corefile_pattern_path or '' }} +{%- if extra_vars is defined and extra_vars.corefile_pattern is defined %} + corefile_pattern: {{ extra_vars.corefile_pattern or '' }} +{%- endif %} +{%- if extra_vars is defined and extra_vars.corefile_match_regex is defined %} + corefile_match_regex: {{ extra_vars.corefile_match_regex or '' }} {%- endif %} # 进程采集:同步 CMDB 进程配置文件到 bkmonitorbeat 子任务文件夹下 procconf_task: diff --git a/pkg/bkmonitorbeat/support-files/templates/windows/x86/project.yaml b/pkg/bkmonitorbeat/support-files/templates/windows/x86/project.yaml index d5490094d..499431417 100644 --- a/pkg/bkmonitorbeat/support-files/templates/windows/x86/project.yaml +++ b/pkg/bkmonitorbeat/support-files/templates/windows/x86/project.yaml @@ -31,8 +31,11 @@ config_templates: items: title: interface type: string - corefile_pattern_path: - title: corefile_pattern_path + corefile_pattern: + title: corefile_pattern + type: string + corefile_match_regex: + title: corefile_match_regex type: string - plugin_version: "*" name: bkmonitorbeat_prometheus.conf diff --git a/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/etc/bkmonitorbeat.conf.tpl b/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/etc/bkmonitorbeat.conf.tpl index 9710091ba..3feb3f27b 100644 --- a/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/etc/bkmonitorbeat.conf.tpl +++ b/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/etc/bkmonitorbeat.conf.tpl @@ -129,8 +129,11 @@ bkmonitorbeat: check_oom_interval: 10 used_max_disk_space_percent: 95 free_min_disk_space: 10 -{%- if extra_vars is defined and extra_vars.corefile_pattern_path is defined %} - corefile_pattern: {{ extra_vars.corefile_pattern_path or '' }} +{%- if extra_vars is defined and extra_vars.corefile_pattern is defined %} + corefile_pattern: {{ extra_vars.corefile_pattern or '' }} +{%- endif %} +{%- if extra_vars is defined and extra_vars.corefile_match_regex is defined %} + corefile_match_regex: {{ extra_vars.corefile_match_regex or '' }} {%- endif %} # 进程采集:同步 CMDB 进程配置文件到 bkmonitorbeat 子任务文件夹下 procconf_task: diff --git a/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/project.yaml b/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/project.yaml index d5490094d..499431417 100644 --- a/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/project.yaml +++ b/pkg/bkmonitorbeat/support-files/templates/windows/x86_64/project.yaml @@ -31,8 +31,11 @@ config_templates: items: title: interface type: string - corefile_pattern_path: - title: corefile_pattern_path + corefile_pattern: + title: corefile_pattern + type: string + corefile_match_regex: + title: corefile_match_regex type: string - plugin_version: "*" name: bkmonitorbeat_prometheus.conf diff --git a/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/collector_unix.go b/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/collector_unix.go index 0e6d473f8..8cab7dbc6 100644 --- a/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/collector_unix.go +++ b/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/collector_unix.go @@ -14,6 +14,7 @@ package corefile import ( "context" + "regexp" "time" "github.com/fsnotify/fsnotify" @@ -41,6 +42,7 @@ type CoreFileCollector struct { done chan bool state int coreFilePattern string + matchRegx *regexp.Regexp corePath string pattern string patternArr [][]string @@ -78,6 +80,14 @@ func (c *CoreFileCollector) Start(ctx context.Context, e chan<- define.Event, co } c.reportTimeInfo = make(map[string]*ReportInfo) c.coreFilePattern = conf.CoreFilePattern + if conf.CoreFileMatchRegex != "" { + r, err := regexp.Compile(conf.CoreFileMatchRegex) + if err != nil { + logger.Errorf("faield to compile regex pattern(%s), err: %v", conf.CoreFileMatchRegex, err) + } else { + c.matchRegx = r + } + } logger.Infof("CoreFileColletor start success with config data_id->[%d] report_gap->[%s]", c.dataid, c.reportTimeGap) go c.statistic(ctx, e) diff --git a/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix.go b/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix.go index 0b48f89ef..e58d9a8ca 100644 --- a/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix.go +++ b/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix.go @@ -488,9 +488,20 @@ func (c *CoreFileCollector) parseDimensions(groups []regexGroup) beat.MapStr { return dimensions } +func (c *CoreFileCollector) fillDimension(filePath string) (beat.MapStr, bool) { + m, ok := c.fillDimensionV0(filePath) + // 正则匹配模式下,不需要关心是否 dimensions 能否匹配到 + if c.matchRegx != nil { + matched := c.matchRegx.MatchString(filePath) + return m, matched + } + + return m, ok +} + // fillDimension: 填充维度信息到dimensions当中,如果解析失败,那么直接返回dimensions,不对其中的任何内容进行修改 // 返回内容表示是否可以按照正则正常解析;如果正则解析失败的,很可能是用户自己瞎写的文件,不应该触发告警 -func (c *CoreFileCollector) fillDimension(filePath string) (beat.MapStr, bool) { +func (c *CoreFileCollector) fillDimensionV0(filePath string) (beat.MapStr, bool) { // 获取core file文件名 fileName, errFileName := c.getCoreFileName(filePath) diff --git a/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix_test.go b/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix_test.go index 3e1c05e2d..561af9e56 100644 --- a/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix_test.go +++ b/pkg/bkmonitorbeat/tasks/exceptionbeat/collector/corefile/utils_unix_test.go @@ -15,6 +15,7 @@ package corefile import ( "os" "path" + "regexp" "testing" "github.com/stretchr/testify/assert" @@ -193,234 +194,261 @@ func TestCoreFileCollector_fillDimension(t *testing.T) { fields fields args args want beat.MapStr + reg *regexp.Regexp want1 bool }{ { - "路径和信号", - fields{ + name: "路径和信号", + fields: fields{ pattern: "corefile-%E-%e-%I-%i-%s-%t", isUsesPid: false, }, - args{ + args: args{ filePath: "/corefile/corefile-!tmp!test!test-test-25486-25486-8-1607502386", }, - beat.MapStr{ + want: beat.MapStr{ "executable_path": "/tmp/test/test", "executable": "test", "signal": "SIGFPE", "event_time": "1607502386", }, - true, + want1: true, }, { - "路径和信号带pid扩展名", - fields{ + name: "路径和信号带pid扩展名", + fields: fields{ pattern: "corefile-%E-%e-%I-%i-%s-%t", isUsesPid: true, }, - args{ + args: args{ filePath: "/corefile/corefile-!tmp!test!test-test-25486-25486-8-1607502386.25486", }, - beat.MapStr{ + want: beat.MapStr{ "executable_path": "/tmp/test/test", "executable": "test", "signal": "SIGFPE", "event_time": "1607502386", }, - true, + want1: true, }, { - "pattern和文件名不匹配", - fields{ + name: "pattern和文件名不匹配", + fields: fields{ pattern: "corefile-%E-%e-%I-%i-%s-%t", isUsesPid: false, }, - args{ + args: args{ filePath: "/corefile/corefile-!tmp!test!t~ded。est-tes8-1607502386.25486", }, - beat.MapStr{}, - false, + want: beat.MapStr{}, + want1: false, }, { - "分隔符包含正则元字符", - fields{ + name: "分隔符包含正则元字符", + fields: fields{ pattern: "corefile-%E.%e\\%I~%i-%stt%t", isUsesPid: false, }, - args{ + args: args{ filePath: "/corefile/corefile-!tmp!test!test.test\\25486~25486-8tt1607502386", }, - beat.MapStr{ + want: beat.MapStr{ "executable_path": "/tmp/test/test", "executable": "test", "signal": "SIGFPE", "event_time": "1607502386", }, - true, + want1: true, }, { - "分隔符和内容冲突-!", - fields{ + name: "分隔符和内容冲突-!", + fields: fields{ pattern: "corefile-%E!%e-%I-%i-%s-%t", isUsesPid: false, }, - args{ + args: args{ filePath: "/corefile/corefile-!tmp!test!test!test-25486-25486-8-1607502386", }, - beat.MapStr{ + want: beat.MapStr{ "event_time": "1607502386", "signal": "SIGFPE", }, - true, + want1: true, }, { - "分隔符和内容冲突-8", - fields{ + name: "分隔符和内容冲突-8", + fields: fields{ pattern: "corefile-%E-%e-%I-%i8%s-%t", isUsesPid: false, }, - args{ + args: args{ filePath: "/corefile/corefile-!tmp!test!test-test-25486-2548688-1607502386", }, - beat.MapStr{ + want: beat.MapStr{ "event_time": "1607502386", "executable": "test", "executable_path": "/tmp/test/test", }, - true, + want1: true, }, { - "根据%E补充%e维度", - fields{ + name: "根据%E补充%e维度", + fields: fields{ pattern: "corefile-%E-%I-%i8%s-%t", isUsesPid: false, }, - args{ + args: args{ filePath: "/corefile/corefile-!tmp!test!test1-25486-2548688-1607502386", }, - beat.MapStr{ + want: beat.MapStr{ "event_time": "1607502386", "executable_path": "/tmp/test/test1", "executable": "test1", }, - true, + want1: true, }, { - "存在不可用的占位符", - fields{ + name: "存在不可用的占位符", + fields: fields{ pattern: "core_%w_%e", isUsesPid: false, }, - args{ + args: args{ filePath: "/data/corefile/core__demo", }, - beat.MapStr{ + want: beat.MapStr{ "executable": "demo", }, - true, + want1: true, }, { - "测试将pid占位符加入", - fields{ + name: "测试将pid占位符加入", + fields: fields{ pattern: "core_%e_%p", isUsesPid: false, }, - args{ + args: args{ filePath: "/data/corefile/core_demo_77190", }, - beat.MapStr{ + want: beat.MapStr{ "executable": "demo", }, - true, + want1: true, }, { - "测试特意将pid占位符,而且存在不可用的占位符 加入到pattern中的情形", - fields{ + name: "测试特意将pid占位符,而且存在不可用的占位符 加入到pattern中的情形", + fields: fields{ pattern: "core_%w_%e_%t_%p", isUsesPid: false, }, - args{ + args: args{ filePath: "/data/corefile/core__demo_1616056187_77190", }, - beat.MapStr{ + want: beat.MapStr{ "executable": "demo", "event_time": "1616056187", }, - true, + want1: true, }, { - "设置了use_pid,但是实际上已经手动匹配过了,此时不需要划分后缀", - fields{ + name: "设置了use_pid,但是实际上已经手动匹配过了,此时不需要划分后缀", + fields: fields{ pattern: "core_%w_%e_%t_%p", isUsesPid: true, }, - args{ + args: args{ filePath: "/data/corefile/core__demo_1616056187_77190", }, - beat.MapStr{ + want: beat.MapStr{ "executable": "demo", "event_time": "1616056187", }, - true, + want1: true, }, { - "第一个自身匹配出分隔符", - fields{ + name: "第一个自身匹配出分隔符", + fields: fields{ pattern: "core_%e_%t", isUsesPid: true, }, - args{ + args: args{ filePath: "/data/corefile/core_gen_core_test_1668062442.10453", }, - beat.MapStr{ + want: beat.MapStr{ "executable": "gen_core_test", "event_time": "1668062442", }, - true, + want1: true, }, { - "匹配出上一个分隔符造成歧义", - fields{ + name: "匹配出上一个分隔符造成歧义", + fields: fields{ pattern: "core_%et%h_%t", isUsesPid: true, }, - args{ + args: args{ filePath: "/data/corefile/core_gen_test_centos_1668062442.10453", }, - beat.MapStr{ + want: beat.MapStr{ "event_time": "1668062442", }, - true, + want1: true, }, { - "连续三个有歧义", - fields{ + name: "连续三个有歧义", + fields: fields{ pattern: "core_%et%ht%E_%t", isUsesPid: true, }, - args{ + args: args{ filePath: "/data/corefile/core_gen_test_centos_test_path_1668062442.10453", }, - beat.MapStr{ + want: beat.MapStr{ "event_time": "1668062442", }, - true, + want1: true, }, { - "匹配出前后分隔符但和前后都不匹配", - fields{ + name: "匹配出前后分隔符但和前后都不匹配", + fields: fields{ pattern: "core_%t_%e_%s", isUsesPid: false, }, - args{ + args: args{ filePath: "/data/corefile/core_1668062442_gen_core_test_8", }, - beat.MapStr{ + want: beat.MapStr{ "executable": "gen_core_test", "event_time": "1668062442", "signal": "SIGFPE", }, - true, + want1: true, + }, + { + name: "正则过滤(success)", + fields: fields{ + pattern: "core_%t_%e_%s", + isUsesPid: false, + }, + args: args{ + filePath: "/data/corefile/core_gen_core_test", + }, + reg: regexp.MustCompile("gen_core_test"), + want: beat.MapStr{}, + want1: true, + }, + { + name: "正则过滤(failed)", + fields: fields{ + pattern: "core_%t_%e_%s", + isUsesPid: false, + }, + args: args{ + filePath: "/data/corefile/core_gen_core_xtest", + }, + reg: regexp.MustCompile("gen_core_test"), + want: beat.MapStr{}, + want1: false, }, } for _, tt := range tests { @@ -428,6 +456,7 @@ func TestCoreFileCollector_fillDimension(t *testing.T) { c := &CoreFileCollector{ pattern: tt.fields.pattern, isUsesPid: tt.fields.isUsesPid, + matchRegx: tt.reg, } err := c.checkPattern() assert.NoError(t, err, "checkPattern", tt.fields.pattern)