I want to be able to select a grok pattern and add “my_body” field to it to force an action later.
I can get it to add multiple tags or no tags, but not a single tag.
Below is the latest filter version of many iterations, but I can never get it to work as above.
I have tried:
if "_grokparsefailure" in [tabs] {
if !( [tabs] =~ “grok27” ){
etc.
${LOGSTASH_DIR}/bin/logstash --version
logstash 2.3.1
Test Events:
dplrgid8@:/home/dplrgid8/logstash/dev/templates/$ cat /tmp/out
[15 Dec 2016, 09:01:18 ] ERROR : com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.LinuxVirtualMachine.(LinuxVirtualMachine.java:106)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:78)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:255)
at com.globalids.env.SystemHealthMonitor.(SystemHealthMonitor.java:131)
at com.globalids.env.SystemHealthMonitor$PeriodicTask.run(SystemHealthMonitor.java:761)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Filter shm.exception:
dplrgid8@:/home/dplrgid8/logstash/dev/bin/$ cat ../templates/shm.exception.filter.template
if [type] == "MSG_TYPE" {
grok {
match => { "message" => "^\[%{MONTHDAY}%{SPACE}%{MONTH}%{SPACE}%{YEAR},%{SPACE}%{TIME}%{SPACE}\]%{SPACE}%{WORD:msg_level}%{SPACE}:%{SPACE}%{JAVACLASS:javaclass}:%{SPACE}%{NOTSPACE:err_num}:%{SPACE}%{GREEDYDATA:narrative}" }
remove_tag => ["_grokparsefailure"]
add_field => { "tags" => "grok2701" }
}
if "_grokparsefailure" in [tabs] {
grok {
match => { "message" => "^\[%{MONTHDAY}%{SPACE}%{MONTH}%{SPACE}%{YEAR},%{SPACE}%{TIME}%{SPACE}\]%{SPACE}%{NOTSPACE:msg_level}%{SPACE}:%{SPACE}Index:%{SPACE}%{NOTSPACE:index},%{SPACE}Size:%{SPACE}%{NOTSPACE:size}" }
remove_tag => ["_grokparsefailure"]
add_field => { "tags" => "grok2702" }
}
}
else if "_grokparsefailure" in [tabs] {
grok {
match => { "message" => "^\[%{MONTHDAY}%{SPACE}%{MONTH}%{SPACE}%{YEAR},%{SPACE}%{TIME}%{SPACE}\]%{SPACE}%{NOTSPACE:msg_level}%{SPACE}:%{SPACE}%{INT:err_num}%{SPACE}:%{SPACE}%{GREEDYDATA:narrative}" }
remove_tag => ["_grokparsefailure"]
add_field => { "tags" => "grok2703" }
}
}
else if "_grokparsefailure" in [tabs] {
grok {
match => { "message" => "^\[%{MONTHDAY}%{SPACE}%{MONTH}%{SPACE}%{YEAR},%{SPACE}%{TIME}%{SPACE}\]%{SPACE}%{WORD:msg_level}%{SPACE}:%{SPACE}%{JAVACLASS:javaclass}%{SPACE}:%{SPACE}%{GREEDYDATA:narrative}" }
remove_tag => ["_grokparsefailure"]
add_field => { "tags" => "grok2706" }
add_field => { "my_body" => "%{msg_level} from %{host}:%{path}:\n\n%{narrative}\n\nJavaClass: %{javaclass}" }
}
}
Test Below
else if "_grokparsefailure" in [tabs] {
grok {
match => { "message" => "^\[%{MONTHDAY}%{SPACE}%{MONTH}%{SPACE}%{YEAR},%{SPACE}%{TIME}%{SPACE}\]%{SPACE}%{WORD:msg_level}%{SPACE}:%{SPACE}%{JAVACLASS:javaclass}%{SPACE}:%{SPACE}%{GREEDYDATA:narrative}" }
remove_tag => ["_grokparsefailure"]
add_field => { "tags" => "grok2707" }
add_field => { "my_body" => "%{msg_level} from %{host}:%{path}:\n\n%{narrative}\n\nJavaClass: %{javaclass}" }
}
}
TEST Below
else if "_grokparsefailure" in [tabs] {
mutate {
add_field => { "tags" => "grok2799" }
}
}
}
Results:
Settings: Default pipeline workers: 8
Pipeline main started
{
"@timestamp" => "2016-12-15T21:18:15.934Z",
"message" => "[15 Dec 2016, 09:01:18 ] ERROR : com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded\n\tat sun.tools.attach.LinuxVirtualMachine.(LinuxVirtualMachine.java:106)\n\tat sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:78)\n\tat com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:255)\n\tat com.globalids.env.SystemHealthMonitor.(SystemHealthMonitor.java:131)\n\tat com.globalids.env.SystemHealthMonitor$PeriodicTask.run(SystemHealthMonitor.java:761)\n\tat java.util.TimerThread.mainLoop(Timer.java:555)\n\tat java.util.TimerThread.run(Timer.java:505)",
"@version" => "1",
"tags" => [
[0] "multiline",
[1] "_grokparsefailure"
],
"path" => "/opt/app/globalid/data/server/Release-9-0/logs/shm_exception.log",
"host" => "hltv0777.hydc.sbc.com",
"type" => "shm.exception",
"application" => "DPLR_GID",
"environment" => "qa",
"component" => "CHILD",
"logstash_version" => "2.3.1",
"filter_date" => "2016/12/15 15:17:52 CST"
}