如何从 logstash 输出中获取 grep particulr 字段



我正在尝试仅从logstash 1.repository#create 2.\"repo\":\"用户名/reponame\"的输出中仅grep几个字段。 请分享您的想法,以从此输出中获取 grep 特定信息并将其分配给另一个变量

"消息" => "<190>11

月 01 20:35:15 10-254-128-66 github_audit: {\"actor_ip\":\"192.168.1.1

\",\"from\":\"存储库#create\",\"actor\":\"myuserid\",\"repo\":\"用户名/reponame\",\"action\":\"staff.repo_route\",\"created_at\":1516286634991,\"repo_id\":44743,\"actor_id\":1033,\"data\":{\"actor_location\":{\"位置\":{\"lat\":null,\"lon\":null}}}}",

我正在使用这个 syslog.conf 文件来获取输出。

input {
  tcp {
    port => 8088
    type => syslog
  }
  udp {
    port => 8088
    type => syslog
  }
}
filter {
  if [type] == "syslog" {
    grok {
      match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp}"
    }
    grep {
      match => { "message" => "repositories#create" }
    }
  }
}
output {
  elasticsearch { host => localhost }
  stdout { codec => rubydebug }
}

我无法为您的回复添加我的评论,非常感谢您的回复。

能否分享您的想法以获取用户名:和存储库:仅从此输出中,我正在尝试从此特定输出中分配值,再次感谢

消息: "

github_audit: {"actor_ip":"192.168.1.1","from":"存储库#创建","actor":"用户名","存储库":"用户名/logstashrepo","user":"用户名","created_at":1416299104782,"操作":"repo.create","user_id":1033,"repo_id":44744,"actor_id":1033,"数据":{"actor_location":{"位置":{"lat":null,"lon":null}}}}",@version:"1",@timestamp:"2014-11-18T08:25:05.427Z",主持人:"15-274-145-63",类型:"系统日志",syslog5424_pri:"190",时间戳:"11 月 18 日 00:25:05",actor_ip:"10.239.37.185",来自:"存储库#创建",演员:"用户名",repo: "username/logstashrepo",用户:"用户名",created_at: 1416299104782,操作:"repo.create",user_id: 1033,repo_id: 44744,actor_id: 1033,

使用 grok 筛选器将 JSON

有效负载提取到单独的字段中,然后使用 json 筛选器从 JSON 对象中提取字段。以下示例有效,但仅从前缀为"github_audit:"的消息中提取 JSON 有效负载。我还猜测时间戳后面的字段是一个主机名,应该覆盖当前可能位于"主机"字段中的任何内容。不要忘记添加一个日期过滤器,将"时间戳"字段中的字符串解析为"@timestamp"。

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

最新更新