Class: LogStash::Outputs::NagiosNsca
- Defined in:
- lib/logstash/outputs/nagios_nsca.rb
Overview
The nagios_nsca output is used for sending passive check results to Nagios through the NSCA protocol.
This is useful if your Nagios server is not the same as the source host from where you want to send logs or alerts. If you only have one server, this output is probably overkill # for you, take a look at the ‘nagios’ output instead.
Here is a sample config using the nagios_nsca output:
output {
nagios_nsca {
# specify the hostname or ip of your nagios server
host => "nagios.example.com"
# specify the port to connect to
port => 5667
}
}
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Outputs::Base
Instance Method Details
#receive(event) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/logstash/outputs/nagios_nsca.rb', line 66 def receive(event) # exit if type or tags don't match return unless output?(event) # catch logstash shutdown if event == LogStash::SHUTDOWN finished return end # skip if 'send_nsca' binary doesn't exist if !File.exists?(@send_nsca_bin) @logger.warn("Skipping nagios_nsca output; send_nsca_bin file is missing", "send_nsca_bin" => @send_nsca_bin, "missed_event" => event) return end # interpolate params nagios_host = event.sprintf(@nagios_host) nagios_service = event.sprintf(@nagios_service) # escape basic things in the log message # TODO: find a way to escape the message correctly msg = event.sprintf(@message_format) msg.gsub!("\n", "<br/>") msg.gsub!("'", "’") status = event.sprintf(@nagios_status) if status.to_i.to_s != status # Check it round-trips to int correctly msg = "status '#{status}' is not numeric" status = 2 else status = status.to_i if status > 3 || status < 0 msg "status must be > 0 and <= 3, not #{status}" status = 2 end end # build the command # syntax: echo '<server>!<nagios_service>!<status>!<text>' | \ # /usr/sbin/send_nsca -H <nagios_host> -d '!' -c <nsca_config>" cmd = %(echo '#{nagios_host}~#{nagios_service}~#{status}~#{msg}' |) cmd << %( #{@send_nsca_bin} -H #{@host} -p #{@port} -d '~') cmd << %( -c #{@send_nsca_config}) if @send_nsca_config cmd << %( 2>/dev/null >/dev/null) @logger.debug("Running send_nsca command", "nagios_nsca_command" => cmd) begin system cmd rescue => e @logger.warn("Skipping nagios_nsca output; error calling send_nsca", "error" => $!, "nagios_nsca_command" => cmd, "missed_event" => event) @logger.debug("Backtrace", e.backtrace) end end |
#register ⇒ Object
61 62 63 |
# File 'lib/logstash/outputs/nagios_nsca.rb', line 61 def register #nothing for now end |