watchmonkey_cli 1.12.1 → 1.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c990a60379408431ec45840429e9ea183cf6723569c6f457384c6564a95e559
4
- data.tar.gz: b788e5f5e2da8999ca9bf7c66b68bf9f86d3efe496da09d2c08a6121b6b49de6
3
+ metadata.gz: eca45a77465ff32cc6166c9c97ae857e411a00020d274154278006d0a3c06cbc
4
+ data.tar.gz: 5468bb0a67d96d3533bdd643ba81555304b9951bee3aa0ef3a63815ad1b1dda2
5
5
  SHA512:
6
- metadata.gz: b135b4d3f834975825617a61333a8aef949f730ecfa06b605ccca2830799fd5943559e4e4db65730d108929e966ed0cc9fa5162ffffb95461e081260ccb50b82
7
- data.tar.gz: 43b5b2cdcd087eb4cf6e06352ed124423136e1b818b7543e1a953ad6b92d3a653744da80ca5d9e2e0fcd32ea2e0a462cf487c5c81ac7569dda84d91b08bd8f78
6
+ metadata.gz: ad691ffdc29b81ca2c07f5a483aea72bc4414932e558b41f0d97ac1be7a5f4664eff6f3c4d8b7d224c45f663c3bafe20c7c05699264c44a49a3585830276e2dd
7
+ data.tar.gz: ec9598dd812eb9da77bc53b9a12e3838b9f161e56a2f93af24188bab336532c0b4b61842aaa350eca27ec9b2461c3a6172dccdaeaba0473274df2449c264f46c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.12.1
1
+ 1.14.0
@@ -1 +1 @@
1
- 4be25f6a1529ae4b0015f42448afe751eaf3f8c10a7402d93c84a454b4496c7768b70267d014352a94b08e9d38de75d31bd758e9c8e811b07730900a4b31b175
1
+ 55896784ac9e3bc3bfe0998cb907cd13721d773860429de292208dffb19bc34f44d9783cb68814842ceabf982531ee8e650560d882e6b0e90dbd52b59b4d18db
@@ -0,0 +1 @@
1
+ 7cf1f0f16532184d11682df569b8c78da903166820e5355275bda41b76519e3bf021d8713cbe916b55f6d8c739b2a9af21136fb3aa0e14126ab7533b74a37de2
@@ -20,6 +20,12 @@ module MyWatchmonkeyCheckers
20
20
  #self.maxrt = 5.minutes
21
21
  #self.maxrt = ->(app, checker, args){ app.opts[:maxrt] && app.opts[:maxrt] * 2 }
22
22
 
23
+ # Maximum amount of time this task may retry on error.
24
+ # Set to proc to evaluate at runtime
25
+ # Defaults to app.opts[:max_retry] if nil/unset
26
+ #self.max_retry = 1
27
+ #self.max_retry = ->(app, checker, args){ app.opts[:max_retry] && app.opts[:max_retry] * 2 }
28
+
23
29
  # Called by configuration defining a check with all the arguments.
24
30
  # e.g. my_checker "http://google.com", some_option: true
25
31
  # Should invoke `app.enqueue` which will by default call `#check!` method with given arguments.
@@ -3,7 +3,7 @@ module WatchmonkeyCli
3
3
  module Core
4
4
  def filtered_threads
5
5
  Thread.list.reject do |thr|
6
- @opts[:filtered_threads].any?{ thr.backtrace[0][_1] }
6
+ @opts[:filtered_threads].any?{ thr.backtrace.first&.include?(_1) }
7
7
  end
8
8
  end
9
9
 
@@ -136,7 +136,9 @@ module WatchmonkeyCli
136
136
  a << taskopts
137
137
 
138
138
  checker.debug(result.str_running)
139
- checker.rsafe(result) {
139
+ max_retry = checker.class.max_retry.nil? ? @opts[:max_retry] : checker.class.max_retry
140
+ max_retry = max_retry.call(self, checker, a) if max_retry.respond_to?(:call)
141
+ checker.rsafe(result, max_retry: max_retry) {
140
142
  timeout = checker.class.maxrt.nil? ? @opts[:maxrt] : checker.class.maxrt
141
143
  timeout = timeout.call(self, checker, a) if timeout.respond_to?(:call)
142
144
  begin
@@ -60,6 +60,7 @@ module WatchmonkeyCli
60
60
  debug: false, # -d flag
61
61
  threads: 10, # -t flag
62
62
  maxrt: 120.seconds, # max runtime of a single task after which it will be terminated (may break SSH connection), 0/false to not limit runtime
63
+ max_retry: 3, # max retry on error for a single task
63
64
  conclosewait: 10, # max seconds to wait for connections to be closed (may never if they got killed by maxrt)
64
65
  loop_forever: false, # (internal) loop forever (app mode)
65
66
  loop_wait_empty: 1, # (internal) time to wait in thread if queue is empty
@@ -25,6 +25,22 @@ module WatchmonkeyCli
25
25
  @maxrt = seconds
26
26
  end
27
27
 
28
+ def self.max_retry
29
+ @max_retry
30
+ end
31
+
32
+ def self.max_retry= num
33
+ @max_retry = num
34
+ end
35
+
36
+ def self.default_options
37
+ @default_options ||= {}
38
+ end
39
+
40
+ def self.default_options= val
41
+ @default_options = val
42
+ end
43
+
28
44
  module AppHelper
29
45
  def init_checkers!
30
46
  @checkers = {}
@@ -118,6 +134,14 @@ module WatchmonkeyCli
118
134
  sync { @type == meth }
119
135
  end
120
136
  end
137
+
138
+ def fatal! msg = nil
139
+ sync do
140
+ @spool[:error] << msg if msg
141
+ @type = :error
142
+ throw(:checker, :fatal)
143
+ end
144
+ end
121
145
  end
122
146
 
123
147
  # -------------------
@@ -177,13 +201,13 @@ module WatchmonkeyCli
177
201
  @app.fetch_connection(:loopback, :local)
178
202
  end
179
203
 
180
- def safe descriptor = nil, &block
204
+ def safe descriptor = nil, max_retry: 3, &block
181
205
  tries = 0
182
206
  begin
183
207
  tries += 1
184
208
  block.call
185
209
  rescue StandardError => e
186
- unless tries > 3
210
+ unless tries > max_retry
187
211
  app.sync do
188
212
  error "#{descriptor}retry #{tries} reason is `#{e.class}: #{e.message}'"
189
213
  e.backtrace.each{|l| debug "\t\t#{l}" }
@@ -197,13 +221,21 @@ module WatchmonkeyCli
197
221
  end
198
222
  end
199
223
 
200
- def rsafe resultobj, &block
224
+ def rsafe resultobj, max_retry: 3, &block
201
225
  tries = 0
226
+ checker_ctrl = false
227
+
202
228
  begin
203
229
  tries += 1
204
- block.call
230
+ checker_ctrl = catch(:checker, &block)
205
231
  rescue StandardError => e
206
- unless tries > 3
232
+ if checker_ctrl == :fatal
233
+ resultobj.sync do
234
+ resultobj.error! "fatal reason is `#{e.class}: #{e.message}'"
235
+ e.backtrace.each{|l| resultobj.debug "\t\t#{l}" }
236
+ resultobj.dump!
237
+ end
238
+ elsif tries <= max_retry
207
239
  resultobj.sync do
208
240
  resultobj.error! "retry #{tries} reason is `#{e.class}: #{e.message}'"
209
241
  e.backtrace.each{|l| resultobj.debug "\t\t#{l}" }
@@ -213,9 +245,10 @@ module WatchmonkeyCli
213
245
  sleep 1
214
246
  retry
215
247
  end
248
+ else
249
+ resultobj.error! "retries exceeded"
250
+ resultobj.dump!
216
251
  end
217
- resultobj.error! "retries exceeded"
218
- resultobj.dump!
219
252
  end
220
253
  end
221
254
 
@@ -5,6 +5,7 @@ module WatchmonkeyCli
5
5
  self.maxrt = false
6
6
 
7
7
  def enqueue host, opts = {}
8
+ opts = {}.merge(self.class.default_options, opts)
8
9
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
10
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
11
  app.enqueue(self, host, opts)
@@ -4,7 +4,7 @@ module WatchmonkeyCli
4
4
  self.checker_name = "ftp_availability"
5
5
 
6
6
  def enqueue host, opts = {}
7
- opts = {}.merge(opts)
7
+ opts = {}.merge(self.class.default_options, opts)
8
8
  app.enqueue(self, host, opts)
9
9
  end
10
10
 
@@ -4,7 +4,11 @@ module WatchmonkeyCli
4
4
  self.checker_name = "mysql_replication"
5
5
 
6
6
  def enqueue host, opts = {}
7
- opts = { host: "127.0.0.1", user: "root", sbm_threshold: 60 }.merge(opts)
7
+ opts = {
8
+ host: "127.0.0.1",
9
+ user: "root",
10
+ sbm_threshold: 60,
11
+ }.merge(self.class.default_options, opts)
8
12
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
13
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
14
  app.enqueue(self, host, opts)
@@ -4,7 +4,11 @@ module WatchmonkeyCli
4
4
  self.checker_name = "ssl_expiration"
5
5
 
6
6
  def enqueue page, opts = {}
7
- opts = { threshold: 28.days, verify: true, timeout: 20 }.merge(opts)
7
+ opts = {
8
+ threshold: 28.days,
9
+ verify: true,
10
+ timeout: 20,
11
+ }.merge(self.class.default_options, opts)
8
12
  app.enqueue(self, page, opts)
9
13
  end
10
14
 
@@ -4,7 +4,10 @@ module WatchmonkeyCli
4
4
  self.checker_name = "tcp_port"
5
5
 
6
6
  def enqueue host, port, opts = {}
7
- opts = { message: "Port #{port} (TCP) is not reachable!", timeout: 2 }.merge(opts)
7
+ opts = {
8
+ message: "Port #{port} (TCP) is not reachable!",
9
+ timeout: 2
10
+ }.merge(self.class.default_options, opts)
8
11
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
12
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
13
  app.enqueue(self, host, port, opts)
@@ -4,7 +4,9 @@ module WatchmonkeyCli
4
4
  self.checker_name = "ts3_license"
5
5
 
6
6
  def enqueue host, file, opts = {}
7
- opts = { threshold: 1.months }.merge(opts)
7
+ opts = {
8
+ threshold: 1.month,
9
+ }.merge(self.class.default_options, opts)
8
10
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
11
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
12
  app.enqueue(self, host, file, opts)
@@ -4,7 +4,10 @@ module WatchmonkeyCli
4
4
  self.checker_name = "udp_port"
5
5
 
6
6
  def enqueue host, port, opts = {}
7
- opts = { message: "Port #{port} (UDP) is not reachable!", timeout: 2 }.merge(opts)
7
+ opts = {
8
+ message: "Port #{port} (UDP) is not reachable!",
9
+ timeout: 2,
10
+ }.merge(self.class.default_options, opts)
8
11
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
12
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
13
  app.enqueue(self, host, port, opts)
@@ -4,7 +4,9 @@ module WatchmonkeyCli
4
4
  self.checker_name = "unix_cpu_governor"
5
5
 
6
6
  def enqueue host, opts = {}
7
- opts = { expect: "performance" }.merge(opts)
7
+ opts = {
8
+ expect: "performance",
9
+ }.merge(self.class.default_options, opts)
8
10
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
11
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
12
  app.enqueue(self, host, opts)
@@ -5,7 +5,13 @@ module WatchmonkeyCli
5
5
 
6
6
  def enqueue host, opts = {}
7
7
  return if app.running? # we only ever want to run this once to spawn sub checkers
8
- opts = { unix_load: {}, unix_memory: {}, unix_df: {}, unix_mdadm: {}, unix_cpu_governor: {} }.merge(opts)
8
+ opts = {
9
+ unix_load: {},
10
+ unix_memory: {},
11
+ unix_df: {},
12
+ unix_mdadm: {},
13
+ unix_cpu_governor: {},
14
+ }.merge(self.class.default_options, opts)
9
15
 
10
16
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
11
17
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
@@ -4,7 +4,9 @@ module WatchmonkeyCli
4
4
  self.checker_name = "unix_df"
5
5
 
6
6
  def enqueue host, opts = {}
7
- opts = { min_percent: 25 }.merge(opts)
7
+ opts = {
8
+ min_percent: 25,
9
+ }.merge(self.class.default_options, opts)
8
10
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
11
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
12
  app.enqueue(self, host, opts)
@@ -4,7 +4,9 @@ module WatchmonkeyCli
4
4
  self.checker_name = "unix_file_exists"
5
5
 
6
6
  def enqueue host, file, opts = {}
7
- opts = { message: "File #{file} does not exist!" }.merge(opts)
7
+ opts = {
8
+ message: "File #{file} does not exist!",
9
+ }.merge(self.class.default_options, opts)
8
10
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
11
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
12
  app.enqueue(self, host, file, opts)
@@ -4,7 +4,9 @@ module WatchmonkeyCli
4
4
  self.checker_name = "unix_load"
5
5
 
6
6
  def enqueue host, opts = {}
7
- opts = { limits: [4, 2, 1.5] }.merge(opts)
7
+ opts = {
8
+ limits: [4, 2, 1.5],
9
+ }.merge(self.class.default_options, opts)
8
10
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
11
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
12
  app.enqueue(self, host, opts)
@@ -4,7 +4,9 @@ module WatchmonkeyCli
4
4
  self.checker_name = "unix_mdadm"
5
5
 
6
6
  def enqueue host, opts = {}
7
- opts = { log_checking: true }.merge(opts)
7
+ opts = {
8
+ log_checking: true,
9
+ }.merge(self.class.default_options, opts)
8
10
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
11
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
12
  app.enqueue(self, host, opts)
@@ -4,7 +4,9 @@ module WatchmonkeyCli
4
4
  self.checker_name = "unix_memory"
5
5
 
6
6
  def enqueue host, opts = {}
7
- opts = { min_percent: 25 }.merge(opts)
7
+ opts = {
8
+ min_percent: 25,
9
+ }.merge(self.class.default_options, opts)
8
10
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
11
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
12
  app.enqueue(self, host, opts)
@@ -29,7 +31,7 @@ module WatchmonkeyCli
29
31
  chunks = line.split(":").map(&:strip)
30
32
  r[chunks[0]] = chunks[1].to_i
31
33
  end
32
- r["free"] = ((r["MemFree"].to_i + r["Buffers"].to_i + r["Cached"].to_i) / r["MemTotal"].to_f * 100).round(2)
34
+ r["free"] = (r["MemAvailable"].to_i / r["MemTotal"].to_f * 100).round(2)
33
35
  end
34
36
  end
35
37
  end
@@ -1,4 +1,4 @@
1
1
  module WatchmonkeyCli
2
- VERSION = "1.12.1"
2
+ VERSION = "1.14.0"
3
3
  UPDATE_URL = "https://raw.githubusercontent.com/2called-chaos/watchmonkey_cli/master/VERSION"
4
4
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = WatchmonkeyCli::VERSION
9
9
  spec.authors = ["Sven Pachnit"]
10
10
  spec.email = ["sven@bmonkeys.net"]
11
- spec.summary = %q{Watchmonkey CLI - dead simple agentless monitoring via SSH, HTTP, FTP, etc}
11
+ spec.summary = %q{Watchmonkey CLI - dead simple agentless monitoring via SSH, HTTP, FTP, etc.}
12
12
  spec.description = %q{If you want an easy way to monitor services without the need of installing agents let a monkey do the job by polling status information via transport protocols.}
13
13
  spec.homepage = "https://github.com/2called-chaos/watchmonkey_cli"
14
14
  spec.license = "MIT"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchmonkey_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.1
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Pachnit
@@ -70,6 +70,7 @@ files:
70
70
  - bin/watchmonkey
71
71
  - bin/watchmonkey.sh
72
72
  - checksums/watchmonkey_cli-1.12.1.gem.sha512
73
+ - checksums/watchmonkey_cli-1.13.0.gem.sha512
73
74
  - doc/checker_example.rb
74
75
  - doc/config_example.rb
75
76
  - lib/watchmonkey_cli.rb
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubygems_version: 4.0.5
126
+ rubygems_version: 4.0.22
126
127
  specification_version: 4
127
- summary: Watchmonkey CLI - dead simple agentless monitoring via SSH, HTTP, FTP, etc
128
+ summary: Watchmonkey CLI - dead simple agentless monitoring via SSH, HTTP, FTP, etc.
128
129
  test_files: []