logstash-output-applicationinsights 0.9.0

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: 4ee4596c361e88edab65f8aa680efe054dc22661
4
+ data.tar.gz: 6453ed63749c76d8d19411453dacdec2481f952f
5
+ SHA512:
6
+ metadata.gz: 39b0079c0ee0add3155ec296a38fb56555595138feaddf997440ce2eb7f19e0ce304778aedb5d980d29ef3f994c805c10838cbd239877c24d9d3233d8f93935c
7
+ data.tar.gz: 6861932fb600a9bcb92b13030ff870af483b66776cccecc397a14385e253df0adca3dfe8f09ac6527b96b89230c0a7c51c9e40b60fb6ad0d06d211cf9f875561
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 2016.06.03
2
+ * First version.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Copyright (c) Microsoft. All rights reserved.
2
+ Microsoft would like to thank its contributors, a list
3
+ of whom are at http://aka.ms/entlib-contributors
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License"); you
6
+ may not use this file except in compliance with the License. You may
7
+ obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
+ implied. See the License for the specific language governing permissions
15
+ and limitations under the License.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Logstash output plugin for Application Insights
2
+
3
+ ## Summary
4
+
5
+
6
+ ## Installation
7
+ You can install this plugin using the Logstash "plugin" or "logstash-plugin" (for newer versions of Logstash) command:
8
+ ```sh
9
+ logstash-plugin install logstash-output-applicationinsights
10
+ ```
11
+ For more information, see Logstash reference [Working with plugins](https://www.elastic.co/guide/en/logstash/current/working-with-plugins.html).
12
+
13
+ ## Configuration
14
+ ### Required Parameters
15
+ __*ikey*__
16
+
17
+ The Application Insights Instrumentation key.
18
+
19
+ ### Optional Parameters
20
+ __*ai_message_field*__
21
+
22
+ Specifies the name of the event field to be used as the Message field of the Application Insights trace. If not specified, Message in Application Insights will be "Null".
23
+
24
+ __*ai_properties_field*__
25
+
26
+ Specifies the name of the event field to be used as the Properties field of the Application Insights trace. The type of the field needs to be Hash. If not specified, all fields in event will be used.
27
+
28
+ __*ai_severity_level_field*__
29
+
30
+ Specifies the name of the event field to be used as the Severity level of the Application Insights trace. If not specified, all traces will be "Informational".
31
+
32
+ __*ai_severity_level_mapping*__
33
+
34
+ Specifies how to map the values read from *ai_severity_level_field* to Application Insights severity level. This is a hash containing the possible values from event as keys and corresponding Application Insights Severity Level constants as values.
35
+
36
+ See example below for how to map [Azure diagnostics log level values](https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.diagnostics.loglevel.aspx) to [Application Insights severity values](https://github.com/Microsoft/ApplicationInsights-Ruby/blob/master/lib/application_insights/channel/contracts/severity_level.rb).
37
+
38
+ __*dev_mode*__
39
+
40
+ If this is set to True, the plugin sends telemetry to Application Insights immediately; otherwise the plugin respects production sending policies defined by other properties.
41
+
42
+ ### Examples
43
+ ```
44
+ output
45
+ {
46
+ applicationinsights
47
+ {
48
+ ikey => "00000000-0000-0000-0000-000000000000"
49
+ dev_mode => true
50
+ ai_message_field => "EventMessage"
51
+ ai_properties_field => "EventProperties"
52
+ ai_severity_level_field => "level"
53
+ ai_severity_level_mapping => { 5 => 0 4 => 1 3 => 2 2 => 3 1 => 4 0 => 4 }
54
+ }
55
+ }
56
+ ```
57
+
58
+ ## More information
59
+ The source code of this plugin is hosted in GitHub repo [Microsoft Azure Diagnostics with ELK](https://github.com/Azure/azure-diagnostics-tools). We welcome you to provide feedback and/or contribute to the project.
60
+
61
+ Please also see [Analyze Diagnostics Data with ELK template](https://github.com/Azure/azure-quickstart-templates/tree/master/diagnostics-with-elk) for quick deployment of ELK to Azure.
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require "application_insights"
5
+
6
+ include ApplicationInsights
7
+ include ApplicationInsights::Channel
8
+
9
+ class LogStash::Outputs::ApplicationInsights < LogStash::Outputs::Base
10
+ config_name "applicationinsights"
11
+
12
+ config :ikey, :validate => :string, :required => true
13
+ config :dev_mode, :validate => :boolean, :required => false, :default => false
14
+ config :ai_message_field, :validate => :string, :required => false, :default => nil
15
+ config :ai_properties_field, :validate => :string, :required => false, :default => nil
16
+ config :ai_severity_level_field, :validate => :string, :required => false, :default => nil
17
+ config :ai_severity_level_mapping, :validate => :hash, :required => false, :default => nil
18
+
19
+ public
20
+ def register
21
+ create_client
22
+ end # def register
23
+
24
+ public
25
+ def multi_receive(events)
26
+ events.each do |event|
27
+ begin
28
+ ai_message = get_ai_message(event)
29
+ ai_properties = get_ai_properties(event)
30
+ ai_severity = get_ai_severity(event)
31
+
32
+ @client.track_trace(ai_message, ai_severity, { :properties => ai_properties })
33
+ @client.flush if @dev_mode
34
+
35
+ rescue => e
36
+ @logger.error("Error occurred sending data to AI.", :exception => e)
37
+ end # begin
38
+ end # do
39
+ end # def multi_receive
40
+
41
+ def close
42
+ @client.flush
43
+ end # def close
44
+
45
+ def create_client
46
+ telemetry_context = TelemetryContext.new
47
+ async_queue = AsynchronousQueue.new(AsynchronousSender.new)
48
+ telemetry_channel = TelemetryChannel.new(telemetry_context, async_queue)
49
+ @client = TelemetryClient.new(@ikey, telemetry_channel)
50
+ end # def create_client
51
+
52
+ def get_ai_message(event)
53
+ return nil if @ai_message_field.nil?
54
+
55
+ ai_message = event[@ai_message_field] # Extracts specified field value as the AI Message.
56
+ @logger.warn("#{@ai_message_field} specified in ai_message_field not found in event data. AI Message will be null.") if ai_message.nil?
57
+ event.remove(@ai_message_field) unless ai_message.nil? # Removes the duplicated AI Message field.
58
+ ai_message
59
+ end # def get_ai_message
60
+
61
+ def get_ai_properties(event)
62
+ ai_properties = event.to_hash.fetch(@ai_properties_field, nil)
63
+ if !@ai_properties_field.nil? && ai_properties.nil?
64
+ @logger.warn("#{@ai_properties_field} specified in ai_properties_field not found in event data. Will use all fields in event as AI properties.")
65
+ end # if
66
+
67
+ ai_properties || event.to_hash
68
+ end # def get_ai_properties
69
+
70
+ def get_ai_severity(event)
71
+ return nil if @ai_severity_level_field.nil?
72
+
73
+ severity_value = event[@ai_severity_level_field]
74
+
75
+ if !@ai_severity_level_mapping.nil? && @ai_severity_level_mapping.any?
76
+ ai_severity_level = @ai_severity_level_mapping.fetch(severity_value, nil)
77
+ else
78
+ ai_severity_level = severity_value
79
+ end # unless
80
+
81
+ if ai_severity_level.nil?
82
+ @logger.warn("Cannot map value '#{severity_value}' from '#{@ai_severity_level_field}' to AI severity level. Will use default value.")
83
+ else
84
+ event.remove(@ai_severity_level_field) # Removes the duplicated severity field.
85
+ end # if
86
+
87
+ ai_severity_level
88
+ end # def get_ai_severity
89
+
90
+ end # LogStash::Outputs::ApplicationInsights
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-applicationinsights'
3
+ s.version = '0.9.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This plugin sends data to Application Insights."
6
+ s.description = "This gem is a Logstash plugin. It sends data to Application Insights."
7
+ s.authors = ["Microsoft Corporation"]
8
+ s.email = 'azdiag@microsoft.com'
9
+ s.homepage = "https://github.com/Azure/azure-diagnostics-tools"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency 'logstash-core', '~> 2.0'
22
+ s.add_runtime_dependency 'application_insights', '~> 0.5.3'
23
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
24
+ end
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-applicationinsights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Microsoft Corporation
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-11 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'
19
+ name: logstash-core
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.5.3
33
+ name: application_insights
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.3
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.16
47
+ name: logstash-devutils
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.16
55
+ description: This gem is a Logstash plugin. It sends data to Application Insights.
56
+ email: azdiag@microsoft.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - Gemfile
63
+ - LICENSE
64
+ - README.md
65
+ - lib/logstash/outputs/applicationinsights.rb
66
+ - logstash-output-applicationinsights.gemspec
67
+ - spec/outputs/applicationinsights_spec.rb
68
+ homepage: https://github.com/Azure/azure-diagnostics-tools
69
+ licenses:
70
+ - Apache License (2.0)
71
+ metadata:
72
+ logstash_plugin: 'true'
73
+ logstash_group: output
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.8
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: This plugin sends data to Application Insights.
94
+ test_files:
95
+ - spec/outputs/applicationinsights_spec.rb