fluent-plugin-process-snmptrap 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c63e0495e12f75e27b6ef4f8fcc487bd829d81f20d482ddc05c0886d4478c07d
4
+ data.tar.gz: bef2af01ad3967da1b4040d6dc6551a142f5c24ee29596656d8310c581e38b88
5
+ SHA512:
6
+ metadata.gz: dd277475c190a92f1ed1c62076a80f52d0081c6ef3a1b5fc0da2efa0ae2fe5567b0107381906a4a9136569861398cbc62e2ebce0142467b5fa20d0b5d692752e
7
+ data.tar.gz: fdf13a578c7db0592cdd8aebb10a276fbce895d0ef918c6076c6a83cc0dd467a7e5494928ae3bfd112c3f661495dfe10bbda5186e930e124db1d2e7a319bed37
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
22
+
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Contributing
2
+
3
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
4
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5
+ the rights to use your contribution. For details, visit https://cla.microsoft.com.
6
+
7
+ When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
8
+ a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
9
+ provided by the bot. You will only need to do this once across all repos using our CLA.
10
+
11
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
14
+
15
+ # fluent-plugin-process-snmptrap
16
+
17
+ [Fluentd](https://fluentd.org/) filter plugin to do something.
18
+
19
+ This is a filter plugin for SNMP V2 traps. The plugin check the SNMP messages and maps the OID and associated values in SNMP Traps.
20
+ It adds machineID, event, SNMP Trap type, host, status of machine, severity, device and message to events received. It detects the
21
+ SNMP Traps based on the format <OID>:<Value>
22
+ The OID is of the format /SNMPv2-(\w+)(::)(\w+)((\.)(\d+)){1,13}/
23
+
24
+ Machin ID format
25
+ HPE:<Coloregion>:<ChassisSerialNo>
26
+
27
+ Events detected:
28
+ Power ON
29
+ Power OFF
30
+
31
+ ## Configuration
32
+
33
+ You can generate configuration template:
34
+
35
+ ```
36
+ $ fluent-plugin-config-format filter process_snmptrap
37
+ ```
38
+
39
+ <filter SNMPTrap.Alert>
40
+ @type process_snmptrap
41
+ HPEHostName ServerHostName
42
+ coloregion <colo region>
43
+ domain <domain>
44
+ </filter>
45
+
46
+
47
+
48
+ ## Copyright
49
+
50
+ * Copyright(c) 2018- aj-rame3/Microsoft
51
+
52
+ ## Trademarks
53
+
54
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs.push("lib", "test")
8
+ t.test_files = FileList["test/**/test_*.rb"]
9
+ t.verbose = true
10
+ t.warning = true
11
+ end
12
+
13
+ task default: [:test]
data/SECURITY.md ADDED
@@ -0,0 +1,41 @@
1
+ <!-- BEGIN MICROSOFT SECURITY.MD V0.0.3 BLOCK -->
2
+
3
+ ## Security
4
+
5
+ Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6
+
7
+ If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
8
+
9
+ ## Reporting Security Issues
10
+
11
+ **Please do not report security vulnerabilities through public GitHub issues.**
12
+
13
+ Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
14
+
15
+ If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
16
+
17
+ You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18
+
19
+ Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20
+
21
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22
+ * Full paths of source file(s) related to the manifestation of the issue
23
+ * The location of the affected source code (tag/branch/commit or direct URL)
24
+ * Any special configuration required to reproduce the issue
25
+ * Step-by-step instructions to reproduce the issue
26
+ * Proof-of-concept or exploit code (if possible)
27
+ * Impact of the issue, including how an attacker might exploit the issue
28
+
29
+ This information will help us triage your report more quickly.
30
+
31
+ If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
32
+
33
+ ## Preferred Languages
34
+
35
+ We prefer all communications to be in English.
36
+
37
+ ## Policy
38
+
39
+ Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
40
+
41
+ <!-- END MICROSOFT SECURITY.MD BLOCK -->
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-process-snmptrap"
6
+ spec.version = "0.1.0"
7
+ spec.authors = ["Gabe de la Mora", "Pratik Karia"]
8
+ spec.email = ["gadelamo@microsoft.com", "pratikkaria@microsoft.com"]
9
+
10
+ spec.description = "A filter plugin which appends various fields to SNMP Traps received from HPE Servers"
11
+ spec.summary = spec.description
12
+ spec.name = "fluent-plugin-process-snmptrap"
13
+ spec.homepage = "https://github.com/Azure/fluent-plugin-process-snmptrap"
14
+ spec.license = "MIT"
15
+
16
+ test_files, files = `git ls-files -z`.split("\x0").partition do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.files = `git ls-files`.split("\n")
20
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ spec.test_files = test_files
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", ">= 2.2.10"
25
+ spec.add_development_dependency "rake", "~> 12.0"
26
+ spec.add_development_dependency "test-unit", "~> 3.0"
27
+ spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
28
+ end
@@ -0,0 +1,40 @@
1
+ require 'fluent/plugin/filter'
2
+ require 'json'
3
+
4
+ module Fluent
5
+ class ProcessSnmptrap < Filter
6
+ Fluent::Plugin.register_filter('process_snmptrap', self)
7
+
8
+ # config_param
9
+ config_param :coloregion, :string
10
+ # A set of character subsitution for cases in which they are invalid on the collector side.
11
+ config_param :invalidChars, :hash, default: {'.'=>'_'}
12
+
13
+ def configure(conf)
14
+ super
15
+ end
16
+
17
+ def start
18
+ super
19
+ end
20
+
21
+ def filter(tag, time, record)
22
+
23
+ # Replace invalid characters
24
+ fixedRecord = Hash.new
25
+ record.each { |recKey, recValue|
26
+ newKey = recKey
27
+ invalidChars.each { |invalidKey, subChar|
28
+ newKey = newKey.gsub(invalidKey, subChar)
29
+ }
30
+ record.delete(recKey)
31
+ fixedRecord[newKey] = recValue
32
+ }
33
+ record.replace(fixedRecord)
34
+
35
+ return record
36
+ end
37
+
38
+
39
+ end
40
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
+ require "test-unit"
3
+ require "fluent/test"
4
+ require "fluent/test/driver/filter"
5
+ require "fluent/test/helpers"
6
+
7
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
+ Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -0,0 +1,64 @@
1
+ require "fluent/test"
2
+ require "fluent/test/driver/filter"
3
+ require "fluent/test/helpers"
4
+ require "fluent/plugin/filter_process_snmptrap.rb"
5
+
6
+ class ProcessSnmptrapFilterTest < Test::Unit::TestCase
7
+ include Fluent::Test::Helpers
8
+
9
+ setup do
10
+ Fluent::Test.setup
11
+ end
12
+
13
+ CONFIG = %[
14
+ @type process_snmptrap
15
+ coloregion testcolo
16
+ invalidChars {".":"_", "-":"_", "::":"_"}
17
+ ]
18
+
19
+
20
+ def create_driver(conf)
21
+ Fluent::Test::Driver::Filter.new(Fluent::ProcessSnmptrap).configure(conf)
22
+ end
23
+
24
+ def test_configure
25
+ d = create_driver(CONFIG)
26
+ assert_equal 'testcolo', d.instance.coloregion
27
+ end
28
+
29
+ def filter(records, conf = CONFIG)
30
+ d = create_driver(conf)
31
+ d.run(default_tag: "TestTrap") do
32
+ records.each do |record|
33
+ d.feed(record)
34
+ end
35
+ end
36
+ d.filtered_records
37
+ end
38
+
39
+
40
+ def test_snmptrap_filter
41
+ records = [
42
+ {
43
+ "SNMPv2-MIB::sysUpTime.0"=>"179 days,13:26:54.66",
44
+ "SNMPv2-MIB::snmpTrapOID.0"=>"SGI-UV300::chassisSensor",
45
+ "SGI-UV300::ssnName"=>"UV300-00000547",
46
+ "SGI-UV300::chassisName"=>"r001i24b",
47
+ "SGI-UV300::chassisSensorName"=>"PSU2_COMP_TEMP1",
48
+ "SGI-UV300::chassisSensorValue"=>"10.3289",
49
+ "SGI-UV300::chassisSensorStatus"=>"1",
50
+ "host"=>"172.17.0.2"
51
+ }
52
+ ]
53
+ filtered_records = filter(records)
54
+ assert_equal(records[0].length, filtered_records[0].length, "Incorrect record size")
55
+ assert_equal(records[0]["host"], filtered_records[0]["host"], "Non MIB value was modified")
56
+ # Values should remain unmodified.
57
+ records.each { |recKey, recValue|
58
+ fixedKey = recKey.to_s.gsub("-","_").gsub(".","_").gsub("::","_")
59
+ assert_equal(records[0][recKey], filtered_records[0][fixedKey], "Value has been modified")
60
+ }
61
+ end
62
+
63
+ end
64
+
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-process-snmptrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabe de la Mora
8
+ - Pratik Karia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2023-10-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 2.2.10
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.2.10
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '12.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '12.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: test-unit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: fluentd
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.14.10
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: '2'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.14.10
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: '2'
76
+ description: A filter plugin which appends various fields to SNMP Traps received from
77
+ HPE Servers
78
+ email:
79
+ - gadelamo@microsoft.com
80
+ - pratikkaria@microsoft.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - ".gitignore"
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - SECURITY.md
91
+ - fluent-plugin-process-snmptrap.gemspec
92
+ - lib/fluent/plugin/filter_process_snmptrap.rb
93
+ - test/helper.rb
94
+ - test/plugin/test_filter_process_snmptrap.rb
95
+ homepage: https://github.com/Azure/fluent-plugin-process-snmptrap
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.3.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A filter plugin which appends various fields to SNMP Traps received from
118
+ HPE Servers
119
+ test_files:
120
+ - test/helper.rb
121
+ - test/plugin/test_filter_process_snmptrap.rb