riemann-opensearch 0.0.1

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: 6ad75c8e4d2492c09bf3d837e26f95d7afc4969c840ea981cae193ba047b2a0c
4
+ data.tar.gz: becbc3a64ac8adfc216d614821638bad5c9cdda449f8398a6d7ddd48ba86e3dc
5
+ SHA512:
6
+ metadata.gz: 29d052cff7131832712db0b85493af178c8a4d10b3ee81270da43978747d86811b3a0e687fb8c0099dddf626dcd343f73e1fa37fcc8d6f1cc84cedc33146d4fe
7
+ data.tar.gz: 4763cf0dfb57bbabaacffd8db98c8df6c0ca06e42c160edfdb3c77d0c9f08a70494b760faf6e70d9282d5a1b078346de2c38efd0ea88d707995a74ce62823f38
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at romain@blogreen.org. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in riemann-opensearch.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "standard", "~> 1.3"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Romain Tartière
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # riemann-opensearch
2
+
3
+ Send OpenSearch metrics to Riemann.
4
+
5
+ ## Get started
6
+
7
+ ```
8
+ $ gem install riemann-opensearch
9
+ ```
10
+
11
+ See `riemann-opensearch --help` for options.
12
+
13
+ ## Development
14
+
15
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
16
+
17
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
18
+
19
+ ## Contributing
20
+
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/opus-codium/riemann-opensearch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/riemann-opensearch/blob/main/CODE_OF_CONDUCT.md).
22
+
23
+ ## License
24
+
25
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
26
+
27
+ ## Code of Conduct
28
+
29
+ Everyone interacting in the riemann-opensearch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/opus-codium/riemann-opensearch/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[standard spec]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "riemann/opensearch"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Process.setproctitle($PROGRAM_NAME)
4
+
5
+ require "riemann/tools/opensearch"
6
+
7
+ Riemann::Tools::OpenSearch.run
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "riemann/tools"
4
+ require "opensearch-ruby"
5
+
6
+ module Riemann
7
+ module Tools
8
+ class OpenSearch
9
+ class JsonMapper
10
+ def initialize(values)
11
+ values.each do |k, v|
12
+ components = k.split(".")
13
+ last_component = components.pop
14
+
15
+ s = self
16
+ components.each do |c|
17
+ s = s.send(c)
18
+ end
19
+ s.send(:"#{last_component}=", normalize(v))
20
+ end
21
+ end
22
+
23
+ def normalize(value)
24
+ case value
25
+ when "true" then true
26
+ when "false" then false
27
+ when /\A\d+\z/ then value.to_i
28
+ when /\A\d+\.\d+\z/ then value.to_f
29
+ when /\A\d+\.\d+%\z/ then value.to_f * 0.01
30
+ when "-" then nil
31
+ else value
32
+ end
33
+ end
34
+ end
35
+
36
+ class Allocation < JsonMapper
37
+ class Disk
38
+ attr_accessor :indices, :used, :avail, :total, :percent
39
+ end
40
+
41
+ attr_accessor :shards, :disk, :host, :ip, :node
42
+
43
+ def initialize(values)
44
+ # @disk = Disk.new
45
+ @disk = Struct.new(:indices, :used, :avail, :total, :percent).new
46
+ super
47
+ end
48
+ end
49
+
50
+ class Health < JsonMapper
51
+ class Node
52
+ attr_accessor :total, :data
53
+ end
54
+
55
+ attr_accessor :epoch, :timestamp, :cluster, :status, :node, :discovered_cluster_manager, :shards, :pri, :relo, :init, :unassign, :pending_tasks, :max_task_wait_time, :active_shards_percent
56
+
57
+ def initialize(values)
58
+ @node = Node.new
59
+ super
60
+ end
61
+ end
62
+
63
+ include Riemann::Tools
64
+
65
+ opt :os_host, "OpenSearch cluster to connect to", short: :none, default: "https://admin:admin@localhost:9200"
66
+ opt :os_ca_cert, "Path to CA certificate file", short: :none, type: :string
67
+ opt :os_cert, "Path to certificate file", short: :none, type: :string
68
+ opt :os_key, "Path to key file", short: :none, type: :string
69
+ opt :os_insecure, "Do not check remote host certificate", short: "-k", default: false
70
+
71
+ opt :os_shard_allocation_warning, "Shard allocation warning threshold", short: :none, default: 0.90
72
+ opt :os_shard_allocation_error, "Shard allocation error threshold", short: :none, default: 0.95
73
+
74
+ opt :os_disk_usage_warning, "Disk usage warning threshold", short: :none, default: 0.90
75
+ opt :os_disk_usage_error, "Disk usage error threshold", short: :none, default: 0.95
76
+
77
+ HEALTH_STATUS_STATE = {
78
+ "green" => :ok,
79
+ "yellow" => :warning,
80
+ "red" => :critical
81
+ }
82
+
83
+ def tick
84
+ invalidate_cache
85
+
86
+ @client = ::OpenSearch::Client.new(
87
+ host: opts[:os_host],
88
+ transport_options: {
89
+ ssl: {
90
+ ca_file: opts[:os_ca_cert],
91
+ client_cert: opts[:os_cert],
92
+ client_key: opts[:os_key],
93
+ verify: !opts[:os_insecure]
94
+ }
95
+ }
96
+ )
97
+
98
+ report({
99
+ service: "#{health.cluster} cluster health",
100
+ state: HEALTH_STATUS_STATE[health.status],
101
+ description: health.status
102
+ })
103
+
104
+ max_shards_per_node = setting("cluster.max_shards_per_node")
105
+ allocations.each do |allocation|
106
+ report({
107
+ service: "#{health.cluster} #{allocation.node} shard allocation",
108
+ state: shard_allocation_state(allocation.shards, max_shards_per_node),
109
+ metric: allocation.shards,
110
+ description: "#{allocation.shards}/#{max_shards_per_node}"
111
+ })
112
+
113
+ usage = allocation.disk.used.to_f / allocation.disk.total
114
+ report({
115
+ service: "#{health.cluster} #{allocation.node} disk usage",
116
+ state: disk_usage_state(usage),
117
+ metric: usage,
118
+ description: format("%.3f %%", usage * 100)
119
+ })
120
+ end
121
+ end
122
+
123
+ def allocations
124
+ @allocations ||= @client.cat.allocation(format: "json", bytes: "b").map do |allocation|
125
+ Allocation.new(allocation)
126
+ end
127
+ end
128
+
129
+ def health
130
+ @health ||= @client.cat.health(format: "json").map do |health|
131
+ Health.new(health)
132
+ end.first
133
+ end
134
+
135
+ def settings
136
+ @settings ||= @client.cluster.get_settings(include_defaults: true)
137
+ end
138
+
139
+ def setting(name)
140
+ pieces = name.split(".")
141
+
142
+ value = settings.dig(*(["persistent"] + pieces)) ||
143
+ settings.dig(*(["transient"] + pieces)) ||
144
+ settings.dig(*(["defaults"] + pieces))
145
+
146
+ Integer(value)
147
+ rescue ArgumentError
148
+ value
149
+ end
150
+
151
+ def disk_usage_state(usage)
152
+ if usage >= opts[:os_disk_usage_error]
153
+ :critical
154
+ elsif usage >= opts[:os_disk_usage_warning]
155
+ :warning
156
+ else
157
+ :ok
158
+ end
159
+ end
160
+
161
+ def shard_allocation_state(count, limit)
162
+ if count >= opts[:os_shard_allocation_error] * limit
163
+ :critical
164
+ elsif count >= opts[:os_shard_allocation_warning] * limit
165
+ :warning
166
+ else
167
+ :ok
168
+ end
169
+ end
170
+
171
+ private
172
+
173
+ def invalidate_cache
174
+ @allocations = nil
175
+ @health = nil
176
+ @settings = nil
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "riemann-opensearch"
5
+ spec.version = "0.0.1"
6
+ spec.authors = ["Romain Tartière"]
7
+ spec.email = ["romain@blogreen.org"]
8
+
9
+ spec.summary = "Send OpenSearch metrics to Riemann"
10
+ spec.homepage = "https://github.com/opus-codium/riemann-opensearch"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 2.7.0"
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = spec.homepage
19
+
20
+ spec.metadata["rubygems_mfa_required"] = "true"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables =
29
+ spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "faraday-net_http_persistent"
33
+ spec.add_dependency "opensearch-ruby", "~> 3.0"
34
+ spec.add_dependency "riemann-tools", "~> 1.0"
35
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-opensearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Romain Tartière
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday-net_http_persistent
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opensearch-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: riemann-tools
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description:
56
+ email:
57
+ - romain@blogreen.org
58
+ executables:
59
+ - riemann-opensearch
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - exe/riemann-opensearch
73
+ - lib/riemann/tools/opensearch.rb
74
+ - riemann-opensearch.gemspec
75
+ homepage: https://github.com/opus-codium/riemann-opensearch
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org/
80
+ homepage_uri: https://github.com/opus-codium/riemann-opensearch
81
+ source_code_uri: https://github.com/opus-codium/riemann-opensearch
82
+ changelog_uri: https://github.com/opus-codium/riemann-opensearch
83
+ rubygems_mfa_required: 'true'
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.7.0
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.3.15
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Send OpenSearch metrics to Riemann
103
+ test_files: []