在 Logstash 配置中创建一组服务器 IP?

Creating an array of server IPs in the Logstash configuration?

我想知道是否可以创建一个服务器 IP 地址数组,使 Logstash 配置文件更易于编辑和阅读。我用“linux”标记我们的 CentOS 机器,用“networking”标记我们的 ASA。现在,我配置的过滤器部分看起来像这样:

filter {
    if [host] == “10.x.x.1” or [host] == “10.x.x.2” or … or [host] “10.x.x.30” {
        mutate {
            add_tag => “linux”
        }
    }

    if [host] == “10.x.x.200” or [host] == “10.x.x.201” or … or [host] “10.x.x.250” {
        mutate {
            add_tag => “networking”
        }
}

这行得通,但由于我在每个类别中有 30 多个节点,所以这条线非常长。我正在考虑做这样的事情(在伪代码中):

array [linux_hosts] = [“10.x.x.1”,
                       “10.x.x.2”,
                       “10.x.x.3”]

if [host] in [linux_hosts] {
    mutate {
        add_tag => “linux”
    }
}

这样的事情可能吗?有更好的方法吗?

考虑到您的其他限制,我认为 translate{} 可能是最佳选择。不是很好,但也许是最好的...

translate {
    dictionary => [
        "10.1.1.1",   "linux",
        "10.1.1.200", "networking"
    ],
    destination => "source_type"
}

如果有帮助,您还可以从文件中阅读字典。