使用 GeoIP 信息丰富事件数据
您可以结合使用 Auditbeat 和 Elasticsearch 中的 GeoIP 处理器来导出基于 IP 地址的地理位置信息。然后,您可以使用此信息在 Kibana 的地图上可视化显示 IP 地址的位置。
geoip 处理器会根据 Maxmind GeoLite2 City 数据库中的数据,添加有关 IP 地址地理位置的信息。由于该处理器使用的是安装在 Elasticsearch 上的 geoIP 数据库,因此您无需在运行 Auditbeat 的机器上安装 geoIP 数据库。
如果您的用例涉及使用 Logstash,则可以使用 Logstash 中提供的 GeoIP 过滤器 (GeoIP filter),而不是使用 geoip 处理器。但是,当您不需要 Logstash 的额外处理能力时,使用 geoip 处理器是最简单的方法。
配置 Auditbeat 和 geoip 处理器
定义一个引入管道(ingest pipeline),该管道使用一个或多个
geoip处理器向事件中添加位置信息。例如,您可以使用 Kibana 中的控制台 (Console) 创建以下管道PUT _ingest/pipeline/geoip-info{ "description": "Add geoip info", "processors": [ { "geoip": { "field": "client.ip", "target_field": "client.geo", "ignore_missing": true } }, { "geoip": { "database_file": "GeoLite2-ASN.mmdb", "field": "client.ip", "target_field": "client.as", "properties": [ "asn", "organization_name" ], "ignore_missing": true } }, { "geoip": { "field": "source.ip", "target_field": "source.geo", "ignore_missing": true } }, { "geoip": { "database_file": "GeoLite2-ASN.mmdb", "field": "source.ip", "target_field": "source.as", "properties": [ "asn", "organization_name" ], "ignore_missing": true } }, { "geoip": { "field": "destination.ip", "target_field": "destination.geo", "ignore_missing": true } }, { "geoip": { "database_file": "GeoLite2-ASN.mmdb", "field": "destination.ip", "target_field": "destination.as", "properties": [ "asn", "organization_name" ], "ignore_missing": true } }, { "geoip": { "field": "server.ip", "target_field": "server.geo", "ignore_missing": true } }, { "geoip": { "database_file": "GeoLite2-ASN.mmdb", "field": "server.ip", "target_field": "server.as", "properties": [ "asn", "organization_name" ], "ignore_missing": true } }, { "geoip": { "field": "host.ip", "target_field": "host.geo", "ignore_missing": true } }, { "rename": { "field": "server.as.asn", "target_field": "server.as.number", "ignore_missing": true } }, { "rename": { "field": "server.as.organization_name", "target_field": "server.as.organization.name", "ignore_missing": true } }, { "rename": { "field": "client.as.asn", "target_field": "client.as.number", "ignore_missing": true } }, { "rename": { "field": "client.as.organization_name", "target_field": "client.as.organization.name", "ignore_missing": true } }, { "rename": { "field": "source.as.asn", "target_field": "source.as.number", "ignore_missing": true } }, { "rename": { "field": "source.as.organization_name", "target_field": "source.as.organization.name", "ignore_missing": true } }, { "rename": { "field": "destination.as.asn", "target_field": "destination.as.number", "ignore_missing": true } }, { "rename": { "field": "destination.as.organization_name", "target_field": "destination.as.organization.name", "ignore_missing": true } } ] }在此示例中,管道 ID 为
geoip-info。field指定包含用于地理查找的 IP 地址的字段,而target_field是将保存地理信息的字段。"ignore_missing": true将管道配置为在遇到没有指定字段的事件时继续处理。有关更多选项,请参阅 GeoIP 处理器 (GeoIP Processor)。
要了解有关向事件添加主机信息的更多信息,请参阅 add_host_metadata。
在 Auditbeat 配置文件中,配置 Elasticsearch 输出以使用该管道。在
output.elasticsearch下的pipeline选项中指定管道 ID。例如output.elasticsearch: hosts: ["localhost:9200"] pipeline: geoip-info运行 Auditbeat。如果配置文件归 root 所有,请记得使用
sudo。./auditbeat -e如果查找成功,事件将包含
geo_point字段(例如client.geo.location和host.geo.location),您可以使用这些字段在 Kibana 中填充可视化。
如果您添加了一个尚未在索引模板中定义为 geo_point 的字段,请添加一个映射,以便该字段能被正确索引。
要可视化 IP 地址的位置,你可以在 Kibana 中创建一个新的 坐标地图,并选择位置字段(例如 client.geo.location 或 host.geo.location)作为 Geohash。
