logstash-filter-cpu_temp 1.0.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: f404a3943dc2f75c32b250de395aecf1eceedd63
4
+ data.tar.gz: 5a7c5c6fb21dbcb2924a64fbd9f2905cfa7d1b84
5
+ SHA512:
6
+ metadata.gz: e4e2ea0eb3b871d14458168a056f3f44c2966796b3859c8b420dc09ada98f1946dd1c11a76b1be31db7a5e27591dbd4f379d8dda8f297244d2189d942eef4656
7
+ data.tar.gz: 920e29cf76acca2517d28d6bdf61de6ffadf3068d1fb7a846d54e9894b11db6985b9e01fedf9cad64dc5015889deef3fb10a8e59922d4f24709198db1d1a9a76
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 2.0.0
2
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
4
+ - Dependency on logstash-core update to 2.0
5
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Aaron Mildenstein (untergeek)
6
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-filter-example
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ #source 'https://repository.porscheinformatik.com/repository/rubygems-inhouse/'
2
+ source 'https://rubygems.org/'
3
+ gemspec
4
+ gem 'simplecov', require: false, group: :test
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-example.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-example)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
+
7
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
8
+
9
+ ## Documentation
10
+
11
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
62
+ bin/plugin install --no-verify
63
+
64
+ ```
65
+ - Run Logstash with your plugin
66
+ ```sh
67
+ bin/logstash -e 'filter {awesome {}}'
68
+ ```
69
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
70
+
71
+ #### 2.2 Run in an installed Logstash
72
+
73
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
74
+
75
+ - Build your plugin gem
76
+ ```sh
77
+ gem build logstash-filter-awesome.gemspec
78
+ ```
79
+ - Install the plugin from the Logstash home
80
+ ```sh
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
95
+
96
+ It is more important to the community that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,51 @@
1
+ # filter for c2 server out file (but the one with the naming context in the filename -- has date information included!)
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ class LogStash::Filters::CPU_TEMP < LogStash::Filters::Base
6
+
7
+ config_name "cpu_temp"
8
+
9
+ # New plugins should start life at milestone 1.
10
+ milestone 1
11
+
12
+ def register
13
+ # nothing to do
14
+ end # def register
15
+
16
+ def filter(event)
17
+ # return nothing unless there's an actual filter event
18
+ return unless filter?(event)
19
+
20
+ originalmessage = event.get('message')
21
+
22
+ # 12-10-2018 11:26:58 32.968
23
+ # Trying to match the timestamp
24
+ if /^([\d]{2}-[\d]{2}-[\d]{4}\s[\d]{2}:[\d]{2}:[\d]{2})\s([^*]+)$/.match(event.get('message'))
25
+
26
+ begin
27
+ rubytime = Time.strptime($1, "%d-%m-%Y %H:%M:%S")
28
+ logstash_time = LogStash::Timestamp.new(rubytime)
29
+ event.set('@timestamp', logstash_time)
30
+ rescue Exception => e
31
+ event.set('debuginfo', 'Failed to parse date <' + $1 + '>')
32
+ @logger.warn('Failed to parse date <' + $1 + '>; message: ' + e.message + ', stacktrace:' + e.backtrace.inspect)
33
+ end
34
+
35
+ event.set('message', $2)
36
+ # Trying to match the temperature
37
+ if /^([\d]+\.[\d]+)$/.match(event.get('message'))
38
+ event.set('temperature', $1.to_f)
39
+ else
40
+ event.set('debuginfo', "cannot read cpu temperature")
41
+ end
42
+ else
43
+ event.set('debuginfo', "cannot read timestamp, bad format")
44
+ end
45
+
46
+ event.set('message', originalmessage)
47
+
48
+ filter_matched(event)
49
+
50
+ end # def filter
51
+ end # class LogStash::Filters::CPU_TEMP
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-cpu_temp'
3
+ s.version = '1.0.0'
4
+ s.licenses = 'Apache-2.0'
5
+ s.summary = "This example filter replaces the contents of the message field with the specified value."
6
+ s.description = "This gem is a Logstash 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"
7
+ s.authors = "Danel Roelle, Manuel Metzger"
8
+ s.require_paths = ["lib"]
9
+
10
+ # Files
11
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
12
+ # Tests
13
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
14
+
15
+ # Special flag to let us know this is actually a logstash plugin
16
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
17
+
18
+ # Gem dependencies
19
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
20
+ s.add_development_dependency 'logstash-devutils'
21
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/cpu_temp"
4
+
5
+ describe LogStash::Filters::CPU_TEMP do
6
+ subject(:plugin) { LogStash::Filters::CPU_TEMP.new (config) }
7
+ let(:config) { Hash.new }
8
+
9
+ let(:doc) { "" }
10
+ let(:event) { LogStash::Event.new("message" => doc) }
11
+
12
+ before(:each) do
13
+ plugin.register
14
+ end
15
+
16
+ describe "Positive Tests - " do
17
+
18
+ describe "filter one complete message - " do
19
+
20
+ let(:doc) { "12-10-2018 11:27:02 32.999" }
21
+
22
+ it "should extract timestamp and cpu temperature" do
23
+ plugin.filter(event)
24
+ expect(event.get("@timestamp").to_f).to eq(1539343622.0)
25
+ expect(event.get("temperature")).to eq(32.999)
26
+ expect(event.get("message")).to eq("12-10-2018 11:27:02 32.999")
27
+ end
28
+ end
29
+
30
+ describe "filter another complete message - " do
31
+ let(:doc) { "24-12-2018 22:58:42 0.321" }
32
+
33
+ it "should extract timestamp" do
34
+ plugin.filter(event)
35
+ expect(event.get("@timestamp").to_f).to eq(1545692322.0)
36
+ expect(event.get("temperature")).to eq(0.321)
37
+ expect(event.get("message")).to eq("24-12-2018 22:58:42 0.321")
38
+ end
39
+ end
40
+ end # end Positive Tests
41
+
42
+ describe "Negative Tests - " do
43
+
44
+ describe "filter a wrong datetime format - " do
45
+
46
+ let(:doc) { "12-50-2018 11:27:02 32.999" }
47
+
48
+ it "set a debuginfo field" do
49
+ plugin.filter(event)
50
+ expect(event.get("debuginfo")).to eq("Failed to parse date <12-50-2018 11:27:02>")
51
+ expect(event.get("message")).to eq("12-50-2018 11:27:02 32.999")
52
+ end
53
+ end
54
+
55
+ describe "filter a wrong formatted cpu temperature - " do
56
+
57
+ let(:doc) { "12-10-2018 11:27:02 32,999" }
58
+
59
+ it "set a debuginfo field" do
60
+ plugin.filter(event)
61
+ expect(event.get("debuginfo")).to eq("cannot read cpu temperature")
62
+ expect(event.get("message")).to eq("12-10-2018 11:27:02 32,999")
63
+ end
64
+ end
65
+ end # end Negative Tests
66
+
67
+ end # LogStash::Filters::CPU_TEMP
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-cpu_temp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Danel Roelle, Manuel Metzger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-13 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-plugin-api
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'
33
+ name: logstash-devutils
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem is a Logstash 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
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - CONTRIBUTORS
49
+ - DEVELOPER.md
50
+ - Gemfile
51
+ - LICENSE
52
+ - NOTICE.TXT
53
+ - README.md
54
+ - lib/logstash/filters/cpu_temp.rb
55
+ - logstash-filter-cpu_temp.gemspec
56
+ - spec/filters/cpu_temp_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage:
59
+ licenses:
60
+ - Apache-2.0
61
+ metadata:
62
+ logstash_plugin: 'true'
63
+ logstash_group: filter
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.8
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: This example filter replaces the contents of the message field with the specified value.
84
+ test_files:
85
+ - spec/filters/cpu_temp_spec.rb
86
+ - spec/spec_helper.rb