Logstash Aggregate Problem tag in subdirectories Please Help

Hi i trying to use logstash aggregate to tag all log events i main and sub folders.

I want all logs in APP1 folders and subfolders to have tag "APP1" and all logs in app2 folders to have APP2 etc.

My friend did some kind of loop down here.

But i dont understand what he did.

The events in each app folder has a stop and end event.

This below here is not for tagging every event but i want to have the tagging to work.

Please help me.

BR Dennis

Main
├───APP1-LOG-MAIN-DIR
│ ├───SUB-DIR
| │ ├───APP1-LOG-SUB-DIR
| | | ├───file1
| | | ├───file2
| | | ├───file3
| | | ├───file4
├───APP2-LOG-MAIN-DIR
│ ├───SUB-DIR
| │ ├───APP2-LOG-SUB-DIR
| | | ├───file1
| | | ├───file2
| | | ├───file3
| | | ├───file4

filter {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} [%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - %{GREEDYDATA:automation_status}"}
}

if "NUIX-RUNNER-START" in [tags] {
    ruby {
        code => '
            event.set("[nuix_log]", {
                "runner" => event.get("nuix_class").delete_prefix("SCRIPT.").delete_suffix(".gen"), 
                "path" => File.dirname(event.get("[log][file][path]")),
                "host" => event.get("[agent][hostname]"),
            })
        '
    }
    aggregate {
        task_id => "%{[nuix_log][host]}"
        code => "map[event.get('[nuix_log][path]')] = event.get('[nuix_log]')"
        map_action => "create"
    }
} else if "NUIX-RUNNER-END" in [tags] {
    ruby {
        code => 'event.set("[nuix_log][host]", event.get("[agent][hostname]"))'
    }
    aggregate {
        task_id => "%{[nuix_log][host]}"
        code => '
            log_dir = File.dirname(event.get("[log][file][path]"))
            (0..6).each do |i|
                if map.key?(log_dir)
                    event.set("[nuix_log]", map[log_dir])
                    break
                end
                log_dir = File.dirname(log_dir)
            end
        '
        map_action => "update"
        end_of_task => true
        timeout => 120
    }
} else {
    ruby {
        code => 'event.set("[nuix_log][host]", event.get("[agent][hostname]"))'
    }
    aggregate {
        task_id => "%{[nuix_log][host]}"
        code => '
            log_dir = File.dirname(event.get("[log][file][path]"))
            (0..6).each do |i|
                if map.key?(log_dir)
                    event.set("[nuix_log]", map[log_dir])
                    break
                end
                log_dir = File.dirname(log_dir)
            end
        '
        map_action => "update"
    }
}

}

Those aggregates will add

  "nuix_log" => {
      "path" => "/Main/APP1-LOG-MAIN-DIR/SUB-DIR/APP1-LOG-SUB-DIR",
      "host" => "foo",
    "runner" => "blah"
},

to each event where [log][file][path] is "/Main/APP1-LOG-MAIN-DIR/SUB-DIR/APP1-LOG-SUB-DIR". If you literally want to add a tag with the app name I would suggest adding

grok { match => { "[nuix_log][path]" => "/\w+/%{WORD:[@metadata][appname]}-" } add_tag => [ "%{[@metadata][appname]}" ] }

after the aggregates.

Thanks a lot Badger.

Your help is invaluable for me.

I will explain a little more what I want to do.

Nuix is a program for forensic examination's and it create logs everytime you start a new ingestion.

Let say case1 starting and ingesting it creates a main folder for main log.

that long is called Nuix.log and it for the main log.

2 steps below it creates something called worker logs these also belong to case1

All logs in 20211230131416 folder belongs to same case.

as you see here in the list all cases starts with a main folder with a muix.log and 2 folder below its creates something called worker logs filename is also nuix.log.

What I'm trying to do here is to add the case name in all logs events below to the case.

first I use filebeat to tag the files and read them in

  • type: log
    paths:

    • \share.avian.dk\AvianShare\LAB\Logs\Workstation*****\nuix.log
      tags: ["NUIX-LOG", "NUIX-LOG-WORKSTATION", "NUIX-WORKER-LOG-WORKSTATION"]
      multiline.type: pattern
      multiline.pattern: '[1]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}'
      multiline.negate: true
      multiline.match: after
      scan_frequency: 10s
  • type: log
    paths:

    • \share.avian.dk\AvianShare\LAB\Logs\Workstation***\nuix.log
      tags: ["NUIX-LOG", "NUIX-LOG-WORKSTATION", "NUIX-MAIN-LOG-WORKSTATION"]
      multiline.type: pattern
      multiline.pattern: '[2]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}'
      multiline.negate: true
      multiline.match: after
      scan_frequency: 10s

  1. 0-9 ↩︎

  2. 0-9 ↩︎

After that sens it to Logstash.

The case name can be found in Nuix.log from the main log.

Here is a snippet from the log

2021-12-30 13:15:08.614 +0100 [AWT-EventQueue-0] 51818 INFO com.nuix.data.keystore.b - Read 0 passwords from C:\CASE\Test Log 1-1\Stores\DecryptionKeys\pgpkeylist.dat

so the case name is "Test Log 1-1"

So in logstach a can get it by using

else if "NUIX-RUNNER-START-WS" in [tags] and "NUIX-LOG" in [tags] {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} [%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - (?<case_name>.+?(?=\Stores\DecryptionKeys\pgpkeylist.dat))"}
}
mutate {
gsub => [
# replace backslashes and forward slashes with a hyphen
"case_name", "[\/]", "€ "
]
}
grok {
match => {"case_name" => " (?<nuix_case>([^€]+$))"}

So what I'm doing here is within the aggregate loop I sent here yestoday I want to tag every event with case name or add a filed with the case name to every event.

I post my whole lostasch conf here so maybe you can se what I'm doing wrong .

The Logstash do alto more but my main problem is to tag it with case name.

input {
beats {
port => 5044
}
}

filter {
if "AUTOMATION" in [tags] {
grok {
match => { "ts" => "(?^.{0,23})" }
}
date {
match => [ "ts1", "ISO8601", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss.ZZZ", "UNIX" ]
target => "@timestamp"
locale => "en"
}
ruby {
code => '
t = event.get("@timestamp")
event.set("automation_timestamp_fixed", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
'
}
}

}

filter {
if "MULTILINE" in [tags] and "NUIX-LOG" in [tags] {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} [%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - (?<nuix_short_message>[\s\S]{0,50})%{DATA:nuix_second_short_message}\n(?m)%{GREEDYDATA:nuix_multilines}"}
}
} else if "AUTOMATION" in [tags] {
grok {
match => {"message" => "%{LOGLEVEL:level}%{GREEDYDATA:log_message}"}
}
} else if "INVESTIGATE" in [tags] and "MULTILINE" in [tags] {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:investigate_timestamp} %{DATA:message}\n(?m)%{GREEDYDATA:message_multilines}"}
}
} else if "METRICBEAT" in [tags] {
grok {
match => {"message" => "%{GREEDYDATA:log_message}"}
}
} else if "INVESTIGATE" in [tags] {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:investigate_timestamp}%{GREEDYDATA:log_message}"}
}
} else if "_grokparsefailure" in [tags] {
grok {
match => {"message" => "%{GREEDYDATA:log_message}"}
}
} else if "NUIX-RUNNER-START-WS" in [tags] and "NUIX-LOG" in [tags] {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} [%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - (?<case_name>.+?(?=\Stores\DecryptionKeys\pgpkeylist.dat))"}
}
mutate {
gsub => [
# replace backslashes and forward slashes with a hyphen
"case_name", "[\/]", "€ "
]
}
grok {
match => {"case_name" => " (?<nuix_case>([^€]+$))"}
}
} else if "OCR-LOG" in [tags] {
grok {
match => {"message" => "%{GREEDYDATA:log_message}"}
}
} else if "ABBY-WORKER-LOG" in [tags] {
grok {
match => {"message" => "%{GREEDYDATA:log_message}"}
}
} else {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} [%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - %{GREEDYDATA:automation_status}"}
add_tag => [ "SINGLE-LINE" ]
}
}

if "NUIX-RUNNER-START" in [tags] {        
    ruby {   
        code => '
            event.set("[nuix_log]", {
                "runner" => event.get("nuix_class").delete_prefix("SCRIPT.").delete_suffix(".gen"),
                "path" => File.dirname(event.get("[log][file][path]")),
                "host" => event.get("[agent][hostname]"),
            })
        '
    }
    aggregate {

        task_id => "%{[nuix_log][host]}"

        code => "map[event.get('[nuix_log][path]')] = event.get('[nuix_log]')"
        map_action => "create"

    }

} else if "NUIX-RUNNER-END" in [tags] {       
    ruby {
        code => 'event.set("[nuix_log][host]", event.get("[agent][hostname]"))'
    }
    aggregate {
        task_id => "%{[nuix_log][host]}"
        code => '
            log_dir = File.dirname(event.get("[log][file][path]"))
            if map.key?(log_dir)
                event.set("[nuix_log]", map[log_dir])
            end
        '
        timeout => 2629743
        inactivity_timeout => 300            
        map_action => "update"                    
        end_of_task => true           
    }
} else {      
    ruby {
        code => 'event.set("[nuix_log][host]", event.get("[agent][hostname]"))'
    }
    aggregate {           
        task_id => "%{[nuix_log][host]}"
        code => '
            log_dir = File.dirname(event.get("[log][file][path]"))

             (0..6).each do |i|
                if map.key?(log_dir)
                    event.set("[nuix_log]", map[log_dir])
                    break
                end
                log_dir = File.dirname(log_dir)
            end
        '
        map_action => "update" 
            
    
    
    }

grok { match => { "[nuix_log][path]" => "/\w+/%{WORD:[@metadata][appname]}-" } add_tag => [ "%{[@metadata][appname]}" ] }

}    

}

##########################################################
filter {
if "MULTILINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-MAIN-LOG-ERROR" in [tags] {
mutate {
add_field => { "nuix_error_message" => "%{nuix_short_message}%{nuix_second_short_message}" }
}
}
}

filter {
if "MULTILINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-WORKER-LOG-ERROR" in [tags] {
mutate {
add_field => { "nuix_error_message" => "%{nuix_short_message}%{nuix_second_short_message}" }
}
}
}

filter {
if "SINGLE-LINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-WORKER-LOG-ERROR" in [tags] {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp_blaj} %{NUMBER:nuix_timezone_blaj} [%{DATA:nuix_source_blaj}] %{NUMBER:nuix_thread-blaj} %{GREEDYDATA:nuix_error_message}"}
}
mutate {
remove_field => [ "nuix_timestamp_blaj", "nuix_timezone_blaj", "nuix_source_blaj", "uix_thread-blaj" ]
}
}
}

filter {
if "SINGLE-LINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-MAIN-LOG-ERROR" in [tags] {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp-blaj} %{NUMBER:nuix_timezone_blaj} [%{DATA:nuix_source_blaj}] %{NUMBER:nuix_thread_blaj} %{GREEDYDATA:nuix_error_message}"}
}
mutate {
remove_field => [ "nuix_timestamp_blaj", "nuix_timezone_blaj", "nuix_source_blaj", "uix_thread-blaj" ]
}
}
}

###########################################################

filter {
if "NUIX-SINGLE-WORKER" in [tags] {
mutate { convert => ["process_pid", "string"] }
ruby {
code => '
event.set("nuix_running_worker", event.get("[process][name]") + "-" + event.get("process_pid"))
'
}
}
}

#filter {

if "DISK-SPACE-UTIL" in [tags] {

mutate { convert => ["[system][filesystem][used][bytes]", "string"] }

mutate { convert => ["[system][filesystem][total]", "string"] }

mutate {

add_field => {

"nuix_disc_event" => " Drive %{[system][filesystem][device_name]} %{[system][filesystem][used][bytes]} of %{[system][filesystem][total]}"

}

}

}

#}

#filter {

if "DISK-SPACE-UTIL" in [tags] {

mutate { convert => ["system_filesystem_free", "string"] }

mutate { convert => ["system_filesystem_total", "string"] }

mutate {

add_field => {

"nuix_disc_event" => " Drive %{[system][filesystem][device_name]} %{system_filesystem_free} of %{system_filesystem_total}"

}

}

#}

############ From here Metricbeat

#event.set("nuix_running_worker", "Host=" + event.get("[agent][hostname]") + event.get("[process][name]") + event.get("process_pid"))

filter {
if "NUIX-LOG" in [tags] {
date {
match => [ "nuix_timestamp", "ISO8601", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss.ZZZ" ]
target => "@timestamp"
locale => "en"
}
}

}

filter {
if "INVESTIGATE" in [tags] {
date {
match => [ "investigate_timestamp", "ISO8601", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss.ZZZ" ]
target => "@timestamp"
locale => "en"
}
}

}

filter {
if "RU" in [tags] {
elapsed {
start_tag => "STARTING-RUNNER"
end_tag => "ENDING-RUNNER"
periodic_flush => false
unique_id_field => "runner"
timeout => 2629743
new_event_on_match => false
}
} else if "ST" in [tags] {
elapsed {
start_tag => "STARTING-STAGE"
end_tag => "ENDING-STAGE"
periodic_flush => false
unique_id_field => "[automation][stage_id]"
timeout => 2629743
new_event_on_match => false
}
}
}

filter {
if [elapsed_time] {
ruby {
code => '
event.set("[elapsed_hr]", Time.at(event.get("[elapsed_time]")).utc.strftime("%T.%L"))
'
}
}
}

filter {
if "STARTING-RUNNER" in [tags] {
ruby {
code => '
t = event.get("@timestamp")
event.set("elapsed_timestamp_event_start_runner", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
'
}
mutate {
add_field => { "elapsed_timestamp_event_end_runner" => "--------------->" }
}
mutate {
add_field => { "elapsed_hr" => "Runner Started" }
}
}
}

filter {
if "STARTING-STAGE" in [tags] {
ruby {
code => '
t = event.get("@timestamp")
event.set("elapsed_timestamp_event_start_stage", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
'
}
mutate {
add_field => { "elapsed_timestamp_event_end_stage" => "--------------->" }
}
mutate {
add_field => { "elapsed_hr" => "Stage Started" }
}
}
}

filter {
if "ENDING-STAGE" in [tags] {
ruby {
code => '
t = event.get("elapsed_timestamp_start")
event.set("elapsed_timestamp_event_start_stage", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
'
}
}
}

filter {
if "ENDING-RUNNER" in [tags] {
ruby {
code => '
t = event.get("elapsed_timestamp_start")
event.set("elapsed_timestamp_event_start_runner", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
'
}
}
}

filter {
if "AUTOMATION-FINISHED-STAGE" in [tags] {
ruby {
code => '
t = event.get("@timestamp")
event.set("elapsed_timestamp_event_end_stage", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
'
}
}
}

filter {
if "AUTOMATION-FINISHED-RUNNER" in [tags] {
ruby {
code => '
t = event.get("@timestamp")
event.set("elapsed_timestamp_event_end_runner", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
'
}
}
}

filter {
mutate {
remove_tag => [ "beats_input_codec_plain_applied", "beats_input_raw_event" ]
}
}

filter {
if "_grokparsefailure" in [tags] {
drop{}
}
}

#filter {

if "NUIX-LOG" in [tags] {

mutate {

copy => { "[nuix_log][runner]" => "nuix_case" }

}

}

#}

output {
Elasticsearch {
hosts => ["http://automation.avian.dk:9200", "http://automation.avian.dk:9201"]
index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
}
}

  1. input {

  2. beats {

  3. port => 5044
    
  4. }

  5. }

  6. filter {

  7. if "AUTOMATION" in [tags] {
    
  8.     grok {
    
  9.         match =>  { "ts" => "(?<ts1>^.{0,23})" }
    
  10.     }
    
  11.     date {
    
  12.         match => [ "ts1", "ISO8601", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss.ZZZ", "UNIX" ]
    
  13.         target => "@timestamp"
    
  14.         locale => "en"
    
  15.     }
    
  16.     ruby {
    
  17.         code => '
    
  18.         t = event.get("@timestamp")
    
  19.         event.set("automation_timestamp_fixed", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
    
  20.     '
    
  21.     }
    
  22. }
    
  23. }

  24. filter {

  25. if "MULTILINE" in [tags] and "NUIX-LOG" in [tags] {
    
  26.     grok {
    
  27.         match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} \[%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - (?<nuix_short_message>[\s\S]{0,50})%{DATA:nuix_second_short_message}\n(?m)%{GREEDYDATA:nuix_multilines}"}
    
  28.     }
    
  29. } else if "AUTOMATION" in [tags]   {
    
  30.     grok {
    
  31.         match => {"message" => "%{LOGLEVEL:level}%{GREEDYDATA:log_message}"}
    
  32.     }
    
  33. } else if "INVESTIGATE" in [tags] and "MULTILINE" in [tags]  {
    
  34.     grok {
    
  35.         match => {"message" => "%{TIMESTAMP_ISO8601:investigate_timestamp} %{DATA:message}\n(?m)%{GREEDYDATA:message_multilines}"}
    
  36.     }           
    
  37. } else if "METRICBEAT" in [tags]  {
    
  38.     grok {
    
  39.         match => {"message" => "%{GREEDYDATA:log_message}"}
    
  40.     }   
    
  41. } else if "INVESTIGATE" in [tags]  {
    
  42.     grok {
    
  43.         match => {"message" => "%{TIMESTAMP_ISO8601:investigate_timestamp}%{GREEDYDATA:log_message}"}
    
  44.     }      
    
  45. } else if "_grokparsefailure" in [tags]  {
    
  46.     grok {
    
  47.         match => {"message" => "%{GREEDYDATA:log_message}"}        
    
  48.     }
    
  49. } else if "NUIX-RUNNER-START-WS" in [tags] and "NUIX-LOG" in [tags]  {
    
  50.     grok {
    
  51.         match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} \[%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - (?<case_name>.+?(?=\\Stores\\DecryptionKeys\\pgpkeylist.dat))"}
    
  52.     }
    
  53.     mutate {
    
  54.     gsub => [      
    
  55.       # replace backslashes and forward slashes with a hyphen
    
  56.       "case_name", "[\\/]", "€ "
    
  57.     ]
    
  58.     }
    
  59.     grok {
    
  60.         match => {"case_name" => " (?<nuix_case>([^€]+$))"}        
    
  61.     }
    
  62. } else if "OCR-LOG" in [tags]  {
    
  63.     grok {
    
  64.         match => {"message" => "%{GREEDYDATA:log_message}"}
    
  65.     }
    
  66. } else if "ABBY-WORKER-LOG" in [tags]  {
    
  67.     grok {
    
  68.         match => {"message" => "%{GREEDYDATA:log_message}"}
    
  69.     } 
    
  70. } else {
    
  71.     grok {
    
  72.         match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp} %{NUMBER:nuix_timezone} \[%{DATA:nuix_source}] %{NUMBER:nuix_thread} %{LOGLEVEL:nuix_loglevel}%{SPACE}%{DATA:nuix_class} - %{GREEDYDATA:automation_status}"}
    
  73.         add_tag => [ "SINGLE-LINE" ]
    
  74.     }
    
  75. }
    
  76. if "NUIX-RUNNER-START" in [tags] {        
    
  77.     ruby {   
    
  78.         code => '
    
  79.             event.set("[nuix_log]", {
    
  80.                 "runner" => event.get("nuix_class").delete_prefix("SCRIPT.").delete_suffix(".gen"),
    
  81.                 "path" => File.dirname(event.get("[log][file][path]")),
    
  82.                 "host" => event.get("[agent][hostname]"),
    
  83.             })
    
  84.         '
    
  85.     }
    
  86.     aggregate {
    
  87.         task_id => "%{[nuix_log][host]}"
    
  88.         code => "map[event.get('[nuix_log][path]')] = event.get('[nuix_log]')"
    
  89.         map_action => "create"
    
  90.     }
    
  91. } else if "NUIX-RUNNER-END" in [tags] {       
    
  92.     ruby {
    
  93.         code => 'event.set("[nuix_log][host]", event.get("[agent][hostname]"))'
    
  94.     }
    
  95.     aggregate {
    
  96.         task_id => "%{[nuix_log][host]}"
    
  97.         code => '
    
  98.             log_dir = File.dirname(event.get("[log][file][path]"))
    
  99.             if map.key?(log_dir)
    
  100.                 event.set("[nuix_log]", map[log_dir])
    
  101.             end
    
  102.         '
    
  103.         timeout => 2629743
    
  104.         inactivity_timeout => 300            
    
  105.         map_action => "update"                    
    
  106.         end_of_task => true           
    
  107.     }
    
  108. } else {      
    
  109.     ruby {
    
  110.         code => 'event.set("[nuix_log][host]", event.get("[agent][hostname]"))'
    
  111.     }
    
  112.     aggregate {           
    
  113.         task_id => "%{[nuix_log][host]}"
    
  114.         code => '
    
  115.             log_dir = File.dirname(event.get("[log][file][path]"))
    
  116.              (0..6).each do |i|
    
  117.                 if map.key?(log_dir)
    
  118.                     event.set("[nuix_log]", map[log_dir])
    
  119.                     break
    
  120.                 end
    
  121.                 log_dir = File.dirname(log_dir)
    
  122.             end
    
  123.         '
    
  124.         map_action => "update" 
    
  125.     }
    
  126. grok { match => { "[nuix_log][path]" => "/\w+/%{WORD:[@metadata][appname]}-" } add_tag => [ "%{[@metadata][appname]}" ] }

  127. }    
    
  128. }

  129. ##########################################################

  130. filter {

  131. if "MULTILINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-MAIN-LOG-ERROR" in [tags] {
    
  132.     mutate {
    
  133.         add_field => { "nuix_error_message" => "%{nuix_short_message}%{nuix_second_short_message}" }
    
  134.     }
    
  135. }    
    
  136. }

  137. filter {

  138. if "MULTILINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-WORKER-LOG-ERROR" in [tags] {
    
  139.     mutate {
    
  140.         add_field => { "nuix_error_message" => "%{nuix_short_message}%{nuix_second_short_message}" }
    
  141.     }
    
  142. }    
    
  143. }

  144. filter {

  145. if "SINGLE-LINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-WORKER-LOG-ERROR" in [tags] {
    
  146.     grok {
    
  147.        match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp_blaj} %{NUMBER:nuix_timezone_blaj} \[%{DATA:nuix_source_blaj}] %{NUMBER:nuix_thread-blaj} %{GREEDYDATA:nuix_error_message}"}            
    
  148.     }
    
  149.     mutate {
    
  150.        remove_field => [ "nuix_timestamp_blaj", "nuix_timezone_blaj", "nuix_source_blaj", "uix_thread-blaj" ] 
    
  151.     }
    
  152. }    
    
  153. }

  154. filter {

  155. if "SINGLE-LINE" in [tags] and "NUIX-LOG" in [tags] and "NUIX-MAIN-LOG-ERROR" in [tags] {
    
  156.     grok {
    
  157.         match => {"message" => "%{TIMESTAMP_ISO8601:nuix_timestamp-blaj} %{NUMBER:nuix_timezone_blaj} \[%{DATA:nuix_source_blaj}] %{NUMBER:nuix_thread_blaj} %{GREEDYDATA:nuix_error_message}"}            
    
  158.     }
    
  159.      mutate {
    
  160.        remove_field => [ "nuix_timestamp_blaj", "nuix_timezone_blaj", "nuix_source_blaj", "uix_thread-blaj" ] 
    
  161.     }
    
  162. }    
    
  163. }

  164. ###########################################################

  165. filter {

  166. if "NUIX-SINGLE-WORKER" in [tags] {
    
  167.     mutate { convert => ["process_pid", "string"] }
    
  168.     ruby {
    
  169.         code => '
    
  170.                event.set("nuix_running_worker", event.get("[process][name]") + "-" + event.get("process_pid"))                 
    
  171.         '
    
  172.     }
    
  173. }
    
  174. }

  175. #filter {

  176. if "DISK-SPACE-UTIL" in [tags] {

  177. mutate { convert => ["[system][filesystem][used][bytes]", "string"] }

  178. mutate { convert => ["[system][filesystem][total]", "string"] }

  179. mutate {

  180. add_field => {

  181. "nuix_disc_event" => " Drive %{[system][filesystem][device_name]} %{[system][filesystem][used][bytes]} of %{[system][filesystem][total]}"

  182. }

  183. }

  184. }

  185. #}

  186. #filter {

  187. if "DISK-SPACE-UTIL" in [tags] {

  188. mutate { convert => ["system_filesystem_free", "string"] }

  189. mutate { convert => ["system_filesystem_total", "string"] }

  190. mutate {

  191. add_field => {

  192. "nuix_disc_event" => " Drive %{[system][filesystem][device_name]} %{system_filesystem_free} of %{system_filesystem_total}"

  193. }

  194. }

  195. #}

  196. ############ From here Metricbeat

  197. #event.set("nuix_running_worker", "Host=" + event.get("[agent][hostname]") + event.get("[process][name]") + event.get("process_pid"))

  198. filter {

  199. if "NUIX-LOG" in [tags] {
    
  200.     date {
    
  201.         match => [ "nuix_timestamp", "ISO8601", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss.ZZZ" ]
    
  202.         target => "@timestamp"
    
  203.         locale => "en"
    
  204.     }
    
  205. }
    
  206. }

  207. filter {

  208. if "INVESTIGATE" in [tags] {
    
  209.     date {
    
  210.         match => [ "investigate_timestamp", "ISO8601", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss.ZZZ" ]
    
  211.         target => "@timestamp"
    
  212.         locale => "en"
    
  213.     }
    
  214. }
    
  215. }

  216. filter {

  217. if "RU" in [tags] {        
    
  218.     elapsed {
    
  219.         start_tag => "STARTING-RUNNER"
    
  220.         end_tag => "ENDING-RUNNER"
    
  221.         periodic_flush => false
    
  222.         unique_id_field => "runner"
    
  223.         timeout => 2629743
    
  224.         new_event_on_match => false
    
  225.     }        
    
  226. } else if "ST" in [tags] {        
    
  227.     elapsed {
    
  228.         start_tag => "STARTING-STAGE"
    
  229.         end_tag => "ENDING-STAGE"
    
  230.         periodic_flush => false
    
  231.         unique_id_field => "[automation][stage_id]"
    
  232.         timeout => 2629743
    
  233.         new_event_on_match => false
    
  234.     }        
    
  235. }
    
  236. }

  237. filter {

  238. if [elapsed_time] {
    
  239.      ruby {
    
  240.         code => '
    
  241.             event.set("[elapsed_hr]", Time.at(event.get("[elapsed_time]")).utc.strftime("%T.%L"))
    
  242.         '
    
  243.     }
    
  244. }
    
  245. }

  246. filter {

  247. if "STARTING-RUNNER" in [tags] {

  248.     ruby {
    
  249.     code => '
    
  250.         t = event.get("@timestamp")
    
  251.         event.set("elapsed_timestamp_event_start_runner", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
    
  252.     '
    
  253.     }
    
  254.     mutate {
    
  255.         add_field => { "elapsed_timestamp_event_end_runner" => "--------------->" }
    
  256.     }        
    
  257.     mutate {
    
  258.         add_field => { "elapsed_hr" => "Runner Started" }
    
  259.     }
    
  260. }
    
  261. }

  262. filter {

  263. if "STARTING-STAGE" in [tags] {

  264.     ruby {
    
  265.     code => '
    
  266.         t = event.get("@timestamp")
    
  267.         event.set("elapsed_timestamp_event_start_stage", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
    
  268.     '
    
  269.     }
    
  270.     mutate {
    
  271.         add_field => { "elapsed_timestamp_event_end_stage" => "--------------->" }
    
  272.     }        
    
  273.     mutate {
    
  274.         add_field => { "elapsed_hr" => "Stage Started" }
    
  275.     }
    
  276. }
    
  277. }

  278. filter {

  279. if "ENDING-STAGE" in [tags] {

  280.     ruby {
    
  281.     code => '
    
  282.         t = event.get("elapsed_timestamp_start")
    
  283.         event.set("elapsed_timestamp_event_start_stage", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
    
  284.     '
    
  285. }
    
  286. }

  287. }

  288. filter {

  289. if "ENDING-RUNNER" in [tags] {

  290.     ruby {
    
  291.     code => '
    
  292.         t = event.get("elapsed_timestamp_start")
    
  293.         event.set("elapsed_timestamp_event_start_runner", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
    
  294.     '
    
  295. }
    
  296. }

  297. }

  298. filter {

  299. if "AUTOMATION-FINISHED-STAGE" in [tags] {

  300.     ruby {
    
  301.     code => '
    
  302.         t = event.get("@timestamp")
    
  303.         event.set("elapsed_timestamp_event_end_stage", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
    
  304.     '
    
  305. }
    
  306. }

  307. }

  308. filter {

  309. if "AUTOMATION-FINISHED-RUNNER" in [tags] {

  310.     ruby {
    
  311.     code => '
    
  312.         t = event.get("@timestamp")
    
  313.         event.set("elapsed_timestamp_event_end_runner", Time.at(t.to_f).strftime("%Y-%m-%d %H:%M:%S"))
    
  314.     '
    
  315. }
    
  316. }

  317. }

  318. filter {

  319. mutate {

  320. remove_tag => [ "beats_input_codec_plain_applied", "beats_input_raw_event" ]
    
  321. }

  322. }

  323. filter {

  324. if "_grokparsefailure" in [tags] {

  325. drop{}
    
  326. }
    
  327. }

  328. #filter {

  329. if "NUIX-LOG" in [tags] {

  330. mutate {

  331. copy => { "[nuix_log][runner]" => "nuix_case" }

  332. }

  333. }

  334. #}

  335. output {

  336. Elasticsearch {

  337. hosts => ["http://automation.avian.dk:9200", "http://automation.avian.dk:9201"]
    
  338. index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    
  339. }

  340. }

  341. emphasized text

Sorry I dont know how to post code here as in a windows

The case name is just showing upp in one row in the logs. So I need to remember that over all events in the log. and also I have a stop event in the logs.

Like the old memorize filter but I can't get that filter to work in 7.16

All events between start and stop should have a tags with case name.

I feel stupid that I can't solve it

Dennis

You need to use markdown. If you Google "markdown tutorial" you will find multiple sites that provide one. Use the preview pane on the right of the edit pane to make sure the code is formatted correctly.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.