senedsa 0.0.7 → 0.1.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/senedsa/cli.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'optparse'
2
2
  require 'yaml'
3
+ require 'senedsa/version'
4
+ require 'senedsa/about'
5
+
3
6
 
4
7
  module Senedsa
5
8
 
@@ -48,10 +51,10 @@ module Senedsa
48
51
  opts.separator ""
49
52
 
50
53
  opts.separator "Send_Nsca options:"
51
- opts.on('-T', '--send_nsca-timeout TIMEOUT', Integer, "send_nsca connection timeout") { |timeout| @cli_options[:send_nsca_timeout] = timeout }
52
- opts.on('-D', '--send_nsca-delim DELIM', String, "send_nsca field delimited") { |delim| @cli_options[:send_nsca_delim] = delim }
53
- opts.on('-C', '--send_nsca-config CONFIG', String, "send_nsca configuration file") { |config| @cli_options[:send_nsca_config] = config }
54
- opts.on('-B', '--send_nsca-binary BINARY', String, "send_nsca binary path") { |binary| @cli_options[:send_nsca_binary] = binary }
54
+ opts.on('-T', '--send_nsca_timeout TIMEOUT', Integer, "send_nsca connection timeout") { |timeout| @cli_options[:send_nsca_timeout] = timeout }
55
+ opts.on('-D', '--send_nsca_delim DELIM', String, "send_nsca field delimited") { |delim| @cli_options[:send_nsca_delim] = delim }
56
+ opts.on('-C', '--send_nsca_config CONFIG', String, "send_nsca configuration file") { |config| @cli_options[:send_nsca_config] = config }
57
+ opts.on('-B', '--send_nsca_binary BINARY', String, "send_nsca binary path") { |binary| @cli_options[:send_nsca_binary] = binary }
55
58
  opts.separator ""
56
59
 
57
60
  opts.separator "Service options:"
@@ -102,7 +105,7 @@ module Senedsa
102
105
  end
103
106
 
104
107
  def process_arguments
105
- @cli_options[:svc_output] = @arguments.join(' ')
108
+ @options[:svc_output] = @arguments.join(' ')
106
109
  end
107
110
 
108
111
  def output_message(message, exitstatus=nil)
@@ -34,7 +34,7 @@ module Senedsa
34
34
  begin
35
35
  cfg_options = YAML.load File.open(cfg_file)
36
36
  raise ConfigurationError, "senedsa_config not allowed in configuration file (#{cfg_file})" unless cfg_options[:senedsa_config].nil?
37
- rescue Psych::SyntaxError => e
37
+ rescue SyntaxError::Psych::SyntaxError => e
38
38
  raise ConfigurationError, "syntax error in configuration file #{cfg_file}: #{e.message}"
39
39
  rescue Errno::ENOENT, Errno::EACCES => e
40
40
  raise ConfigurationError, e.message
@@ -52,6 +52,8 @@ module Senedsa
52
52
 
53
53
  def initialize(*args)
54
54
 
55
+ @options = {}
56
+
55
57
  case args.size
56
58
 
57
59
  when 1
@@ -67,7 +69,7 @@ module Senedsa
67
69
 
68
70
  when 2
69
71
  raise InitializationError, "invalid argument types" unless args[0].is_a? String and args[1].is_a? String
70
- cfg_options = SendNsca.configure(args[0][:senedsa_config])
72
+ cfg_options = SendNsca.configure(@options[:senedsa_config])
71
73
  hsh_options = { :svc_hostname => args[0], :svc_descr => args[1] }
72
74
 
73
75
  when 3
@@ -76,13 +78,30 @@ module Senedsa
76
78
  hsh_options = args[2].merge({ :svc_hostname => args[0], :svc_descr => args[1] })
77
79
 
78
80
  else
79
- raise InitializationError, "invalid number of arguments"
81
+ raise ArgumentError, "wrong number of arguments"
80
82
  end
81
83
  @options = SendNsca.defaults.merge(cfg_options).merge(hsh_options)
82
84
  end
83
85
 
84
86
  def send(*args)
85
- run(@options[:status],@options[:svc_output])
87
+
88
+ case args.size
89
+ when 0
90
+ # svc_status and svc_output should be set on @options
91
+ raise ArgumentError, "svc_status or svc_output not set" if @options[:svc_status].nil? or @options[:svc_output].nil?
92
+ svc_status = @options[:status]
93
+ svc_output = @options[:svc_output]
94
+ when 2
95
+ raise ArgumentError, "invalid svc_status" unless args[0].is_a? Symbol and STATUS.keys.include?(args[0])
96
+ raise ArgumentError, "invalid svc_output" unless args[1].is_a? String
97
+ svc_status = args[0]
98
+ svc_output = args[1]
99
+ else
100
+ raise ArgumentError, "wrong number of arguments"
101
+ end
102
+ raise StandardError , "foo" # unless @options[:nsca_hostname].nil?
103
+ puts @options[:nsca_hostname]
104
+ run svc_status, svc_output
86
105
  end
87
106
 
88
107
  SendNsca.defaults.keys.each do |attr|
@@ -1,3 +1,3 @@
1
1
  module Senedsa
2
- VERSION = '0.0.7'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/senedsa.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'senedsa/version'
2
- require 'senedsa/about'
3
1
  require 'senedsa/send_nsca'
4
2
 
5
3
  module Senedsa
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senedsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.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: 2012-05-30 00:00:00.000000000 Z
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Senedsa is a small utility and library wrapper for the Nagios send_nsca.
15
15
  email: gerir@evernote.com