riemann-client 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d87901a4f9a48ce3fcae0940d204c36cdabd949d4495b99f2445735fb2deddd8
4
- data.tar.gz: d64e574731d1a1dce475fb2227eaf2fdd4f3bf581bd20bae33fb92a22321adb2
3
+ metadata.gz: 33657c1dcec6dce903bd90154f17f3a31174b6e0fa146609941dc36960c2b6e2
4
+ data.tar.gz: 372a73585a2046e5af3a16ddd84254af64e6f6d17c6911183cf6c408eb22ac07
5
5
  SHA512:
6
- metadata.gz: b75e2bd1256a168dc185ceaf53c80f045e2011fa1fa2e2717147e48c35d65b767df60182884a154575e09598b4305cda0e9cc16c0f5a2d3e0ab3218fc6d4380f
7
- data.tar.gz: 1b5d7a51402e65c7994b91bd903f2dae9881390ee890058a881311c3bb57bfb12139065c1a0d466c76f2438677789ad8f3347351e26d1005f704f673f8c06025
6
+ metadata.gz: 694404b98fe75bb304f8d8da0903eb128d2600ecd83bc3b6c3d4e2b41eef2695a82e6df00c0f9c3a59115837e58314e6cdb88d56c1b10c959bd912d69ace479c
7
+ data.tar.gz: 874fdd45638f808e1bf9641616fe5342c01c3a51245f9d66542a9aec60751a093462e70c123e027a463dcedfcb608dfc98087ae4ad189fd02aa97210b8e90fdd
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
@@ -10,16 +10,30 @@ on:
10
10
  - main
11
11
 
12
12
  jobs:
13
+ lint:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Setup ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: '2.7'
21
+ bundler-cache: true
22
+ - name: Run rubocop
23
+ run: bundle exec rubocop
13
24
  test:
25
+ needs: lint
14
26
  runs-on: ubuntu-latest
15
27
  strategy:
16
28
  matrix:
17
29
  ruby-version:
18
- - 2.7
19
- - 3.0
20
- - 3.1
30
+ - '2.6'
31
+ - '2.7'
32
+ - '3.0'
33
+ - '3.1'
34
+ - '3.2'
21
35
  steps:
22
- - uses: actions/checkout@v2
36
+ - uses: actions/checkout@v3
23
37
  - name: Setup Ruby
24
38
  uses: ruby/setup-ruby@v1
25
39
  with:
@@ -42,4 +56,4 @@ jobs:
42
56
 
43
57
  while ! nc -z localhost 5555; do sleep 1; done
44
58
  - name: Run the test suite
45
- run: bundle exec bacon spec/*.rb
59
+ run: bundle exec rspec
@@ -0,0 +1,72 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ "main" ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ "main" ]
20
+ schedule:
21
+ - cron: '33 17 * * 6'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v3
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v2
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+
52
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53
+ # queries: security-extended,security-and-quality
54
+
55
+
56
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57
+ # If this step fails, then you should remove it and run the build manually (see below)
58
+ - name: Autobuild
59
+ uses: github/codeql-action/autobuild@v2
60
+
61
+ # ℹ️ Command-line programs to run using the OS shell.
62
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63
+
64
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
65
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66
+
67
+ # - run: |
68
+ # echo "Run, Build Application using script"
69
+ # ./location_of_script_within_repo/buildscript.sh
70
+
71
+ - name: Perform CodeQL Analysis
72
+ uses: github/codeql-action/analyze@v2
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format doc
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ ---
2
+ require:
3
+ - rubocop-rspec
4
+ Metrics/AbcSize:
5
+ Enabled: false
6
+ Metrics/BlockLength:
7
+ Enabled: false
8
+ Metrics/ClassLength:
9
+ Enabled: false
10
+ Metrics/CyclomaticComplexity:
11
+ Enabled: false
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+ Metrics/PerceivedComplexity:
15
+ Enabled: false
16
+ Naming/VariableNumber:
17
+ AllowedIdentifiers:
18
+ - TLSv1_2
19
+ Style/Documentation:
20
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,8 +1,34 @@
1
1
  # Changelog
2
2
 
3
- ## [1.0.0](https://github.com/riemann/riemann-ruby-client/tree/1.0.0) (2022-06-16)
3
+ ## [v1.1.0](https://github.com/riemann/riemann-ruby-client/tree/v1.1.0) (2023-01-23)
4
4
 
5
- [Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/0.2.6...1.0.0)
5
+ [Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/v1.0.1...v1.1.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Add support for sending events in bulk [\#44](https://github.com/riemann/riemann-ruby-client/pull/44) ([smortex](https://github.com/smortex))
10
+
11
+ **Fixed bugs:**
12
+
13
+ - Fix UDP fallback to TCP on large messages [\#46](https://github.com/riemann/riemann-ruby-client/pull/46) ([smortex](https://github.com/smortex))
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Modernize unit tests [\#45](https://github.com/riemann/riemann-ruby-client/pull/45) ([smortex](https://github.com/smortex))
18
+ - Switch from Bacon to RSpec [\#43](https://github.com/riemann/riemann-ruby-client/pull/43) ([smortex](https://github.com/smortex))
19
+ - Create codeql-analysis.yml [\#40](https://github.com/riemann/riemann-ruby-client/pull/40) ([jamtur01](https://github.com/jamtur01))
20
+
21
+ ## [v1.0.1](https://github.com/riemann/riemann-ruby-client/tree/v1.0.1) (2022-06-25)
22
+
23
+ [Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/v1.0.0...v1.0.1)
24
+
25
+ **Merged pull requests:**
26
+
27
+ - Setup Rubocop and lower required Ruby version [\#37](https://github.com/riemann/riemann-ruby-client/pull/37) ([smortex](https://github.com/smortex))
28
+
29
+ ## [v1.0.0](https://github.com/riemann/riemann-ruby-client/tree/v1.0.0) (2022-06-16)
30
+
31
+ [Full Changelog](https://github.com/riemann/riemann-ruby-client/compare/0.2.6...v1.0.0)
6
32
 
7
33
  **Implemented enhancements:**
8
34
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/README.markdown CHANGED
@@ -1,12 +1,16 @@
1
- Installing
2
- ==========
1
+ # Riemann Ruby Client
3
2
 
4
- gem install riemann-client
3
+ [![CI](https://github.com/riemann/riemann-ruby-client/actions/workflows/ci.yml/badge.svg)](https://github.com/riemann/riemann-ruby-client/actions/workflows/ci.yml)
5
4
 
6
- Use
7
- ===
5
+ ## Installing
8
6
 
9
- ``` ruby
7
+ ```shell
8
+ gem install riemann-client
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```ruby
10
14
  require 'riemann/client'
11
15
 
12
16
  # Create a client. Host, port and timeout are optional.
@@ -38,8 +42,8 @@ c['host =~ "%.dc1" and (state = "critical" or state = "warning")']
38
42
 
39
43
  ```
40
44
 
41
- Transports
42
- ==========
45
+ ## Transports
46
+
43
47
 
44
48
  Riemann::Client sends small events over UDP by default, and uses TCP for
45
49
  queries and large events. UDP sends are essentially "shouting into the void".
@@ -54,8 +58,7 @@ c.tcp["true"] # => [#<Event ... >, ...]
54
58
  c.udp["true"] # => raise Riemann::Client::Unsupported
55
59
  ```
56
60
 
57
- Client state management
58
- =======================
61
+ ## Client state management
59
62
 
60
63
  Riemann::Client provides some classes to make managing state updates easier.
61
64
 
@@ -64,3 +67,9 @@ be used to flush an accumulated value to ustate at regular intervals.
64
67
 
65
68
  Riemann::AutoState bundles a state and a client together. Any changes to the
66
69
  AutoState automatically send the new state to the client.
70
+
71
+ ## License
72
+
73
+ The MIT License
74
+
75
+ Copyright (c) 2011-2022 Kyle Kingsbury
data/Rakefile CHANGED
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'riemann'
2
4
 
3
- require "bundler/gem_tasks"
5
+ require 'bundler/gem_tasks'
4
6
 
5
7
  require 'github_changelog_generator/task'
6
8
 
7
9
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
8
10
  config.user = 'riemann'
9
11
  config.project = 'riemann-ruby-client'
10
- config.future_release = Riemann::VERSION
12
+ config.exclude_labels = ['skip-changelog']
13
+ config.future_release = "v#{Riemann::VERSION}"
11
14
  config.add_issues_wo_labels = false
12
15
  end
data/SECURITY.md ADDED
@@ -0,0 +1,42 @@
1
+ # Riemann Security and Disclosure Information
2
+ This page describes Riemann security and disclosure information.
3
+
4
+ ## Supported Versions
5
+
6
+ The currently supported version of Riemann for security-patching purposes is always the latest version.
7
+
8
+ ## Security Announcements
9
+
10
+ Will be made on the [Riemann mailing list](https://groups.google.com/g/riemann-users?pli=1).
11
+
12
+ ## Report a Vulnerability
13
+
14
+ We're extremely grateful for security researchers and users that report vulnerabilities to Riemann. All reports are thoroughly investigated by the maintainers.
15
+
16
+ To make a report, you should email the private security@riemann.io list with the details.
17
+
18
+ ## When Should I Report a Vulnerability?
19
+
20
+ * You think you discovered a potential security vulnerability in Riemann.
21
+ * You are unsure how a vulnerability affects Riemann.
22
+ * You think you discovered a vulnerability in another project that Riemann depends on
23
+
24
+ For projects with their own vulnerability reporting and disclosure process, please report it directly there.
25
+
26
+ ## When Should I NOT Report a Vulnerability?
27
+
28
+ * You need help tuning Riemann components for security
29
+ * You need help applying security related updates
30
+ * Your issue is not security related
31
+
32
+ ## Security Vulnerability Response
33
+
34
+ Each report is acknowledged and analyzed within 5 working days.
35
+
36
+ Any vulnerability information shared stays within Riemann project and will not be disseminated to other projects unless it is necessary to get the issue fixed.
37
+
38
+ As the security issue moves from triage, to identified fix, to release planning we will keep the reporter updated.
39
+
40
+ ## Public Disclosure Timing
41
+
42
+ A public disclosure date is negotiated by the Riemann maintainers nd the bug submitter. We prefer to fully disclose the bug as soon as possible once a user mitigation is available. It is reasonable to delay disclosure when the bug or the fix is not yet fully understood, the solution is not well-tested, or for vendor coordination. The timeframe for disclosure is from immediate (especially if it's already publicly known) to a few weeks. For a vulnerability with a straightforward mitigation, we expect report date to disclosure date to be on the order of 7 days. The Riemann maintainers hold the final say when setting a disclosure date.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Riemann
2
4
  class Attribute
3
5
  include Beefcake::Message
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Riemann
2
4
  class AutoState
3
5
  # Binds together a state hash and a Client. Any change made here
@@ -40,7 +42,7 @@ module Riemann
40
42
  # @state.state = 'heavy lifting b'
41
43
  # ...
42
44
  # end
43
-
45
+
44
46
  def initialize(client = Client.new, state = {})
45
47
  @client = client
46
48
  @state = state
@@ -95,7 +97,11 @@ module Riemann
95
97
  def once(opts)
96
98
  o = @state.merge opts
97
99
  o[:time] = Time.now.to_i
98
- o[:tags] = ((o[:tags] | ["once"]) rescue ["once"])
100
+ o[:tags] = begin
101
+ (o[:tags] | ['once'])
102
+ rescue StandardError
103
+ ['once']
104
+ end
99
105
  @client << o
100
106
  end
101
107
 
@@ -111,7 +117,7 @@ module Riemann
111
117
  def service=(service)
112
118
  @state[:service] = service
113
119
  flush
114
- end
120
+ end
115
121
 
116
122
  def service
117
123
  @state[:service]
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
  require_relative 'tcp_socket'
3
5
 
4
6
  module Riemann
5
7
  class Client
6
- # Socket: A specialized socket that has been configure
8
+ # Socket: A specialized socket that has been configure
7
9
  class SSLSocket < TcpSocket
8
-
9
10
  def initialize(options = {})
10
11
  super(options)
11
12
  @key_file = options[:key_file]
@@ -16,11 +17,11 @@ module Riemann
16
17
 
17
18
  def ssl_context
18
19
  @ssl_context ||= OpenSSL::SSL::SSLContext.new.tap do |ctx|
19
- ctx.key = OpenSSL::PKey::RSA.new(open(@key_file) {|f| f.read})
20
- ctx.cert = OpenSSL::X509::Certificate.new(open(@cert_file) {|f| f.read})
21
- ctx.ca_file = @ca_file if @ca_file
22
- ctx.ssl_version = :TLSv1_2
23
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER if @ssl_verify
20
+ ctx.key = OpenSSL::PKey::RSA.new(File.read(@key_file))
21
+ ctx.cert = OpenSSL::X509::Certificate.new(File.read(@cert_file))
22
+ ctx.ca_file = @ca_file if @ca_file
23
+ ctx.ssl_version = :TLSv1_2
24
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER if @ssl_verify
24
25
  end
25
26
  end
26
27
 
@@ -30,7 +31,7 @@ module Riemann
30
31
  #
31
32
  # Return the ::Socket when it is connected, or raise an Error if no
32
33
  # connection was possible.
33
- def connect_nonblock( addr, timeout )
34
+ def connect_nonblock(addr, timeout)
34
35
  sock = super(addr, timeout)
35
36
  ssl_socket = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
36
37
  ssl_socket.sync = true
@@ -38,17 +39,17 @@ module Riemann
38
39
  begin
39
40
  ssl_socket.connect_nonblock
40
41
  rescue IO::WaitReadable
41
- if IO.select([ssl_socket], nil, nil, timeout)
42
- retry
43
- else
42
+ unless IO.select([ssl_socket], nil, nil, timeout)
44
43
  raise Timeout, "Could not read from #{host}:#{port} in #{timeout} seconds"
45
44
  end
45
+
46
+ retry
46
47
  rescue IO::WaitWritable
47
- if IO.select(nil, [ssl_socket], nil, timeout)
48
- retry
49
- else
48
+ unless IO.select(nil, [ssl_socket], nil, timeout)
50
49
  raise Timeout, "Could not write to #{host}:#{port} in #{timeout} seconds"
51
50
  end
51
+
52
+ retry
52
53
  end
53
54
  ssl_socket
54
55
  end
@@ -60,13 +61,13 @@ module Riemann
60
61
  #
61
62
  # Returns the bytes read
62
63
  def readpartial(maxlen, outbuf = nil)
63
- return super(maxlen, outbuf)
64
+ super(maxlen, outbuf)
64
65
  rescue OpenSSL::SSL::SSLErrorWaitReadable
65
- if wait_readable(read_timeout)
66
- retry
67
- else
66
+ unless wait_readable(read_timeout)
68
67
  raise Timeout, "Could not read from #{host}:#{port} in #{read_timeout} seconds"
69
68
  end
69
+
70
+ retry
70
71
  end
71
72
 
72
73
  # Internal: Write the given data to the socket
@@ -80,11 +81,11 @@ module Riemann
80
81
  def write(buf)
81
82
  super(buf)
82
83
  rescue OpenSSL::SSL::SSLErrorWaitWritable
83
- if wait_writable(write_timeout)
84
- retry
85
- else
84
+ unless wait_writable(write_timeout)
86
85
  raise Timeout, "Could not write to #{host}:#{port} in #{write_timeout} seconds"
87
86
  end
87
+
88
+ retry
88
89
  end
89
90
  end
90
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'monitor'
2
4
  require 'riemann/client/tcp_socket'
3
5
  require 'riemann/client/ssl_socket'
@@ -5,12 +7,12 @@ require 'riemann/client/ssl_socket'
5
7
  module Riemann
6
8
  class Client
7
9
  class TCP < Client
8
- attr_accessor :host, :port, :socket
10
+ attr_accessor :host, :port
9
11
 
10
12
  # Public: Set a socket factory -- an object responding
11
13
  # to #call(options) that returns a Socket object
12
- def self.socket_factory=(factory)
13
- @socket_factory = factory
14
+ class << self
15
+ attr_writer :socket_factory
14
16
  end
15
17
 
16
18
  # Public: Return a socket factory
@@ -24,16 +26,14 @@ module Riemann
24
26
  }
25
27
  end
26
28
 
27
- def initialize(options = {})
29
+ def initialize(options = {}) # rubocop:disable Lint/MissingSuper
28
30
  @options = options
29
31
  @locket = Monitor.new
30
32
  end
31
33
 
32
34
  def socket
33
35
  @locket.synchronize do
34
- if @pid && @pid != Process.pid
35
- close
36
- end
36
+ close if @pid && @pid != Process.pid
37
37
 
38
38
  return @socket if connected?
39
39
 
@@ -58,32 +58,32 @@ module Riemann
58
58
  end
59
59
 
60
60
  # Read a message from a stream
61
- def read_message(s)
62
- if buffer = s.read(4) and buffer.size == 4
63
- length = buffer.unpack('N').first
64
- begin
65
- str = s.read length
66
- message = Riemann::Message.decode str
67
- rescue => e
68
- puts "Message was #{str.inspect}"
69
- raise
70
- end
61
+ def read_message(socket)
62
+ unless (buffer = socket.read(4)) && (buffer.size == 4)
63
+ raise InvalidResponse, 'unexpected EOF'
64
+ end
71
65
 
72
- unless message.ok
73
- puts "Failed"
74
- raise ServerError, message.error
75
- end
66
+ length = buffer.unpack1('N')
67
+ begin
68
+ str = socket.read length
69
+ message = Riemann::Message.decode str
70
+ rescue StandardError
71
+ puts "Message was #{str.inspect}"
72
+ raise
73
+ end
76
74
 
77
- message
78
- else
79
- raise InvalidResponse, "unexpected EOF"
75
+ unless message.ok
76
+ puts 'Failed'
77
+ raise ServerError, message.error
80
78
  end
79
+
80
+ message
81
81
  end
82
82
 
83
83
  def send_recv(message)
84
- with_connection do |s|
85
- s.write(message.encode_with_length)
86
- read_message(s)
84
+ with_connection do |socket|
85
+ socket.write(message.encode_with_length)
86
+ read_message(socket)
87
87
  end
88
88
  end
89
89
 
@@ -94,17 +94,17 @@ module Riemann
94
94
  tries = 0
95
95
 
96
96
  @locket.synchronize do
97
- begin
98
- tries += 1
99
- yield(socket)
100
- rescue IOError, Errno::EPIPE, Errno::ECONNREFUSED, InvalidResponse, Timeout::Error, Riemann::Client::TcpSocket::Error
101
- close
102
- raise if tries > 3
103
- retry
104
- rescue Exception
105
- close
106
- raise
107
- end
97
+ tries += 1
98
+ yield(socket)
99
+ rescue IOError, Errno::EPIPE, Errno::ECONNREFUSED, InvalidResponse, Timeout::Error,
100
+ Riemann::Client::TcpSocket::Error
101
+ close
102
+ raise if tries > 3
103
+
104
+ retry
105
+ rescue StandardError
106
+ close
107
+ raise
108
108
  end
109
109
  end
110
110
  end