lib/logstash/outputs/nagios_nsca.rb in logstash-output-nagios_nsca-2.0.2 vs lib/logstash/outputs/nagios_nsca.rb in logstash-output-nagios_nsca-2.0.3
- old
+ new
@@ -64,12 +64,10 @@
end
public
def receive(event)
# exit if type or tags don't match
-
-
# catch logstash shutdown
return if event == LogStash::SHUTDOWN
# skip if 'send_nsca' binary doesn't exist
if !command_file_exist?
@@ -102,18 +100,16 @@
# build the command
# syntax: echo '<server>!<nagios_service>!<status>!<text>' | \
# /usr/sbin/send_nsca -H <nagios_host> -d '!' -c <nsca_config>"
- cmd = [@send_nsca_bin, "-H", @host, "-p", @port, "-d", "~"]
- cmd = cmd + ["-c", @send_nsca_config] if @send_nsca_config
- message = "#{nagios_host}~#{nagios_service}~#{status}~#{msg}"
+ message = "#{nagios_host}:#{nagios_service}:#{status}:#{msg}"
@logger.debug("Running send_nsca command", :nagios_nsca_command => cmd.join(" "), :message => message)
begin
- send_to_nagios(cmd)
+ send_to_nagios(cmd, message)
rescue => e
@logger.warn(
"Skipping nagios_nsca output; error calling send_nsca",
:error => $!,
:nagios_nsca_command => cmd.join(" "),
@@ -126,12 +122,19 @@
def command_file_exist?
File.exists?(@send_nsca_bin)
end
- def send_to_nagios(cmd)
+ def cmd
+ return @cmd if @cmd
+ @cmd = [@send_nsca_bin, "-H", @host, "-p", @port, "-d", ":"]
+ @cmd = @cmd + ["-c", @send_nsca_config] if @send_nsca_config
+ @cmd
+ end
+
+ def send_to_nagios(cmd, message)
Open3.popen3(*cmd) do |i, o, e|
- i.puts(message)
+ i.puts(message)
i.close
end
end
end # class LogStash::Outputs::NagiosNsca