-3

我正在尝试分配“actor”:“githubuser”,例如 $actor = “gituser” 和 $repo = “gituser/logstashreppo”,如果我将值分配给变量,我可以使用此处复制的 exec 函数执行我的脚本。请分享你的想法

整个输出是

{
_index: "logstash-2014.11.20",
_type: "syslog",
_id: "76ggV_gfWS5u2L9rcMNCWaQ",
_score: 0.35005248,
_source: {
message: "github_audit: {"actor_ip":"192.168.1.1","from":"repositories#create","actor":"gituser","repo":"gituser/logstashreppo","action":"staff.repo_route","created_at":1236483708817,"repo_id":44758,"actor_id":1033,"data":{"actor_location":{"location":{"lat":null,"lon":null}}}}",
@version: "1",
@timestamp: "2014-11-17T11:41:50.142Z",
host: "192.168.1.1",
type: "syslog",
syslog5424_pri: "190",
timestamp: "Nov 17 03:41:50",
actor_ip: "192.168.1.1",
from: "repositories#create",
actor: "gituser",
repo: "gituser/logstashrepo",
action: "staff.repo_route",
created_at: 1236483708817,
repo_id: 44758,
actor_id: 1033,
data: {
actor_location: {
location: {
lat: null,
lon: null
}
}
}
}
}

,

我的配置文件是:

filter {
  grok {
    match => [
      "message",
      "%{SYSLOG5424PRI}%{SYSLOGTIMESTAMP:timestamp} %{HOSTNAME:host} %{GREEDYDATA:message}"
    ]
    overwrite => ["host", "message"]
  }
  if [message] =~ /^git_audit: / {
    grok {
      match => ["message", "^git_audit: %{GREEDYDATA:json_payload}"]
    }
    json {
      source => "json_payload"
      remove_field => "json_payload"
    }
mutate {
  rename => ["[json][repo]", "repo"]
  remove_field => "json"
}
  }
}

input {
exec {
    type => "audit-log"
    command => "perl test.pl $actor"

  }
}
output {
  elasticsearch { host => localhost }
  stdout { codec => rubydebug }
}
4

1 回答 1

0

在exec 插件的文档中有一个您想要的示例。

exec {
    type => "audit-log"
    command => "perl test.pl %{actor}"
}

另请参阅配置文件格式文档中的“sprintf 格式”部分,但请注意该%{fieldname}语法不适用于所有字符串(并且没有很好地记录它在哪里工作以及在哪里不工作)。

最后,请注意,type对于像 exec 这样的输出插件,该属性已被弃用。你应该像这样重写它:

if [type] == "audit-log" {
    exec {
        command => "perl test.pl %{actor}"
    }
}
于 2014-11-22T19:08:57.533 回答