sensu-plugins-openbsd 1.0.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 +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +22 -0
- data/README.md +0 -0
- data/bin/check-cmd.rb +79 -0
- data/bin/check-ntp.rb +109 -0
- data/bin/check-process.rb +312 -0
- data/lib/sensu-plugins-openbsd/version.rb +9 -0
- data/lib/sensu-plugins-openbsd.rb +1 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: db8816ea53afa997acae002497a73cba48018af3a9841d5fae89452cbac56d98
|
4
|
+
data.tar.gz: ac50ac99560d47a1c65fc1d3a324c19c321c1e1bf310a77be714f1d2db14de67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0efbdfde14400de870849668c8d05449aca86c3bad4ea6d85bc66590994e071c7e018c04da7860ebe22e9ab1845e637f0d4ff41daf52327dd0c8760c86d1ad14
|
7
|
+
data.tar.gz: db7c1e464624e08293bd25d4e398e4c68df721404abddae6ab450b6af394392713d30256ba6255865cfa98ffabe78fe06404d835a0ffd8dc852caae6f3bca2ee
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed at [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## [1.0.0] - 2018-11-28
|
9
|
+
### Added Checks
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018-2019 Sigterm AS
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/bin/check-cmd.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-cmd
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Generic check raising an error if exit code of command is not N.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
# OpenBSD
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: english
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Jean-Francois Theroux <failshell@gmail.com>
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'sensu-plugin/check/cli'
|
30
|
+
require 'English'
|
31
|
+
|
32
|
+
#
|
33
|
+
# Check Command Status
|
34
|
+
#
|
35
|
+
class CheckCmdStatus < Sensu::Plugin::Check::CLI
|
36
|
+
option :command,
|
37
|
+
description: 'command to run (might need quotes)',
|
38
|
+
short: '-c',
|
39
|
+
long: '--command COMMAND',
|
40
|
+
required: true
|
41
|
+
|
42
|
+
option :status,
|
43
|
+
description: 'exit status code the check should get',
|
44
|
+
short: '-s',
|
45
|
+
long: '--status STATUS',
|
46
|
+
default: '0'
|
47
|
+
|
48
|
+
option :check_output,
|
49
|
+
description: 'Optionally check the process stdout against a regex',
|
50
|
+
short: '-o',
|
51
|
+
long: '--check_output REGEX'
|
52
|
+
|
53
|
+
# Acquire the exit code and/or output of a command and alert if it is not
|
54
|
+
# what is expected.
|
55
|
+
#
|
56
|
+
def acquire_cmd_status
|
57
|
+
stdout = `#{config[:command]}`
|
58
|
+
# #YELLOW
|
59
|
+
unless $CHILD_STATUS.exitstatus.to_s == config[:status] # rubocop:disable UnlessElse
|
60
|
+
critical "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
|
61
|
+
else
|
62
|
+
if config[:check_output]
|
63
|
+
if Regexp.new(config[:check_output]).match(stdout)
|
64
|
+
ok "#{config[:command]} matched #{config[:check_output]} and exited with #{$CHILD_STATUS.exitstatus}"
|
65
|
+
else
|
66
|
+
critical "#{config[:command]} output didn't match #{config[:check_output]} (exit #{$CHILD_STATUS.exitstatus})"
|
67
|
+
end
|
68
|
+
else
|
69
|
+
ok "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# main function
|
75
|
+
#
|
76
|
+
def run
|
77
|
+
acquire_cmd_status
|
78
|
+
end
|
79
|
+
end
|
data/bin/check-ntp.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-ntp
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
#
|
7
|
+
# OUTPUT:
|
8
|
+
# plain text
|
9
|
+
#
|
10
|
+
# PLATFORMS:
|
11
|
+
# OpenBSD
|
12
|
+
#
|
13
|
+
# DEPENDENCIES:
|
14
|
+
# gem: sensu-plugin
|
15
|
+
#
|
16
|
+
# USAGE:
|
17
|
+
#
|
18
|
+
# NOTES:
|
19
|
+
# warning and critical values are offsets in milliseconds.
|
20
|
+
#
|
21
|
+
# LICENSE:
|
22
|
+
# Copyright 2018 Sigterm AS, Mikal Villa <support@sigterm.no>
|
23
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
24
|
+
# for details.
|
25
|
+
#
|
26
|
+
# Stratum Levels
|
27
|
+
# 1: Primary reference (e.g., calibrated atomic clock, radio clock, etc...)
|
28
|
+
# 2-15: Secondary reference (via NTP, calculated as the stratum of your system peer plus one)
|
29
|
+
# 16: Unsynchronized
|
30
|
+
# 17-255: Reserved
|
31
|
+
#
|
32
|
+
# Source Field Status Codes
|
33
|
+
# http://doc.ntp.org/current-stable/decode.html
|
34
|
+
|
35
|
+
require 'sensu-plugin/check/cli'
|
36
|
+
|
37
|
+
class CheckNTP < Sensu::Plugin::Check::CLI
|
38
|
+
option :warn,
|
39
|
+
short: '-w WARN',
|
40
|
+
proc: proc(&:to_f),
|
41
|
+
default: 10
|
42
|
+
|
43
|
+
option :crit,
|
44
|
+
short: '-c CRIT',
|
45
|
+
proc: proc(&:to_f),
|
46
|
+
default: 100
|
47
|
+
|
48
|
+
option :stratum,
|
49
|
+
short: '-s STRATUM',
|
50
|
+
description: 'check that stratum meets or exceeds desired value',
|
51
|
+
proc: proc(&:to_i),
|
52
|
+
default: 15
|
53
|
+
|
54
|
+
option :unsynced_status,
|
55
|
+
short: '-u CODE',
|
56
|
+
description: 'If ntp_status is unsynced (that is, not yet connected to or disconnected from ntp), what should the response be.',
|
57
|
+
proc: proc(&:downcase),
|
58
|
+
default: 'unknown'
|
59
|
+
|
60
|
+
def run
|
61
|
+
output=''
|
62
|
+
begin
|
63
|
+
output=`ntpctl -s status`
|
64
|
+
# Peers
|
65
|
+
peersIdx=output.index('peers')
|
66
|
+
peersStr=output[0, peersIdx].strip
|
67
|
+
peersArray=peersStr.split('/')
|
68
|
+
numConnected = peersArray[0]
|
69
|
+
numAvailable = peersArray[1]
|
70
|
+
# End peers
|
71
|
+
stratumEndIdx = output.index('stratum')+7
|
72
|
+
stratum = output[stratumEndIdx,stratumEndIdx+3].strip.to_i
|
73
|
+
|
74
|
+
# Synced
|
75
|
+
synced='clock synced'
|
76
|
+
unsynced='clock unsynced'
|
77
|
+
|
78
|
+
# Offset
|
79
|
+
offset=output[/offset (...), clock/, 1].strip
|
80
|
+
|
81
|
+
rescue
|
82
|
+
unknown 'NTP command Failed'
|
83
|
+
end
|
84
|
+
|
85
|
+
if output.include? unsynced
|
86
|
+
case config[:unsynced_status]
|
87
|
+
when 'warn'
|
88
|
+
warning 'NTP state unsynced'
|
89
|
+
when 'crit'
|
90
|
+
critical 'NTP state unsynced'
|
91
|
+
when 'unknown'
|
92
|
+
unknown 'NTP state unsynced'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if stratum > 15
|
97
|
+
critical 'NTP not synced'
|
98
|
+
elsif stratum > config[:stratum]
|
99
|
+
critical "NTP stratum (#{stratum}) above limit (#{config[:stratum]})"
|
100
|
+
end
|
101
|
+
|
102
|
+
offset_f = offset.sub('s','').to_f
|
103
|
+
|
104
|
+
message = "NTP offset by #{offset}"
|
105
|
+
critical message if offset_f >= config[:crit] || offset_f <= -config[:crit]
|
106
|
+
warning message if offset_f >= config[:warn] || offset_f <= -config[:warn]
|
107
|
+
ok message
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,312 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-process
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Finds processes matching various filters (name, state, etc). Will not
|
7
|
+
# match itself by default. The number of processes found will be tested
|
8
|
+
# against the Warning/critical thresholds. By default, fails with a
|
9
|
+
# CRITICAL if more than one process matches -- you must specify values
|
10
|
+
# for -w and -c to override this.
|
11
|
+
#
|
12
|
+
# Attempts to work on Cygwin (where ps does not have the features we
|
13
|
+
# need) by calling Windows' tasklist.exe, but this is not well tested.#
|
14
|
+
#
|
15
|
+
# OUTPUT:
|
16
|
+
# plain text
|
17
|
+
#
|
18
|
+
# PLATFORMS:
|
19
|
+
# Linux
|
20
|
+
# OpenBSD
|
21
|
+
#
|
22
|
+
# DEPENDENCIES:
|
23
|
+
# gem: sensu-plugin
|
24
|
+
# gem: english
|
25
|
+
#
|
26
|
+
# USAGE:
|
27
|
+
# # chef-client is running
|
28
|
+
# check-process.rb -p chef-client -W 1
|
29
|
+
#
|
30
|
+
# # there are not too many zombies
|
31
|
+
# check-process.rb -s Z -w 5 -c 10
|
32
|
+
#
|
33
|
+
# NOTES:
|
34
|
+
#
|
35
|
+
# LICENSE:
|
36
|
+
# Copyright 2011 Sonian, Inc <chefs@sonian.net>
|
37
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
38
|
+
# for details.
|
39
|
+
#
|
40
|
+
|
41
|
+
require 'sensu-plugin/check/cli'
|
42
|
+
require 'English'
|
43
|
+
|
44
|
+
#
|
45
|
+
# Check Processes
|
46
|
+
#
|
47
|
+
class CheckProcess < Sensu::Plugin::Check::CLI
|
48
|
+
option :warn_over,
|
49
|
+
short: '-w N',
|
50
|
+
long: '--warn-over N',
|
51
|
+
description: 'Trigger a warning if over a number',
|
52
|
+
proc: proc(&:to_i)
|
53
|
+
|
54
|
+
option :crit_over,
|
55
|
+
short: '-c N',
|
56
|
+
long: '--critical-over N',
|
57
|
+
description: 'Trigger a critical if over a number',
|
58
|
+
proc: proc(&:to_i)
|
59
|
+
|
60
|
+
option :warn_under,
|
61
|
+
short: '-W N',
|
62
|
+
long: '--warn-under N',
|
63
|
+
description: 'Trigger a warning if under a number',
|
64
|
+
proc: proc(&:to_i),
|
65
|
+
default: 1
|
66
|
+
|
67
|
+
option :crit_under,
|
68
|
+
short: '-C N',
|
69
|
+
long: '--critical-under N',
|
70
|
+
description: 'Trigger a critial if under a number',
|
71
|
+
proc: proc(&:to_i),
|
72
|
+
default: 1
|
73
|
+
|
74
|
+
option :metric,
|
75
|
+
short: '-t METRIC',
|
76
|
+
long: '--metric METRIC',
|
77
|
+
description: 'Trigger a critical if there are METRIC procs',
|
78
|
+
proc: proc(&:to_sym)
|
79
|
+
|
80
|
+
option :match_self,
|
81
|
+
short: '-m',
|
82
|
+
long: '--match-self',
|
83
|
+
description: 'Match itself',
|
84
|
+
boolean: true,
|
85
|
+
default: false
|
86
|
+
|
87
|
+
option :match_parent,
|
88
|
+
short: '-M',
|
89
|
+
long: '--match-parent',
|
90
|
+
description: 'Match parent process it uses ruby {process.ppid}',
|
91
|
+
boolean: true,
|
92
|
+
default: false
|
93
|
+
|
94
|
+
option :cmd_pat,
|
95
|
+
short: '-p PATTERN',
|
96
|
+
long: '--pattern PATTERN',
|
97
|
+
description: 'Match a command against this pattern'
|
98
|
+
|
99
|
+
option :exclude_pat,
|
100
|
+
short: '-x PATTERN',
|
101
|
+
long: '--exclude-pattern PATTERN',
|
102
|
+
description: "Don't match against a pattern to prevent false positives"
|
103
|
+
|
104
|
+
option :file_pid,
|
105
|
+
short: '-f PID',
|
106
|
+
long: '--file-pid PID',
|
107
|
+
description: 'Check against a specific PID'
|
108
|
+
|
109
|
+
option :file_pid_crit,
|
110
|
+
short: '-F',
|
111
|
+
long: '--file-pid-crit',
|
112
|
+
description: 'Trigger a critical if pid file is specified but non-existent'
|
113
|
+
|
114
|
+
option :vsz,
|
115
|
+
short: '-z VSZ',
|
116
|
+
long: '--virtual-memory-size VSZ',
|
117
|
+
description: 'Trigger on a Virtual Memory size is bigger than this',
|
118
|
+
proc: proc(&:to_i)
|
119
|
+
|
120
|
+
option :rss,
|
121
|
+
short: '-r RSS',
|
122
|
+
long: '--resident-set-size RSS',
|
123
|
+
description: 'Trigger on a Resident Set size is bigger than this',
|
124
|
+
proc: proc(&:to_i)
|
125
|
+
|
126
|
+
option :cpu_utilization,
|
127
|
+
short: '-P xx',
|
128
|
+
long: '--cpu-utilization xx',
|
129
|
+
description: 'Trigger on a Proportional Set Size is bigger than this',
|
130
|
+
proc: proc(&:to_f)
|
131
|
+
|
132
|
+
option :thcount,
|
133
|
+
short: '-T THCOUNT',
|
134
|
+
long: '--thread-count THCOUNT',
|
135
|
+
description: 'Trigger on a Thread Count is bigger than this',
|
136
|
+
proc: proc(&:to_i)
|
137
|
+
|
138
|
+
option :state,
|
139
|
+
short: '-s STATE',
|
140
|
+
long: '--state STATE',
|
141
|
+
description: 'Trigger on a specific state, example: Z for zombie',
|
142
|
+
proc: proc { |a| a.split(',') }
|
143
|
+
|
144
|
+
option :user,
|
145
|
+
short: '-u USER',
|
146
|
+
long: '--user USER',
|
147
|
+
description: 'Trigger on a specific user',
|
148
|
+
proc: proc { |a| a.split(',') }
|
149
|
+
|
150
|
+
option :esec_over,
|
151
|
+
short: '-e SECONDS',
|
152
|
+
long: '--esec-over SECONDS',
|
153
|
+
proc: proc(&:to_i),
|
154
|
+
description: 'Match processes that are older than this, in SECONDS'
|
155
|
+
|
156
|
+
option :esec_under,
|
157
|
+
short: '-E SECONDS',
|
158
|
+
long: '--esec-under SECONDS',
|
159
|
+
proc: proc(&:to_i),
|
160
|
+
description: 'Match process that are younger than this, in SECONDS'
|
161
|
+
|
162
|
+
option :cpu_over,
|
163
|
+
short: '-i SECONDS',
|
164
|
+
long: '--cpu-over SECONDS',
|
165
|
+
proc: proc(&:to_i),
|
166
|
+
description: 'Match processes cpu time that is older than this, in SECONDS'
|
167
|
+
|
168
|
+
option :cpu_under,
|
169
|
+
short: '-I SECONDS',
|
170
|
+
long: '--cpu-under SECONDS',
|
171
|
+
proc: proc(&:to_i),
|
172
|
+
description: 'Match processes cpu time that is younger than this, in SECONDS'
|
173
|
+
|
174
|
+
option :encoding,
|
175
|
+
description: 'Explicit encoding when reading process list',
|
176
|
+
long: '--encoding ENCODING',
|
177
|
+
default: 'ASCII-8BIT'
|
178
|
+
|
179
|
+
# Read the pid file
|
180
|
+
# @param path [String] the path to the pid file, including the file
|
181
|
+
def read_pid(path)
|
182
|
+
if File.exist?(path)
|
183
|
+
File.read(path).strip.to_i
|
184
|
+
elsif config[:file_pid_crit].nil?
|
185
|
+
unknown "Could not read pid file #{path}"
|
186
|
+
else
|
187
|
+
critical "Could not read pid file #{path}"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# read the output of a command
|
192
|
+
# @param cmd [String] the command to read the output from
|
193
|
+
def read_lines(cmd)
|
194
|
+
IO.popen(cmd + ' 2>&1', external_encoding: config[:encoding]) do |child|
|
195
|
+
child.read.split("\n")
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# create a hash from the output of each line of a command
|
200
|
+
# @param line [String]
|
201
|
+
# @param cols
|
202
|
+
#
|
203
|
+
def line_to_hash(line, *cols)
|
204
|
+
Hash[cols.zip(line.strip.split(/\s+/, cols.size))]
|
205
|
+
end
|
206
|
+
|
207
|
+
# Is this running on cygwin
|
208
|
+
#
|
209
|
+
#
|
210
|
+
def on_cygwin?
|
211
|
+
# #YELLOW
|
212
|
+
`ps -W 2>&1`; $CHILD_STATUS.exitstatus.zero? # rubocop:disable Semicolon
|
213
|
+
end
|
214
|
+
|
215
|
+
# Acquire all the proceeses on a system for further analysis
|
216
|
+
#
|
217
|
+
def acquire_procs
|
218
|
+
if on_cygwin?
|
219
|
+
read_lines('ps -aWl').drop(1).map do |line|
|
220
|
+
# Horrible hack because cygwin's ps has no o option, every
|
221
|
+
# format includes the STIME column (which may contain spaces),
|
222
|
+
# and the process state (which isn't actually a column) can be
|
223
|
+
# blank. As of revision 1.35, the format is:
|
224
|
+
# const char *lfmt = "%c %7d %7d %7d %10u %4s %4u %8s %s\n";
|
225
|
+
state = line.slice!(0..0)
|
226
|
+
_stime = line.slice!(45..53)
|
227
|
+
line_to_hash(line, :pid, :ppid, :pgid, :winpid, :tty, :uid, :etime, :command, :time).merge(state: state)
|
228
|
+
end
|
229
|
+
else
|
230
|
+
read_lines('ps axwwo user,pid,vsz,rss,pcpu,nlwp,state,etime,time,command').drop(1).map do |line|
|
231
|
+
line_to_hash(line, :user, :pid, :vsz, :rss, :cpu, :thcount, :state, :etime, :time, :command)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# Match to a time
|
237
|
+
#
|
238
|
+
def etime_to_esec(etime)
|
239
|
+
m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(etime)
|
240
|
+
(m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
|
241
|
+
end
|
242
|
+
|
243
|
+
# Match to a time
|
244
|
+
#
|
245
|
+
def cputime_to_csec(time)
|
246
|
+
m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(time)
|
247
|
+
(m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
|
248
|
+
end
|
249
|
+
|
250
|
+
# The main function
|
251
|
+
#
|
252
|
+
def run
|
253
|
+
procs = acquire_procs
|
254
|
+
|
255
|
+
if config[:file_pid] && (file_pid = read_pid(config[:file_pid]))
|
256
|
+
procs.select! { |p| p[:pid].to_i == file_pid }
|
257
|
+
end
|
258
|
+
|
259
|
+
procs.reject! { |p| p[:pid].to_i == $PROCESS_ID } unless config[:match_self]
|
260
|
+
procs.reject! { |p| p[:pid].to_i == Process.ppid } unless config[:match_parent]
|
261
|
+
procs.reject! { |p| p[:command] =~ /#{config[:exclude_pat]}/ } if config[:exclude_pat]
|
262
|
+
procs.select! { |p| p[:command] =~ /#{config[:cmd_pat]}/ } if config[:cmd_pat]
|
263
|
+
procs.select! { |p| p[:vsz].to_f > config[:vsz] } if config[:vsz]
|
264
|
+
procs.select! { |p| p[:rss].to_f > config[:rss] } if config[:rss]
|
265
|
+
procs.select! { |p| p[:cpu].to_f > config[:cpu_utilization] } if config[:cpu_utilization]
|
266
|
+
procs.select! { |p| p[:thcount].to_i > config[:thcount] } if config[:thcount]
|
267
|
+
procs.reject! { |p| etime_to_esec(p[:etime]) >= config[:esec_under] } if config[:esec_under]
|
268
|
+
procs.reject! { |p| etime_to_esec(p[:etime]) <= config[:esec_over] } if config[:esec_over]
|
269
|
+
procs.reject! { |p| cputime_to_csec(p[:time]) >= config[:cpu_under] } if config[:cpu_under]
|
270
|
+
procs.reject! { |p| cputime_to_csec(p[:time]) <= config[:cpu_over] } if config[:cpu_over]
|
271
|
+
procs.select! { |p| config[:state].include?(p[:state]) } if config[:state]
|
272
|
+
procs.select! { |p| config[:user].include?(p[:user]) } if config[:user]
|
273
|
+
|
274
|
+
msg = "Found #{procs.size} matching processes"
|
275
|
+
msg += "; cmd /#{config[:cmd_pat]}/" if config[:cmd_pat]
|
276
|
+
msg += "; state #{config[:state].join(',')}" if config[:state]
|
277
|
+
msg += "; user #{config[:user].join(',')}" if config[:user]
|
278
|
+
msg += "; vsz > #{config[:vsz]}" if config[:vsz]
|
279
|
+
msg += "; rss > #{config[:rss]}" if config[:rss]
|
280
|
+
msg += "; cpu > #{config[:cpu_utilization]}" if config[:cpu_utilization]
|
281
|
+
msg += "; thcount > #{config[:thcount]}" if config[:thcount]
|
282
|
+
msg += "; esec < #{config[:esec_under]}" if config[:esec_under]
|
283
|
+
msg += "; esec > #{config[:esec_over]}" if config[:esec_over]
|
284
|
+
msg += "; csec < #{config[:cpu_under]}" if config[:cpu_under]
|
285
|
+
msg += "; csec > #{config[:cpu_over]}" if config[:cpu_over]
|
286
|
+
msg += "; pid #{config[:file_pid]}" if config[:file_pid]
|
287
|
+
|
288
|
+
if config[:metric]
|
289
|
+
# #YELLOW
|
290
|
+
count = procs.map { |p| p[config[:metric]].to_i }.reduce { |a, b| a + b }
|
291
|
+
msg += "; #{config[:metric]} == #{count}"
|
292
|
+
else
|
293
|
+
count = procs.size
|
294
|
+
end
|
295
|
+
|
296
|
+
# #YELLOW
|
297
|
+
if !!config[:crit_under] && count < config[:crit_under] # rubocop:disable Style/DoubleNegation
|
298
|
+
critical msg
|
299
|
+
# #YELLOW
|
300
|
+
elsif !!config[:crit_over] && count > config[:crit_over] # rubocop:disable Style/DoubleNegation
|
301
|
+
critical msg
|
302
|
+
# #YELLOW
|
303
|
+
elsif !!config[:warn_under] && count < config[:warn_under] # rubocop:disable Style/DoubleNegation
|
304
|
+
warning msg
|
305
|
+
# #YELLOW
|
306
|
+
elsif !!config[:warn_over] && count > config[:warn_over] # rubocop:disable Style/DoubleNegation
|
307
|
+
warning msg
|
308
|
+
else
|
309
|
+
ok msg
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-openbsd/version'
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-openbsd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sensu-Plugins and contributors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sensu-plugin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: english
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.6.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: github-markup
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.5'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: redcarpet
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.2'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.2'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.4'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.4'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.9.11
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.9.11
|
153
|
+
description: This plugin provides common checks for OpenBSD hosts
|
154
|
+
email: "<support@sigterm.no>"
|
155
|
+
executables:
|
156
|
+
- check-ntp.rb
|
157
|
+
- check-process.rb
|
158
|
+
- check-cmd.rb
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- CHANGELOG.md
|
163
|
+
- LICENSE
|
164
|
+
- README.md
|
165
|
+
- bin/check-cmd.rb
|
166
|
+
- bin/check-ntp.rb
|
167
|
+
- bin/check-process.rb
|
168
|
+
- lib/sensu-plugins-openbsd.rb
|
169
|
+
- lib/sensu-plugins-openbsd/version.rb
|
170
|
+
homepage: https://github.com/Sigterm-no/sensu-plugins-openbsd
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata:
|
174
|
+
maintainer: "@mikalv"
|
175
|
+
development_status: active
|
176
|
+
production_status: unstable - testing recommended
|
177
|
+
release_draft: 'false'
|
178
|
+
release_prerelease: 'false'
|
179
|
+
post_install_message: Checks can be expected to find under /usr/local/bin, ensure
|
180
|
+
the sensu user include it to PATH
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 2.0.0
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.7.7
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: Sensu plugins for OpenBSD
|
200
|
+
test_files: []
|