Hello,
After searching and surfing for hours and hours, I am still unable to preserve the value of an event field in a global variable.
This is what I am trying to achive.
I have a log file something like:
INFO: ServerInstanceId : ServerManager_1 : starting scan for target id : 1 and walk : 1 of scan mode : single server
FINEST: com.soft.filetemp.DataFetcher FileUpload File: l:\test10\ntlm1.pcap DownloadByteContentSize: 1232 Time taken: 3
My logstash config file:
filter {
  grok {
    match => { "message" => "(?<Custom>[Ff]inest|FINEST|[Ff]iner|FINER|[Ff]ine|FINE|[Dd]ebug|DEBUG|[Ss]evere|SEVERE|[Ii]nfo|INFO|[Ww]arn?(?:ing)?|WARN?(?:ING)?|[Ee]rr?(?:or)?|ERR?(?:OR)?|[Ff]atal|FATAL?):\sServerInstanceId\s:\s%{DATA:ServerInstanceId}\s:\s%{DATA:ScanState}\sfor\s%{DATA}:\s%{NUMBER:TargetID}\sand\s%{DATA}:\s%{NUMBER:WalkID}\s%{DATA}:\s%{GREEDYDATA:ScanMode}" }
    
    match => { "message" => "(?<Custom>[Ff]inest|FINEST|[Ff]iner|FINER|[Ff]ine|FINE|[Dd]ebug|DEBUG|[Ss]evere|SEVERE|[Ii]nfo|INFO|[Ww]arn?(?:ing)?|WARN?(?:ING)?|[Ee]rr?(?:or)?|ERR?(?:OR)?|[Ff]atal|FATAL?):\s%{JAVACLASS:JavaClass}\s(?<DetectionAction>[Ff]ile[Dd]ownload|FILEDOWNLOAD?)\sFile:\s%{GREEDYDATA:FilePath}DownloadByteContentSize:\s%{NUMBER:DownloadByteContentSize}\s%{GREEDYDATA:FilePath}:\s%{NUMBER:TimeTaken}" }
  }
mutate {
        add_field => {"ScanIDConfig" => "%{@timestamp}%{ServerInstanceId}%{TargetID}%{WalkID}"}
  }
ruby {
        init => "@@ScanIDConfig = ''"
        code => "@@ScanIDConfig=event.get('[ScanIDConfig]')
        event.set('ScanIDConfig',@@ScanIDConfig)"
  }
}
Based on first log line, I am generating a custom field named ScanIDConfig. I want to store and use the value of this variable in all subsequent events.
However, logstash output for second event depicts:
"ScanIDConfig" => "2019-03-28T09:57:40.680Z%{ServerInstanceId}%{TargetID}%{WalkID}"
For first event, it is as desired:
"ScanIDConfig" => "2019-03-28T10:19:51.160Z ServerManager_111",
I tried multiple combinations of Ruby filter, but no luck.
Can someone please help me here.