fluent-plugin-juniper-telemetry 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,147 @@
1
+ module Fluent
2
+ class TextParser
3
+ class JuniperNaParser < Parser
4
+
5
+ Plugin.register_parser("juniper_na", 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
+ # This is the main method. The input "text" is the unit of data to be parsed.
22
+ # If this is the in_tail plugin, it would be a line. If this is for in_syslog,
23
+ # it is a single syslog message.
24
+ def parse(text)
25
+
26
+ resources = JSON.parse(text)
27
+ time = Engine.now
28
+
29
+ resources.each do |resource|
30
+ resource["Resources"].each do |data|
31
+ name = data["Res_ID"]
32
+
33
+ name_h = Hash.new
34
+ type = ''
35
+ if output_format.to_s == 'flat' ||
36
+ output_format.to_s == 'statsd'
37
+ name_gr = name_flat(name)
38
+
39
+ elsif output_format.to_s == 'structured'
40
+ name_h = name_hash(name)
41
+ type = name_h['type']
42
+
43
+ else
44
+ $log.warn "Output_format '#{output_format.to_s}' not supported."
45
+ end
46
+
47
+ ##
48
+ ## Extract data
49
+ ## First check if the value is a hash or not
50
+ ##
51
+ data["Data"].each do |key, value|
52
+ if value.is_a?(Hash)
53
+
54
+ ## If data is within a Hash, extract all values and construct new keys
55
+ data["Data"][key].each do |key2, value2|
56
+ sub_type = key + "." + key2
57
+
58
+ record = {}
59
+ if output_format.to_s == 'flat'
60
+ full_name = "#{name_gr}.#{sub_type}"
61
+ record[full_name.downcase]= value2
62
+
63
+ elsif output_format.to_s == 'structured'
64
+ name_h['type'] = type + sub_type
65
+ record['value'] = value2
66
+ record.merge!(name_h)
67
+
68
+ elsif output_format.to_s == 'statsd'
69
+ full_name = "#{name_gr}.#{sub_type}"
70
+ record[:statsd_type] = 'gauge'
71
+ record[:statsd_key] = full_name.downcase
72
+ record[:statsd_gauge] = value2
73
+ else
74
+ $log.warn "Output_format '#{output_format.to_s}' not supported for #{sub_type}"
75
+ end
76
+
77
+ yield time, record
78
+ end
79
+ else
80
+ record = {}
81
+ sub_type = key
82
+
83
+ if output_format.to_s == 'flat'
84
+ full_name = "#{name_gr}.#{sub_type}"
85
+ record[full_name.downcase]= value
86
+
87
+ elsif output_format.to_s == 'structured'
88
+ name_h['type'] = type + sub_type
89
+ record['value'] = value
90
+ record.merge!(name_h)
91
+
92
+ elsif output_format.to_s == 'statsd'
93
+ full_name = "#{name_gr}.#{sub_type}"
94
+ record[:statsd_type] = 'gauge'
95
+ record[:statsd_key] = full_name.downcase
96
+ record[:statsd_gauge] = value
97
+ else
98
+ $log.warn "Output_format '#{output_format.to_s}' not supported for #{sub_type}"
99
+ end
100
+
101
+ yield time, record
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ def name_flat(res_id)
109
+
110
+ res_id.sub!(/^\//, "")
111
+
112
+ # ## Replace all / and : per .
113
+ res_id.gsub!('/', '.')
114
+ res_id.gsub!(':', '.')
115
+
116
+ return res_id
117
+ end
118
+
119
+ def name_hash(res_id)
120
+
121
+ # Parse Res_ID and convert to hash
122
+ # 1- Remove leading /
123
+ # 2- Split String by /
124
+ # 3- for each attribute split by : to extract key / value
125
+
126
+ res_id.sub!(/^\//, "")
127
+ attributes = res_id.split("/")
128
+
129
+ res_hash = Hash.new
130
+ type = ''
131
+
132
+ attributes.each do |attribute|
133
+ key_value = attribute.split(":")
134
+ res_hash[key_value[0].downcase] = key_value[1].downcase
135
+
136
+ if key_value[0].downcase != 'device'
137
+ type = type + key_value[0].downcase + '.'
138
+ end
139
+ end
140
+
141
+ res_hash['type'] = type
142
+
143
+ return res_hash
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,289 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # This file is auto-generated. DO NOT EDIT!
5
+ #
6
+ require 'protobuf/message'
7
+
8
+ module Google
9
+ module Protobuf
10
+
11
+ ##
12
+ # Message Classes
13
+ #
14
+ class FileDescriptorSet < ::Protobuf::Message; end
15
+ class FileDescriptorProto < ::Protobuf::Message; end
16
+ class DescriptorProto < ::Protobuf::Message
17
+ class ExtensionRange < ::Protobuf::Message; end
18
+ class ReservedRange < ::Protobuf::Message; end
19
+
20
+ end
21
+
22
+ class FieldDescriptorProto < ::Protobuf::Message
23
+ class Type < ::Protobuf::Enum
24
+ define :TYPE_DOUBLE, 1
25
+ define :TYPE_FLOAT, 2
26
+ define :TYPE_INT64, 3
27
+ define :TYPE_UINT64, 4
28
+ define :TYPE_INT32, 5
29
+ define :TYPE_FIXED64, 6
30
+ define :TYPE_FIXED32, 7
31
+ define :TYPE_BOOL, 8
32
+ define :TYPE_STRING, 9
33
+ define :TYPE_GROUP, 10
34
+ define :TYPE_MESSAGE, 11
35
+ define :TYPE_BYTES, 12
36
+ define :TYPE_UINT32, 13
37
+ define :TYPE_ENUM, 14
38
+ define :TYPE_SFIXED32, 15
39
+ define :TYPE_SFIXED64, 16
40
+ define :TYPE_SINT32, 17
41
+ define :TYPE_SINT64, 18
42
+ end
43
+
44
+ class Label < ::Protobuf::Enum
45
+ define :LABEL_OPTIONAL, 1
46
+ define :LABEL_REQUIRED, 2
47
+ define :LABEL_REPEATED, 3
48
+ end
49
+
50
+ end
51
+
52
+ class OneofDescriptorProto < ::Protobuf::Message; end
53
+ class EnumDescriptorProto < ::Protobuf::Message; end
54
+ class EnumValueDescriptorProto < ::Protobuf::Message; end
55
+ class ServiceDescriptorProto < ::Protobuf::Message; end
56
+ class MethodDescriptorProto < ::Protobuf::Message; end
57
+ class FileOptions < ::Protobuf::Message
58
+ class OptimizeMode < ::Protobuf::Enum
59
+ define :SPEED, 1
60
+ define :CODE_SIZE, 2
61
+ define :LITE_RUNTIME, 3
62
+ end
63
+
64
+ end
65
+
66
+ class MessageOptions < ::Protobuf::Message; end
67
+ class FieldOptions < ::Protobuf::Message
68
+ class CType < ::Protobuf::Enum
69
+ define :STRING, 0
70
+ define :CORD, 1
71
+ define :STRING_PIECE, 2
72
+ end
73
+
74
+ class JSType < ::Protobuf::Enum
75
+ define :JS_NORMAL, 0
76
+ define :JS_STRING, 1
77
+ define :JS_NUMBER, 2
78
+ end
79
+
80
+ end
81
+
82
+ class EnumOptions < ::Protobuf::Message; end
83
+ class EnumValueOptions < ::Protobuf::Message; end
84
+ class ServiceOptions < ::Protobuf::Message; end
85
+ class MethodOptions < ::Protobuf::Message; end
86
+ class UninterpretedOption < ::Protobuf::Message
87
+ class NamePart < ::Protobuf::Message; end
88
+
89
+ end
90
+
91
+ class SourceCodeInfo < ::Protobuf::Message
92
+ class Location < ::Protobuf::Message; end
93
+
94
+ end
95
+
96
+
97
+
98
+ ##
99
+ # Message Fields
100
+ #
101
+ class FileDescriptorSet
102
+ repeated ::Google::Protobuf::FileDescriptorProto, :file, 1
103
+ end
104
+
105
+ class FileDescriptorProto
106
+ optional :string, :name, 1
107
+ optional :string, :package, 2
108
+ repeated :string, :dependency, 3
109
+ repeated :int32, :public_dependency, 10
110
+ repeated :int32, :weak_dependency, 11
111
+ repeated ::Google::Protobuf::DescriptorProto, :message_type, 4
112
+ repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 5
113
+ repeated ::Google::Protobuf::ServiceDescriptorProto, :service, 6
114
+ repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 7
115
+ optional ::Google::Protobuf::FileOptions, :options, 8
116
+ optional ::Google::Protobuf::SourceCodeInfo, :source_code_info, 9
117
+ optional :string, :syntax, 12
118
+ end
119
+
120
+ class DescriptorProto
121
+ class ExtensionRange
122
+ optional :int32, :start, 1
123
+ optional :int32, :end, 2
124
+ end
125
+
126
+ class ReservedRange
127
+ optional :int32, :start, 1
128
+ optional :int32, :end, 2
129
+ end
130
+
131
+ optional :string, :name, 1
132
+ repeated ::Google::Protobuf::FieldDescriptorProto, :field, 2
133
+ repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 6
134
+ repeated ::Google::Protobuf::DescriptorProto, :nested_type, 3
135
+ repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 4
136
+ repeated ::Google::Protobuf::DescriptorProto::ExtensionRange, :extension_range, 5
137
+ repeated ::Google::Protobuf::OneofDescriptorProto, :oneof_decl, 8
138
+ optional ::Google::Protobuf::MessageOptions, :options, 7
139
+ repeated ::Google::Protobuf::DescriptorProto::ReservedRange, :reserved_range, 9
140
+ repeated :string, :reserved_name, 10
141
+ end
142
+
143
+ class FieldDescriptorProto
144
+ optional :string, :name, 1
145
+ optional :int32, :number, 3
146
+ optional ::Google::Protobuf::FieldDescriptorProto::Label, :label, 4
147
+ optional ::Google::Protobuf::FieldDescriptorProto::Type, :type, 5
148
+ optional :string, :type_name, 6
149
+ optional :string, :extendee, 2
150
+ optional :string, :default_value, 7
151
+ optional :int32, :oneof_index, 9
152
+ optional :string, :json_name, 10
153
+ optional ::Google::Protobuf::FieldOptions, :options, 8
154
+ end
155
+
156
+ class OneofDescriptorProto
157
+ optional :string, :name, 1
158
+ end
159
+
160
+ class EnumDescriptorProto
161
+ optional :string, :name, 1
162
+ repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2
163
+ optional ::Google::Protobuf::EnumOptions, :options, 3
164
+ end
165
+
166
+ class EnumValueDescriptorProto
167
+ optional :string, :name, 1
168
+ optional :int32, :number, 2
169
+ optional ::Google::Protobuf::EnumValueOptions, :options, 3
170
+ end
171
+
172
+ class ServiceDescriptorProto
173
+ optional :string, :name, 1
174
+ repeated ::Google::Protobuf::MethodDescriptorProto, :method, 2
175
+ optional ::Google::Protobuf::ServiceOptions, :options, 3
176
+ end
177
+
178
+ class MethodDescriptorProto
179
+ optional :string, :name, 1
180
+ optional :string, :input_type, 2
181
+ optional :string, :output_type, 3
182
+ optional ::Google::Protobuf::MethodOptions, :options, 4
183
+ optional :bool, :client_streaming, 5, :default => false
184
+ optional :bool, :server_streaming, 6, :default => false
185
+ end
186
+
187
+ class FileOptions
188
+ optional :string, :java_package, 1
189
+ optional :string, :java_outer_classname, 8
190
+ optional :bool, :java_multiple_files, 10, :default => false
191
+ optional :bool, :java_generate_equals_and_hash, 20, :default => false
192
+ optional :bool, :java_string_check_utf8, 27, :default => false
193
+ optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED
194
+ optional :string, :go_package, 11
195
+ optional :bool, :cc_generic_services, 16, :default => false
196
+ optional :bool, :java_generic_services, 17, :default => false
197
+ optional :bool, :py_generic_services, 18, :default => false
198
+ optional :bool, :deprecated, 23, :default => false
199
+ optional :bool, :cc_enable_arenas, 31, :default => false
200
+ optional :string, :objc_class_prefix, 36
201
+ optional :string, :csharp_namespace, 37
202
+ optional :bool, :javanano_use_deprecated_package, 38
203
+ repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
204
+ # Extension Fields
205
+ extensions 1000...536870912
206
+ end
207
+
208
+ class MessageOptions
209
+ optional :bool, :message_set_wire_format, 1, :default => false
210
+ optional :bool, :no_standard_descriptor_accessor, 2, :default => false
211
+ optional :bool, :deprecated, 3, :default => false
212
+ optional :bool, :map_entry, 7
213
+ repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
214
+ # Extension Fields
215
+ extensions 1000...536870912
216
+ end
217
+
218
+ class FieldOptions
219
+ optional ::Google::Protobuf::FieldOptions::CType, :ctype, 1, :default => ::Google::Protobuf::FieldOptions::CType::STRING
220
+ optional :bool, :packed, 2
221
+ optional ::Google::Protobuf::FieldOptions::JSType, :jstype, 6, :default => ::Google::Protobuf::FieldOptions::JSType::JS_NORMAL
222
+ optional :bool, :lazy, 5, :default => false
223
+ optional :bool, :deprecated, 3, :default => false
224
+ optional :bool, :weak, 10, :default => false
225
+ repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
226
+ # Extension Fields
227
+ extensions 1000...536870912
228
+ end
229
+
230
+ class EnumOptions
231
+ optional :bool, :allow_alias, 2
232
+ optional :bool, :deprecated, 3, :default => false
233
+ repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
234
+ # Extension Fields
235
+ extensions 1000...536870912
236
+ end
237
+
238
+ class EnumValueOptions
239
+ optional :bool, :deprecated, 1, :default => false
240
+ repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
241
+ # Extension Fields
242
+ extensions 1000...536870912
243
+ end
244
+
245
+ class ServiceOptions
246
+ optional :bool, :deprecated, 33, :default => false
247
+ repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
248
+ # Extension Fields
249
+ extensions 1000...536870912
250
+ end
251
+
252
+ class MethodOptions
253
+ optional :bool, :deprecated, 33, :default => false
254
+ repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
255
+ # Extension Fields
256
+ extensions 1000...536870912
257
+ end
258
+
259
+ class UninterpretedOption
260
+ class NamePart
261
+ required :string, :name_part, 1
262
+ required :bool, :is_extension, 2
263
+ end
264
+
265
+ repeated ::Google::Protobuf::UninterpretedOption::NamePart, :name, 2
266
+ optional :string, :identifier_value, 3
267
+ optional :uint64, :positive_int_value, 4
268
+ optional :int64, :negative_int_value, 5
269
+ optional :double, :double_value, 6
270
+ optional :bytes, :string_value, 7
271
+ optional :string, :aggregate_value, 8
272
+ end
273
+
274
+ class SourceCodeInfo
275
+ class Location
276
+ repeated :int32, :path, 1, :packed => true
277
+ repeated :int32, :span, 2, :packed => true
278
+ optional :string, :leading_comments, 3
279
+ optional :string, :trailing_comments, 4
280
+ repeated :string, :leading_detached_comments, 6
281
+ end
282
+
283
+ repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1
284
+ end
285
+
286
+ end
287
+
288
+ end
289
+
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # This file is auto-generated. DO NOT EDIT!
5
+ #
6
+ require 'protobuf/message'
7
+
8
+
9
+ ##
10
+ # Imports
11
+ #
12
+ require 'google/protobuf/descriptor.pb'
13
+
14
+
15
+ ##
16
+ # Message Classes
17
+ #
18
+ class TelemetryFieldOptions < ::Protobuf::Message; end
19
+ class TelemetryStream < ::Protobuf::Message; end
20
+ class IETFSensors < ::Protobuf::Message; end
21
+ class EnterpriseSensors < ::Protobuf::Message; end
22
+ class JuniperNetworksSensors < ::Protobuf::Message; end
23
+
24
+
25
+ ##
26
+ # Message Fields
27
+ #
28
+ class TelemetryFieldOptions
29
+ optional :bool, :is_key, 1
30
+ optional :bool, :is_timestamp, 2
31
+ optional :bool, :is_counter, 3
32
+ optional :bool, :is_gauge, 4
33
+ end
34
+
35
+ class TelemetryStream
36
+ required :string, :system_id, 1
37
+ optional :uint32, :component_id, 2
38
+ optional :uint32, :sub_component_id, 3
39
+ optional :string, :sensor_name, 4
40
+ optional :uint32, :sequence_number, 5
41
+ optional :uint64, :timestamp, 6
42
+ optional :uint32, :version_major, 7
43
+ optional :uint32, :version_minor, 8
44
+ optional ::IETFSensors, :ietf, 100
45
+ optional ::EnterpriseSensors, :enterprise, 101
46
+ end
47
+
48
+
49
+ ##
50
+ # Extended Message Fields
51
+ #
52
+ class ::Google::Protobuf::FieldOptions < ::Protobuf::Message
53
+ optional ::TelemetryFieldOptions, :telemetry_options, 1024, :extension => true
54
+ end
55
+
56
+ class ::EnterpriseSensors < ::Protobuf::Message
57
+ optional ::JuniperNetworksSensors, :juniperNetworks, 2636, :extension => true
58
+ end
59
+