senedsa 0.2.2 → 0.2.5

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
1
  require 'open3'
2
2
  require 'psych'
3
+ require 'socket'
3
4
 
4
5
  module Senedsa
5
6
 
@@ -59,10 +60,12 @@ module Senedsa
59
60
 
60
61
  when 1
61
62
  if args[0].is_a? String
62
- cfg_options = SendNsca.configure(args[0])
63
+ cfg_file = args[0].nil? ? nil : args[0]
64
+ cfg_options = cfg_file.nil? ? {} : SendNsca.configure(cfg_file)
63
65
  hsh_options = {}
64
66
  elsif args[0].is_a? Hash
65
- cfg_options = SendNsca.configure(args[0][:senedsa_config])
67
+ cfg_file = args[0][:senedsa_config].nil? ? nil : args[0][:senedsa_config]
68
+ cfg_options = cfg_file.nil? ? {} : SendNsca.configure(cfg_file)
66
69
  hsh_options = args[0]
67
70
  else
68
71
  raise InitializationError, "invalid argument types"
@@ -82,6 +85,7 @@ module Senedsa
82
85
  raise ArgumentError, "wrong number of arguments"
83
86
  end
84
87
  @options = SendNsca.defaults.merge(cfg_options).merge(hsh_options)
88
+ @options[:svc_hostname] = Socket.gethostname if @options[:svc_hostname].nil?
85
89
  end
86
90
 
87
91
  def send(*args)
@@ -108,6 +112,10 @@ module Senedsa
108
112
  define_method(attr.to_s + '=') { |value| @options[attr.to_sym] = value }
109
113
  end
110
114
 
115
+ def inspect
116
+ @options
117
+ end
118
+
111
119
  private
112
120
 
113
121
  def command
@@ -120,7 +128,7 @@ module Senedsa
120
128
  begin
121
129
  Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
122
130
  stdin.write("%s\n" % [svc_hostname,svc_descr,STATUS[status],svc_output].join(send_nsca_delim))
123
- $stdout.write stdout.gets
131
+ $stdout.write stdout.gets if STDIN.tty?
124
132
  raise SendNscaError, stderr.gets.chomp unless wait_thr.value.exitstatus == 0
125
133
  end
126
134
  rescue Errno::ENOENT, Errno::EACCES => e
@@ -1,3 +1,3 @@
1
1
  module Senedsa
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.5'
3
3
  end
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.2.2
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -52,3 +52,4 @@ signing_key:
52
52
  specification_version: 3
53
53
  summary: Utility and library wrapper for Nagios send_nsca utility
54
54
  test_files: []
55
+ has_rdoc: