sensu-plugins-hardware 1.2.0 → 1.3.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 +4 -4
- data/CHANGELOG.md +15 -2
- data/README.md +44 -1
- data/bin/check-hardware-fail.rb +92 -9
- data/lib/sensu-plugins-hardware/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: add709f0d1e2d01a5c413288108b35aba31da5969574d89202d89642ae5d71c5
|
4
|
+
data.tar.gz: bc700abd5e7165dd0c0cd304cadc0dbe76505deb0e2b3cb034fe8e5cbb693964
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6128d23dd44c90d1584a8e7d19436e5a1ef21a620d5e4fdf87f19b61a91e5186cb89cd11fda23834c0e666d1ac59501f4f012d325ee0adeb469f88a782282efb
|
7
|
+
data.tar.gz: 93305d33ec53cd2dcca52fbc5c9ad90b5abd42cfc4f9e822d9e09c7ca3a828463cc590f27a740a62809abffdb538b3348f0a42b7432636000e4425c2a4bdb3f5
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
# Change Log
|
2
2
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
3
|
|
4
|
-
This CHANGELOG follows the format listed at [
|
4
|
+
This CHANGELOG follows the format listed at [Our CHANGELOG Guidelines](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [1.3.0] - 2017-12-05
|
9
|
+
### Added
|
10
|
+
- Options `--facility`, `--level` and `--kernel` to restrict dmesg output on linux OS (@epierotto)
|
11
|
+
- Option `--seconds` to specify the amount of seconds to lookbehind on dmesg output on linux OS (@epierotto)
|
12
|
+
- Options validation to prevent running incompatible arguments (@epierotto)
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- updated changelog guidelines location (@majormoses)
|
16
|
+
- Replaced the use of `tail` and `head` commands when specifying the option `--invert`, now uses pure ruby (@epierotto)
|
17
|
+
- Updated rubocop version to 0.49.0 (@epierotto)
|
18
|
+
- Rubocop test pass (@epierotto)
|
19
|
+
|
8
20
|
## [1.2.0] - 2017-11-02
|
9
21
|
### Changed
|
10
22
|
- check-hardware-fail.rb: Return the actual and entire query line match if found (@phantasm66)
|
@@ -44,7 +56,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
44
56
|
### Changed
|
45
57
|
- removed cruft from /lib
|
46
58
|
|
47
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-hardware/compare/1.
|
59
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-hardware/compare/1.3.0...HEAD
|
60
|
+
[1.3.0]: https://github.com/sensu-plugins/sensu-plugins-hardware/compare/1.2.0...1.3.0
|
48
61
|
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-hardware/compare/1.1.0...1.2.0
|
49
62
|
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-hardware/compare/1.0.0...1.1.0
|
50
63
|
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-hardware/compare/0.0.4...1.0.0
|
data/README.md
CHANGED
@@ -7,14 +7,57 @@
|
|
7
7
|
[](https://gemnasium.com/sensu-plugins/sensu-plugins-hardware)
|
8
8
|
|
9
9
|
## Functionality
|
10
|
+
**check-hardware-fail** will lookup in the output of `dmesg` for lines matching a provided query, it accepts `--facility`, `--level` and `--kernel` options to run `dmesg` command. Returns CRITICAL if any occurrence is found and UNKNOWN if provided options are invalid or the command execution fails.
|
10
11
|
|
11
12
|
## Files
|
12
13
|
* bin/check-hardware-fail
|
13
14
|
|
14
15
|
## Usage
|
16
|
+
```
|
17
|
+
Usage: ./check-hardware-fail.rb (options)
|
18
|
+
-f FACILITY[,FACILITY], Restrict output to defined facilities. Supported log facilities: kern,user,mail,daemon,auth,syslog,lpr,news
|
19
|
+
--facility
|
20
|
+
--invert Invert order
|
21
|
+
-k, --kernel Include kernel messages
|
22
|
+
-L, --level LEVEL[,LEVEL] Restrict output to defined levels, otherwise all levels are included. Supported log levels: emerg,alert,crit,err,warn,notice,info,debug
|
23
|
+
-l, --lines NUMBER Maximum number of lines to read from dmesg, 0 (default) means all
|
24
|
+
-q, --query QUERY What pattern to look for in the output of dmesg (regex or literal)
|
25
|
+
-s, --seconds SECONDS Amount of seconds to lookbehind from dmesg output. This option is incompatible with --lines
|
26
|
+
```
|
27
|
+
|
28
|
+
Example of usage:
|
29
|
+
|
30
|
+
Check the first 100 lines for 'killed as a result of limit'
|
31
|
+
```
|
32
|
+
check-hardware-fail.rb -l 100 --invert -q 'killed as a result of limit'
|
33
|
+
```
|
34
|
+
|
35
|
+
Check the last 100 lines for 'killed as a result of limit'
|
36
|
+
```
|
37
|
+
check-hardware-fail.rb -l 100 -q 'killed as a result of limit'
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
The following options are only available for linux OS:
|
42
|
+
|
43
|
+
* `--seconds` Amount of seconds to lookbehind from dmesg output. This option is incompatible with `--lines`
|
44
|
+
* `--facility` Restrict output to defined facilities. Supported log facilities: `kern,user,mail,daemon,auth,syslog,lpr,news`
|
45
|
+
* `--level` Restrict output to defined levels, otherwise all levels are included. Supported log levels: `emerg,alert,crit,err,warn,notice,info,debug`
|
46
|
+
* `--kernel` Include kernel messages
|
47
|
+
|
48
|
+
Check the last 300 seconds for 'killed as a result of limit'
|
49
|
+
```
|
50
|
+
check-hardware-fail.rb -s 300 -q 'killed as a result of limit'
|
51
|
+
```
|
52
|
+
|
53
|
+
Check the last 300 seconds for 'killed' on `auth` and `syslog` facilities
|
54
|
+
```
|
55
|
+
check-hardware-fail.rb -s 300 -f auth,syslog -q 'killed'
|
56
|
+
```
|
57
|
+
|
15
58
|
|
16
59
|
## Installation
|
17
60
|
|
18
61
|
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
19
62
|
|
20
|
-
## Notes
|
63
|
+
## Notes
|
data/bin/check-hardware-fail.rb
CHANGED
@@ -25,6 +25,7 @@
|
|
25
25
|
# for details.
|
26
26
|
#
|
27
27
|
|
28
|
+
require 'os'
|
28
29
|
require 'English'
|
29
30
|
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
30
31
|
require 'sensu-plugin/check/cli'
|
@@ -34,7 +35,6 @@ class CheckHardwareFail < Sensu::Plugin::Check::CLI
|
|
34
35
|
short: '-l NUMBER',
|
35
36
|
long: '--lines NUMBER',
|
36
37
|
proc: proc(&:to_i),
|
37
|
-
default: 0,
|
38
38
|
description: 'Maximum number of lines to read from dmesg, 0 (default) means all'
|
39
39
|
|
40
40
|
option :query,
|
@@ -43,21 +43,104 @@ class CheckHardwareFail < Sensu::Plugin::Check::CLI
|
|
43
43
|
default: 'Hardware Error',
|
44
44
|
description: 'What pattern to look for in the output of dmesg (regex or literal)'
|
45
45
|
|
46
|
+
option :seconds,
|
47
|
+
short: '-s SECONDS',
|
48
|
+
long: '--seconds SECONDS',
|
49
|
+
proc: proc(&:to_i),
|
50
|
+
description: 'Amount of seconds to lookbehind from dmesg output. This option is incompatible with --lines'
|
51
|
+
|
52
|
+
option :facility,
|
53
|
+
short: '-f FACILITY[,FACILITY]',
|
54
|
+
long: '--facility FACILITY[,FACILITY]',
|
55
|
+
description: 'Restrict output to defined facilities. Supported log facilities: kern,user,mail,daemon,auth,syslog,lpr,news',
|
56
|
+
required: false,
|
57
|
+
proc: proc { |a| a.split(',') }
|
58
|
+
|
59
|
+
option :level,
|
60
|
+
short: '-L LEVEL[,LEVEL]',
|
61
|
+
long: '--level LEVEL[,LEVEL]',
|
62
|
+
description: 'Restrict output to defined levels, otherwise all levels are included. Supported log levels: emerg,alert,crit,err,warn,notice,info,debug',
|
63
|
+
proc: proc { |a| a.split(',') }
|
64
|
+
|
65
|
+
option :kernel,
|
66
|
+
short: '-k',
|
67
|
+
long: '--kernel',
|
68
|
+
description: 'Include kernel messages',
|
69
|
+
boolean: true
|
70
|
+
|
46
71
|
option :invert,
|
47
72
|
long: '--invert',
|
48
73
|
description: 'Invert order',
|
49
|
-
boolean: true
|
50
|
-
default: false
|
74
|
+
boolean: true
|
51
75
|
|
52
76
|
def run
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
77
|
+
# Validate options
|
78
|
+
unknown incompatible_options if incompatible_options
|
79
|
+
|
80
|
+
# Build the command based on the options provided
|
81
|
+
cmd = 'dmesg '
|
82
|
+
cmd += "--facility #{config[:facility].join(',')} " if config[:facility]
|
83
|
+
cmd += "--level #{config[:level].join(',')} " if config[:level]
|
84
|
+
cmd += '--kernel ' if config[:kernel]
|
85
|
+
|
86
|
+
# Run command
|
87
|
+
lines = `#{cmd}`.lines
|
59
88
|
unknown 'Command execution failed!' unless $CHILD_STATUS.success?
|
89
|
+
|
90
|
+
if config[:seconds]
|
91
|
+
uptime = File.read('/proc/uptime').split(' ').first.to_i
|
92
|
+
seconds_limit = uptime - config[:seconds]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Option --invert
|
96
|
+
# Flipping the array to start the iteration from the last line (newest entry)
|
97
|
+
# unless `--invert` which means that you want to start reading from the first line (oldest entry)
|
98
|
+
lines.reverse! unless config[:invert]
|
99
|
+
|
100
|
+
output = []
|
101
|
+
|
102
|
+
lines.each_with_index do |line, index|
|
103
|
+
break if config[:lines] && index >= config[:lines]
|
104
|
+
if config[:seconds]
|
105
|
+
timestamp = line.split(']').first.delete('[').to_i
|
106
|
+
break if timestamp < seconds_limit
|
107
|
+
end
|
108
|
+
output << line if line[/#{config[:query]}/]
|
109
|
+
end
|
110
|
+
|
60
111
|
critical "Problem Detected: #{output[0]}" if output.any?
|
61
112
|
ok 'OK'
|
62
113
|
end
|
114
|
+
|
115
|
+
def incompatible_options
|
116
|
+
if OS.linux?
|
117
|
+
if incompatible_linux.any?
|
118
|
+
"The use of the options --seconds and [--#{incompatible_linux.join(' --')}] is incompatible."
|
119
|
+
elsif invalid_facility.any?
|
120
|
+
"Invalid dmesg facility requested: #{invalid_facility}"
|
121
|
+
elsif invalid_level.any?
|
122
|
+
"Invalid dmesg level requested: #{invalid_level}"
|
123
|
+
end
|
124
|
+
elsif OS.posix?
|
125
|
+
"Incompatible options: [--#{incompatible_posix.join(' --')}] for OS #{OS.host_os}" if incompatible_posix.any?
|
126
|
+
else
|
127
|
+
"OS #{OS.host_os} is not supported"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def incompatible_linux
|
132
|
+
config[:seconds] ? config.keys & %i[lines invert] : []
|
133
|
+
end
|
134
|
+
|
135
|
+
def incompatible_posix
|
136
|
+
config.keys & %i[facility level kernel seconds]
|
137
|
+
end
|
138
|
+
|
139
|
+
def invalid_facility
|
140
|
+
config[:facility].to_a - %w[kern user mail daemon auth syslog lpr news]
|
141
|
+
end
|
142
|
+
|
143
|
+
def invalid_level
|
144
|
+
config[:level].to_a - %w[emerg alert crit err warn notice info debug]
|
145
|
+
end
|
63
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-hardware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: os
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.6
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +128,14 @@ dependencies:
|
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
131
|
+
version: 0.49.0
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
138
|
+
version: 0.49.0
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rspec
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
206
|
version: '0'
|
193
207
|
requirements: []
|
194
208
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.7.
|
209
|
+
rubygems_version: 2.7.3
|
196
210
|
signing_key:
|
197
211
|
specification_version: 4
|
198
212
|
summary: Sensu plugins for physical hardware
|