logstash-output-application_insights 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/CONTRIBUTORS +9 -0
  4. data/DEVELOPER.md +0 -0
  5. data/Gemfile +26 -0
  6. data/LICENSE +17 -0
  7. data/README.md +495 -0
  8. data/Rakefile +22 -0
  9. data/lib/logstash/outputs/application_insights.rb +393 -0
  10. data/lib/logstash/outputs/application_insights/blob.rb +923 -0
  11. data/lib/logstash/outputs/application_insights/block.rb +118 -0
  12. data/lib/logstash/outputs/application_insights/channel.rb +259 -0
  13. data/lib/logstash/outputs/application_insights/channels.rb +142 -0
  14. data/lib/logstash/outputs/application_insights/client.rb +110 -0
  15. data/lib/logstash/outputs/application_insights/clients.rb +113 -0
  16. data/lib/logstash/outputs/application_insights/config.rb +341 -0
  17. data/lib/logstash/outputs/application_insights/constants.rb +208 -0
  18. data/lib/logstash/outputs/application_insights/exceptions.rb +55 -0
  19. data/lib/logstash/outputs/application_insights/flow_control.rb +80 -0
  20. data/lib/logstash/outputs/application_insights/multi_io_logger.rb +69 -0
  21. data/lib/logstash/outputs/application_insights/shutdown.rb +96 -0
  22. data/lib/logstash/outputs/application_insights/state.rb +89 -0
  23. data/lib/logstash/outputs/application_insights/storage_cleanup.rb +214 -0
  24. data/lib/logstash/outputs/application_insights/sub_channel.rb +75 -0
  25. data/lib/logstash/outputs/application_insights/telemetry.rb +99 -0
  26. data/lib/logstash/outputs/application_insights/timer.rb +90 -0
  27. data/lib/logstash/outputs/application_insights/utils.rb +139 -0
  28. data/lib/logstash/outputs/application_insights/version.rb +24 -0
  29. data/logstash-output-application-insights.gemspec +50 -0
  30. data/spec/outputs/application_insights_spec.rb +42 -0
  31. metadata +151 -0
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+
3
+ # ----------------------------------------------------------------------------------
4
+ # Logstash Output Application Insights
5
+ #
6
+ # Copyright (c) Microsoft Corporation
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the License);
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ #
18
+ # See the Apache Version 2.0 License for specific language governing
19
+ # permissions and limitations under the License.
20
+ # ----------------------------------------------------------------------------------
21
+
22
+ class LogStash::Outputs::Application_insights
23
+ class Timer
24
+ public
25
+
26
+ attr_accessor :state
27
+ attr_reader :expiration
28
+ attr_reader :object
29
+ attr_reader :callback
30
+
31
+ def self.config ( configuration )
32
+ @@configuration = configuration
33
+ @@logger = configuration[:logger]
34
+ @@timers = []
35
+ @@timers_modified = false
36
+ @@timers_mutex = Mutex.new
37
+
38
+ Thread.new do
39
+ loop do
40
+ sleep( 1 )
41
+
42
+ curr_time = Time.now.utc
43
+ timers_triggerd = [ ]
44
+
45
+ @@timers_mutex.synchronize {
46
+ @@timers.each do |timer|
47
+ if :on == timer.state && curr_time >= timer.expiration
48
+ timer.state = :trigger
49
+ timers_triggerd << [ timer.object, timer.callback ]
50
+ end
51
+ end
52
+ }
53
+
54
+ timers_triggerd.each do |pair|
55
+ (object, callback) = pair
56
+ callback.call( object )
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ def initialize
64
+ @@timers_mutex.synchronize {
65
+ @@timers << self
66
+ }
67
+ @state = :off
68
+ end
69
+
70
+ def set ( expiration, object, &callback )
71
+ @@timers_mutex.synchronize {
72
+ @@timers_modified= true
73
+ @state = :on
74
+ @object = object
75
+ @expiration = expiration
76
+ @callback = callback
77
+ }
78
+ end
79
+
80
+ def cancel
81
+ @@timers_mutex.synchronize {
82
+ state = @state
83
+ @state = :off
84
+ @@timers_modified = true if :on == state
85
+ state != :trigger
86
+ }
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,139 @@
1
+ # encoding: utf-8
2
+
3
+ # ----------------------------------------------------------------------------------
4
+ # Logstash Output Application Insights
5
+ #
6
+ # Copyright (c) Microsoft Corporation
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the License);
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ #
18
+ # See the Apache Version 2.0 License for specific language governing
19
+ # permissions and limitations under the License.
20
+ # ----------------------------------------------------------------------------------
21
+
22
+ class LogStash::Outputs::Application_insights
23
+ class Utils
24
+
25
+ def self.string_to_hex_string(str, readable = true)
26
+ unpacked = str.unpack('H*').first
27
+ if readable
28
+ unpacked.gsub(/(..)/,'\1 ').rstrip
29
+ else
30
+ unpacked
31
+ end
32
+ end
33
+ UNESCAPES = {
34
+ 'a' => "\x07", 'b' => "\x08", 't' => "\x09",
35
+ 'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c",
36
+ 'r' => "\x0d", 'e' => "\x1b", "\\\\" => "\x5c",
37
+ "\"" => "\x22", "'" => "\x27"
38
+ }
39
+
40
+ def self.os
41
+ host_os = RbConfig::CONFIG['host_os']
42
+ case host_os
43
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
44
+ "Windows #{host_os}"
45
+ when /darwin|mac os/
46
+ "MacOS #{host_os}"
47
+ when /linux/
48
+ "Linux #{host_os}"
49
+ when /solaris|bsd/
50
+ "Unix #{host_os}"
51
+ else
52
+ "Unknown #{host_os}"
53
+ end
54
+ end
55
+
56
+
57
+ def self.unescape(str)
58
+ # Escape all the things
59
+ str.gsub(/\\(?:([#{UNESCAPES.keys.join}])|u([\da-fA-F]{4}))|\\0?x([\da-fA-F]{2})/) {
60
+ if $1
61
+ if $1 == '\\' then '\\' else UNESCAPES[$1] end
62
+ elsif $2 # escape \u0000 unicode
63
+ ["#$2".hex].pack('U*')
64
+ elsif $3 # escape \0xff or \xff
65
+ [$3].pack('H2')
66
+ end
67
+ }
68
+ end
69
+
70
+ def self.integer? ( s )
71
+ s =~ /\A[-+]?[0-9]*\z/
72
+ end
73
+
74
+ def self.numeric? ( s )
75
+ s =~ /\A[-+]?[0-9]*\.?[0-9]+\z/
76
+ end
77
+
78
+ def self.guid? ( s )
79
+ s =~ /\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i
80
+ end
81
+
82
+ def self.valid_container_name? ( s )
83
+ s =~ /\A[a-z0-9](?:[a-z0-9]|(\-(?!\-))){1,61}[a-z0-9]\z/
84
+ end
85
+
86
+ def self.valid_table_name? ( s )
87
+ s =~ /\A[a-zA-Z][a-zA-Z0-9]{2,62}\z/
88
+ end
89
+
90
+ def self.alphanumeric? ( s )
91
+ s =~ /\A[a-zA-Z0-9]*\z/
92
+ end
93
+
94
+ def self.valid_file_path
95
+ s =~ /\A(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+\z/
96
+ end
97
+
98
+ def self.ext? ( s )
99
+ s =~ /\A[a-zA-Z0-9\-\_]*\z/
100
+ end
101
+
102
+ def self.base64? ( s )
103
+ s =~ /\A(?:[A-Za-z0-9\+\/]{4})*(?:[A-Za-z0-9\+\/]{2}==|[A-Za-z0-9\+\/]{3}\=)?\z/
104
+ end
105
+
106
+ def self.url? ( s )
107
+ s =~ /\A#{URI::regexp(['http', 'https'])}\z/
108
+ end
109
+
110
+ def self.hostname? ( s )
111
+ s =~ /\A(?<hostname>([A-Za-z0-9\.\-]+)|\[[0-9A-Fa-f\:]+\])(:(?<port>\d+))?\z/
112
+ end
113
+
114
+ def self.to_storage_name ( s )
115
+ s.nil? ? nil : s.downcase.gsub(/[^0-9a-z]/i, '')
116
+ end
117
+
118
+ def self.symbolize_hash_keys ( hash )
119
+ # to_h not supported in Ruby 2.0 and below
120
+ # hash.map {|k, v| [k.to_sym, v] }.to_h
121
+ new_hash = {}
122
+ hash.each_pair do |k, v|
123
+ new_hash[k.to_sym] = v
124
+ end
125
+ new_hash
126
+ end
127
+
128
+ def self.downcase_hash_keys ( hash )
129
+ # to_h not supported in Ruby 2.0 and below
130
+ # hash.map {|k, v| [k.downcase, v] }.to_h
131
+ new_hash = {}
132
+ hash.each_pair do |k, v|
133
+ new_hash[k.downcase] = v
134
+ end
135
+ new_hash
136
+ end
137
+ end
138
+
139
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ # ----------------------------------------------------------------------------------
4
+ # Logstash Output Application Insights
5
+ #
6
+ # Copyright (c) Microsoft Corporation
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the License);
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ #
18
+ # See the Apache Version 2.0 License for specific language governing
19
+ # permissions and limitations under the License.
20
+ # ----------------------------------------------------------------------------------
21
+
22
+ # class LogStash::Outputs::Application_insights
23
+ APPLICATION_INSIGHTS_VERSION ||= "0.1.3"
24
+ # end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ # ----------------------------------------------------------------------------------
4
+ # Logstash Output Application Insights
5
+ #
6
+ # Copyright (c) Microsoft Corporation
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the License);
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ #
18
+ # See the Apache Version 2.0 License for specific language governing
19
+ # permissions and limitations under the License.
20
+ # ----------------------------------------------------------------------------------
21
+
22
+ require 'date'
23
+ require File.expand_path('../lib/logstash/outputs/application_insights/version', __FILE__)
24
+
25
+ Gem::Specification.new do |s|
26
+ s.name = 'logstash-output-application_insights'
27
+ s.version = APPLICATION_INSIGHTS_VERSION
28
+ s.licenses = ['Apache License (2.0)']
29
+ s.summary = "Microsoft Application Insights openschema Logstash output plugin. 'Output events to Application Insights"
30
+ s.description = "Outputs events to Microsoft Application Insights Analytics. This gem is a Logstash output plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
31
+ s.authors = ["Microsoft Corporation"]
32
+ s.email = "info@microsoft.com"
33
+ s.homepage = "https://github.com/Microsoft/logstash-output-application-insights"
34
+ s.require_paths = ["lib"]
35
+
36
+ # Files
37
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','Rakefile','LICENSE','NOTICE.TXT','LICENSE.TXT']
38
+ # Tests
39
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
40
+
41
+ # Special flag to let us know this is actually a logstash plugin
42
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
43
+
44
+ # Gem dependencies
45
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
46
+ s.add_runtime_dependency "azure-storage", "0.10.1.preview"
47
+ s.add_runtime_dependency "azure-core", "0.1.2"
48
+ s.add_runtime_dependency "application_insights", ">= 0.5.3"
49
+ s.add_development_dependency "logstash-devutils"
50
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ # ----------------------------------------------------------------------------------
4
+ # Logstash Output Application Insights
5
+ #
6
+ # Copyright (c) Microsoft Corporation
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the License);
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ #
18
+ # See the Apache Version 2.0 License for specific language governing
19
+ # permissions and limitations under the License.
20
+ # ----------------------------------------------------------------------------------
21
+
22
+ require "logstash/devutils/rspec/spec_helper"
23
+ require "logstash/outputs/application_insights"
24
+ require "logstash/codecs/plain"
25
+ require "logstash/event"
26
+
27
+ describe LogStash::Outputs::Application_insights do
28
+ let(:sample_event) { LogStash::Event.new }
29
+ let(:output) { LogStash::Outputs::Application_insights.new }
30
+
31
+ before do
32
+ output.register
33
+ end
34
+
35
+ describe "receive message" do
36
+ subject { output.receive(sample_event) }
37
+
38
+ it "returns a string" do
39
+ expect(subject).to eq("Event received")
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-application_insights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Microsoft Corporation
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.0.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '='
37
+ - !ruby/object:Gem::Version
38
+ version: 0.10.1.preview
39
+ name: azure-storage
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.10.1.preview
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '='
51
+ - !ruby/object:Gem::Version
52
+ version: 0.1.2
53
+ name: azure-core
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.2
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.5.3
67
+ name: application_insights
68
+ prerelease: false
69
+ type: :runtime
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.5.3
75
+ - !ruby/object:Gem::Dependency
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ name: logstash-devutils
82
+ prerelease: false
83
+ type: :development
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Outputs events to Microsoft Application Insights Analytics. This gem is a Logstash output plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
90
+ email: info@microsoft.com
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - CHANGELOG.md
96
+ - CONTRIBUTORS
97
+ - DEVELOPER.md
98
+ - Gemfile
99
+ - LICENSE
100
+ - README.md
101
+ - Rakefile
102
+ - lib/logstash/outputs/application_insights.rb
103
+ - lib/logstash/outputs/application_insights/blob.rb
104
+ - lib/logstash/outputs/application_insights/block.rb
105
+ - lib/logstash/outputs/application_insights/channel.rb
106
+ - lib/logstash/outputs/application_insights/channels.rb
107
+ - lib/logstash/outputs/application_insights/client.rb
108
+ - lib/logstash/outputs/application_insights/clients.rb
109
+ - lib/logstash/outputs/application_insights/config.rb
110
+ - lib/logstash/outputs/application_insights/constants.rb
111
+ - lib/logstash/outputs/application_insights/exceptions.rb
112
+ - lib/logstash/outputs/application_insights/flow_control.rb
113
+ - lib/logstash/outputs/application_insights/multi_io_logger.rb
114
+ - lib/logstash/outputs/application_insights/shutdown.rb
115
+ - lib/logstash/outputs/application_insights/state.rb
116
+ - lib/logstash/outputs/application_insights/storage_cleanup.rb
117
+ - lib/logstash/outputs/application_insights/sub_channel.rb
118
+ - lib/logstash/outputs/application_insights/telemetry.rb
119
+ - lib/logstash/outputs/application_insights/timer.rb
120
+ - lib/logstash/outputs/application_insights/utils.rb
121
+ - lib/logstash/outputs/application_insights/version.rb
122
+ - logstash-output-application-insights.gemspec
123
+ - spec/outputs/application_insights_spec.rb
124
+ homepage: https://github.com/Microsoft/logstash-output-application-insights
125
+ licenses:
126
+ - Apache License (2.0)
127
+ metadata:
128
+ logstash_plugin: 'true'
129
+ logstash_group: output
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.6.4
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Microsoft Application Insights openschema Logstash output plugin. 'Output events to Application Insights
150
+ test_files:
151
+ - spec/outputs/application_insights_spec.rb