Class: Fluent::TextParser::JuniperAnalyticsdParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/fluent/plugin/parser_juniper_analyticsd.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

This method is called after config_params have read configuration parameters



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fluent/plugin/parser_juniper_analyticsd.rb', line 12

def configure(conf)
  super

  ## Check if "output_format" has a valid value
  unless  @output_format.to_s == "structured" ||
          @output_format.to_s == "flat" ||
          @output_format.to_s == "statsd"

    raise ConfigError, "output_format value '#{@output_format}' is not valid. Must be : structured, flat or statsd"
  end
end

#parse(text) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
# File 'lib/fluent/plugin/parser_juniper_analyticsd.rb', line 24

def parse(text)

  payload = JSON.parse(text)

  ## Extract contextual info
  record_type = payload["record-type"]
  record_time = payload["time"]
  device_name = payload["router-id"]
  port_name = payload["port"]

  ## Record time is in microsecond and until 0.14 Fluentd do not support lower than 1s
  ## We need to trim record time for now to fit fluentd
  json_time = (record_time/1000000).to_i

  if record_type == 'traffic-stats'

    ## Delete contextual info
    payload.delete("record-type")
    payload.delete("time")
    payload.delete("router-id")
    payload.delete("port")

    payload.each do |key, value|

      # Save all info extracted on a list
      sensor_data = []
      sensor_data.push({ 'device' => device_name })
      sensor_data.push({ 'interface' => port_name })
      sensor_data.push({ 'type' => record_type + '.' + key })
      sensor_data.push({ 'value' => value })

      record = build_record(output_format, sensor_data)
      yield json_time, record
    end
  elsif record_type == 'queue-stats'

    ## Delete contextual info
    payload.delete("record-type")
    payload.delete("time")
    payload.delete("router-id")
    payload.delete("port")

    payload.each do |key, value|

      sensor_data = []
      sensor_data.push({ 'device' => device_name })
      sensor_data.push({ 'interface' => port_name })
      sensor_data.push({ 'type' => record_type + '.' + key })
      sensor_data.push({ 'value' => value })

      record = build_record(output_format, sensor_data)
      yield json_time, record
    end
  else
    $log.warn "Recard type '#{record_type}' not supported"
  end
end