Geoip logstash过滤器

问题描述 投票:0回答:1

我有一个配置文件,如下所示:

input {
  file {
      path => "/home/kibana/Documents/external_noise.log"
      type => "external_noise"
      start_position => "beginning"
      sincedb_path => "/dev/null"
  }
}
filter {

grok {
match => { 'message' => '%{CISCOTIMESTAMP:timestamp} %{WORD:action}%{SPACE}%{DATA:logsource} %{DATA:interface} %{GREEDYDATA:kvpairs}' }

     }


kv   {
source => "kvpairs"
field_split => ";"
value_split => ":"
remove_field => "kvpairs"
}
mutate {
    remove_field => [ "message" ]

}
geoip {

source => "src"
target => "geoip"
database => "/etc/logstash/GeoLiteCity.dat"
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ]
}

 mutate {
convert => [ " [geoip][coordinates]", "float"]
}


date {
    match => [ "timestamp" , "MMM dd HH:mm:ss" ]
    target => "@timestamp"
    }

if "_grokparsefailure" in [tags] {
    drop {}
    }

}


output {

stdout {
    codec => rubydebug
        }
elasticsearch {
    action => "index"
    host => "localhost"
    index => "external-%{+dd.MM.YYYY}"
    workers => 1

}
}

我的示例日志文件是:

Jan 1 22:54:17 drop   %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 70.77.116.190; dst: %DSTIP%; proto: tcp; product: VPN-1 & FireWall-1; service: 445; s_port: 2612;
Jan 1 22:54:22 drop   %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 61.164.41.144; dst: %DSTIP%; proto: udp; product: VPN-1 & FireWall-1; service: 5060; s_port: 5069;
Jan 1 22:54:23 drop   %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 69.55.245.136; dst: %DSTIP%; proto: tcp; product: VPN-1 & FireWall-1; service: 445; s_port: 2970;
Jan 1 22:54:41 drop   %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 95.104.65.30; dst: %DSTIP%; proto: tcp; product: VPN-1 & FireWall-1; service: 445; s_port: 2565;
Jan 1 22:54:43 drop   %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 222.186.24.11; dst: %DSTIP%; proto: tcp; product: VPN-1 & FireWall-1; service: 2967; s_port: 6000;
Jan 1 22:54:54 drop   %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 74.204.108.202; dst: %DSTIP%; proto: udp; product: VPN-1 & FireWall-1; service: 137; s_port: 53038;
Jan 1 22:55:10 drop   %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 71.111.186.26; dst: %DSTIP%; proto: tcp; product: VPN-1 & FireWall-1; service: 445; s_port: 38548;

我试图想象我在Kibana上的geoip,但它显示没有找到结果。我的geoip配置有什么东西吗?我下载了数据库,我没有遇到任何问题。但似乎geoip无法读取存储IP地址的src?另外,我扩展了字段表。我没有看到一些新的geoip字段,其中包含有关将src IP地址映射到真实地理位置的信息。

需要一些帮助男孩

elasticsearch logstash kibana geoip
1个回答
1
投票

你唯一的问题是你的kv过滤器由于空格而没有正确地分割出字段。

现在,当logstash解析您的日志时,您将获得以下事件:

{
      "@version" => "1",
    "@timestamp" => "2015-01-01T22:15:13.000Z",
          "host" => "iMac-de-Consulthys.local",
          "path" => "/home/kibana/Documents/external_noise.log",
          "type" => "external_noise",
     "timestamp" => "Jan 1 23:15:13",
        "action" => "drop",
     "logsource" => "%LOGSOURCE%",
     "interface" => ">eth1",
          " rule" => " 7",
      " rule_uid" => " {C1336766-9489-4049-9817-50584D83A245}",
           " src" => " 218.8.245.123",
           " dst" => " %DSTIP%",
         " proto" => " tcp",
       " product" => " VPN-1&FireWall-1",
       " service" => " 2967",
        " s_port" => " 6000",
}

您可以注意到kv过滤器提取的所有字段在开头都有一个空格。这意味着geoip过滤器无法找到src字段。

所以你要做的就是修改你的kv过滤器来修剪你的键和值,如下所示:

kv   {
    source => "kvpairs"
    field_split => ";"
    value_split => ":"
    trim => "\s"                 <--- add this line
    trimkey => "\s"              <--- add this line
    remove_field => "kvpairs"
}

然后你会得到一个正确创建的geoip字段的好事件,如下所示:

{
      "@version" => "1",
    "@timestamp" => "2015-01-01T22:15:13.000Z",
          "host" => "iMac-de-Consulthys.local",
          "path" => "/home/kibana/Documents/external_noise.log",
          "type" => "external_noise",
     "timestamp" => "Jan 1 23:15:13",
        "action" => "drop",
     "logsource" => "%LOGSOURCE%",
     "interface" => ">eth1",
          "rule" => "7",
      "rule_uid" => "{C1336766-9489-4049-9817-50584D83A245}",
           "src" => "218.8.245.123",
           "dst" => "%DSTIP%",
         "proto" => "tcp",
       "product" => "VPN-1&FireWall-1",
       "service" => "2967",
        "s_port" => "6000",
         "geoip" => {
                      "ip" => "218.8.245.123",
           "country_code2" => "CN",
           "country_code3" => "CHN",
            "country_name" => "China",
          "continent_code" => "AS",
             "region_name" => "08",
               "city_name" => "Harbin",
                "latitude" => 45.75,
               "longitude" => 126.64999999999998,
                "timezone" => "Asia/Harbin",
        "real_region_name" => "Heilongjiang",
                "location" => [
            [0] 126.64999999999998,
            [1] 45.75
        ],
             "coordinates" => [
            [0] 126.64999999999998,
            [1] 45.75
        ]
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.