nagios_output 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56ebd9834f69026b161b769f7fbd32fac374017bd88673aa2549807a49962b76
4
- data.tar.gz: 3ad6ac12234a3c829bd8dad2868d38e4c3593b364c71579e837bfc11c053ab9c
3
+ metadata.gz: 4172f5d8746d3b5e1e9e087d4831a7906f3e8cb1496fc93ebe5b47c5089b776d
4
+ data.tar.gz: 11b3228d492c3815cbd91543e29ee457a81aae0d62d528079068136a873f0c17
5
5
  SHA512:
6
- metadata.gz: '09021e4e4f59cace6ed07ac74bc99f35c5a9c72bd173a14849b42109a889ef20538951ae6c6cec2419ffd5cbddda06341ff798c64dd5016bc3eb071440d48a77'
7
- data.tar.gz: 86f2c2265967cc491110397a90cb729edd486cf719fb488d8ae838ec6571b517366f7c65e487034ec30c7c5972945d02da0ee8784063db39b921e96004d49e64
6
+ metadata.gz: d7158efab6d70fdb0c65b56c562d444790d40af3987bd2d0cdcd8d3eb2645b98aa0d7d693c67899b2037acb708c11c1edc879e09c4b05da5f89d67ababb8db1d
7
+ data.tar.gz: 5e44474adf8eb041d28661e56bc05c866df4d19fb808caeff7c82c0d444314f64767c14a872dda2923ae5c45fe5c8522e70d94fed37bf1878bb8fd2c37c16edf
@@ -30,7 +30,5 @@ matrix:
30
30
  - ./travis/awesomebot/scan.sh
31
31
  notifications:
32
32
  email: false
33
- slack:
34
- notifications:
35
33
  slack:
36
34
  secure: N7+MOIX567Z2E2eyKaLngafy8QeJ4uvgWkWhp7nEWTbw989namVeymljYrNLSuykVgX6rn0Wq95LUPm0uUuRawULzMgzFv0wIMcbbbX+4ZAuEUvWxHWCGo8qfins15Px9EgkT/UrYYblywYlwelQHOu++MkxyQ9mHwypKS4z5IyzW/mwFoZ+HKQCOqYw8TrR7aHGSpe9PUVK9Lj2XXmK1QaaBW7GabW6ugmHMbL46xhxMdBBpJfotRbwdHnyKXPfrhSbj95+tZxY1NY33ZOBdgiQDuOYpkA51GObBUZ4TKwhQS3OX0pp490QvJBR0Jf84waF7sMBx1E03haPgFwNiLayvtA8YkpJBJTOaVhCc6i504r9Sf3ZBBdjVULLG0W1hGZuhXZrsrTE6IyTomIjifmA1L795CRgLAPyecqAVf2Z2JQlN48Pt7TbGEUWXxUlCSlen45B4XBZaNoqX02AzugcztqEdqdAAe6mga0bHwjrzErkAxUXP4u9GyTKCy8FV8KEg6k//g0TLkQzaFM1p521TBMI9AsGwO4OvE0mXq3sRK5wJ1ojQCleINP6ijAg0F186DzD4l8Uj22K44IidSa4P9rxRM2drMttNscNGfFddBbcG8isLTVoldsZHvzMa90lVe86xtiGo2/Kjt7g490pvMRXOf2XzEG3yy3nec8=
@@ -1,3 +1,13 @@
1
+ ## 2.0.0 (January 25, 2019)
2
+
3
+ IMPROVEMENTS:
4
+
5
+ * Move the code inside of a module namespace. ([@TGWolf][])
6
+ * Extend the string class so that str.ok, str.warn, str.critical and str.unknown works. ([@TGWolf][])
7
+ * Extend the integer class so that str.ok, str.warn, str.critical and str.unknown works. ([@TGWolf][])
8
+ * Update the documentation. ([@TGWolf][])
9
+ * Removed the old static and global access methods as they were a hack. ([@TGWolf][])
10
+
1
11
  ## 1.0.0 (January 18, 2019)
2
12
 
3
13
  * Initial Release ([@TGWolf][])
data/README.md CHANGED
@@ -28,43 +28,85 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage
30
30
 
31
- There are 3 different ways to access the 4 nagios output methods. Those methods are ok, warning, critical and unknown, they have the following spective exit codes 0, 1, 2 and 3.
31
+ ### OK Messages
32
32
 
33
- ### Class Method
33
+ ```ruby
34
+ require 'nagios_output'
35
+
36
+ NagiosOutput::Nagios.ok('Everything is ok')
37
+
38
+ # or
39
+
40
+ 'Everything is ok'.nagios_ok
41
+ ```
42
+
43
+ ### Warning Messages
44
+
45
+ ```ruby
46
+ require 'nagios_output'
47
+
48
+ NagiosOutput::Nagios.warning('This is a warning')
49
+
50
+ # or
51
+
52
+ 'This is a warning'.nagios_warning
53
+ ```
54
+
55
+ ### Critical Messages
34
56
 
35
57
  ```ruby
36
- require 'nagios_output'
58
+ require 'nagios_output'
37
59
 
38
- n = NagiosOutput.new
39
- n.ok('Everything is ok (Class))')
40
- n.warning('Everything is ok-ish (Class)')
41
- n.critical('Everything is cirtial (Class)')
42
- n.unknown('Everything is erm - I don\'t know (Class)')
60
+ NagiosOutput::Nagios.critical('Everything is on fire')
61
+
62
+ # or
63
+
64
+ 'Everything is on fire'.nagios_critical
43
65
  ```
44
66
 
45
- ### Static Method
67
+ ### Unknown Messages
46
68
 
47
69
  ```ruby
48
- require 'nagios_output'
70
+ require 'nagios_output'
71
+
72
+ NagiosOutput::Nagios.unknown('Everything is erm...')
73
+
74
+ # or
49
75
 
50
- NagiosOutputStatic.ok('Everything is ok (Static)')
51
- NagiosOutputStatic.warning('Everything is ok-ish (Static)')
52
- NagiosOutputStatic.critical('Everything is cirtial (Static)')
53
- NagiosOutputStatic.unknown('Everything is erm - I don\'t know (Static)')
76
+ 'Everything is erm...'.nagios_unknown
54
77
  ```
55
78
 
56
- ### Direct Method
79
+ ## Colours
80
+
81
+ By default output is coloured however this can be turned off (or back on)
57
82
 
58
83
  ```ruby
59
- require 'nagios_output'
84
+ require 'nagios_output'
85
+
86
+ NagiosOutput::Nagios.use_colour(false)
87
+
88
+ # or
60
89
 
61
- ok('Everything is ok (Direct)')
62
- warning('Everything is ok-ish (Direct)')
63
- critical('Everything is cirtial (Direct)')
64
- unknown('Everything is erm - I don\'t know (Direct)')
90
+ NagiosOutput::Nagios.use_color(false)
65
91
  ```
66
92
 
67
- It is worth noting that the above examples will not function as you might first expect if you cut and paste them and run them. They will all show the ok() message then stop. Remember each function also makes a call to exit().
93
+ You can also turn colour off for single alerts
94
+
95
+ ```ruby
96
+ require 'nagios_output'
97
+
98
+ 'message'.nagios_ok(false)
99
+ 'message'.nagios_warning(false)
100
+ 'message'.nagios_critical(false)
101
+ 'message'.nagios_unknown(false)
102
+
103
+ # or
104
+
105
+ 'message'.nagios_ok(false)
106
+ 'message'.nagios_warning(false)
107
+ 'message'.nagios_critical(false)
108
+ 'message'.nagios_unknown(false)
109
+ ```
68
110
 
69
111
  ## Development
70
112
 
@@ -13,76 +13,50 @@
13
13
 
14
14
  require 'nagios_output'
15
15
 
16
- n = NagiosOutput.new
17
-
18
- begin
19
- n.ok('Everything is ok (Class))')
20
- rescue SystemExit => e
21
- _actual = e
22
- end
23
-
24
- begin
25
- n.warning('Everything is ok-ish (Class)')
26
- rescue SystemExit => e
27
- _actual = e
28
- end
29
-
30
- begin
31
- n.critical('Everything is cirtial (Class)')
32
- rescue SystemExit => e
33
- _actual = e
34
- end
35
-
36
- begin
37
- n.unknown('Everything is erm - I don\'t know (Class)')
38
- rescue SystemExit => e
39
- _actual = e
40
- end
41
-
42
16
  begin
43
- NagiosOutputStatic.ok('Everything is ok (Static)')
17
+ NagiosOutput::Nagios.ok('Everything is ok')
44
18
  rescue SystemExit => e
45
19
  _actual = e
46
20
  end
47
21
 
48
22
  begin
49
- NagiosOutputStatic.warning('Everything is ok-ish (Static)')
23
+ NagiosOutput::Nagios.warning('Everything is ok-ish')
50
24
  rescue SystemExit => e
51
25
  _actual = e
52
26
  end
53
27
 
54
28
  begin
55
- NagiosOutputStatic.critical('Everything is cirtial (Static)')
29
+ NagiosOutput::Nagios.critical('Everything is critical')
56
30
  rescue SystemExit => e
57
31
  _actual = e
58
32
  end
59
33
 
60
34
  begin
61
- NagiosOutputStatic.unknown('Everything is erm - I don\'t know (Static)')
35
+ NagiosOutput::Nagios.unknown('Everything is erm - I don\'t know')
62
36
  rescue SystemExit => e
63
37
  _actual = e
64
38
  end
65
39
 
66
40
  begin
67
- ok('Everything is ok (Direct)')
41
+ 'Everything is ok'.nagios_ok
68
42
  rescue SystemExit => e
69
43
  _actual = e
70
44
  end
71
45
 
72
46
  begin
73
- warning('Everything is ok-ish (Direct)')
47
+ 'Everything is ok-ish'.nagios_warning
74
48
  rescue SystemExit => e
75
49
  _actual = e
76
50
  end
77
51
 
78
52
  begin
79
- critical('Everything is cirtial (Direct)')
53
+ 'Everything is critical'.nagios_critical
80
54
  rescue SystemExit => e
81
55
  _actual = e
82
56
  end
83
57
 
84
58
  begin
85
- unknown('Everything is erm - I don\'t know (Direct)')
59
+ 'Everything is erm - I don\'t know'.nagios_unknown
86
60
  rescue SystemExit => e
87
61
  _actual = e
88
62
  end
@@ -1,110 +1,94 @@
1
1
  require 'colorize'
2
+
2
3
  require 'nagios_output/version'
4
+ require 'nagios_output/overloads'
5
+
6
+ #
7
+ # Docs to follow
8
+ #
9
+ module NagiosOutput
10
+ #
11
+ # Docs to follow
12
+ #
13
+ class Nagios
14
+ $use_colour = true
15
+
16
+ def self.use_colour(colour = true)
17
+ raise ArgumentError.new('Invalid option: use true or false only') unless [true, false].include? colour
18
+
19
+ $use_colour = colour
20
+ end
3
21
 
4
- # -------------------------------------------------------------------------------- #
5
- # Description #
6
- # -------------------------------------------------------------------------------- #
7
- # Display elapsed time in a more human readable way. #
8
- # -------------------------------------------------------------------------------- #
22
+ singleton_class.send(:alias_method, :use_color, :use_colour)
9
23
 
10
- def ok(message = nil, config = { 'colour' => true })
11
- n = NagiosOutput.new(config)
12
- n.ok(message)
13
- end
24
+ def self.check_colour(use_colour_local = nil)
25
+ unless use_colour_local.nil?
26
+ return true if use_colour_local
27
+ return false unless use_colour_local
28
+ end
29
+ return true if $use_colour
30
+ return false unless $use_colour
31
+ end
14
32
 
15
- def warning(message = nil, config = { 'colour' => true })
16
- n = NagiosOutput.new(config)
17
- n.warning(message)
18
- end
33
+ def self.clean_string(message)
34
+ return nil if message.nil?
19
35
 
20
- def critical(message = nil, config = { 'colour' => true })
21
- n = NagiosOutput.new(config)
22
- n.critical(message)
23
- end
36
+ message = message.to_s.rstrip
37
+ return nil if message.empty?
24
38
 
25
- def unknown(message = nil, config = { 'colour' => true })
26
- n = NagiosOutput.new(config)
27
- n.unknown(message)
28
- end
29
-
30
- # -------------------------------------------------------------------------------- #
31
- # Description #
32
- # -------------------------------------------------------------------------------- #
33
- # This is a static access wrapper to the main HumanDuration class below. #
34
- # -------------------------------------------------------------------------------- #
35
- class NagiosOutputStatic
36
- def self.ok(message = nil, config = { 'colour' => true })
37
- n = NagiosOutput.new(config)
38
- n.ok(message)
39
- end
39
+ message
40
+ end
40
41
 
41
- def self.warning(message = nil, config = { 'colour' => true })
42
- n = NagiosOutput.new(config)
43
- n.warning(message)
44
- end
42
+ def self.ok(message = nil, use_colour_local = nil)
43
+ message = clean_string(message)
45
44
 
46
- def self.critical(message = nil, config = { 'colour' => true })
47
- n = NagiosOutput.new(config)
48
- n.critical(message)
49
- end
45
+ exit 0 if message.nil?
50
46
 
51
- def self.unknown(message = nil, config = { 'colour' => true })
52
- n = NagiosOutput.new(config)
53
- n.unknown(message)
54
- end
55
- end
47
+ if check_colour(use_colour_local)
48
+ puts "OK - #{message}".green
49
+ else
50
+ puts "OK - #{message}"
51
+ end
52
+ exit 0
53
+ end
56
54
 
57
- # -------------------------------------------------------------------------------- #
58
- # Description #
59
- # -------------------------------------------------------------------------------- #
60
- # Display elapsed time in a more human readable way. #
61
- # -------------------------------------------------------------------------------- #
62
- class NagiosOutput
63
- def initialize(config = { 'colour' => true })
64
- @colour = config['colour']
65
- end
55
+ def self.warning(message = nil, use_colour_local = nil)
56
+ message = clean_string(message)
66
57
 
67
- def ok(message = nil)
68
- exit 0 if message.nil? || message.empty?
58
+ exit 1 if message.nil?
69
59
 
70
- if @colour
71
- puts "OK - #{message}".green
72
- else
73
- puts "OK - #{message}"
60
+ if check_colour(use_colour_local)
61
+ puts "WARNING - #{message}".yellow
62
+ else
63
+ puts "WARNING - #{message}"
64
+ end
65
+ exit 1
74
66
  end
75
- exit 0
76
- end
77
67
 
78
- def warning(message = nil)
79
- exit 1 if message.nil? || message.empty?
68
+ def self.critical(message = nil, use_colour_local = nil)
69
+ message = clean_string(message)
80
70
 
81
- if @colour
82
- puts "WARNING - #{message}".yellow
83
- else
84
- puts "WARNING - #{message}"
85
- end
86
- exit 1
87
- end
88
-
89
- def critical(message = nil)
90
- exit 2 if message.nil? || message.empty?
71
+ exit 2 if message.nil?
91
72
 
92
- if @colour
93
- puts "CRITICAL - #{message}".red
94
- else
95
- puts "CRITICAL - #{message}"
73
+ if check_colour(use_colour_local)
74
+ puts "CRITICAL - #{message}".red
75
+ else
76
+ puts "CRITICAL - #{message}"
77
+ end
78
+ exit 2
96
79
  end
97
- exit 2
98
- end
99
80
 
100
- def unknown(message = nil)
101
- exit 3 if message.nil? || message.empty?
81
+ def self.unknown(message = nil, use_colour_local = nil)
82
+ message = clean_string(message)
83
+
84
+ exit 3 if message.nil?
102
85
 
103
- if @colour
104
- puts "UNKNOWN - #{message}".blue
105
- else
106
- puts "UNKNOWN - #{message}"
86
+ if check_colour(use_colour_local)
87
+ puts "UNKNOWN - #{message}".blue
88
+ else
89
+ puts "UNKNOWN - #{message}"
90
+ end
91
+ exit 3
107
92
  end
108
- exit 3
109
93
  end
110
94
  end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Overload the integer class
3
+ #
4
+ class Integer
5
+ def nagios_ok(colour = nil)
6
+ NagiosOutput::Nagios.ok(to_s, colour)
7
+ end
8
+
9
+ def nagios_warning(colour = nil)
10
+ NagiosOutput::Nagios.warning(to_s, colour)
11
+ end
12
+
13
+ def nagios_critical(colour = nil)
14
+ NagiosOutput::Nagios.critical(to_s, colour)
15
+ end
16
+
17
+ def nagios_unknown(colour = nil)
18
+ NagiosOutput::Nagios.unknown(to_s, colour)
19
+ end
20
+ end
21
+
22
+ #
23
+ # Overload the string class
24
+ #
25
+ class String
26
+ def nagios_ok(colour = nil)
27
+ NagiosOutput::Nagios.ok(self, colour)
28
+ end
29
+
30
+ def nagios_warning(colour = nil)
31
+ NagiosOutput::Nagios.warning(self, colour)
32
+ end
33
+
34
+ def nagios_critical(colour = nil)
35
+ NagiosOutput::Nagios.critical(self, colour)
36
+ end
37
+
38
+ def nagios_unknown(colour = nil)
39
+ NagiosOutput::Nagios.unknown(self, colour)
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
- class NagiosOutput
2
- VERSION = '1.0.0'.freeze
1
+ module NagiosOutput
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -7,10 +7,10 @@ RSpec.describe NagiosOutput do
7
7
  expect(NagiosOutput::VERSION).not_to be nil
8
8
  end
9
9
 
10
- context 'Test ok()' do
11
- context 'Class method access' do
10
+ context 'Class Accessor Method' do
11
+ context 'Test ok()' do
12
12
  before(:each) do
13
- @n = NagiosOutput.new
13
+ @n = NagiosOutput::Nagios
14
14
  end
15
15
 
16
16
  context 'With a message' do
@@ -50,91 +50,9 @@ RSpec.describe NagiosOutput do
50
50
  end
51
51
  end
52
52
 
53
- context 'Static method access' do
53
+ context 'Test warning()' do
54
54
  before(:each) do
55
- @n = NagiosOutputStatic
56
- end
57
-
58
- context 'With a message' do
59
- it 'says OK - test 1 2 3' do
60
- begin
61
- expect(@n.ok('test 1 2 3')).to eql('OK - test 1 2 3')
62
- rescue SystemExit => e
63
- _actual = e.status
64
- end
65
- end
66
-
67
- it 'the exit value should be 0' do
68
- begin
69
- @n.ok('test 1 2 3')
70
- rescue SystemExit => e
71
- expect(e.status).to eq(0)
72
- end
73
- end
74
- end
75
-
76
- context 'Without a message' do
77
- it 'says nothing at all' do
78
- begin
79
- expect(@n.ok).to eql
80
- rescue SystemExit => e
81
- _actual = e.status
82
- end
83
- end
84
-
85
- it 'the exit value should be 0' do
86
- begin
87
- @n.ok
88
- rescue SystemExit => e
89
- expect(e.status).to eq(0)
90
- end
91
- end
92
- end
93
- end
94
-
95
- context 'Direct method access' do
96
- context 'With a message' do
97
- it 'says OK - test 1 2 3' do
98
- begin
99
- expect(ok('test 1 2 3')).to eql('OK - test 1 2 3')
100
- rescue SystemExit => e
101
- _actual = e.status
102
- end
103
- end
104
-
105
- it 'the exit value should be 0' do
106
- begin
107
- ok('test 1 2 3')
108
- rescue SystemExit => e
109
- expect(e.status).to eq(0)
110
- end
111
- end
112
- end
113
-
114
- context 'Without a message' do
115
- it 'says nothing at all' do
116
- begin
117
- expect(ok).to eql
118
- rescue SystemExit => e
119
- _actual = e.status
120
- end
121
- end
122
-
123
- it 'the exit value should be 0' do
124
- begin
125
- ok
126
- rescue SystemExit => e
127
- expect(e.status).to eq(0)
128
- end
129
- end
130
- end
131
- end
132
- end
133
-
134
- context 'Test warning()' do
135
- context 'Class method access' do
136
- before(:each) do
137
- @n = NagiosOutput.new
55
+ @n = NagiosOutput::Nagios
138
56
  end
139
57
 
140
58
  context 'With a message' do
@@ -174,25 +92,25 @@ RSpec.describe NagiosOutput do
174
92
  end
175
93
  end
176
94
 
177
- context 'Static method access' do
95
+ context 'Test critical()' do
178
96
  before(:each) do
179
- @n = NagiosOutputStatic
97
+ @n = NagiosOutput::Nagios
180
98
  end
181
99
 
182
100
  context 'With a message' do
183
- it 'says Warning - test 1 2 3' do
101
+ it 'says CRITICAL - test 1 2 3' do
184
102
  begin
185
- expect(@n.warning('test 1 2 3')).to eql('WARNING - test 1 2 3')
103
+ expect(@n.critical('test 1 2 3')).to eql('CRITICAL - test 1 2 3')
186
104
  rescue SystemExit => e
187
105
  _actual = e.status
188
106
  end
189
107
  end
190
108
 
191
- it 'the exit value should be 1' do
109
+ it 'the exit value should be 2' do
192
110
  begin
193
- @n.warning('test 1 2 3')
111
+ @n.critical('test 1 2 3')
194
112
  rescue SystemExit => e
195
- expect(e.status).to eq(1)
113
+ expect(e.status).to eq(2)
196
114
  end
197
115
  end
198
116
  end
@@ -200,37 +118,41 @@ RSpec.describe NagiosOutput do
200
118
  context 'Without a message' do
201
119
  it 'says nothing at all' do
202
120
  begin
203
- expect(@n.warning).to eql
121
+ expect(@n.critical).to eql
204
122
  rescue SystemExit => e
205
123
  _actual = e.status
206
124
  end
207
125
  end
208
126
 
209
- it 'the exit value should be 0' do
127
+ it 'the exit value should be 2' do
210
128
  begin
211
- @n.warning
129
+ @n.critical
212
130
  rescue SystemExit => e
213
- expect(e.status).to eq(1)
131
+ expect(e.status).to eq(2)
214
132
  end
215
133
  end
216
134
  end
217
135
  end
218
136
 
219
- context 'Direct method access' do
137
+ context 'Test unknown()' do
138
+ before(:each) do
139
+ @n = NagiosOutput::Nagios
140
+ end
141
+
220
142
  context 'With a message' do
221
- it 'says WARNING - test 1 2 3' do
143
+ it 'says UNKNOWN - test 1 2 3' do
222
144
  begin
223
- expect(warning('test 1 2 3')).to eql('WARNING - test 1 2 3')
145
+ expect(@n.unknown('test 1 2 3')).to eql('UNKNOWN - test 1 2 3')
224
146
  rescue SystemExit => e
225
147
  _actual = e.status
226
148
  end
227
149
  end
228
150
 
229
- it 'the exit value should be 1' do
151
+ it 'the exit value should be 3' do
230
152
  begin
231
- warning('test 1 2 3')
153
+ @n.unknown('test 1 2 3')
232
154
  rescue SystemExit => e
233
- expect(e.status).to eq(1)
155
+ expect(e.status).to eq(3)
234
156
  end
235
157
  end
236
158
  end
@@ -238,43 +160,39 @@ RSpec.describe NagiosOutput do
238
160
  context 'Without a message' do
239
161
  it 'says nothing at all' do
240
162
  begin
241
- expect(warning).to eql
163
+ expect(@n.unknown).to eql
242
164
  rescue SystemExit => e
243
165
  _actual = e.status
244
166
  end
245
167
  end
246
168
 
247
- it 'the exit value should be 1' do
169
+ it 'the exit value should be 3' do
248
170
  begin
249
- warning
171
+ @n.unknown
250
172
  rescue SystemExit => e
251
- expect(e.status).to eq(1)
173
+ expect(e.status).to eq(3)
252
174
  end
253
175
  end
254
176
  end
255
177
  end
256
178
  end
257
179
 
258
- context 'Test critical()' do
259
- context 'Class method access' do
260
- before(:each) do
261
- @n = NagiosOutput.new
262
- end
263
-
180
+ context 'String Accessor Method' do
181
+ context 'Test ok()' do
264
182
  context 'With a message' do
265
- it 'says CRITICAL - test 1 2 3' do
183
+ it 'says OK - test 1 2 3' do
266
184
  begin
267
- expect(@n.critical('test 1 2 3')).to eql('CRITICAL - test 1 2 3')
185
+ expect('test 1 2 3'.nagios_ok).to eql('OK - test 1 2 3')
268
186
  rescue SystemExit => e
269
187
  _actual = e.status
270
188
  end
271
189
  end
272
190
 
273
- it 'the exit value should be 2' do
191
+ it 'the exit value should be 0' do
274
192
  begin
275
- @n.critical('test 1 2 3')
193
+ 'test 1 2 3'.nagios_ok
276
194
  rescue SystemExit => e
277
- expect(e.status).to eq(2)
195
+ expect(e.status).to eq(0)
278
196
  end
279
197
  end
280
198
  end
@@ -282,41 +200,37 @@ RSpec.describe NagiosOutput do
282
200
  context 'Without a message' do
283
201
  it 'says nothing at all' do
284
202
  begin
285
- expect(@n.critical).to eql
203
+ expect(''.nagios_ok).to eql('')
286
204
  rescue SystemExit => e
287
205
  _actual = e.status
288
206
  end
289
207
  end
290
208
 
291
- it 'the exit value should be 2' do
209
+ it 'the exit value should be 0' do
292
210
  begin
293
- @n.critical
211
+ expect(''.nagios_ok)
294
212
  rescue SystemExit => e
295
- expect(e.status).to eq(2)
213
+ expect(e.status).to eq(0)
296
214
  end
297
215
  end
298
216
  end
299
217
  end
300
218
 
301
- context 'Static method access' do
302
- before(:each) do
303
- @n = NagiosOutputStatic
304
- end
305
-
219
+ context 'Test warning()' do
306
220
  context 'With a message' do
307
- it 'says CRITICAL - test 1 2 3' do
221
+ it 'says WARNING - test 1 2 3' do
308
222
  begin
309
- expect(@n.critical('test 1 2 3')).to eql('CRITICAL - test 1 2 3')
223
+ expect('test 1 2 3'.nagios_warning).to eql('WARNING - test 1 2 3')
310
224
  rescue SystemExit => e
311
225
  _actual = e.status
312
226
  end
313
227
  end
314
228
 
315
- it 'the exit value should be 2' do
229
+ it 'the exit value should be 1' do
316
230
  begin
317
- @n.critical('test 1 2 3')
231
+ 'test 1 2 3'.nagios_warning
318
232
  rescue SystemExit => e
319
- expect(e.status).to eq(2)
233
+ expect(e.status).to eq(1)
320
234
  end
321
235
  end
322
236
  end
@@ -324,27 +238,27 @@ RSpec.describe NagiosOutput do
324
238
  context 'Without a message' do
325
239
  it 'says nothing at all' do
326
240
  begin
327
- expect(@n.critical).to eql
241
+ expect(''.nagios_warning).to eql('')
328
242
  rescue SystemExit => e
329
243
  _actual = e.status
330
244
  end
331
245
  end
332
246
 
333
- it 'the exit value should be 2' do
247
+ it 'the exit value should be 1' do
334
248
  begin
335
- @n.critical
249
+ ''.nagios_warning
336
250
  rescue SystemExit => e
337
- expect(e.status).to eq(2)
251
+ expect(e.status).to eq(1)
338
252
  end
339
253
  end
340
254
  end
341
255
  end
342
256
 
343
- context 'Direct method access' do
257
+ context 'Test critical()' do
344
258
  context 'With a message' do
345
259
  it 'says CRITICAL - test 1 2 3' do
346
260
  begin
347
- expect(critical('test 1 2 3')).to eql('CRITICAL - test 1 2 3')
261
+ expect('test 1 2 3'.nagios_critical).to eql('CRITICAL - test 1 2 3')
348
262
  rescue SystemExit => e
349
263
  _actual = e.status
350
264
  end
@@ -352,7 +266,7 @@ RSpec.describe NagiosOutput do
352
266
 
353
267
  it 'the exit value should be 2' do
354
268
  begin
355
- critical('test 1 2 3')
269
+ 'test 1 2 3'.nagios_critical
356
270
  rescue SystemExit => e
357
271
  expect(e.status).to eq(2)
358
272
  end
@@ -362,7 +276,7 @@ RSpec.describe NagiosOutput do
362
276
  context 'Without a message' do
363
277
  it 'says nothing at all' do
364
278
  begin
365
- expect(critical).to eql
279
+ expect(''.nagios_critical).to eql('')
366
280
  rescue SystemExit => e
367
281
  _actual = e.status
368
282
  end
@@ -370,25 +284,19 @@ RSpec.describe NagiosOutput do
370
284
 
371
285
  it 'the exit value should be 2' do
372
286
  begin
373
- critical
287
+ ''.nagios_critical
374
288
  rescue SystemExit => e
375
289
  expect(e.status).to eq(2)
376
290
  end
377
291
  end
378
292
  end
379
293
  end
380
- end
381
-
382
- context 'Test unknown()' do
383
- context 'Class method access' do
384
- before(:each) do
385
- @n = NagiosOutput.new
386
- end
387
294
 
295
+ context 'Test unknown()' do
388
296
  context 'With a message' do
389
297
  it 'says UNKNOWN - test 1 2 3' do
390
298
  begin
391
- expect(@n.unknown('test 1 2 3')).to eql('UNKNOWN - test 1 2 3')
299
+ expect('test 1 2 3'.nagios_unknown).to eql('UNKNOWN - test 1 2 3')
392
300
  rescue SystemExit => e
393
301
  _actual = e.status
394
302
  end
@@ -396,7 +304,7 @@ RSpec.describe NagiosOutput do
396
304
 
397
305
  it 'the exit value should be 3' do
398
306
  begin
399
- @n.unknown('test 1 2 3')
307
+ 'test 1 2 3'.nagios_unknown
400
308
  rescue SystemExit => e
401
309
  expect(e.status).to eq(3)
402
310
  end
@@ -406,7 +314,7 @@ RSpec.describe NagiosOutput do
406
314
  context 'Without a message' do
407
315
  it 'says nothing at all' do
408
316
  begin
409
- expect(@n.unknown).to eql
317
+ expect(''.nagios_unknown).to eql('')
410
318
  rescue SystemExit => e
411
319
  _actual = e.status
412
320
  end
@@ -414,79 +322,81 @@ RSpec.describe NagiosOutput do
414
322
 
415
323
  it 'the exit value should be 3' do
416
324
  begin
417
- @n.unknown
325
+ ''.nagios_unknown
418
326
  rescue SystemExit => e
419
327
  expect(e.status).to eq(3)
420
328
  end
421
329
  end
422
330
  end
423
331
  end
332
+ end
424
333
 
425
- context 'Static method access' do
426
- before(:each) do
427
- @n = NagiosOutputStatic
428
- end
429
-
334
+ context 'Int Accessor Method' do
335
+ context 'Test ok()' do
430
336
  context 'With a message' do
431
- it 'says WARNING - test 1 2 3' do
337
+ it 'says OK - 123' do
432
338
  begin
433
- expect(@n.unknown('test 1 2 3')).to eql('WARNING - test 1 2 3')
339
+ expect(123.nagios_ok).to eql('OK - 123')
434
340
  rescue SystemExit => e
435
341
  _actual = e.status
436
342
  end
437
343
  end
438
344
 
439
- it 'the exit value should be 3' do
345
+ it 'the exit value should be 0' do
440
346
  begin
441
- @n.unknown('test 1 2 3')
347
+ 123.nagios_ok
442
348
  rescue SystemExit => e
443
- expect(e.status).to eq(3)
349
+ expect(e.status).to eq(0)
444
350
  end
445
351
  end
446
352
  end
353
+ end
447
354
 
448
- context 'Without a message' do
449
- it 'says nothing at all' do
355
+ context 'Test warning()' do
356
+ context 'With a message' do
357
+ it 'says WARNING - 123' do
450
358
  begin
451
- expect(@n.unknown).to eql
359
+ expect(123.nagios_warning).to eql('WARNING - 123')
452
360
  rescue SystemExit => e
453
361
  _actual = e.status
454
362
  end
455
363
  end
456
364
 
457
- it 'the exit value should be 3' do
365
+ it 'the exit value should be 1' do
458
366
  begin
459
- @n.unknown
367
+ 123.nagios_warning
460
368
  rescue SystemExit => e
461
- expect(e.status).to eq(3)
369
+ expect(e.status).to eq(1)
462
370
  end
463
371
  end
464
372
  end
465
373
  end
466
374
 
467
- context 'Direct method access' do
375
+ context 'Test critical()' do
468
376
  context 'With a message' do
469
- it 'says UNKNOWN - test 1 2 3' do
377
+ it 'says CRITICAL - 123' do
470
378
  begin
471
- expect(unknown('test 1 2 3')).to eql('UNKNOWN - test 1 2 3')
379
+ expect(123.nagios_critical).to eql('CRITICAL - 123')
472
380
  rescue SystemExit => e
473
381
  _actual = e.status
474
382
  end
475
383
  end
476
384
 
477
- it 'the exit value should be 3' do
385
+ it 'the exit value should be 2' do
478
386
  begin
479
- unknown('test 1 2 3')
387
+ 123.nagios_critical
480
388
  rescue SystemExit => e
481
- expect(e.status).to eq(3)
389
+ expect(e.status).to eq(2)
482
390
  end
483
391
  end
484
392
  end
393
+ end
485
394
 
486
- context 'Without a message' do
487
- it 'says nothing at all' do
395
+ context 'Test unknown()' do
396
+ context 'With a message' do
397
+ it 'says UNKNOWN - 123' do
488
398
  begin
489
- expect(unknown).to eql
399
+ expect(123.nagios_unknown).to eql('UNKNOWN - 123')
490
400
  rescue SystemExit => e
491
401
  _actual = e.status
492
402
  end
@@ -494,7 +404,7 @@ RSpec.describe NagiosOutput do
494
404
 
495
405
  it 'the exit value should be 3' do
496
406
  begin
497
- unknown
407
+ 123.nagios_unknown
498
408
  rescue SystemExit => e
499
409
  expect(e.status).to eq(3)
500
410
  end
@@ -502,6 +412,16 @@ RSpec.describe NagiosOutput do
502
412
  end
503
413
  end
504
414
  end
415
+
416
+ context 'Test Error Handling' do
417
+ it 'Test invalid set colour type raises an exception direct call' do
418
+ expect { NagiosOutput::Nagios.use_colour('invalid') }.to raise_error(ArgumentError, 'Invalid option: use true or false only')
419
+ end
420
+
421
+ it 'Test invalid set colour type raises an exception aliases call' do
422
+ expect { NagiosOutput::Nagios.use_color('invalid') }.to raise_error(ArgumentError, 'Invalid option: use true or false only')
423
+ end
424
+ end
505
425
  end
506
426
 
507
427
  # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios_output
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Gurney aka Wolf
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-18 00:00:00.000000000 Z
11
+ date: 2019-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ files:
88
88
  - bin/setup
89
89
  - example/example.rb
90
90
  - lib/nagios_output.rb
91
+ - lib/nagios_output/overloads.rb
91
92
  - lib/nagios_output/version.rb
92
93
  - nagios_output.gemspec
93
94
  - spec/nagios_output_spec.rb