PatternFilter
PatternFilter support regex pattern to filter data.
- class duetector.filters.pattern.PatternFilter(config: Config | dict[str, Any] | None = None, *args, **kwargs)[source]
Bases:
FilterA Filter support regex pattern to filter data.
- There are following config build-in:
re_exclude_fname: Regex pattern to filter outfnamefieldre_exclude_comm: Regex pattern to filter outcommfieldexclude_pid: Filter outpidfieldexclude_uid: Filter outuidfieldexclude_gid: Filter outgidfield
- Customize exclude is also supported:
re_exclude_custom: Regex pattern to filter outcustomfieldexclude_custom: Filter outcustomfield
You can change
customto any field you want to filter out.Config
enable_customize_excludeto enable customize exclude, default isTrue.- Use
(?!…)for include pattern: re_exclude_custom:["(?!/proc/)"]will include/procbut exclude others.
Note
- We using python literal to parse config, so you can use environment variable to pass list:
Recommended:
{PREFIX...}RE_EXCLUDE_FNAME="['/proc*', '/sys*']".Remember to quote the value, otherwise it will be parsed as a expression, e.g.
{PREFIX...}RE_EXCLUDE_FNAME=[/proc*]will cause SyntaxError or ValueError. and will fallback to split by comma.
- So either use python literal or string split by comma:
Recommended:
{PREFIX...}RE_EXCLUDE_FNAME="['/proc*', '/sys*']"It’s OK:
{PREFIX...}RE_EXCLUDE_FNAME="/proc*, /sys*"Wrong:
{PREFIX...}RE_EXCLUDE_FNAME=[/proc*, /sys*], this will be converted to a list of"[/proc*"and"/sys*]".
- _re_cache = {}
Cache for re pattern
- static _wrap_exclude_list(value: str | list[str]) set[str][source]
Wrap exclude list to list if it’s not a list
- default_config = {'disabled': False, 'enable_customize_exclude': True, 'exclude_gid': [0], 'exclude_pid': [], 'exclude_uid': [0], 'ignore_current_pid': True, 're_exclude_comm': [], 're_exclude_fname': ['/proc', '/sys', '/lib', '/dev', '/run', '/usr/lib', '/etc/ld.so.cache']}
Default config for
PatternFilter
- property enable_customize_exclude: bool
If enable customize exclude
- filter(data: namedtuple) namedtuple | None[source]
Filter data, return
Noneto drop data, return data to keep data.
- property ignore_current_pid: bool