Class: LogStash::Codecs::Mtrraw

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/codecs/mtrraw.rb

Instance Method Summary collapse

Instance Method Details

#decode(data) {|wholepathevent| ... } ⇒ Object

def register

Yields:

  • (wholepathevent)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/logstash/codecs/mtrraw.rb', line 55

def decode(data)
  mtrlines = data.split(';')
  mtrrecs = mtrlines.collect {|each| MtrRec.new(each) }
  if mtrrecs[0].type == 's'
    target = mtrrecs.shift.data
  pingcount = 0
  if target =~ /(\w+) (\w+) (\d+)/
origin = $1
target = $2
pingcount = $3
  elsif target =~ /(\w+) (\d+)/
origin = "ORIGIN"
target = $1
pingcount = $2
  end
  end
  id = SecureRandom.uuid
  hops = Array.new
  mtrrecs.each { |rec|
  if rec.type == 'h'
hop = MtrHost.new(rec,pingcount,mtrrecs.select{|each| each.id == rec.id }).to_event_struct
if hops.size > 1
  if (hops[hops.size - 1][:addr] != hop[:addr])
    hops.push(hop)
  else
    # It's a duplicate of the last hop - drop it
  end
else
  hops.push(hop)
end
  end
  }
  path = hops.collect {|each|each[:addr]}
  pathsig = Digest::MD5.hexdigest(path.join('-'))
  avgloss = hops.inject(0) {|loss,each| loss += each[:pingloss]} / path.size
  avgrtt = hops.inject(0.0) {|rtt,each| rtt += each[:avgrtt]} / path.size
  tracedata = {   "id" => id,
  "origin" => origin,
  "target" => target,
  "message" => data ,
  "hops" => hops,
  "path" => path ,
  "pathsig" => pathsig,
  "pingcount"=>pingcount,
  "avgloss"=>avgloss,
  "avgrtt" => avgrtt,
  "tags" => ["wholepath"]
  }
  wholepathevent = LogStash::Event.new(tracedata)
  yield wholepathevent
  # Construct a starting point for trace to target
  yield LogStash::Event.new({
  "id" => id,
  "origin" => origin,
  "target" => target,
  "tags" => ["hop"],
  "seq" => -1,
  "pathsig" => pathsig,
  "A_node" => "#{origin}->#{target}",
  "Z_node" => hops[0][:addr],
  "dns" => origin,
  "avgrtt" => 0,
  "avgloss" => 0
  })
  0.upto(path.size - 2) {
     |index|
     yield LogStash::Event.new({  "id" => id,
      "origin" => origin,
      "target" => target,
                                  "tags" => ["hop"],
      "pathsig" => pathsig,
      "seq" => index,
        "A_node" => hops[index][:addr],
      "Z_node" => hops[index + 1][:addr],
      "dns" => hops[index + 1][:dns],
      "avgrtt" => hops[index + 1][:avgrtt],
      "avgloss" => hops[index + 1][:avgloss]
  })
  }
end

#encode_sync(event) ⇒ Object

Encode a single event, this returns the raw data to be returned as a String



137
138
139
140
# File 'lib/logstash/codecs/mtrraw.rb', line 137

def encode_sync(event)
  # Nothing to do.
  @on_event.call(event, event)
end

#registerObject

Append a string to the message config :append, :validate => :string, :default => ‘, Hello World!’



52
53
# File 'lib/logstash/codecs/mtrraw.rb', line 52

def register
end