watchmonkey_cli 1.6 → 1.7

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
  SHA1:
3
- metadata.gz: c8e8b3281a2641174927f13de6f09d0bf2c35988
4
- data.tar.gz: 1dbd8ec4d401dae1651fae131a874381242365f6
3
+ metadata.gz: 312311aaf04df5cc1d42249ec5202c0e01a35ef6
4
+ data.tar.gz: b1e0f912c416b626a876d16663fa466e75bb9b7d
5
5
  SHA512:
6
- metadata.gz: 41cffe415bdb00af10d9ee99ce1a5a59db0f9fa989c2938eefb329c378f4b16687774713946a82b02e4b44c23f6a48187f942ed96ace18a992f235ea58935ba1
7
- data.tar.gz: 6be8aa148f2a41b3a4766e34ed02f9192d6591aa7486c49250190adced0e3546b1dfb4b7b898a098741d82ff089622541743ab4ddb4d8104c4933741c3d552c1
6
+ metadata.gz: 1fb4acc683cbe5fc57b3bc37034f0c5f8e2b339aad8d21e226d2adefe07c1e560f7484d69073fb3e951ab09d61f58f502a3b0b37607a1ec0158ca7195df315d8
7
+ data.tar.gz: 3f9b86d3acb7956be9b9cef6dceddbf2d2aa63c730139f4d7e1b760e8a39837e54bbf009e45a19f04a3ac297983a816dc35a9519396993835cfe3f8d39cb3c14
data/README.md CHANGED
@@ -18,7 +18,7 @@ If you need help or have problems [open an issue](https://github.com/2called-cha
18
18
  ## Features
19
19
  * Monitor external resources (Web, FTP, Server health via SSH)
20
20
  * Run once or loop forever with ReQueue (define intervals globally, per checker or per single test)
21
- * Includes a selection of buildin checkers (basic *nix health, WWW availability & SSL expiration, FTP)
21
+ * Includes a selection of buildin checkers (see [list](https://github.com/2called-chaos/watchmonkey_cli/tree/master/lib/watchmonkey_cli/checkers) or [config template](https://github.com/2called-chaos/watchmonkey_cli/blob/master/lib/watchmonkey_cli/application/configuration.tpl))
22
22
 
23
23
 
24
24
  ## Requirements
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6
1
+ 1.7
@@ -25,13 +25,13 @@ module WatchmonkeyCli
25
25
  def config_files
26
26
  Dir["#{config_directory}/**/*.rb"].reject do |file|
27
27
  file.gsub(config_directory, "").split("/").any?{|fp| fp.start_with?("__") }
28
- end
28
+ end.sort
29
29
  end
30
30
 
31
31
  def checker_files
32
32
  Dir["#{checker_directory}/**/*.rb"].reject do |file|
33
33
  file.gsub(config_directory, "").split("/").any?{|fp| fp.start_with?("__") }
34
- end
34
+ end.sort
35
35
  end
36
36
 
37
37
  def load_configs!
@@ -67,6 +67,13 @@ www_availability "https://example.com", ssl_expiration: { threshold: 4.weeks }
67
67
  ftp_availability "ftp.example.com", user: "somebody", password: "thatiusedtoknow"
68
68
 
69
69
 
70
+ # -----
71
+ # TeamSpeak3 license expiration
72
+ # -----
73
+ # Checks ts3 license file for expiration. Default threshold is 1.month
74
+ ts3_license :my_server, "/path/to/licensekey.dat", threshold: 1.month
75
+
76
+
70
77
  # -----
71
78
  # MySQL replication
72
79
  # -----
@@ -10,11 +10,16 @@ module WatchmonkeyCli
10
10
  $wm_runtime_exiting = true
11
11
  Kernel.puts "Interrupting..."
12
12
  end
13
+ Signal.trap("TERM") do
14
+ $wm_runtime_exiting = true
15
+ Kernel.puts "Terminating..."
16
+ end
13
17
  end
14
18
 
15
19
  def release_signals
16
20
  debug "Releasing INT signal..."
17
21
  Signal.trap("INT", "DEFAULT")
22
+ Signal.trap("TERM", "DEFAULT")
18
23
  end
19
24
 
20
25
  def haltpoint
@@ -106,6 +106,7 @@ module WatchmonkeyCli
106
106
 
107
107
  # -------------------
108
108
 
109
+ include Helper
109
110
  attr_reader :app
110
111
 
111
112
  def initialize app
@@ -19,65 +19,22 @@ module WatchmonkeyCli
19
19
  end
20
20
 
21
21
  if cert.not_before > Time.current
22
- result.error! "Certificate is not yet valid (will in #{fseconds(cert.not_before - Time.current)}, #{cert.not_before})!"
22
+ result.error! "Certificate is not yet valid (will in #{human_seconds(cert.not_before - Time.current)}, #{cert.not_before})!"
23
23
  return
24
24
  end
25
25
 
26
26
  if cert.not_after <= Time.current
27
- result.error! "Certificate is EXPIRED (since #{fseconds(cert.not_after - Time.current)}, #{cert.not_after})!"
27
+ result.error! "Certificate is EXPIRED (since #{human_seconds(cert.not_after - Time.current)}, #{cert.not_after})!"
28
28
  return
29
29
  end
30
30
 
31
31
  if cert.not_after <= Time.current + opts[:threshold]
32
- result.error! "Certificate is about to expire within threshold (in #{fseconds(cert.not_after - Time.current)}, #{cert.not_after})!"
32
+ result.error! "Certificate is about to expire within threshold (in #{human_seconds(cert.not_after - Time.current)}, #{cert.not_after})!"
33
33
  return
34
34
  else
35
- result.info! "Certificate for `#{page}' expires in #{fseconds(cert.not_after - Time.current)} (#{cert.not_after})!"
35
+ result.info! "Certificate for `#{page}' expires in #{human_seconds(cert.not_after - Time.current)} (#{cert.not_after})!"
36
36
  end
37
37
  end
38
-
39
- def fseconds secs
40
- secs = secs.to_i
41
- t_minute = 60
42
- t_hour = t_minute * 60
43
- t_day = t_hour * 24
44
- t_week = t_day * 7
45
- t_month = t_day * 30
46
- t_year = t_month * 12
47
- "".tap do |r|
48
- if secs >= t_year
49
- r << "#{secs / t_year}y "
50
- secs = secs % t_year
51
- end
52
-
53
- if secs >= t_month
54
- r << "#{secs / t_month}m "
55
- secs = secs % t_month
56
- end
57
-
58
- if secs >= t_week
59
- r << "#{secs / t_week}w "
60
- secs = secs % t_week
61
- end
62
-
63
- if secs >= t_day || !r.blank?
64
- r << "#{secs / t_day}d "
65
- secs = secs % t_day
66
- end
67
-
68
- if secs >= t_hour || !r.blank?
69
- r << "#{secs / t_hour}h "
70
- secs = secs % t_hour
71
- end
72
-
73
- if secs >= t_minute || !r.blank?
74
- r << "#{secs / t_minute}m "
75
- secs = secs % t_minute
76
- end
77
-
78
- r << "#{secs}s" unless r.include?("d")
79
- end.strip
80
- end
81
38
  end
82
39
  end
83
40
  end
@@ -0,0 +1,69 @@
1
+ module WatchmonkeyCliCustom
2
+ class Ts3License < WatchmonkeyCli::Checker
3
+ self.checker_name = "ts3_license"
4
+
5
+ def enqueue host, file, opts = {}
6
+ opts = { threshold: 1.months }.merge(opts)
7
+ host = app.fetch_connection(:loopback, :local) if !host || host == :local
8
+ host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
9
+ app.enqueue(self, host, file, opts)
10
+ end
11
+
12
+ def check! result, host, file, opts = {}
13
+ result.command = "cat #{Shellwords.escape(file)}"
14
+ result.result = host.exec(result.command).force_encoding('UTF-8')
15
+
16
+ if result.result.downcase["no such file"]
17
+ result.error! "Failed to read file #{file} (#{result.result})"
18
+ else
19
+ result.data = _parse_response(result.result)
20
+ start_at = zone_parse "UTC", result.data["start date"]
21
+ end_at = zone_parse "UTC", result.data["end date"]
22
+
23
+ if start_at > Time.current
24
+ result.error! "TS3 license is not yet valid (will in #{human_seconds(start_at - Time.current)}, #{start_at})!"
25
+ return
26
+ end
27
+
28
+ if end_at <= Time.current
29
+ result.error! "TS3 license is EXPIRED (since #{human_seconds(end_at - Time.current)}, #{end_at})!"
30
+ return
31
+ end
32
+
33
+ if end_at <= Time.current + opts[:threshold]
34
+ result.error! "TS3 license is about to expire within threshold (in #{human_seconds(end_at - Time.current)}, #{end_at})!"
35
+ return
36
+ else
37
+ result.info! "TS3 license for `#{page}' expires in #{human_seconds(end_at - Time.current)} (#{end_at})!"
38
+ end
39
+ end
40
+ end
41
+
42
+ def zone_parse tz, date
43
+ tz_was = Time.zone
44
+ Time.zone = "UTC"
45
+ Time.zone.parse(date)
46
+ ensure
47
+ Time.zone = tz_was
48
+ end
49
+
50
+ def _parse_response res
51
+ {}.tap do |r|
52
+ lines = res.split("\n")
53
+ reached_key = false
54
+ lines.each do |l|
55
+ next if l.blank?
56
+ if l[":"]
57
+ c = l.split(":", 2)
58
+ r[c[0].strip] = c[1].strip
59
+ elsif l["==key=="]
60
+ reached_key = true
61
+ elsif reached_key
62
+ r["key"] ||= ""
63
+ r["key"] += l
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -11,9 +11,8 @@ module WatchmonkeyCli
11
11
  end
12
12
 
13
13
  def check! result, host, file, opts = {}
14
- descriptor = "[#{self.class.checker_name} | #{host} | #{file} | #{opts}]\n\t"
15
14
  if host.is_a?(WatchmonkeyCli::LoopbackConnection)
16
- result.error! "#{descriptor}#{opts[:message]} (ENOENT)" if !File.exist?(file)
15
+ result.error! "#{opts[:message]} (ENOENT)" if !File.exist?(file)
17
16
  else
18
17
  result.command = "test -f #{Shellwords.escape(file)} && echo exists"
19
18
  result.result = host.exec(result.command)
@@ -15,5 +15,48 @@ module WatchmonkeyCli
15
15
  def human_number(n)
16
16
  n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
17
17
  end
18
+
19
+ def human_seconds secs
20
+ secs = secs.to_i
21
+ t_minute = 60
22
+ t_hour = t_minute * 60
23
+ t_day = t_hour * 24
24
+ t_week = t_day * 7
25
+ t_month = t_day * 30
26
+ t_year = t_month * 12
27
+ "".tap do |r|
28
+ if secs >= t_year
29
+ r << "#{secs / t_year}y "
30
+ secs = secs % t_year
31
+ end
32
+
33
+ if secs >= t_month
34
+ r << "#{secs / t_month}m "
35
+ secs = secs % t_month
36
+ end
37
+
38
+ if secs >= t_week
39
+ r << "#{secs / t_week}w "
40
+ secs = secs % t_week
41
+ end
42
+
43
+ if secs >= t_day || !r.blank?
44
+ r << "#{secs / t_day}d "
45
+ secs = secs % t_day
46
+ end
47
+
48
+ if secs >= t_hour || !r.blank?
49
+ r << "#{secs / t_hour}h "
50
+ secs = secs % t_hour
51
+ end
52
+
53
+ if secs >= t_minute || !r.blank?
54
+ r << "#{secs / t_minute}m "
55
+ secs = secs % t_minute
56
+ end
57
+
58
+ r << "#{secs}s" unless r.include?("d")
59
+ end.strip
60
+ end
18
61
  end
19
62
  end
@@ -14,7 +14,6 @@ module WatchmonkeyCli
14
14
  opts = opts.reverse_merge(notifications: 1, progress: true, html: false, draw_delay: 1)
15
15
  opts[:progress] = false if opts[:html]
16
16
  app.instance_eval do
17
- @opts[:stdout] = SilentOutput.new
18
17
  @platypus_status_cache = {
19
18
  errors: [],
20
19
  }
@@ -53,6 +52,8 @@ module WatchmonkeyCli
53
52
 
54
53
  # HTML output (fancy as fuck!)
55
54
  if opts[:html]
55
+ @opts[:stdout] = SilentOutput.new
56
+
56
57
  def escape_javascript str
57
58
  str.gsub(/(\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u) {|match| JS_ESCAPE_MAP[match] }
58
59
  end
@@ -16,6 +16,7 @@ module WatchmonkeyCli
16
16
  # @opts[:default_requeue_ftp_availability] = 60
17
17
  @opts[:default_requeue_mysql_replication] = 30
18
18
  @opts[:default_requeue_ssl_expiration] = 1.hour
19
+ @opts[:default_requeue_ts3_license] = 1.hour
19
20
  @opts[:default_requeue_unix_defaults] = false
20
21
  # @opts[:default_requeue_unix_df] = 60
21
22
  # @opts[:default_requeue_unix_file_exists] = 60
@@ -1,4 +1,4 @@
1
1
  module WatchmonkeyCli
2
- VERSION = "1.6"
2
+ VERSION = "1.7"
3
3
  UPDATE_URL = "https://raw.githubusercontent.com/2called-chaos/watchmonkey_cli/master/VERSION"
4
4
  end
@@ -13,6 +13,7 @@ require 'net/https'
13
13
  # 3rd party
14
14
  require "active_support"
15
15
  require "active_support/core_ext"
16
+ require "active_support/time_with_zone"
16
17
  begin ; require "pry" ; rescue LoadError ; end
17
18
  require "httparty"
18
19
  require 'net/ssh'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchmonkey_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.6'
4
+ version: '1.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Pachnit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-29 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -126,6 +126,7 @@ files:
126
126
  - lib/watchmonkey_cli/checkers/ftp_availability.rb
127
127
  - lib/watchmonkey_cli/checkers/mysql_replication.rb
128
128
  - lib/watchmonkey_cli/checkers/ssl_expiration.rb
129
+ - lib/watchmonkey_cli/checkers/ts3_license.rb
129
130
  - lib/watchmonkey_cli/checkers/unix_defaults.rb
130
131
  - lib/watchmonkey_cli/checkers/unix_df.rb
131
132
  - lib/watchmonkey_cli/checkers/unix_file_exists.rb