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.
@@ -1,5 +1,6 @@
1
- == 0.2.0 (Not released yet)
1
+ == 0.2.1 2010-06-18
2
2
 
3
+ * sms-credit now supports nagios exit codes/output
3
4
  * Upgraded to V5 of mymobileapi.com API
4
5
  * Cleaned up internals
5
6
  * Better specs
@@ -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
- puts "Credits left: #{Smsinabox.credits}"
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
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  module Smsinabox
14
14
 
15
- VERSION = '0.2.0'
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{smsinabox}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kenneth.kalmer@gmail.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smsinabox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kenneth.kalmer@gmail.com