class LogStash::Inputs::Nagioscheck
Generate a repeating message.
This plugin is intented only as an example.
Public Instance Methods
execute(queue)
click to toggle source
Override the execute routine from the exec input
# File lib/logstash/inputs/nagioscheck.rb, line 22 def execute(queue) start = Time.now output = exit_status = nil begin @logger.debug? && @logger.debug("Running exec", :command => @command) output, exit_status = run_command() rescue StandardError => e @logger.error("Error while running command", :command => @command, :e => e, :backtrace => e.backtrace) rescue Exception => e @logger.error("Exception while running command", :command => @command, :e => e, :backtrace => e.backtrace) end duration = Time.now - start unless exit_status.nil? #exit status will be nil if the command never completed running @logger.debug? && @logger.debug("Command completed", :command => @command, :duration => duration) @codec.decode(output) do |event| decorate(event) cmd_message, cmd_perf = event.get("message").split('|') event.set("check_uuid", SecureRandom.uuid) unless cmd_perf.nil? cmd_perf.strip.split_by_spaces_except_single_quoted.each { |metric| results = parse_performance(metric) if results.nil? @logger.warn("Error parsing nagios performance data (malformed)", :raw => event.get("message")) event.tag(@failure_tag) else perf_event = event.clone perf_event.remove("message") perf_event.set("type", "nagiosmetric") perf_event.set("name", @name) perf_event.set("label", results[1]) perf_event.set("uom", results[3]) perf_event.set("value", results[2].to_f) perf_event.set("warning", results[4].to_f) perf_event.set("critical", results[5].to_f) perf_event.set("min", results[6].to_f) perf_event.set("max", results[7].to_f) queue << perf_event end } end event.set("host", @hostname) event.set("command", @command) event.set("type", "nagioscheck") event.set("message", cmd_message.nil? ? "" : cmd_message.strip) event.set("name", @name) event.set("took_ms", duration * 1000) event.set("status_code", exit_status) event.set("status", nice_status(exit_status)) queue << event end end duration end