hq-check-misc 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ name = ARGV[0]
4
+ states = (ARGV[1] || "").split(",").map { |state| state.to_i }
5
+
6
+ num_ok = states.count { |state| state == 0 }
7
+ num_warning = states.count { |state| state == 1 }
8
+ num_critical = states.count { |state| state == 2 }
9
+ num_unknown = states.count { |state| state == 3 }
10
+
11
+ message = [
12
+ num_critical > 0 ? "#{num_critical} critical" : nil,
13
+ num_warning > 0 ? "#{num_warning} warning" : nil,
14
+ num_unknown > 0 ? "#{num_unknown} unknown" : nil,
15
+ "#{num_ok} ok",
16
+ ].select { |message| message }.join(", ")
17
+
18
+ status = case
19
+ when num_critical > 0 then 2
20
+ when num_warning > 0 then 1
21
+ when num_unknown > 0 then 3
22
+ else 0
23
+ end
24
+
25
+ status_name = [ "OK", "WARNING", "CRITICAL", "UNKNOWN" ][status]
26
+
27
+ puts "#{name} #{status_name}: #{message}"
28
+
29
+ exit status
@@ -0,0 +1,29 @@
1
+ Feature: Check multiple states
2
+
3
+ Scenario: All ok
4
+
5
+ When I run check-multi "name 0,0,0,0"
6
+
7
+ Then the exit status is 0
8
+ And the message is "name OK: 4 ok"
9
+
10
+ Scenario: Some unknown
11
+
12
+ When I run check-multi "name 0,0,0,3"
13
+
14
+ Then the exit status is 3
15
+ And the message is "name UNKNOWN: 1 unknown, 3 ok"
16
+
17
+ Scenario: Some warning
18
+
19
+ When I run check-multi "name 0,1,0,3"
20
+
21
+ Then the exit status is 1
22
+ And the message is "name WARNING: 1 warning, 1 unknown, 2 ok"
23
+
24
+ Scenario: Some critical
25
+
26
+ When I run check-multi "name 0,1,2,3"
27
+
28
+ Then the exit status is 2
29
+ And the message is "name CRITICAL: 1 critical, 1 warning, 1 unknown, 1 ok"
File without changes
@@ -0,0 +1,24 @@
1
+ When /^I run check\-multi "(.*?)"$/ do
2
+ |args_str|
3
+
4
+ @message = `bundle exec hq-check-multi #{args_str}`.strip
5
+
6
+ @status = $?.exitstatus
7
+
8
+ end
9
+
10
+ Then /^the exit status is (\d+)$/ do
11
+ |status_str|
12
+
13
+ status = status_str.to_i
14
+
15
+ @status.should == status
16
+
17
+ end
18
+
19
+ Then /^the message is "(.*?)"$/ do
20
+ |message|
21
+
22
+ @message.should == message
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hq-check-misc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Pharaoh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.2.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.12.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec_junit_formatter
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: HQ miscellaneous check scripts
95
+ email:
96
+ - james@phsys.co.uk
97
+ executables:
98
+ - hq-check-multi
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - features/check-multi.feature
103
+ - features/support/steps.rb
104
+ - features/support/env.rb
105
+ - bin/hq-check-multi
106
+ homepage: https://github.com/jamespharaoh/hq-check-misc
107
+ licenses: []
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: 1.3.6
124
+ requirements: []
125
+ rubyforge_project: hq-check-misc
126
+ rubygems_version: 1.8.23
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: HQ check misc
130
+ test_files:
131
+ - features/check-multi.feature
132
+ - features/support/steps.rb
133
+ - features/support/env.rb