smsinabox 0.2.0 → 0.2.1
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/History.txt +2 -1
- data/bin/sms-credit +41 -3
- data/lib/smsinabox.rb +3 -2
- data/smsinabox.gemspec +1 -1
- metadata +1 -1
data/History.txt
CHANGED
data/bin/sms-credit
CHANGED
@@ -13,7 +13,10 @@ require 'smsinabox'
|
|
13
13
|
require 'optparse'
|
14
14
|
|
15
15
|
OPTIONS = {
|
16
|
-
:config => nil
|
16
|
+
:config => nil,
|
17
|
+
:nagios => false,
|
18
|
+
:crit => 50,
|
19
|
+
:warn => 100
|
17
20
|
}
|
18
21
|
|
19
22
|
parser = OptionParser.new do |opts|
|
@@ -27,12 +30,47 @@ BANNER
|
|
27
30
|
opts.separator ""
|
28
31
|
opts.on("-c", "--config=path/to/config", String,
|
29
32
|
"Path to alternate config file (defaults to ~/.smsinabox)") { |m| OPTIONS[:config] = m }
|
33
|
+
opts.on("--nagios", "Enable nagios mode") { OPTIONS[:nagios] = true }
|
34
|
+
opts.on("--warn=N", "Number of credit for warning, default 100 (nagios-mode only)") { |w| OPTIONS[:warn] = w }
|
35
|
+
opts.on("--critical=N", "Number of credit for critical, default 50 (nagios-mode only)") { |c| OPTIONS[:crit] = c }
|
30
36
|
opts.on("-h", "--help",
|
31
37
|
"Show this help message.") { puts opts; exit }
|
32
38
|
opts.parse!(ARGV)
|
33
|
-
|
34
39
|
end
|
35
40
|
|
36
41
|
Smsinabox.configure!( OPTIONS[:config] )
|
37
42
|
|
38
|
-
|
43
|
+
if !OPTIONS[:nagios]
|
44
|
+
puts "Credits left: #{Smsinabox.credits}"
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
|
48
|
+
errors = {
|
49
|
+
:ok => 0,
|
50
|
+
:warn => 1,
|
51
|
+
:crit => 2,
|
52
|
+
:unknown => 3
|
53
|
+
}
|
54
|
+
|
55
|
+
begin
|
56
|
+
|
57
|
+
credits = Smsinabox.credits
|
58
|
+
msg = "%s: #{credits} sms credits remaining for #{Smsinabox.username}"
|
59
|
+
|
60
|
+
if credits < OPTIONS[:crit]
|
61
|
+
puts msg % [ 'CRITICAL' ]
|
62
|
+
exit errors[:crit]
|
63
|
+
end
|
64
|
+
|
65
|
+
if credits < OPTIONS[:warn]
|
66
|
+
puts msg % [ 'WARNING' ]
|
67
|
+
exit errors[:warn]
|
68
|
+
end
|
69
|
+
|
70
|
+
puts msg % ['OK' ]
|
71
|
+
exit errors[:ok]
|
72
|
+
|
73
|
+
rescue => e
|
74
|
+
puts "UNKNOWN: Could not determine sms credits for #{Smsinabox.username} (#{e.message})"
|
75
|
+
exit errors[:unknown]
|
76
|
+
end
|
data/lib/smsinabox.rb
CHANGED
@@ -12,7 +12,7 @@ end
|
|
12
12
|
|
13
13
|
module Smsinabox
|
14
14
|
|
15
|
-
VERSION = '0.2.
|
15
|
+
VERSION = '0.2.1'
|
16
16
|
|
17
17
|
autoload :Exceptions, 'smsinabox/exceptions'
|
18
18
|
autoload :Message, 'smsinabox/message'
|
@@ -40,6 +40,7 @@ module Smsinabox
|
|
40
40
|
xml.xpath('/api_result/data/credits/text()').to_s.to_i
|
41
41
|
end
|
42
42
|
end
|
43
|
+
alias :credits :credit_remaining
|
43
44
|
|
44
45
|
# Send a #Messages and returns a #DelieryReport
|
45
46
|
def deliver( message )
|
@@ -81,7 +82,7 @@ module Smsinabox
|
|
81
82
|
end
|
82
83
|
|
83
84
|
replies.each { |r| yield r } if block_given?
|
84
|
-
|
85
|
+
|
85
86
|
replies
|
86
87
|
end
|
87
88
|
end
|
data/smsinabox.gemspec
CHANGED