Class: Fluent::TextParser::JuniperAnalyticsdParser
- Inherits:
-
Parser
- Object
- Parser
- Fluent::TextParser::JuniperAnalyticsdParser
- Defined in:
- lib/fluent/plugin/parser_juniper_analyticsd.rb
Instance Method Summary collapse
-
#clean_up_name(name) ⇒ Object
Clean up device name and interface name to remove restricted caracter Used for flat and statsd format.
-
#configure(conf) ⇒ Object
This method is called after config_params have read configuration parameters.
- #parse(text) ⇒ Object
Instance Method Details
#clean_up_name(name) ⇒ Object
Clean up device name and interface name to remove restricted caracter Used for flat and statsd format
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/fluent/plugin/parser_juniper_analyticsd.rb', line 113 def clean_up_name(name) tmp = name tmp.gsub!('/', '_') tmp.gsub!(':', '_') tmp.gsub!('.', '_') return tmp.to_s end |
#configure(conf) ⇒ Object
This method is called after config_params have read configuration parameters
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fluent/plugin/parser_juniper_analyticsd.rb', line 10 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
22 23 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 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 |
# File 'lib/fluent/plugin/parser_juniper_analyticsd.rb', line 22 def parse(text) payload = JSON.parse(text) time = Engine.now ## 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| record = {} if output_format.to_s == 'flat' full_name = "device.#{clean_up_name(device_name)}.interface.#{clean_up_name(port_name)}.type.#{key}" record[full_name.downcase]= value elsif output_format.to_s == 'structured' record['device'] = device_name record['type'] = record_type + '.' + key record['interface'] = port_name record['value'] = value elsif output_format.to_s == 'statsd' full_name = "interface.#{clean_up_name(port_name)}.type.#{key}" record[:statsd_type] = 'gauge' record[:statsd_key] = full_name.downcase record[:statsd_gauge] = value else $log.warn "Output_format '#{output_format.to_s}' not supported for #{record_type}" end 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| record = {} if output_format.to_s == 'flat' full_name = "device.#{clean_up_name(device_name)}.interface.#{clean_up_name(port_name)}.queue.#{key}" record[full_name.downcase]= value elsif output_format.to_s == 'structured' record['device'] = device_name record['type'] = record_type + '.' + key record['interface'] = port_name record['value'] = value elsif output_format.to_s == 'statsd' full_name = "interface.#{clean_up_name(port_name)}.queue.#{key}" record[:statsd_type] = 'gauge' record[:statsd_key] = full_name.downcase record[:statsd_gauge] = value else $log.warn "Output_format '#{output_format.to_s}' not supported for #{record_type}" end yield json_time, record end else $log.warn "Recard type '#{record_type}' not supported" end end |