如何删除 Logstash 过滤器中所有具有 NULL 值的字段

2023-11-24

我正在使用 Logstash 读取 csv 格式的检查点日志文件 并且某些字段具有空值。

我想删除所有具有空值的字段。

我无法准确预见哪些字段(键)将具有空值,因为我的 csv 文件中有 150 列,并且我不想检查其中的每一列。

是否可以在logstash中执行动态过滤器来删除任何具有空值的字段?

我的logstash 配置文件如下所示:

input {
  stdin { tags => "checkpoint" } 
   file {
   type => "file-input"
   path =>  "D:\Browser Downloads\logstash\logstash-1.4.2\bin\checkpoint.csv"
   sincedb_path => "D:\Browser Downloads\logstash\logstash-1.4.2\bin\sincedb-access2"
   start_position => "beginning"
   tags => ["checkpoint","offline"]
  }
}
filter {
 if "checkpoint" in [tags] {
        csv {
        columns => ["num","date","time","orig","type","action","alert","i/f_name","i/f_dir","product","Internal_CA:","serial_num:","dn:","sys_message:","inzone","outzone","rule","rule_uid","rule_name","service_id","src","dst","proto","service","s_port","dynamic object","change type","message_info","StormAgentName","StormAgentAction","TCP packet out of state","tcp_flags","xlatesrc","xlatedst","NAT_rulenum","NAT_addtnl_rulenum","xlatedport","xlatesport","fw_message","ICMP","ICMP Type","ICMP Code","DCE-RPC Interface UUID","rpc_prog","log_sys_message","scheme:","Validation log:","Reason:","Serial num:","Instruction:","fw_subproduct","vpn_feature_name","srckeyid","dstkeyid","user","methods:","peer gateway","IKE:","CookieI","CookieR","msgid","IKE notification:","Certificate DN:","IKE IDs:","partner","community","Session:","L2TP:","PPP:","MAC:","OM:","om_method:","assigned_IP:","machine:","reject_category","message:","VPN internal source IP","start_time","connection_uid","encryption failure:","vpn_user","Log ID","message","old IP","old port","new IP","new port","elapsed","connectivity_state","ctrl_category","description","description ","severity","auth_status","identity_src","snid","src_user_name","endpoint_ip","src_machine_name","src_user_group","src_machine_group","auth_method","identity_type","Authentication trial","roles","dst_user_name","dst_machine_name","spi","encryption fail reason:","information","error_description","domain_name","termination_reason","duration"]
      #  remove_field => [ any fields with null value] how to do it please 
        separator => "|"
        }
    # drop csv header
        if [num] == "num" and [date] == "date" and [time] == "time" and [orig] == "orig" {
        drop { }
    }
    }
  }

}
output {
   stdout {
    codec => rubydebug 
  }
   file {
      path => "output.txt"
   }

我在这里附上一些日志示例:

num|date|time|orig|type|action|alert|i/f_name|i/f_dir|product|Internal_CA:|serial_num:|dn:|sys_message:|inzone|outzone|rule|rule_uid|rule_name|service_id|src|dst|proto|service|s_port|dynamic object|change type|message_info|StormAgentName|StormAgentAction|TCP packet out of state|tcp_flags|xlatesrc|xlatedst|NAT_rulenum|NAT_addtnl_rulenum|xlatedport|xlatesport|fw_message|ICMP|ICMP Type|ICMP Code|DCE-RPC Interface UUID|rpc_prog|log_sys_message|scheme:|Validation log:|Reason:|Serial num:|Instruction:|fw_subproduct|vpn_feature_name|srckeyid|dstkeyid|user|methods:|peer gateway|IKE:|CookieI|CookieR|msgid|IKE notification:|Certificate DN:|IKE IDs:|partner|community|Session:|L2TP:|PPP:|MAC:|OM:|om_method:|assigned_IP:|machine:|reject_category|message:|VPN internal source IP|start_time|connection_uid|encryption failure:|vpn_user|Log ID|message|old IP|old port|new IP|new port|elapsed|connectivity_state|ctrl_category|description|description |severity|auth_status|identity_src|snid|src_user_name|endpoint_ip|src_machine_name|src_user_group|src_machine_group|auth_method|identity_type|Authentication trial|roles|dst_user_name|dst_machine_name|spi|encryption fail reason:|information|error_description|domain_name|termination_reason|duration
0|8Jun2012|16:33:35|10.0.0.1|log|keyinst||daemon|inbound|VPN-1 & FireWall-1|started|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 1|8Jun2012|16:36:34|10.0.0.1|log|keyinst||daemon|inbound|VPN-1 & FireWall-1|started|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 2|8Jun2012|16:52:39|10.0.0.1|log|keyinst||daemon|inbound|VPN-1 & FireWall-1|Certificate initialized|86232|CN=fw-KO,O=sc-KO.KO.dc.obn8cx|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 3|8Jun2012|16:52:39|10.0.0.1|log|keyinst||daemon|inbound|VPN-1 & FireWall-1|Initiated certificate is now valid|86232|CN=fw-KO,O=sc-KO.KO.dc.obn8cx|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 4|8Jun2012|16:55:44|10.0.0.1|log|keyinst||daemon|inbound|VPN-1 & FireWall-1|Issued empty CRL 1|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
20|8Jun2012|16:58:28|10.0.0.1|log|accept||eth1|inbound|VPN-1 & FireWall-1|||||Internal|External|1|{2A42C8CD-148D-4809-A480-3171108AD6C7}||domain-udp|192.168.100.1|198.32.64.12|udp|53|1036|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Ruby过滤器可以满足您的要求。

input {
        stdin {
        }
}

filter {
        csv {
                columns => ["num","date","time","orig","type","action","alert","i/f_name","i/f_dir","product","Internal_CA:","serial_num:","dn:","sys_message:","inzone","outzone","rule","rule_uid","rule_name","service_id","src","dst","proto","service","s_port","dynamic object","change type","message_info","StormAgentName","StormAgentAction","TCP packet out of state","tcp_flags","xlatesrc","xlatedst","NAT_rulenum","NAT_addtnl_rulenum","xlatedport","xlatesport","fw_message","ICMP","ICMP Type","ICMP Code","DCE-RPC Interface UUID","rpc_prog","log_sys_message","scheme:","Validation log:","Reason:","Serial num:","Instruction:","fw_subproduct","vpn_feature_name","srckeyid","dstkeyid","user","methods:","peer gateway","IKE:","CookieI","CookieR","msgid","IKE notification:","Certificate DN:","IKE IDs:","partner","community","Session:","L2TP:","PPP:","MAC:","OM:","om_method:","assigned_IP:","machine:","reject_category","message:","VPN internal source IP","start_time","connection_uid","encryption failure:","vpn_user","Log ID","message","old IP","old port","new IP","new port","elapsed","connectivity_state","ctrl_category","description","description ","severity","auth_status","identity_src","snid","src_user_name","endpoint_ip","src_machine_name","src_user_group","src_machine_group","auth_method","identity_type","Authentication trial","roles","dst_user_name","dst_machine_name","spi","encryption fail reason:","information","error_description","domain_name","termination_reason","duration"]
                separator => "|"
        }
        ruby {
                code => "
                        hash = event.to_hash
                        hash.each do |k,v|
                                if v == nil
                                        event.remove(k)
                                end
                        end
                "
        }
}

output {
    stdout { codec => rubydebug }
}

您可以使用 ruby​​ 插件来过滤所有字段nil值(Ruby 中为 null)

Updated:

这是我的环境:Windows server 2008 和 Logstash 1.4.1。 你的日志样本对我有用!我已经更新了配置、输入和输出。

Input

2|8Jun2012|16:52:39|10.0.0.1|log|keyinst||daemon|inbound|VPN-1 & FireWall-1|Certificate initialized|86232|CN=fw-KO,O=sc-KO.KO.dc.obn8cx|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Output:

{
        "@version" => "1",
      "@timestamp" => "2015-03-12T00:30:34.123Z",
            "host" => "BENLIM",
             "num" => "2",
            "date" => "8Jun2012",
            "time" => "16:52:39",
            "orig" => "10.0.0.1",
            "type" => "log",
          "action" => "keyinst",
        "i/f_name" => "daemon",
         "i/f_dir" => "inbound",
         "product" => "VPN-1 & FireWall-1",
    "Internal_CA:" => "Certificate initialized",
     "serial_num:" => "86232",
             "dn:" => "CN=fw-KO,O=sc-KO.KO.dc.obn8cx"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何删除 Logstash 过滤器中所有具有 NULL 值的字段 的相关文章

随机推荐

  • matplotlib 颜色条中的小刻度

    我目前正在尝试在颜色栏中设置小刻度 但根本无法使其工作 我尝试过 3 种方法 参见下面的代码 但它们似乎都不起作用 颜色条中是否真的可能有微小的刻度 import numpy as np import matplotlib pyplot a
  • 有符号零的最小值和最大值

    我担心以下情况 min 0 0 0 0 max 0 0 0 0 minmag x x maxmag x x 根据维基百科 IEEE 754 2008说的是关于最小值和最大值 定义了最小和最大操作 但为输入值相等但表示不同的情况留有一些余地
  • 如何在 matplotlib.pyplot.imshow 中使用“范围”

    我设法绘制了我的数据 并想为其添加背景图像 地图 数据是按长 纬度值绘制的 我也有图像三个角 左上角 右上角和左下角 的长 纬度值 我试图弄清楚如何在 imshow 中使用 范围 选项 然而 我发现的例子并没有解释如何为每个角分配 x 和
  • prestashop 将图像添加到产品中

    我有一个产品对象 我正在 PHP 脚本中创建它 我需要添加缩略图和大图像 它们位于 zip 文件中 文件名包含产品 ID 在代码中实现此目的的最佳方法是什么 我假设我需要将图像提取到文件系统中的某个位置 但我不知道 prestashop 如
  • JTable 准备编辑器如何工作

    我不明白prepareEditor是如何工作的 我无法使用prepareEditor中的Action设置prepareRenderer的可见性规则 正如我在附图中捕获的那样 第 1 行的规则按我的预期工作 如果未选择 JCheckBox 也
  • 错误 C2678:二进制“=”:找不到采用“const Recipe”类型的左侧操作数的运算符(或者没有可接受的转换)

    我正在尝试对每个元素中包含一个 int 和一个字符串的向量进行排序 它是一个类类型的向量 称为向量食谱 出现上述错误 这是我的代码 在我的 Recipe h 文件中 struct Recipe public string get cname
  • MySQL 的密钥文件不正确

    我遇到了一个 InnoDB 表的问题 表最初是 MyISAM 但不久前也将其转换为 InnodB 我正在尝试运行此查询 SELECT posts id posts post title FROM rss posts AS posts INN
  • 在 jQuery 中创建 div 元素 [重复]

    这个问题在这里已经有答案了 我如何创建一个div元素在jQuery 从 jQuery 1 4 开始 您可以将属性传递给自封闭元素 如下所示 jQuery div id some id class some class some other
  • socket.error: [Errno 32] 管道损坏

    我编写了一个客户端 服务器 python 程序 其中客户端将列表发送到服务器 服务器接收数组 删除列表的前两个元素并将其发送回客户端 服务器接收列表没有问题 但是当服务器想要发回编辑后的列表时 它显示错误 socket error Errn
  • 如何在 Visual Studio 中静态链接 VCPKG 生成的 .lib 文件

    我使用 VCPKG 构建第三方库 例如 libcurl 我有动态和静态构建 显然 导入 lib和对象 lib文件分别包含在两个不同的文件夹中 x64 windows和x64 windows static 我想将对象 libcurl lib
  • 在 D3.js 中重新排序 SVG ( z-index ) 元素

    我意识到这个问题以前已经被问过 但我无法深入了解 这是我的图表 http www gogeye com financialnews piechart index3 html 我想做的就是将硬币渲染在图表后面 我知道 D3 渲染是按照附加顺序
  • 如何查询pandas中的MultiIndex索引列值

    代码示例 In 171 A np array 1 1 1 1 3 3 3 3 5 5 6 6 In 172 B np array 111 222 222 333 333 777 In 173 C randint 10 99 6 In 174
  • 将图像转换为 Base64,反之亦然

    我想将图像转换为 Base64 然后再次转换回图像 这是我到目前为止尝试过的代码以及错误 请问有什么建议吗 public void Base64ToImage string coded System Drawing Image finalI
  • 在 Java 中构建 SQL 字符串的最简洁方法

    我想构建一个 SQL 字符串来执行数据库操作 更新 删除 插入 选择之类的事情 而不是使用数百万个 和引号的糟糕的字符串连接方法 这充其量是不可读的 有一定是更好的方法 我确实考虑过使用 MessageFormat 但它应该用于用户消息 尽
  • PHP:MySQL 服务器消失了

    我知道这个问题已经被问过很多次了 但我已经尝试了一切 我有一个 PHP 脚本 它会迭代数千个图像 根据需要执行调整大小 然后插入数据库 我收到此错误消息 警告 mysql query function mysql query MySQL 服
  • 后置和前置增量运算符

    当我运行以下示例时 我得到输出 0 2 1 class ZiggyTest2 static int f1 int i System out print i return 0 public static void main String ar
  • Android 中的 TTS 暂停

    我正在开发一个应用程序 它可以读出文档中的文本 我想添加暂停和恢复功能 但我在 TTS 中找不到任何暂停 方法 有什么办法可以让我暂停吗 有一个方法可以暂停 只需致电TextToSpeech playSilence 请参阅下面的代码here
  • 跨源请求被阻止 Spring REST 服务 + AJAX

    无法调用spring REST服务 我的春季服务 RequestMapping value MAS authenticate method RequestMethod POST public ResponseEntity
  • 将掩码应用于字符串

    我正在从表中读取字符串 ID 值 当用户输入 ID 时 是使用用户定义的输入掩码完成的 因此掩码可能类似于000 00 0000 AA 9999999等 掩码会因用户而异 因此必须在运行时进行评估 鉴于表中仅存储字母数字文本 那么应用该掩码
  • 如何删除 Logstash 过滤器中所有具有 NULL 值的字段

    我正在使用 Logstash 读取 csv 格式的检查点日志文件 并且某些字段具有空值 我想删除所有具有空值的字段 我无法准确预见哪些字段 键 将具有空值 因为我的 csv 文件中有 150 列 并且我不想检查其中的每一列 是否可以在log