fluent-plugin-site24x7 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaa27dafc08120c093de5e57ba15b129209637db8759e68a20c2053513cb55e9
4
- data.tar.gz: 6fc10de6e63e332c816935a656cfb234e733710c7849f7578ebaa035eec7a8d4
3
+ metadata.gz: f625b690765ab8a387bfef2ce93ce69a8dbcd42130248fe72913e6947395e204
4
+ data.tar.gz: a47d573e473f76802523ac3e88951c86e058f7577aff44b4fdf1ef221e4826c9
5
5
  SHA512:
6
- metadata.gz: 58d44f268199174dabf93bc3b0fc3ceb0add74b2718001aaab95c3c380bf4f2b18bec949162a47a778a7d78d80a067302cc509506ceac6f8a2f21d5dedcc60ba
7
- data.tar.gz: bd0dc479e64382935a9154006b281b46cad6d93c883b18d5ddb1cbd026ae49d427a35c0e4836ee6cf7eb1996d6d3557cd5d3bb4f862d9149af5655be862ad1d5
6
+ metadata.gz: 450f8c60b8cf1a193d5a2ed8265b2cd9b223368f1df22c37459cdc8d5ca0d21590b6241749432c9b15b5595ae069dfb59b4810bf39e7b40f9bb43193f56eb1bd
7
+ data.tar.gz: d06c06451ed65bdb99b5e61cb7445d22554bb78d6777609ba0faace2a860135f51478fe003d56a023202584d0974eb2d7f8e952a4133e6137cc96bfe01e86b86
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-site24x7"
6
- spec.version = "0.1.4"
6
+ spec.version = "0.1.5"
7
7
  spec.authors = ["Magesh Rajan"]
8
8
  spec.email = ["magesh.rajan@zohocorp.com"]
9
9
 
@@ -143,9 +143,13 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
143
143
  for field,rules in @logtype_config['filterConfig'] do
144
144
  temp = []
145
145
  for value in @logtype_config['filterConfig'][field]['values'] do
146
- temp.push(Regexp.compile(value))
146
+ if @logtype_config['filterConfig'][field]['exact']
147
+ temp.push("\\A"+value+"\\Z")
148
+ else
149
+ temp.push(value)
150
+ end
147
151
  end
148
- @logtype_config['filterConfig'][field]['values'] = temp.join('|')
152
+ @logtype_config['filterConfig'][field]['values'] = Regexp.compile(temp.join('|'))
149
153
  end
150
154
  end
151
155
 
@@ -165,13 +169,13 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
165
169
  if !@is_timezone_present && @logtype_config.has_key?('timezone')
166
170
  @s247_datetime_format_string += '%z'
167
171
  tz_value = @logtype_config['timezone']
168
- if tz_value.start_with?('+')
169
- @s247_tz['hrs'] = Integer('-' + tz_value[1..4])
170
- @s247_tz['mins'] = Integer('-' + tz_value[3..6])
171
- elsif tz_value.start_with?('-')
172
- @s247_tz['hrs'] = Integer('+' + tz_value[1..4])
173
- @s247_tz['mins'] = Integer('+' + tz_value[3..6])
174
- end
172
+ if tz_value.start_with?('+')
173
+ @s247_tz['hrs'] = Integer('-' + tz_value[1..2])
174
+ @s247_tz['mins'] = Integer('-' + tz_value[3..4])
175
+ elsif tz_value.start_with?('-')
176
+ @s247_tz['hrs'] = Integer('+' + tz_value[1..2])
177
+ @s247_tz['mins'] = Integer('+' + tz_value[3..4])
178
+ end
175
179
  end
176
180
  end
177
181
  Thread.new { timer_task() }
@@ -216,10 +220,21 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
216
220
  end
217
221
  end
218
222
 
219
- def log_line_filter()
220
- applyMasking()
221
- applyHashing()
222
- getDerivedFields()
223
+ def data_collector()
224
+ if @formatted_line.has_key?('_zl_timestamp')
225
+ applyMasking()
226
+ applyHashing()
227
+ getDerivedFields()
228
+ if !is_filters_matched()
229
+ @formatted_line = {}
230
+ return
231
+ end
232
+ remove_ignored_fields()
233
+ log_size_calculation()
234
+ else
235
+ @formatted_line = {}
236
+ return
237
+ end
223
238
  end
224
239
 
225
240
  def get_last_group_inregex(s247_custom_regex)
@@ -228,7 +243,9 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
228
243
 
229
244
  def remove_ignored_fields()
230
245
  @s247_ignored_fields.each do |field_name|
231
- @log_size -= if @log_fields.has_key?field_name then @log_fields.delete(field_name).bytesize else 0 end
246
+ if @formatted_line.has_key?field_name
247
+ @formatted_line.delete(field_name)
248
+ end
232
249
  end
233
250
  end
234
251
 
@@ -245,10 +262,7 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
245
262
  match = line.match(@s247_custom_regex)
246
263
  if match
247
264
  @formatted_line.update(@old_formatted_line)
248
- @log_size += @old_log_size
249
- @old_log_size = line.bytesize
250
265
  @log_fields = match&.named_captures
251
- remove_ignored_fields()
252
266
  add_message_metadata()
253
267
  @old_formatted_line = @log_fields
254
268
  @last_line_matched = true
@@ -262,14 +276,13 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
262
276
  @old_log_size += line.bytesize
263
277
  @trace_started = true
264
278
  @last_line_matched = false
265
- end
279
+ end
266
280
  end
267
- end
268
- if @formatted_line.has_key?('_zl_timestamp')
269
- log_line_filter()
281
+ end
282
+ data_collector()
283
+ if @formatted_line.length >0
270
284
  parsed_lines.push(@formatted_line)
271
- @formatted_line = {}
272
- end
285
+ end
273
286
  rescue Exception => e
274
287
  log.error "Exception in parse_line #{e.backtrace}"
275
288
  @formatted_line = {}
@@ -283,12 +296,14 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
283
296
  begin
284
297
  if @logtype_config.has_key?'filterConfig'
285
298
  @logtype_config['filterConfig'].each do |config,value|
286
- if @formatted_line[config].scan(Regexp.new(@logtype_config['filterConfig'][config]['values'])).length > 0
287
- val = true
288
- else
289
- val = false
299
+ if (@formatted_line.has_key?config)
300
+ if @logtype_config['filterConfig'][config]['values'].match(@formatted_line[config])
301
+ val = true
302
+ else
303
+ val = false
304
+ end
290
305
  end
291
- if (@formatted_line.has_key?config) && (@logtype_config['filterConfig'][config]['match'] ^ (val))
306
+ if (@logtype_config['filterConfig'][config]['match'] ^ (val))
292
307
  return false
293
308
  end
294
309
  end
@@ -342,20 +357,18 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
342
357
  matcher = regex.match(@log_fields.delete(key))
343
358
  if matcher
344
359
  @log_fields.update(matcher.named_captures)
345
- remove_ignored_fields()
346
360
  @formatted_line.update(@log_fields)
347
361
  end
348
362
  end
349
363
  end
350
- if !(is_filters_matched())
351
- return false
352
- else
353
- add_message_metadata()
354
- @formatted_line.update(@log_fields)
355
- log_line_filter()
356
- @log_size += json_log_size
364
+ add_message_metadata()
365
+ @formatted_line.update(@log_fields)
366
+ data_collector()
367
+ if @formatted_line.length >0
357
368
  return true
358
- end
369
+ else
370
+ return false
371
+ end
359
372
  end
360
373
 
361
374
  def json_log_parser(lines)
@@ -367,7 +380,7 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
367
380
  if line[0] == '{' && @json_data[-1] == '}'
368
381
  if json_log_applier(@json_data)
369
382
  parsed_lines.push(@formatted_line)
370
- end
383
+ end
371
384
  @json_data=''
372
385
  end
373
386
  @json_data += line
@@ -380,20 +393,14 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
380
393
  end
381
394
 
382
395
  def ml_regex_applier(ml_trace, ml_data)
383
- begin
384
- @log_size += @ml_trace.bytesize
396
+ begin
385
397
  matcher = @s247_custom_regex.match(@ml_trace)
386
398
  @log_fields = matcher.named_captures
387
399
  @log_fields.update(@ml_data)
388
- if @s247_ignored_fields
389
- remove_ignored_fields()
390
- end
391
400
  add_message_metadata()
392
401
  @formatted_line.update(@log_fields)
393
- log_line_filter()
394
402
  rescue Exception => e
395
403
  log.error "Exception occurred in ml_parser : #{e.backtrace}"
396
- @formatted_line = {}
397
404
  end
398
405
  end
399
406
 
@@ -413,14 +420,15 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
413
420
  ml_regex_applier(@ml_trace, @ml_data)
414
421
  if @ml_trace_buffer && @formatted_line
415
422
  @formatted_line[@message_key] = @formatted_line[@message_key] + @ml_trace_buffer
416
- @log_size += @ml_trace_buffer.bytesize
417
423
  end
418
- parsed_lines.push(@formatted_line)
424
+ data_collector()
425
+ if @formatted_line.length >0
426
+ parsed_lines.push(@formatted_line)
427
+ end
419
428
  @ml_trace = ''
420
429
  @ml_trace_buffer = ''
421
430
  if @ml_found
422
431
  @ml_data = ml_start_matcher.named_captures
423
- @log_size += line.bytesize
424
432
  else
425
433
  @ml_data = {}
426
434
  end
@@ -429,7 +437,6 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
429
437
  log.error "Exception occurred in ml_parser : #{e.backtrace}"
430
438
  end
431
439
  elsif @ml_found
432
- @log_size += line.bytesize
433
440
  @ml_data = ml_start_matcher.named_captures
434
441
  end
435
442
  elsif @ml_found
@@ -551,7 +558,7 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
551
558
  begin
552
559
  response = @s247_http_client.request @uri, request
553
560
  resp_headers = response.each_header.to_h
554
-
561
+
555
562
  if response.code == '200'
556
563
  if resp_headers.has_key?'LOG_LICENSE_EXCEEDS' && resp_headers['LOG_LICENSE_EXCEEDS'] == 'True'
557
564
  log.error "Log license limit exceeds so not able to send logs"
@@ -564,6 +571,9 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
564
571
  elsif resp_headers.has_key?'INVALID_LOGTYPE' && resp_headers['INVALID_LOGTYPE'] == 'True'
565
572
  log.error "Log type not present in this account so stopping log collection"
566
573
  @valid_logtype = false
574
+ elsif resp_headers['x-uploadid'] == nil
575
+ log.error "upload id is empty hence retry flag enabled #{gzipped_parsed_lines.size} / #{@log_size}"
576
+ need_retry = true
567
577
  else
568
578
  @log_upload_allowed = true
569
579
  log.debug "Successfully sent logs with size #{gzipped_parsed_lines.size} / #{@log_size} to site24x7. Upload Id : #{resp_headers['x-uploadid']}"
@@ -599,8 +609,7 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
599
609
  ml_regex_applier(@ml_trace, @ml_data)
600
610
  if @ml_trace_buffer
601
611
  if !(@formatted_line.empty?)
602
- @formatted_line[@message_key] = @formatted_line[@message_key] + @ml_trace_buffer
603
- @log_size += @ml_trace_buffer.bytesize
612
+ @formatted_line[@message_key] = @formatted_line[@message_key] + @ml_trace_buffer
604
613
  else
605
614
  @ml_trace += @ml_trace_buffer.gsub('\n', '<NewLine>')
606
615
  ml_regex_applier(@ml_trace, @ml_data)
@@ -615,10 +624,8 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
615
624
  @json_data = ''
616
625
  elsif @old_formatted_line
617
626
  @formatted_line.update(@old_formatted_line)
618
- log_line_filter()
619
- @log_size += @old_log_size
627
+ data_collector()
620
628
  @old_formatted_line = {}
621
- @old_log_size = 0
622
629
  end
623
630
  @logged = true
624
631
  if @format_record
@@ -654,9 +661,7 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
654
661
  end
655
662
  end
656
663
  @formatted_line[key] = field_value
657
- @log_size -= adjust_length
658
664
  else
659
- @log_size -= (@formatted_line[key].bytesize - @masking_config[key]['string'].bytesize)
660
665
  @formatted_line[key] = @masking_config[key]['string']
661
666
  end
662
667
  end
@@ -693,11 +698,6 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
693
698
  end
694
699
  end
695
700
  end
696
- end
697
- if adjust_length
698
- @log_size -= adjust_length
699
- else
700
- @log_size -= (@formatted_line[key].bytesize - field_value.bytesize)
701
701
  end
702
702
  @formatted_line[key] = field_value
703
703
  end
@@ -716,10 +716,7 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
716
716
  if @formatted_line.has_key?key
717
717
  match_derived = each.match(@formatted_line[key])
718
718
  if match_derived
719
- @formatted_line.update(match_derived.named_captures)
720
- for field_name,value in match_derived.named_captures do
721
- @log_size += @formatted_line[field_name].bytesize
722
- end
719
+ @formatted_line.update(match_derived.named_captures)
723
720
  end
724
721
  break
725
722
  end
@@ -727,10 +724,19 @@ class Fluent::Site24x7Output < Fluent::Plugin::Output
727
724
  end
728
725
  rescue Exception => e
729
726
  log.error "Exception occurred in derived fields : #{e.backtrace}"
730
- end
727
+ end
731
728
  end
732
729
  end
733
730
 
731
+ def log_size_calculation()
732
+ data_exclusion = ["_zl", "s247", "inode"]
733
+ @formatted_line.each do |field, value|
734
+ unless data_exclusion.any? { |exclusion| field.start_with?(exclusion) }
735
+ @log_size += value.to_s.bytesize
736
+ end
737
+ end
738
+ end
739
+
734
740
  def timer_task()
735
741
  while true
736
742
  @after_time = Time.now
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-site24x7
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magesh Rajan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.1.6
155
+ rubygems_version: 3.1.2
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Site24x7 output plugin for Fluent event collector.