Class: LogStash::Filters::TransactionTime::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/filters/transaction_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(firstEvent, uid, storeEvent = false) ⇒ Transaction

Returns a new instance of Transaction.



305
306
307
308
309
310
311
312
# File 'lib/logstash/filters/transaction_time.rb', line 305

def initialize(firstEvent, uid, storeEvent = false)
  if(storeEvent)
    @firstEvent = firstEvent
  end
  @firstTimestamp = firstEvent.get(LogStash::Filters::TransactionTime.timestampTag)
  @uid = uid
  @age = 0
end

Instance Attribute Details

#ageObject

Returns the value of attribute age.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def age
  @age
end

#dataObject

Returns the value of attribute data.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def data
  @data
end

#diffObject

Returns the value of attribute diff.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def diff
  @diff
end

#firstEventObject

Returns the value of attribute firstEvent.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def firstEvent
  @firstEvent
end

#firstTimestampObject

Returns the value of attribute firstTimestamp.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def firstTimestamp
  @firstTimestamp
end

#lastEventObject

Returns the value of attribute lastEvent.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def lastEvent
  @lastEvent
end

#secondTimestampObject

Returns the value of attribute secondTimestamp.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def secondTimestamp
  @secondTimestamp
end

#uidObject

Returns the value of attribute uid.



303
304
305
# File 'lib/logstash/filters/transaction_time.rb', line 303

def uid
  @uid
end

Instance Method Details

#addSecond(lastEvent, storeEvent = false) ⇒ Object



341
342
343
344
345
346
347
# File 'lib/logstash/filters/transaction_time.rb', line 341

def addSecond(lastEvent,storeEvent = false)
  if(storeEvent)
    @lastEvent = lastEvent
  end
  @secondTimestamp = lastEvent.get(LogStash::Filters::TransactionTime.timestampTag)
  @diff = calculateDiff()
end

#calculateDiffObject



388
389
390
391
392
393
394
# File 'lib/logstash/filters/transaction_time.rb', line 388

def calculateDiff()
  if invalidTransaction()
    return nil
  end

  return getNewestTimestamp() - getOldestTimestamp()
end

#getData(oldestKeys, newestKeys) ⇒ Object



314
315
316
317
318
319
320
321
322
# File 'lib/logstash/filters/transaction_time.rb', line 314

def getData(oldestKeys, newestKeys)
  if(oldestKeys.any?)
    storeData("oldest",oldestKeys,getOldestEvent())
  end
  if(newestKeys.any?)
    storeData("newest",newestKeys,getNewestEvent())
  end
  return @data
end

#getEventsObject



405
406
407
408
409
410
411
412
413
414
# File 'lib/logstash/filters/transaction_time.rb', line 405

def getEvents()
  events = []
  if(!firstEvent.nil?)
    events << firstEvent
  end
  if(!lastEvent.nil?)
    events << lastEvent
  end
  return events
end

#getNewestEventObject

Gets the newest (based on timestamp) event Or the first if they are equal



369
370
371
372
373
374
375
376
377
378
# File 'lib/logstash/filters/transaction_time.rb', line 369

def getNewestEvent() 
  if invalidTransaction()
    return nil
  end
  if(@firstTimestamp >= @secondTimestamp)
    return @firstEvent
  else
    return @lastEvent
  end
end

#getNewestTimestampObject



380
381
382
# File 'lib/logstash/filters/transaction_time.rb', line 380

def getNewestTimestamp()
  return [@firstTimestamp,@secondTimestamp].max
end

#getOldestEventObject

Gets the oldest (based on timestamp) event Or the second if they are equal



351
352
353
354
355
356
357
358
359
360
361
# File 'lib/logstash/filters/transaction_time.rb', line 351

def getOldestEvent() 
  if invalidTransaction()
    return nil
  end

  if(@firstTimestamp < @secondTimestamp)
    return @firstEvent
  else
    return @lastEvent
  end
end

#getOldestTimestampObject



363
364
365
# File 'lib/logstash/filters/transaction_time.rb', line 363

def getOldestTimestamp()
  return [@firstTimestamp,@secondTimestamp].min
end

#invalidTransactionObject



384
385
386
# File 'lib/logstash/filters/transaction_time.rb', line 384

def invalidTransaction()
  return firstTimestamp.nil? || secondTimestamp.nil?
end

#storeData(subDataName, dataKeys, dataEvent) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/logstash/filters/transaction_time.rb', line 324

def storeData(subDataName, dataKeys, dataEvent)
  if(@data.nil?)
    @data = Hash.new
  end

  if(@data[subDataName].nil?)
    hashData = Hash.new
  else
    hashData = @data.get(subDataName)
  end

  dataKeys.each do |dataKey|
    hashData[dataKey] = dataEvent.get(dataKey)
    @data[subDataName] = hashData
  end
end

#tag(value) ⇒ Object



396
397
398
399
400
401
402
403
# File 'lib/logstash/filters/transaction_time.rb', line 396

def tag(value)
  if(!firstEvent.nil?)
    firstEvent.tag(value)
  end
  if(!lastEvent.nil?)
    lastEvent.tag(value)
  end
end