Class: WatchmonkeyCli::Checkers::Ts3License
Constant Summary
Constants included
from Helper
Helper::BYTE_UNITS
Instance Attribute Summary
#app
Instance Method Summary
collapse
#_tolog, #blank_config, checker_name, checker_name=, #debug, descendants, #error, #info, inherited, #init, #initialize, #local, maxrt, maxrt=, #rsafe, #safe, #spawn_sub, #start, #stop
Methods included from Helper
#human_filesize, #human_number, #human_seconds
Instance Method Details
#_parse_response(res) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/watchmonkey_cli/checkers/ts3_license.rb', line 51
def _parse_response res
{}.tap do |r|
lines = res.split("\n")
reached_key = false
lines.each do |l|
next if l.blank?
if l[":"]
c = l.split(":", 2)
r[c[0].strip] = c[1].strip
elsif l["==key=="]
reached_key = true
elsif reached_key
r["key"] ||= ""
r["key"] += l
end
end
end
end
|
#check!(result, host, file, opts = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/watchmonkey_cli/checkers/ts3_license.rb', line 13
def check! result, host, file, opts = {}
result.command = "cat #{Shellwords.escape(file)}"
result.result = host.exec(result.command).force_encoding('UTF-8')
if result.result.downcase["no such file"]
result.error! "Failed to read file #{file} (#{result.result})"
else
result.data = _parse_response(result.result)
start_at = zone_parse "UTC", result.data["start date"]
end_at = zone_parse "UTC", result.data["end date"]
if start_at > Time.current
result.error! "TS3 license is not yet valid (will in #{human_seconds(start_at - Time.current)}, #{start_at})!"
return
end
if end_at <= Time.current
result.error! "TS3 license is EXPIRED (since #{human_seconds(end_at - Time.current)}, #{end_at})!"
return
end
if end_at <= Time.current + opts[:threshold]
result.error! "TS3 license is about to expire within threshold (in #{human_seconds(end_at - Time.current)}, #{end_at})!"
return
else
result.info! "TS3 license expires in #{human_seconds(end_at - Time.current)} (#{end_at})!"
end
end
end
|
#enqueue(host, file, opts = {}) ⇒ Object
6
7
8
9
10
11
|
# File 'lib/watchmonkey_cli/checkers/ts3_license.rb', line 6
def enqueue host, file, opts = {}
opts = { threshold: 1.months }.merge(opts)
host = app.fetch_connection(:loopback, :local) if !host || host == :local
host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
app.enqueue(self, host, file, opts)
end
|
#zone_parse(tz, date) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/watchmonkey_cli/checkers/ts3_license.rb', line 43
def zone_parse tz, date
tz_was = Time.zone
Time.zone = "UTC"
Time.zone.parse(date)
ensure
Time.zone = tz_was
end
|