dictmap

package
v1.8.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

字段值映射处理

该插件可对指定字段的值查表映射

参数说明

插件类型(type)为 processor_dict_map

参数 类型 必选或可选 参数说明
DictFilePath string 可选 本地的csv字典文件,该csv文件分隔符为,,字段引用标志为"。映射规则为表格第一列为原数据,表格第二列为目标数据。默认为空。
MapDict Map 可选 映射字典,规则为将映射到。若映射字典较小,可直接在设置中的填写,不必提供本地文件,默认为空。当DictFilePath非空,忽略设置中的该字段,只使用DictFilePath数据。
SourceKey string 必选 原数据在日志中的字段名。若有多个同名输入,默认只处理第一个。
DestKey string 可选 映射后数据在日志中的字段名,默认为和SourceKey一致。
HandleMissing bool 可选 是否处理日志中缺失目标字段的情况,默认为false不处理。
Missing string 可选 处理日志中缺失目标字段的情况时的填充值,默认为"Unknown"
Mode string 可选 当映射后字段于原日志中存在时的处理方法,默认为"overwrite"即覆写原字段,若设置为"fill"则不再覆写目标字段。
MaxDictSize int 可选 映射字典的最大大小,默认1000,即最大存储1000条映射规则。若希望限制插件对内存的占用,可以将本设置调小。
配置文件示例
  • 插件设置示例

config.json中:

"processors":[
    {
      "type":"processor_dict_map",
         "detail": {
            "DictFilePath" : "/home/ipExample.csv",
            "MapDict":{
              "1":"TCP",
              "2":"UDP",
              "3":"HTTP",
              "*":"Unknown"
              },
            "SourceKey":"_ip_",
            "DestKey": "_processed_ip_",
            "Mode":"overwrite", 
            "HandleMissing": true,
            "Missing": "Not Detected"
      }
    }
  ],

注意到这里同时设置了两种映射规则来源:本地文件ipExample.csv和配置文件{"1":"TCP","2":"UDP","3":"HTTP","*":"Unknown"}。当两者同时设置时,默认使用配置文件,即ipExample.csv,同时忽略配置文件的内容。

此配置将检查日志中_ip_字段的值是否存在。若不存在,由于设置:"HandleMissing": true,,故会处理这种缺失,将在日志中增加"_processed_ip_"字段并填充缺失值为"Not Detected"。若存在,同样将在日志中增加"_processed_ip_"字段,将查映射字典ipExample.csv得到的值填入该字段内。若查表无,则不处理,日志不发生改变。

  • 映射表文件示例

映射表必须为UFT-8格式输入,每行两列,,将第一列的内容映射到第二列。

ipExample.csv内容为:

"127.0.0.1","LocalHost-LocalHost"
"192.168.0.1","default login"

在配置Logtail时,请将映射表文件(如上文的ipExample.csv)放在用户目录下(如/home/ipExample.csv)而非Logtail的配置文件夹ilogtail中,因ilogtail文件夹会在Logtail升级时被删除。具体配置规则请参考使用Logtail插件处理数据

处理日志示例

当使用如上设置,连续对日志进行映射,处理结果如下:

  • 连续日志输入
{"_ip_":"192.168.0.1","Index":"900000003","__time__":"1627004587"}
{"_ip_":"255.255.255.255","Index":"3","__time__":"1627004587"}
{"_ip_":"192.168.0.1","Index":"900000004","__time__":"1627004588"}
{"_ip_":"255.255.255.255","Index":"4","__time__":"1627004588"}
{"_ip_":"127.0.0.1","Index":"100000004","__time__":"1627004588"}
{"_ip_":"127.0.0.1","Index":"100000005","__time__":"1627004589"}
{"Index":"100000006","__time__":"1627004589"}
  • 配置后结果
{"_ip_":"192.168.0.1",,"Index":"900000003",,"_processed_ip_":"default login","__time__":"1627004587"}
{"_ip_":"255.255.255.255","Index":"3","__time__":"1627004587"}
{"_ip_":"192.168.0.1","Index":"900000004",,"_processed_ip_":"default login","__time__":"1627004588"}
{"_ip_":"255.255.255.255","Index":"4","__time__":"1627004588"}
{"_ip_":"127.0.0.1","Index":"100000004","_processed_ip_":"LocalHost-LocalHost","__time__":"1627004588"}
{"_ip_":"127.0.0.1","Index":"100000005","_processed_ip_":"LocalHost-LocalHost","__time__":"1627004589"}
{"Index":"100000006","_processed_ip_":"Not Detected","__time__":"1627004589"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProcessorDictMap

type ProcessorDictMap struct {
	DictFilePath  string
	MapDict       map[string]string
	SourceKey     string
	DestKey       string
	HandleMissing bool
	Missing       string
	Mode          string
	MaxDictSize   int
	// contains filtered or unexported fields
}

func (*ProcessorDictMap) Description

func (*ProcessorDictMap) Description() string

func (*ProcessorDictMap) Init

func (p *ProcessorDictMap) Init(context pipeline.Context) error

Init called for init some system resources, like socket, mutex...

func (*ProcessorDictMap) ProcessLogs

func (p *ProcessorDictMap) ProcessLogs(logArray []*protocol.Log) []*protocol.Log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL