riemann-nut 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +42 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.rubocop.yml +30 -0
- data/Gemfile +6 -0
- data/README.md +29 -0
- data/Rakefile +14 -0
- data/bin/riemann-nut +8 -0
- data/lib/riemann/tools/nut/version.rb +9 -0
- data/lib/riemann/tools/nut.rb +175 -0
- data/riemann-nut.gemspec +39 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f61ed52eeeb5f1be97e103f3637e2b7a176badd16efbde71431ae3bfce608338
|
4
|
+
data.tar.gz: eb1e03ef41684f4e651c65fe5c66582e6969c72de0d54ede0642968e406b035e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4457b8cbd057b69f8f78e760b33843f24804d670ed499afac16ffe6ca21fa465f8c092031b0ffa8ab78ebe024c057e04dee44e9e395fc5607cbc7d411728fc0
|
7
|
+
data.tar.gz: da71e8f350b87e68722f224f20323f102ea1ca668dbd1f6a1e263cb1748ade1096647edcd6e8d96497aedc4d50aa7a3f0411c5609f0938a3c6769ff44b35b72c
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
name: CI
|
3
|
+
|
4
|
+
on:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- main
|
8
|
+
pull_request:
|
9
|
+
branches:
|
10
|
+
- main
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
lint:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
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
|
24
|
+
test:
|
25
|
+
needs: lint
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
strategy:
|
28
|
+
matrix:
|
29
|
+
ruby-version:
|
30
|
+
- 2.6
|
31
|
+
- 2.7
|
32
|
+
- 3.0
|
33
|
+
- 3.1
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v2
|
36
|
+
- name: Setup Ruby
|
37
|
+
uses: ruby/setup-ruby@v1
|
38
|
+
with:
|
39
|
+
ruby-version: ${{ matrix.ruby-version }}
|
40
|
+
bundler-cache: true
|
41
|
+
- name: Run the test suite
|
42
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
Exclude:
|
4
|
+
- vendor/bundle/**/*
|
5
|
+
Layout/HashAlignment:
|
6
|
+
EnforcedHashRocketStyle: table
|
7
|
+
Layout/LineLength:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/AbcSize:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Enabled: false
|
13
|
+
Metrics/ClassLength:
|
14
|
+
Enabled: false
|
15
|
+
Metrics/CyclomaticComplexity:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Enabled: false
|
19
|
+
Metrics/ParameterLists:
|
20
|
+
Enabled: false
|
21
|
+
Metrics/PerceivedComplexity:
|
22
|
+
Enabled: false
|
23
|
+
Style/Documentation:
|
24
|
+
Enabled: false
|
25
|
+
Style/TrailingCommaInArguments:
|
26
|
+
EnforcedStyleForMultiline: consistent_comma
|
27
|
+
Style/TrailingCommaInArrayLiteral:
|
28
|
+
EnforcedStyleForMultiline: consistent_comma
|
29
|
+
Style/TrailingCommaInHashLiteral:
|
30
|
+
EnforcedStyleForMultiline: consistent_comma
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# riemann-nut
|
2
|
+
|
3
|
+
Submits nut information to riemann.
|
4
|
+
|
5
|
+
## Get started
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install riemann-nut
|
9
|
+
riemann-nut --ups upsa@192.168.0.5 upsb@192.168.0.5 upsc@192.168.0.6
|
10
|
+
```
|
11
|
+
|
12
|
+
## Example metrics
|
13
|
+
|
14
|
+
Syntax: `<service>: <metric> (<state>)\n<description>\n`
|
15
|
+
|
16
|
+
```
|
17
|
+
ups@192.168.100.1 battery charge: 100 (ok)
|
18
|
+
100 %
|
19
|
+
ups@192.168.100.1 battery voltage: 13.5 (ok)
|
20
|
+
13.5 V
|
21
|
+
ups@192.168.100.1 input voltage: 232.0 (ok)
|
22
|
+
232.0 V
|
23
|
+
ups@192.168.100.1 ups alarm: (critical)
|
24
|
+
Replace battery! No battery installed!
|
25
|
+
ups@192.168.100.1 ups load: 13 (ok)
|
26
|
+
13 W
|
27
|
+
ups@192.168.100.1 ups status: (critical)
|
28
|
+
ALARM OL RB
|
29
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools/nut/version'
|
4
|
+
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
|
7
|
+
require 'github_changelog_generator/task'
|
8
|
+
|
9
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
10
|
+
config.user = 'opus-codium'
|
11
|
+
config.project = 'riemann-nut'
|
12
|
+
config.exclude_labels = ['skip-changelog']
|
13
|
+
config.future_release = Riemann::Tools::Nut::VERSION
|
14
|
+
end
|
data/bin/riemann-nut
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
|
5
|
+
require 'open3'
|
6
|
+
|
7
|
+
module Riemann
|
8
|
+
module Tools
|
9
|
+
class Nut
|
10
|
+
include Riemann::Tools
|
11
|
+
|
12
|
+
opt :ups, 'UPS to connect to', type: :strings, default: ['ups@localhost']
|
13
|
+
opt :load_warning, 'Load warning threshold', default: 0.0
|
14
|
+
opt :load_critical, 'Load critical threshold', default: 0.0
|
15
|
+
|
16
|
+
def tick
|
17
|
+
invalidate_cache
|
18
|
+
|
19
|
+
report_battery_charge
|
20
|
+
report_battery_voltage
|
21
|
+
report_input_voltage
|
22
|
+
report_ups_alarm
|
23
|
+
report_ups_load
|
24
|
+
report_ups_status
|
25
|
+
end
|
26
|
+
|
27
|
+
def invalidate_cache
|
28
|
+
@cached_data = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def upsc
|
32
|
+
return @cached_data[:upsc] if @cached_data[:upsc]
|
33
|
+
|
34
|
+
@cached_data[:upsc] = {}
|
35
|
+
|
36
|
+
opts[:ups].each do |ups|
|
37
|
+
output, _status = Open3.capture2('upsc', ups)
|
38
|
+
|
39
|
+
data = {}
|
40
|
+
output.lines.each do |line|
|
41
|
+
next unless line.chomp =~ /\A([^:]+): (.*)\z/
|
42
|
+
|
43
|
+
key = Regexp.last_match[1]
|
44
|
+
value = Regexp.last_match[2].strip
|
45
|
+
|
46
|
+
data[key] = value
|
47
|
+
end
|
48
|
+
|
49
|
+
@cached_data[:upsc][ups] = data
|
50
|
+
rescue Errno::ENOENT
|
51
|
+
@cached_data[:upsc][ups] = {}
|
52
|
+
end
|
53
|
+
|
54
|
+
@cached_data[:upsc]
|
55
|
+
end
|
56
|
+
|
57
|
+
def report_battery_charge
|
58
|
+
opts[:ups].each do |ups|
|
59
|
+
service = "#{ups} battery charge"
|
60
|
+
battery_charge = Integer(upsc[ups]['battery.charge'])
|
61
|
+
battery_state = if battery_charge < Integer(upsc[ups]['battery.charge.low'])
|
62
|
+
'critical'
|
63
|
+
elsif battery_charge < Integer(upsc[ups]['battery.charge.warning'])
|
64
|
+
'warning'
|
65
|
+
else
|
66
|
+
'ok'
|
67
|
+
end
|
68
|
+
|
69
|
+
report(
|
70
|
+
service: service,
|
71
|
+
metric: battery_charge,
|
72
|
+
state: battery_state,
|
73
|
+
description: "#{battery_charge} %",
|
74
|
+
)
|
75
|
+
rescue TypeError
|
76
|
+
report(
|
77
|
+
service: service,
|
78
|
+
state: 'critical',
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def report_battery_voltage
|
84
|
+
opts[:ups].each do |ups|
|
85
|
+
service = "#{ups} battery voltage"
|
86
|
+
battery_voltage = Float(upsc[ups]['battery.voltage'])
|
87
|
+
|
88
|
+
report(
|
89
|
+
service: service,
|
90
|
+
metric: battery_voltage,
|
91
|
+
state: 'ok',
|
92
|
+
description: "#{battery_voltage} V",
|
93
|
+
)
|
94
|
+
rescue TypeError
|
95
|
+
report(
|
96
|
+
service: service,
|
97
|
+
state: 'critical',
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def report_input_voltage
|
103
|
+
opts[:ups].each do |ups|
|
104
|
+
service = "#{ups} input voltage"
|
105
|
+
input_voltage = Float(upsc[ups]['input.voltage'])
|
106
|
+
|
107
|
+
report(
|
108
|
+
service: service,
|
109
|
+
metric: input_voltage,
|
110
|
+
state: 'ok',
|
111
|
+
description: "#{input_voltage} V",
|
112
|
+
)
|
113
|
+
rescue TypeError
|
114
|
+
report(
|
115
|
+
service: service,
|
116
|
+
state: 'critical',
|
117
|
+
)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def report_ups_alarm
|
122
|
+
opts[:ups].each do |ups|
|
123
|
+
report(
|
124
|
+
service: "#{ups} ups alarm",
|
125
|
+
state: 'critical',
|
126
|
+
description: upsc[ups]['ups.alarm'],
|
127
|
+
)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def report_ups_load
|
132
|
+
opts[:ups].each do |ups|
|
133
|
+
service = "#{ups} ups load"
|
134
|
+
ups_load = Float(upsc[ups]['ups.load'])
|
135
|
+
ups_state = if opts[:load_critical].positive? && ups_load > opts[:load_critical]
|
136
|
+
'critical'
|
137
|
+
elsif opts[:load_warning].positive? && ups_load > opts[:load_warning]
|
138
|
+
'warning'
|
139
|
+
else
|
140
|
+
'ok'
|
141
|
+
end
|
142
|
+
|
143
|
+
report(
|
144
|
+
service: service,
|
145
|
+
metric: ups_load,
|
146
|
+
state: ups_state,
|
147
|
+
description: "#{ups_load} W",
|
148
|
+
)
|
149
|
+
rescue TypeError
|
150
|
+
report(
|
151
|
+
service: service,
|
152
|
+
state: 'critical',
|
153
|
+
)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def report_ups_status
|
158
|
+
opts[:ups].each do |ups|
|
159
|
+
# https://github.com/influxdata/telegraf/issues/6316#issuecomment-787008263
|
160
|
+
ups_state = 'ok' if upsc[ups]['ups.status'] =~ /\b(OL)\b/
|
161
|
+
ups_state = 'warning' if upsc[ups]['ups.status'] =~ /\b(OB|DISCHRG|BYPASS)\b/
|
162
|
+
ups_state = 'critical' if upsc[ups]['ups.status'] =~ /\b(ALARM|OVER)\b/
|
163
|
+
|
164
|
+
ups_state ||= 'critical'
|
165
|
+
|
166
|
+
report(
|
167
|
+
service: "#{ups} ups status",
|
168
|
+
state: ups_state,
|
169
|
+
description: upsc[ups]['ups.status'],
|
170
|
+
)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
data/riemann-nut.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/riemann/tools/nut/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'riemann-nut'
|
7
|
+
spec.version = Riemann::Tools::Nut::VERSION
|
8
|
+
spec.authors = ['Romain Tartière']
|
9
|
+
spec.email = ['romain@blogreen.org']
|
10
|
+
|
11
|
+
spec.summary = 'Submits nut information to riemann'
|
12
|
+
spec.homepage = 'https://github.com/opus-codium/riemann-nut'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
15
|
+
|
16
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
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(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = 'bin'
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_runtime_dependency 'riemann-tools', '~> 1.0'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'github_changelog_generator'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rspec'
|
36
|
+
spec.add_development_dependency 'rubocop'
|
37
|
+
spec.add_development_dependency 'rubocop-rake'
|
38
|
+
spec.add_development_dependency 'rubocop-rspec'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riemann-nut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Romain Tartière
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: riemann-tools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: github_changelog_generator
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- romain@blogreen.org
|
114
|
+
executables:
|
115
|
+
- riemann-nut
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".github/workflows/ci.yml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".rubocop.yml"
|
123
|
+
- Gemfile
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/riemann-nut
|
127
|
+
- lib/riemann/tools/nut.rb
|
128
|
+
- lib/riemann/tools/nut/version.rb
|
129
|
+
- riemann-nut.gemspec
|
130
|
+
homepage: https://github.com/opus-codium/riemann-nut
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata:
|
134
|
+
allowed_push_host: https://rubygems.org/
|
135
|
+
homepage_uri: https://github.com/opus-codium/riemann-nut
|
136
|
+
source_code_uri: https://github.com/opus-codium/riemann-nut
|
137
|
+
changelog_uri: https://github.com/opus-codium/riemann-nut
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 2.6.0
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubygems_version: 3.3.17
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Submits nut information to riemann
|
157
|
+
test_files: []
|