Saram Ali Azhar
Saram Ali Azhar

Reputation: 254

Ruby script in Logstash

I'm running a ruby script in logstash to extract information from logs.

if [status] == "Txn posted on POS"
{
    ruby{
      init => "@@map = {}"
      code => "@@map['transactionStartTime'] = event.get('logTimestamp'),@@map['startTxnNumber'] = event.get('txnNumber'),@@map['startTillNumber'] = event.get('tillNumber')"
    }


}
else if [status] == "Txn persisted in MREP" 
{
  ruby{
        code => "if @@map['startTxnNumber'] == event.get('txnNumber')
                    event.set('startedTime', @@map['startTxnNumber'])
                 end"
      }
}

Due to some reason it's not coming in the if clause. I can't seem to understand the problem, there is no syntax error i'm sure

Upvotes: 1

Views: 1005

Answers (1)

Saram Ali Azhar
Saram Ali Azhar

Reputation: 254

I've found the problem and fixed it. The problem was because of datatype mismatch, the condition

if @@map['startTxnNumber'] == event.get('txnNumber')

txnNumber was a string and startTxnNumber was an int, so it was not comparing these values.

Upvotes: 1

Related Questions