hq-tools 0.3.1 → 0.4.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.
- data/lib/hq/tools/check-script.rb +36 -13
- data/spec/hq/tools/check-script-spec.rb +78 -0
- metadata +4 -2
@@ -13,6 +13,7 @@ class CheckScript
|
|
13
13
|
@critical = false
|
14
14
|
@warning = false
|
15
15
|
@unknown = false
|
16
|
+
@performances = []
|
16
17
|
@postscript = []
|
17
18
|
@stdout = $stdout
|
18
19
|
@stderr = $stderr
|
@@ -48,25 +49,36 @@ class CheckScript
|
|
48
49
|
|
49
50
|
def perform_output
|
50
51
|
|
51
|
-
|
52
|
-
@stdout.puts "#{@name} CRITICAL: #{@messages.join ", "}"
|
53
|
-
@status = 2
|
52
|
+
str = StringIO.new
|
54
53
|
|
55
|
-
|
56
|
-
@stdout.puts "#{@name} WARNING: #{@messages.join ", "}"
|
57
|
-
@status = 1
|
54
|
+
str.print @name, " "
|
58
55
|
|
56
|
+
if @critical
|
57
|
+
str.print "CRITICAL"
|
58
|
+
elsif @warning
|
59
|
+
str.print "WARNING"
|
59
60
|
elsif @unknown
|
60
|
-
|
61
|
-
@status = 3
|
62
|
-
|
61
|
+
str.print "UNKNOWN"
|
63
62
|
else
|
64
|
-
|
65
|
-
@status = 0
|
63
|
+
str.print "OK"
|
66
64
|
end
|
67
65
|
|
68
|
-
|
69
|
-
|
66
|
+
str.print ": "
|
67
|
+
|
68
|
+
str.print @messages.join(", ")
|
69
|
+
|
70
|
+
unless @performances.empty?
|
71
|
+
str.print " | "
|
72
|
+
str.print @performances.join(" ")
|
73
|
+
end
|
74
|
+
|
75
|
+
str.print "\n"
|
76
|
+
|
77
|
+
@stdout.print str.string
|
78
|
+
|
79
|
+
@postscript.each do
|
80
|
+
|postscript|
|
81
|
+
@stderr.puts postscript
|
70
82
|
end
|
71
83
|
|
72
84
|
end
|
@@ -90,6 +102,17 @@ class CheckScript
|
|
90
102
|
@unknown = true
|
91
103
|
end
|
92
104
|
|
105
|
+
def performance name, value, options = {}
|
106
|
+
parts = []
|
107
|
+
parts[0] = "%s%s" % [ value, options[:units] ]
|
108
|
+
parts[1] = options[:warning].to_s if options[:warning]
|
109
|
+
parts[2] = options[:critical].to_s if options[:critical]
|
110
|
+
parts[3] = options[:minimum].to_s if options[:minimum]
|
111
|
+
parts[4] = options[:maximum].to_s if options[:maximum]
|
112
|
+
name = "'#{name.gsub "'", "''"}'" if name.include? "'"
|
113
|
+
@performances << "%s=%s" % [ name, parts.join(";") ]
|
114
|
+
end
|
115
|
+
|
93
116
|
end
|
94
117
|
end
|
95
118
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "hq/tools/check-script"
|
2
|
+
|
3
|
+
module HQ
|
4
|
+
module Tools
|
5
|
+
|
6
|
+
describe CheckScript do
|
7
|
+
|
8
|
+
before do
|
9
|
+
subject.stub(:process_args)
|
10
|
+
subject.stub(:perform_checks)
|
11
|
+
subject.stdout = StringIO.new
|
12
|
+
end
|
13
|
+
|
14
|
+
context "performance data" do
|
15
|
+
|
16
|
+
it "none" do
|
17
|
+
subject.stub(:perform_checks) do
|
18
|
+
subject.message "hello"
|
19
|
+
end
|
20
|
+
subject.main
|
21
|
+
subject.stdout.string.should ==
|
22
|
+
"Unnamed OK: hello\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "single metric" do
|
26
|
+
subject.stub(:perform_checks) do
|
27
|
+
subject.message "hello"
|
28
|
+
subject.performance "metric1", 1
|
29
|
+
end
|
30
|
+
subject.main
|
31
|
+
subject.stdout.string.should ==
|
32
|
+
"Unnamed OK: hello | metric1=1\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "special chars" do
|
36
|
+
subject.stub(:perform_checks) do
|
37
|
+
subject.message "hello"
|
38
|
+
subject.performance "apos'trophe", 1
|
39
|
+
end
|
40
|
+
subject.main
|
41
|
+
subject.stdout.string.should ==
|
42
|
+
"Unnamed OK: hello | 'apos''trophe'=1\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "optional fields" do
|
46
|
+
subject.stub(:perform_checks) do
|
47
|
+
subject.message "hello"
|
48
|
+
subject.performance \
|
49
|
+
"metric1",
|
50
|
+
1,
|
51
|
+
:units => "blops",
|
52
|
+
:warning => 2,
|
53
|
+
:critical => 5,
|
54
|
+
:minimum => 0,
|
55
|
+
:maximum => 10
|
56
|
+
end
|
57
|
+
subject.main
|
58
|
+
subject.stdout.string.should ==
|
59
|
+
"Unnamed OK: hello | metric1=1blops;2;5;0;10\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "two metrics" do
|
63
|
+
subject.stub(:perform_checks) do
|
64
|
+
subject.message "hello"
|
65
|
+
subject.performance "metric1", 1
|
66
|
+
subject.performance "metric2", 5
|
67
|
+
end
|
68
|
+
subject.main
|
69
|
+
subject.stdout.string.should ==
|
70
|
+
"Unnamed OK: hello | metric1=1 metric2=5\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
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.
|
4
|
+
version: 0.4.0
|
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-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/hq/tools/escape.rb
|
103
103
|
- lib/hq/tools/check-script.rb
|
104
104
|
- spec/hq/tools/getopt-spec.rb
|
105
|
+
- spec/hq/tools/check-script-spec.rb
|
105
106
|
homepage: https://github.com/jamespharaoh/hq-tools
|
106
107
|
licenses: []
|
107
108
|
post_install_message:
|
@@ -128,3 +129,4 @@ specification_version: 3
|
|
128
129
|
summary: HQ tools
|
129
130
|
test_files:
|
130
131
|
- spec/hq/tools/getopt-spec.rb
|
132
|
+
- spec/hq/tools/check-script-spec.rb
|