lib/logstash/outputs/nagios_nsca.rb in logstash-output-nagios_nsca-1.0.0 vs lib/logstash/outputs/nagios_nsca.rb in logstash-output-nagios_nsca-1.1.0

- old
+ new

@@ -35,11 +35,11 @@ # The port where the NSCA daemon on the nagios host listens. config :port, :validate => :number, :default => 5667 # The path to the 'send_nsca' binary on the local host. - config :send_nsca_bin, :validate => :path, :default => "/usr/sbin/send_nsca" + config :send_nsca_bin, :validate => :string, :default => "/usr/sbin/send_nsca" # The path to the send_nsca config file on the local host. # Leave blank if you don't want to provide a config file. config :send_nsca_config, :validate => :path @@ -73,11 +73,11 @@ finished return end # skip if 'send_nsca' binary doesn't exist - if !File.exists?(@send_nsca_bin) + if !command_file_exist? @logger.warn("Skipping nagios_nsca output; send_nsca_bin file is missing", "send_nsca_bin" => @send_nsca_bin, "missed_event" => event) return end @@ -112,14 +112,11 @@ message = "#{nagios_host}~#{nagios_service}~#{status}~#{msg}" @logger.debug("Running send_nsca command", :nagios_nsca_command => cmd.join(" "), :message => message) begin - Open3.popen3(*cmd) do |i, o, e| - i.puts(message) - i.close - end + send_to_nagios(cmd) rescue => e @logger.warn( "Skipping nagios_nsca output; error calling send_nsca", :error => $!, :nagios_nsca_command => cmd.join(" "), @@ -127,6 +124,18 @@ :missed_event => event ) @logger.debug("Backtrace", :backtrace => e.backtrace) end end # def receive + + def command_file_exist? + File.exists?(@send_nsca_bin) + end + + def send_to_nagios(cmd) + Open3.popen3(*cmd) do |i, o, e| + i.puts(message) + i.close + end + end + end # class LogStash::Outputs::NagiosNsca