hq-tools 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hq/tools/check-script.rb +95 -0
- metadata +3 -2
@@ -0,0 +1,95 @@
|
|
1
|
+
module HQ
|
2
|
+
module Tools
|
3
|
+
class CheckScript
|
4
|
+
|
5
|
+
attr_accessor :args
|
6
|
+
attr_accessor :status
|
7
|
+
attr_accessor :stdout
|
8
|
+
attr_accessor :stderr
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@name = "Unnamed"
|
12
|
+
@messages = []
|
13
|
+
@critical = false
|
14
|
+
@warning = false
|
15
|
+
@unknown = false
|
16
|
+
@postscript = []
|
17
|
+
@stdout = $stdout
|
18
|
+
@stderr = $stderr
|
19
|
+
end
|
20
|
+
|
21
|
+
def main
|
22
|
+
|
23
|
+
process_args
|
24
|
+
|
25
|
+
begin
|
26
|
+
prepare
|
27
|
+
perform_checks
|
28
|
+
rescue => exception
|
29
|
+
|
30
|
+
message = "%s: %s" % [
|
31
|
+
exception.class,
|
32
|
+
exception.message,
|
33
|
+
]
|
34
|
+
|
35
|
+
critical message
|
36
|
+
|
37
|
+
@postscript << message
|
38
|
+
@postscript << exception.backtrace
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
perform_output
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def prepare
|
47
|
+
end
|
48
|
+
|
49
|
+
def perform_output
|
50
|
+
|
51
|
+
if @critical
|
52
|
+
@stdout.puts "#{@name} CRITICAL: #{@messages.join ", "}"
|
53
|
+
@status = 2
|
54
|
+
|
55
|
+
elsif @warning
|
56
|
+
@stdout.puts "#{@name} WARNING: #{@messages.join ", "}"
|
57
|
+
@status = 1
|
58
|
+
|
59
|
+
elsif @unknown
|
60
|
+
@stdout.puts "#{@name} UNKNOWN: #{@messages.join ", "}"
|
61
|
+
@status = 3
|
62
|
+
|
63
|
+
else
|
64
|
+
@stdout.puts "#{@name} OK: #{@messages.join ", "}"
|
65
|
+
@status = 0
|
66
|
+
end
|
67
|
+
|
68
|
+
@postscript.each do |ps|
|
69
|
+
@stderr.puts ps
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def message string
|
75
|
+
@messages << string
|
76
|
+
end
|
77
|
+
|
78
|
+
def critical string
|
79
|
+
@messages << string
|
80
|
+
@critical = true
|
81
|
+
end
|
82
|
+
|
83
|
+
def warning string
|
84
|
+
@messages << string
|
85
|
+
@warning = true
|
86
|
+
end
|
87
|
+
|
88
|
+
def unknown string
|
89
|
+
@messages << string
|
90
|
+
@unknown = true
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hq-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|
@@ -100,6 +100,7 @@ extra_rdoc_files: []
|
|
100
100
|
files:
|
101
101
|
- lib/hq/tools/getopt.rb
|
102
102
|
- lib/hq/tools/escape.rb
|
103
|
+
- lib/hq/tools/check-script.rb
|
103
104
|
- spec/hq/tools/getopt-spec.rb
|
104
105
|
homepage: https://github.com/jamespharaoh/hq-tools
|
105
106
|
licenses: []
|