fluent-plugin-coralogix 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99824ef7a8ceb754b4e82d746d74c148e0133b8e
4
+ data.tar.gz: f7ee5f7908c0b7066bf94b084caf8708400939fc
5
+ SHA512:
6
+ metadata.gz: e64f68f0138f2365d1e8541a2a1a375bad41bdd055f588a59ecd46e010cd84dc0fc83036ea6960cf51ab48ddad523eacf0975dcc96d1405530d80e5cefc3dda0
7
+ data.tar.gz: 8858d50e2d128d8a88afc1447623f83d265797434eb9e679af73caee09bbce7b9d5c295906871c1db5266fd987a77714e52e1f131ca422bf4afa82a0d6dffb25
@@ -0,0 +1,91 @@
1
+ require 'fluent/output'
2
+ require 'coralogix_logger'
3
+
4
+ include Coralogix
5
+
6
+ module Fluent
7
+
8
+ DEFAULT_APP_NAME = "FAILED_APP_NAME"
9
+ DEFAULT_SUB_SYSTEM = "FAILED_SUB_SYSTEM_NAME"
10
+
11
+ class SomeOutput < Output
12
+ # First, register the plugin. NAME is the name of this plugin
13
+ # and identifies the plugin in the configuration file.
14
+ Fluent::Plugin.register_output('coralogix', self)
15
+ config_param :config, :hash
16
+ config_param :log_key_name, :string, :default => nil
17
+ config_param :is_json, :bool, :default => false
18
+ @configured = false
19
+
20
+ # This method is called before starting.
21
+ def configure(conf)
22
+ super
23
+
24
+ begin
25
+ #If config parameters doesn't start with $ then we can configure Coralogix logger now.
26
+ if !config["APP_NAME"].start_with?("$") && !config["SUB_SYSTEM"].start_with?("$")
27
+ CoralogixLogger.configure config["PRIVATE_KEY"], config["APP_NAME"], config["SUB_SYSTEM"]
28
+ @configured = true
29
+ end
30
+ rescue Exception => e
31
+ $log.error "Failed to configure: #{e}"
32
+ end
33
+ end
34
+
35
+ def extract record, key, default
36
+ begin
37
+ res = record
38
+ return key unless key.start_with?("$")
39
+ key[1..-1].split(".").each do |k|
40
+ res = res.fetch(k,nil)
41
+ return default if res == nil
42
+ end
43
+ return res
44
+ rescue Exception => e
45
+ $log.error "Failed to extract #{key}: #{e}"
46
+ return default
47
+ end
48
+ end
49
+
50
+
51
+ def reconfigure(record)
52
+ app_name = extract(record, config["APP_NAME"], DEFAULT_APP_NAME)
53
+ sub_name = extract(record, config["SUB_SYSTEM"], DEFAULT_SUB_SYSTEM)
54
+ CoralogixLogger.configure config["PRIVATE_KEY"], app_name, sub_name
55
+ @configured = true
56
+ end
57
+
58
+
59
+ # This method is called when starting.
60
+ def start
61
+ super
62
+
63
+ @logger = CoralogixLogger.get_logger "Fluentd"
64
+ end
65
+
66
+ # This method is called when shutting down.
67
+ def shutdown
68
+ super
69
+ end
70
+
71
+ # This method is called when an event reaches Fluentd.
72
+ # 'es' is a Fluent::EventStream object that includes multiple events.
73
+ # You can use 'es.each {|time,record| ... }' to retrieve events.
74
+ # 'chain' is an object that manages transactions. Call 'chain.next' at
75
+ # appropriate points and rollback if it raises an exception.
76
+ #
77
+ # NOTE! This method is called by Fluentd's main thread so you should not write slow routine here. It causes Fluentd's performance degression.
78
+ def emit(tag, es, chain)
79
+ chain.next
80
+ es.each {|time,record|
81
+ reconfigure(record) if not @configured
82
+
83
+ log_record = log_key_name != nil ? record.fetch(log_key_name, record) : record
84
+ log_record = is_json ? log_record.to_json : log_record
85
+ log_record = log_record.to_s.empty? ? record : log_record
86
+ puts log_record
87
+ @logger.debug log_record
88
+ }
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-coralogix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Royee Goldberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coralogix_logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.22
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.0.22
33
+ description: Coralogix Fluentd plugin to send logs to Coralogix server.
34
+ email: royee@coralogix.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/fluent/plugin/out_coralogix.rb
40
+ homepage: http://www.coralogix.com
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.5.1
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Coralogix Fluentd out plugin
64
+ test_files: []