fluent-plugin-juniper-telemetry 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fluent/plugin/parser_juniper_analyticsd.rb +74 -116
- data/lib/fluent/plugin/parser_juniper_jti.rb +150 -246
- data/lib/juniper_telemetry_lib.rb +113 -0
- metadata +6 -5
@@ -1,125 +1,83 @@
|
|
1
|
-
|
2
|
-
class TextParser
|
3
|
-
class JuniperAnalyticsdParser < Parser
|
4
|
-
|
5
|
-
Plugin.register_parser("juniper_analyticsd", self)
|
6
|
-
|
7
|
-
config_param :output_format, :string, :default => 'structured'
|
8
|
-
|
9
|
-
# This method is called after config_params have read configuration parameters
|
10
|
-
def configure(conf)
|
11
|
-
super
|
12
|
-
|
13
|
-
## Check if "output_format" has a valid value
|
14
|
-
unless @output_format.to_s == "structured" ||
|
15
|
-
@output_format.to_s == "flat" ||
|
16
|
-
@output_format.to_s == "statsd"
|
17
|
-
|
18
|
-
raise ConfigError, "output_format value '#{@output_format}' is not valid. Must be : structured, flat or statsd"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def parse(text)
|
23
|
-
|
24
|
-
payload = JSON.parse(text)
|
25
|
-
time = Engine.now
|
26
|
-
|
27
|
-
## Extract contextual info
|
28
|
-
record_type = payload["record-type"]
|
29
|
-
record_time = payload["time"]
|
30
|
-
device_name = payload["router-id"]
|
31
|
-
port_name = payload["port"]
|
32
|
-
|
33
|
-
## Record time is in microsecond and until 0.14 Fluentd do not support lower than 1s
|
34
|
-
## We need to trim record time for now to fit fluentd
|
35
|
-
json_time = (record_time/1000000).to_i
|
36
|
-
|
37
|
-
if record_type == 'traffic-stats'
|
38
|
-
|
39
|
-
## Delete contextual info
|
40
|
-
payload.delete("record-type")
|
41
|
-
payload.delete("time")
|
42
|
-
payload.delete("router-id")
|
43
|
-
payload.delete("port")
|
44
|
-
|
45
|
-
payload.each do |key, value|
|
46
|
-
record = {}
|
47
|
-
|
48
|
-
if output_format.to_s == 'flat'
|
49
|
-
full_name = "device.#{clean_up_name(device_name)}.interface.#{clean_up_name(port_name)}.type.#{key}"
|
1
|
+
require 'juniper_telemetry_lib.rb'
|
50
2
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
record['device'] = device_name
|
55
|
-
record['type'] = record_type + '.' + key
|
56
|
-
record['interface'] = port_name
|
57
|
-
record['value'] = value
|
58
|
-
|
59
|
-
elsif output_format.to_s == 'statsd'
|
60
|
-
|
61
|
-
full_name = "interface.#{clean_up_name(port_name)}.type.#{key}"
|
62
|
-
record[:statsd_type] = 'gauge'
|
63
|
-
record[:statsd_key] = full_name.downcase
|
64
|
-
record[:statsd_gauge] = value
|
65
|
-
else
|
66
|
-
$log.warn "Output_format '#{output_format.to_s}' not supported for #{record_type}"
|
67
|
-
end
|
68
|
-
|
69
|
-
yield json_time, record
|
70
|
-
end
|
71
|
-
elsif record_type == 'queue-stats'
|
72
|
-
|
73
|
-
## Delete contextual info
|
74
|
-
payload.delete("record-type")
|
75
|
-
payload.delete("time")
|
76
|
-
payload.delete("router-id")
|
77
|
-
payload.delete("port")
|
78
|
-
|
79
|
-
payload.each do |key, value|
|
80
|
-
record = {}
|
81
|
-
|
82
|
-
if output_format.to_s == 'flat'
|
83
|
-
|
84
|
-
full_name = "device.#{clean_up_name(device_name)}.interface.#{clean_up_name(port_name)}.queue.#{key}"
|
85
|
-
|
86
|
-
record[full_name.downcase]= value
|
87
|
-
|
88
|
-
elsif output_format.to_s == 'structured'
|
89
|
-
record['device'] = device_name
|
90
|
-
record['type'] = record_type + '.' + key
|
91
|
-
record['interface'] = port_name
|
92
|
-
record['value'] = value
|
93
|
-
|
94
|
-
elsif output_format.to_s == 'statsd'
|
95
|
-
full_name = "interface.#{clean_up_name(port_name)}.queue.#{key}"
|
96
|
-
record[:statsd_type] = 'gauge'
|
97
|
-
record[:statsd_key] = full_name.downcase
|
98
|
-
record[:statsd_gauge] = value
|
99
|
-
|
100
|
-
else
|
101
|
-
$log.warn "Output_format '#{output_format.to_s}' not supported for #{record_type}"
|
102
|
-
end
|
3
|
+
module Fluent
|
4
|
+
class TextParser
|
5
|
+
class JuniperAnalyticsdParser < Parser
|
103
6
|
|
104
|
-
|
105
|
-
end
|
106
|
-
else
|
107
|
-
$log.warn "Recard type '#{record_type}' not supported"
|
108
|
-
end
|
109
|
-
end
|
7
|
+
Plugin.register_parser("juniper_analyticsd", self)
|
110
8
|
|
111
|
-
|
112
|
-
## Used for flat and statsd format
|
113
|
-
def clean_up_name(name)
|
9
|
+
config_param :output_format, :string, :default => 'structured'
|
114
10
|
|
115
|
-
|
11
|
+
# This method is called after config_params have read configuration parameters
|
12
|
+
def configure(conf)
|
13
|
+
super
|
116
14
|
|
117
|
-
|
118
|
-
|
119
|
-
|
15
|
+
## Check if "output_format" has a valid value
|
16
|
+
unless @output_format.to_s == "structured" ||
|
17
|
+
@output_format.to_s == "flat" ||
|
18
|
+
@output_format.to_s == "statsd"
|
120
19
|
|
121
|
-
|
122
|
-
|
20
|
+
raise ConfigError, "output_format value '#{@output_format}' is not valid. Must be : structured, flat or statsd"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse(text)
|
25
|
+
|
26
|
+
payload = JSON.parse(text)
|
27
|
+
|
28
|
+
## Extract contextual info
|
29
|
+
record_type = payload["record-type"]
|
30
|
+
record_time = payload["time"]
|
31
|
+
device_name = payload["router-id"]
|
32
|
+
port_name = payload["port"]
|
33
|
+
|
34
|
+
## Record time is in microsecond and until 0.14 Fluentd do not support lower than 1s
|
35
|
+
## We need to trim record time for now to fit fluentd
|
36
|
+
json_time = (record_time/1000000).to_i
|
37
|
+
|
38
|
+
if record_type == 'traffic-stats'
|
39
|
+
|
40
|
+
## Delete contextual info
|
41
|
+
payload.delete("record-type")
|
42
|
+
payload.delete("time")
|
43
|
+
payload.delete("router-id")
|
44
|
+
payload.delete("port")
|
45
|
+
|
46
|
+
payload.each do |key, value|
|
47
|
+
|
48
|
+
# Save all info extracted on a list
|
49
|
+
sensor_data = []
|
50
|
+
sensor_data.push({ 'device' => device_name })
|
51
|
+
sensor_data.push({ 'interface' => port_name })
|
52
|
+
sensor_data.push({ 'type' => record_type + '.' + key })
|
53
|
+
sensor_data.push({ 'value' => value })
|
54
|
+
|
55
|
+
record = build_record(output_format, sensor_data)
|
56
|
+
yield json_time, record
|
57
|
+
end
|
58
|
+
elsif record_type == 'queue-stats'
|
59
|
+
|
60
|
+
## Delete contextual info
|
61
|
+
payload.delete("record-type")
|
62
|
+
payload.delete("time")
|
63
|
+
payload.delete("router-id")
|
64
|
+
payload.delete("port")
|
65
|
+
|
66
|
+
payload.each do |key, value|
|
67
|
+
|
68
|
+
sensor_data = []
|
69
|
+
sensor_data.push({ 'device' => device_name })
|
70
|
+
sensor_data.push({ 'interface' => port_name })
|
71
|
+
sensor_data.push({ 'type' => record_type + '.' + key })
|
72
|
+
sensor_data.push({ 'value' => value })
|
73
|
+
|
74
|
+
record = build_record(output_format, sensor_data)
|
75
|
+
yield json_time, record
|
76
|
+
end
|
77
|
+
else
|
78
|
+
$log.warn "Recard type '#{record_type}' not supported"
|
123
79
|
end
|
80
|
+
end
|
124
81
|
end
|
82
|
+
end
|
125
83
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'juniper_telemetry_lib.rb'
|
1
2
|
require 'protobuf'
|
2
3
|
require 'jvision_top.pb.rb'
|
3
4
|
require 'port.pb.rb'
|
@@ -5,289 +6,192 @@ require 'logical_port.pb.rb'
|
|
5
6
|
require 'firewall.pb.rb'
|
6
7
|
|
7
8
|
module Fluent
|
8
|
-
|
9
|
-
|
9
|
+
class TextParser
|
10
|
+
class JuniperJtiParser < Parser
|
10
11
|
|
11
|
-
|
12
|
+
Plugin.register_parser("juniper_jti", self)
|
12
13
|
|
13
|
-
|
14
|
+
config_param :output_format, :string, :default => 'structured'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
# This method is called after config_params have read configuration parameters
|
17
|
+
def configure(conf)
|
18
|
+
super
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
## Check if "output_format" has a valid value
|
21
|
+
unless @output_format.to_s == "structured" ||
|
22
|
+
@output_format.to_s == "flat" ||
|
23
|
+
@output_format.to_s == "statsd"
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def parse(text)
|
29
|
-
|
30
|
-
## Decode GBP packet
|
31
|
-
jti_msg = TelemetryStream.decode(text)
|
32
|
-
|
33
|
-
resource = ""
|
34
|
-
|
35
|
-
## Extract device name & Timestamp
|
36
|
-
device_name = jti_msg.system_id
|
37
|
-
gpb_time = jti_msg.timestamp
|
25
|
+
raise ConfigError, "output_format value '#{@output_format}' is not valid. Must be : structured, flat or statsd"
|
26
|
+
end
|
27
|
+
end
|
38
28
|
|
39
|
-
|
40
|
-
begin
|
41
|
-
jnpr_sensor = jti_msg.enterprise.juniperNetworks
|
42
|
-
datas_sensors = JSON.parse(jnpr_sensor.to_json)
|
43
|
-
$log.debug "Extract sensor data from #{device_name} with output #{output_format}"
|
44
|
-
rescue => e
|
45
|
-
$log.warn "Unable to extract sensor data sensor from jti_msg.enterprise.juniperNetworks, Error during processing: #{$!}"
|
46
|
-
$log.debug "Unable to extract sensor data sensor from jti_msg.enterprise.juniperNetworks, Data Dump : " + jti_msg.inspect.to_s
|
47
|
-
return
|
48
|
-
end
|
29
|
+
def parse(text)
|
49
30
|
|
31
|
+
## Decode GBP packet
|
32
|
+
jti_msg = TelemetryStream.decode(text)
|
50
33
|
|
51
|
-
|
52
|
-
datas_sensors.each do |sensor, s_data|
|
34
|
+
resource = ""
|
53
35
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
if sensor == "jnpr_interface_ext"
|
36
|
+
## Extract device name & Timestamp
|
37
|
+
device_name = jti_msg.system_id
|
38
|
+
gpb_time = epoc_to_sec(jti_msg.timestamp)
|
58
39
|
|
59
|
-
|
40
|
+
## Extract sensor
|
41
|
+
begin
|
42
|
+
jnpr_sensor = jti_msg.enterprise.juniperNetworks
|
43
|
+
datas_sensors = JSON.parse(jnpr_sensor.to_json)
|
44
|
+
$log.debug "Extract sensor data from #{device_name} with output #{output_format}"
|
45
|
+
rescue => e
|
46
|
+
$log.warn "Unable to extract sensor data sensor from jti_msg.enterprise.juniperNetworks, Error during processing: #{$!}"
|
47
|
+
$log.debug "Unable to extract sensor data sensor from jti_msg.enterprise.juniperNetworks, Data Dump : " + jti_msg.inspect.to_s
|
48
|
+
return
|
49
|
+
end
|
60
50
|
|
61
|
-
|
51
|
+
## Go over each Sensor
|
52
|
+
datas_sensors.each do |sensor, s_data|
|
62
53
|
|
63
|
-
|
64
|
-
|
54
|
+
##############################################################
|
55
|
+
### Support for resource /junos/system/linecard/interface/ ##
|
56
|
+
##############################################################
|
57
|
+
if sensor == "jnpr_interface_ext"
|
65
58
|
|
66
|
-
|
67
|
-
begin
|
68
|
-
## Extract interface name and clean up
|
69
|
-
# interface_name = datas['if_name']
|
70
|
-
sensor_data.push({ 'device' => device_name })
|
71
|
-
sensor_data.push({ 'interface' => datas['if_name'] })
|
59
|
+
resource = "/junos/system/linecard/interface/"
|
72
60
|
|
73
|
-
|
74
|
-
if datas.key?('parent_ae_name')
|
75
|
-
sensor_data.push({ 'interface_parent' => datas['parent_ae_name'] })
|
76
|
-
datas.delete("parent_ae_name")
|
77
|
-
end
|
61
|
+
datas_sensors[sensor]['interface_stats'].each do |datas|
|
78
62
|
|
79
|
-
|
80
|
-
|
81
|
-
datas.delete("init_time")
|
82
|
-
datas.delete("snmp_if_index")
|
63
|
+
# Save all info extracted on a list
|
64
|
+
sensor_data = []
|
83
65
|
|
84
|
-
|
66
|
+
# Catch Exception during parsing
|
67
|
+
begin
|
68
|
+
## Extract interface name and clean up
|
69
|
+
# interface_name = datas['if_name']
|
70
|
+
sensor_data.push({ 'device' => device_name })
|
71
|
+
sensor_data.push({ 'interface' => datas['if_name'] })
|
85
72
|
|
86
|
-
|
87
|
-
|
88
|
-
|
73
|
+
# Check if the interface has a parent
|
74
|
+
if datas.key?('parent_ae_name')
|
75
|
+
sensor_data.push({ 'interface_parent' => datas['parent_ae_name'] })
|
76
|
+
datas.delete("parent_ae_name")
|
77
|
+
end
|
89
78
|
|
90
|
-
|
91
|
-
|
79
|
+
## Clean up Current object
|
80
|
+
datas.delete("if_name")
|
81
|
+
datas.delete("init_time")
|
82
|
+
datas.delete("snmp_if_index")
|
92
83
|
|
93
|
-
|
94
|
-
queue_sensor_data.push({ 'egress_queue' => queue['queue_number'] })
|
95
|
-
queue.delete("queue_number")
|
84
|
+
datas.each do |section, data|
|
96
85
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
local_sensor_data.push({ 'value' => value })
|
86
|
+
## egress_queue_info is an Array
|
87
|
+
if data.kind_of?(Array)
|
88
|
+
data.each do |queue|
|
101
89
|
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
else
|
107
|
-
data.each do |type,value|
|
90
|
+
## Create local copy to avoid variable sharing
|
91
|
+
queue_sensor_data = sensor_data.dup
|
108
92
|
|
109
|
-
|
110
|
-
|
93
|
+
## Save and Cleanup Queue number
|
94
|
+
queue_sensor_data.push({ 'egress_queue' => queue['queue_number'] })
|
95
|
+
queue.delete("queue_number")
|
111
96
|
|
112
|
-
|
113
|
-
|
97
|
+
queue.each do |type,value|
|
98
|
+
local_sensor_data = queue_sensor_data.dup
|
99
|
+
local_sensor_data.push({ 'type' => section + '.' + type })
|
100
|
+
local_sensor_data.push({ 'value' => value })
|
114
101
|
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
rescue => e
|
121
|
-
$log.warn "Unable to parse " + sensor + " sensor, Error during processing: #{$!}"
|
122
|
-
$log.debug "Unable to parse " + sensor + " sensor, Data Dump : " + datas.inspect.to_s
|
123
|
-
end
|
102
|
+
record = build_record(output_format, local_sensor_data)
|
103
|
+
yield gpb_time, record
|
124
104
|
end
|
125
|
-
##############################################################
|
126
|
-
### Support for resource /junos/system/linecard/firewall/ ##
|
127
|
-
##############################################################
|
128
|
-
# elsif sensor == "jnpr_firewall_ext"
|
129
|
-
#
|
130
|
-
# resource = "/junos/system/linecard/firewall"
|
131
|
-
#
|
132
|
-
# datas_sensors[sensor]['firewall_stats'].each do |datas|
|
133
|
-
#
|
134
|
-
# begin
|
135
|
-
# ## Extract interface name and clean up
|
136
|
-
# sensor_data.push({ 'device' => device_name })
|
137
|
-
# sensor_data.push({ 'filter_name' => datas['filter_name'] })
|
138
|
-
#
|
139
|
-
# ## Clean up Current object
|
140
|
-
# # datas.delete("filter_name")
|
141
|
-
#
|
142
|
-
# $log.warn "Sensor Filter : " + datas['filter_name']
|
143
|
-
#
|
144
|
-
# rescue
|
145
|
-
# $log.warn "Unable to parse " + sensor + " sensor, an error occured.."
|
146
|
-
# $log.debug "Unable to parse " + sensor + " sensor, Data Dump : " + datas.inspect.to_s
|
147
|
-
# end
|
148
|
-
# end
|
149
|
-
|
150
|
-
##############################################################
|
151
|
-
### Support for resource /junos/system/linecard/interface/logical/usage ##
|
152
|
-
##############################################################
|
153
|
-
elsif sensor == "jnprLogicalInterfaceExt"
|
154
|
-
|
155
|
-
resource = "/junos/system/linecard/interface/logical/usage"
|
156
|
-
|
157
|
-
datas_sensors[sensor]['interface_info'].each do |datas|
|
158
|
-
|
159
|
-
# Save all info extracted on a list
|
160
|
-
sensor_data = []
|
161
|
-
|
162
|
-
begin
|
163
|
-
## Extract interface name and clean up
|
164
|
-
sensor_data.push({ 'device' => device_name })
|
165
|
-
sensor_data.push({ 'interface' => datas['if_name'] })
|
166
|
-
|
167
|
-
## Clean up Current object
|
168
|
-
datas.delete("if_name")
|
169
|
-
datas.delete("init_time")
|
170
|
-
datas.delete("snmp_if_index")
|
171
|
-
datas.delete("op_state")
|
172
|
-
|
173
|
-
datas.each do |section, data|
|
174
|
-
data.each do |type, value|
|
175
|
-
|
176
|
-
sensor_data.push({ 'type' => section + '.' + type })
|
177
|
-
sensor_data.push({ 'value' => value })
|
178
|
-
|
179
|
-
record = build_record(output_format, sensor_data)
|
180
|
-
yield gpb_time, record
|
181
|
-
|
182
|
-
end
|
183
|
-
end
|
184
|
-
rescue => e
|
185
|
-
$log.warn "Unable to parse " + sensor + " sensor, Error during processing: #{$!}"
|
186
|
-
$log.debug "Unable to parse " + sensor + " sensor, Data Dump : " + datas.inspect.to_s
|
187
|
-
end
|
188
|
-
end
|
189
|
-
else
|
190
|
-
$log.warn "Unsupported sensor : " + sensor
|
191
|
-
# puts datas_sensors[sensor].inspect.to_s
|
192
105
|
end
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
##############################
|
197
|
-
## Supporting functions ##
|
198
|
-
##############################
|
199
|
-
def clean_up_name(name)
|
200
|
-
|
201
|
-
## Create a clean copy of Name and convert to string
|
202
|
-
tmp = name.to_s.dup
|
203
|
-
|
204
|
-
## Clean up device name and interface name to remove restricted caracter
|
205
|
-
tmp.gsub!('/', '_')
|
206
|
-
tmp.gsub!(':', '_')
|
207
|
-
tmp.gsub!('.', '_')
|
208
|
-
|
209
|
-
return tmp
|
210
|
-
end
|
211
|
-
|
212
|
-
def build_record(type, data_to_build)
|
106
|
+
else
|
107
|
+
data.each do |type,value|
|
213
108
|
|
214
|
-
|
109
|
+
## Create local copy to avoid using some variable
|
110
|
+
local_sensor_data = sensor_data.dup
|
215
111
|
|
216
|
-
|
112
|
+
local_sensor_data.push({ 'type' => section + '.' + type })
|
113
|
+
local_sensor_data.push({ 'value' => value })
|
217
114
|
|
218
|
-
|
219
|
-
|
220
|
-
sensor_value = ""
|
221
|
-
|
222
|
-
## Concatene all key/value into a string and stop at "value"
|
223
|
-
data_to_build.each do |entry|
|
224
|
-
entry.each do |key, value|
|
225
|
-
|
226
|
-
if key == "value"
|
227
|
-
sensor_value = value
|
228
|
-
next
|
229
|
-
end
|
230
|
-
|
231
|
-
if name == ""
|
232
|
-
name = key + "." + clean_up_name(value)
|
233
|
-
else
|
234
|
-
name = name + "." + key + "." + clean_up_name(value)
|
115
|
+
record = build_record(output_format, local_sensor_data)
|
116
|
+
yield gpb_time, record
|
235
117
|
end
|
236
118
|
end
|
237
119
|
end
|
120
|
+
rescue => e
|
121
|
+
$log.warn "Unable to parse " + sensor + " sensor, Error during processing: #{$!}"
|
122
|
+
$log.debug "Unable to parse " + sensor + " sensor, Data Dump : " + datas.inspect.to_s
|
123
|
+
end
|
124
|
+
end
|
125
|
+
##############################################################
|
126
|
+
### Support for resource /junos/system/linecard/firewall/ ##
|
127
|
+
##############################################################
|
128
|
+
# elsif sensor == "jnpr_firewall_ext"
|
129
|
+
#
|
130
|
+
# resource = "/junos/system/linecard/firewall"
|
131
|
+
#
|
132
|
+
# datas_sensors[sensor]['firewall_stats'].each do |datas|
|
133
|
+
#
|
134
|
+
# begin
|
135
|
+
# ## Extract interface name and clean up
|
136
|
+
# sensor_data.push({ 'device' => device_name })
|
137
|
+
# sensor_data.push({ 'filter_name' => datas['filter_name'] })
|
138
|
+
#
|
139
|
+
# ## Clean up Current object
|
140
|
+
# # datas.delete("filter_name")
|
141
|
+
#
|
142
|
+
# $log.warn "Sensor Filter : " + datas['filter_name']
|
143
|
+
#
|
144
|
+
# rescue
|
145
|
+
# $log.warn "Unable to parse " + sensor + " sensor, an error occured.."
|
146
|
+
# $log.debug "Unable to parse " + sensor + " sensor, Data Dump : " + datas.inspect.to_s
|
147
|
+
# end
|
148
|
+
# end
|
149
|
+
|
150
|
+
##############################################################
|
151
|
+
### Support for resource /junos/system/linecard/interface/logical/usage ##
|
152
|
+
##############################################################
|
153
|
+
elsif sensor == "jnprLogicalInterfaceExt"
|
154
|
+
|
155
|
+
resource = "/junos/system/linecard/interface/logical/usage"
|
156
|
+
|
157
|
+
datas_sensors[sensor]['interface_info'].each do |datas|
|
158
|
+
|
159
|
+
# Save all info extracted on a list
|
160
|
+
sensor_data = []
|
161
|
+
|
162
|
+
begin
|
163
|
+
## Extract interface name and clean up
|
164
|
+
sensor_data.push({ 'device' => device_name })
|
165
|
+
sensor_data.push({ 'interface' => datas['if_name'] })
|
166
|
+
|
167
|
+
## Clean up Current object
|
168
|
+
datas.delete("if_name")
|
169
|
+
datas.delete("init_time")
|
170
|
+
datas.delete("snmp_if_index")
|
171
|
+
datas.delete("op_state")
|
172
|
+
|
173
|
+
datas.each do |section, data|
|
174
|
+
data.each do |type, value|
|
175
|
+
|
176
|
+
sensor_data.push({ 'type' => section + '.' + type })
|
177
|
+
sensor_data.push({ 'value' => value })
|
178
|
+
|
179
|
+
record = build_record(output_format, sensor_data)
|
180
|
+
yield gpb_time, record
|
238
181
|
|
239
|
-
record = { name => sensor_value }
|
240
|
-
return record
|
241
|
-
|
242
|
-
elsif output_format.to_s == 'structured'
|
243
|
-
|
244
|
-
record = {}
|
245
|
-
## Convert list into Hash
|
246
|
-
## Each entry on the list is a hash with 1 key/value
|
247
|
-
data_to_build.each do |entry|
|
248
|
-
entry.each do |key, value|
|
249
|
-
record[key] = value
|
250
182
|
end
|
251
183
|
end
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
elsif output_format.to_s == 'statsd'
|
256
|
-
|
257
|
-
record = {}
|
258
|
-
|
259
|
-
# initialize variables
|
260
|
-
name = ""
|
261
|
-
sensor_value = ""
|
262
|
-
|
263
|
-
## Concatene all key/value into a string, exclude device & stop at "value"
|
264
|
-
data_to_build.each do |entry|
|
265
|
-
entry.each do |key, value|
|
266
|
-
|
267
|
-
if key == "value"
|
268
|
-
sensor_value = value
|
269
|
-
next
|
270
|
-
elsif key == "device"
|
271
|
-
next
|
272
|
-
else
|
273
|
-
if name == ""
|
274
|
-
name = key + "." + clean_up_name(value)
|
275
|
-
else
|
276
|
-
name = name + "." + key + "." + clean_up_name(value)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
record[:statsd_type] = 'gauge'
|
283
|
-
record[:statsd_key] = name.downcase
|
284
|
-
record[:statsd_gauge] = sensor_value
|
285
|
-
|
286
|
-
return record
|
287
|
-
else
|
288
|
-
$log.warn "Output_format '#{type.to_s}' not supported"
|
184
|
+
rescue => e
|
185
|
+
$log.warn "Unable to parse " + sensor + " sensor, Error during processing: #{$!}"
|
186
|
+
$log.debug "Unable to parse " + sensor + " sensor, Data Dump : " + datas.inspect.to_s
|
289
187
|
end
|
290
188
|
end
|
189
|
+
else
|
190
|
+
$log.warn "Unsupported sensor : " + sensor
|
191
|
+
# puts datas_sensors[sensor].inspect.to_s
|
192
|
+
end
|
291
193
|
end
|
194
|
+
end
|
292
195
|
end
|
196
|
+
end
|
293
197
|
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
|
2
|
+
##############################
|
3
|
+
## Supporting functions ##
|
4
|
+
##############################
|
5
|
+
|
6
|
+
def epoc_to_sec(epoc)
|
7
|
+
|
8
|
+
# Check if sec, usec or msec
|
9
|
+
nbr_digit = epoc.to_s.size
|
10
|
+
|
11
|
+
if nbr_digit == 10
|
12
|
+
return epoc.to_i
|
13
|
+
elsif nbr_digit == 13
|
14
|
+
return (epoc.to_i/1000).to_i
|
15
|
+
elsif nbr_digit == 16
|
16
|
+
return (epoc.to_i/1000000).to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
return epoc
|
20
|
+
end
|
21
|
+
|
22
|
+
def clean_up_name(name)
|
23
|
+
|
24
|
+
## Create a clean copy of Name and convert to string
|
25
|
+
tmp = name.to_s.dup
|
26
|
+
|
27
|
+
## Clean up device name and interface name to remove restricted caracter
|
28
|
+
tmp.gsub!('/', '_')
|
29
|
+
tmp.gsub!(':', '_')
|
30
|
+
tmp.gsub!('.', '_')
|
31
|
+
|
32
|
+
return tmp
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_record(type, data_to_build)
|
36
|
+
|
37
|
+
if type.to_s == 'flat'
|
38
|
+
|
39
|
+
record = {}
|
40
|
+
|
41
|
+
# initialize variables
|
42
|
+
name = ""
|
43
|
+
sensor_value = ""
|
44
|
+
|
45
|
+
## Concatene all key/value into a string and stop at "value"
|
46
|
+
data_to_build.each do |entry|
|
47
|
+
entry.each do |key, value|
|
48
|
+
|
49
|
+
if key == "value"
|
50
|
+
sensor_value = value
|
51
|
+
next
|
52
|
+
end
|
53
|
+
|
54
|
+
if name == ""
|
55
|
+
name = key + "." + clean_up_name(value)
|
56
|
+
else
|
57
|
+
name = name + "." + key + "." + clean_up_name(value)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
record = { name => sensor_value }
|
63
|
+
return record
|
64
|
+
|
65
|
+
elsif output_format.to_s == 'structured'
|
66
|
+
|
67
|
+
record = {}
|
68
|
+
## Convert list into Hash
|
69
|
+
## Each entry on the list is a hash with 1 key/value
|
70
|
+
data_to_build.each do |entry|
|
71
|
+
entry.each do |key, value|
|
72
|
+
record[key] = value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
return record
|
77
|
+
|
78
|
+
elsif output_format.to_s == 'statsd'
|
79
|
+
|
80
|
+
record = {}
|
81
|
+
|
82
|
+
# initialize variables
|
83
|
+
name = ""
|
84
|
+
sensor_value = ""
|
85
|
+
|
86
|
+
## Concatene all key/value into a string, exclude device & stop at "value"
|
87
|
+
data_to_build.each do |entry|
|
88
|
+
entry.each do |key, value|
|
89
|
+
|
90
|
+
if key == "value"
|
91
|
+
sensor_value = value
|
92
|
+
next
|
93
|
+
elsif key == "device"
|
94
|
+
next
|
95
|
+
else
|
96
|
+
if name == ""
|
97
|
+
name = key + "." + clean_up_name(value)
|
98
|
+
else
|
99
|
+
name = name + "." + key + "." + clean_up_name(value)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
record[:statsd_type] = 'gauge'
|
106
|
+
record[:statsd_key] = name.downcase
|
107
|
+
record[:statsd_gauge] = sensor_value
|
108
|
+
|
109
|
+
return record
|
110
|
+
else
|
111
|
+
$log.warn "Output_format '#{type.to_s}' not supported"
|
112
|
+
end
|
113
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-juniper-telemetry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -67,15 +67,16 @@ executables: []
|
|
67
67
|
extensions: []
|
68
68
|
extra_rdoc_files: []
|
69
69
|
files:
|
70
|
+
- lib/fluent/plugin/parser_juniper_na.rb
|
70
71
|
- lib/fluent/plugin/parser_juniper_analyticsd.rb
|
71
72
|
- lib/fluent/plugin/parser_juniper_jti.rb
|
72
|
-
- lib/
|
73
|
-
- lib/firewall.pb.rb
|
73
|
+
- lib/juniper_telemetry_lib.rb
|
74
74
|
- lib/jvision_top.pb.rb
|
75
75
|
- lib/logical_port.pb.rb
|
76
|
-
- lib/lsp_mon.pb.rb
|
77
76
|
- lib/lsp_stats.pb.rb
|
78
77
|
- lib/port.pb.rb
|
78
|
+
- lib/firewall.pb.rb
|
79
|
+
- lib/lsp_mon.pb.rb
|
79
80
|
- lib/google/protobuf/descriptor.pb.rb
|
80
81
|
homepage: https://github.com/JNPRAutomate/fluentd-plugin-juniper-telemetry
|
81
82
|
licenses:
|