mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Merge pull request #298 from jamtur01/nagioslevel
Added support for all Nagios statuses in output
This commit is contained in:
commit
17edd37b97
1 changed files with 29 additions and 10 deletions
|
@ -14,8 +14,12 @@ require "logstash/outputs/base"
|
|||
# * "nagios_annotation"
|
||||
# * "nagios_level"
|
||||
#
|
||||
# The plugin defaults to sending CRITICAL check results. You can send WARNING check
|
||||
# results by setting the "nagios_level" field to "warn".
|
||||
# There are two configuration options:
|
||||
#
|
||||
# * commandfile - The location of the Nagios external command file
|
||||
# * nagios_level - Specifies the level of the check to be sent. Defaults to
|
||||
# CRITICAL and can be overriden by setting the "nagios_level" field to one
|
||||
# of "OK", "WARNING", "CRITICAL", or "UNKNOWN"
|
||||
#
|
||||
# The easiest way to use this output is with the grep filter.
|
||||
# Presumably, you only want certain events matching a given pattern
|
||||
|
@ -41,8 +45,6 @@ require "logstash/outputs/base"
|
|||
# }
|
||||
# }
|
||||
class LogStash::Outputs::Nagios < LogStash::Outputs::Base
|
||||
NAGIOS_CRITICAL = 2
|
||||
NAGIOS_WARN = 1
|
||||
|
||||
config_name "nagios"
|
||||
plugin_status "beta"
|
||||
|
@ -50,6 +52,10 @@ class LogStash::Outputs::Nagios < LogStash::Outputs::Base
|
|||
# The path to your nagios command file
|
||||
config :commandfile, :validate => :string, :default => "/var/lib/nagios3/rw/nagios.cmd"
|
||||
|
||||
# The Nagios check level. Should be one of 0=OK, 1=WARNING, 2=CRITICAL,
|
||||
# 3=UNKNOWN. Defaults to 2 - CRITICAL.
|
||||
config :nagios_level, :validate => [ "0", "1", "2", "3" ], :default => "2"
|
||||
|
||||
public
|
||||
def register
|
||||
# nothing to do
|
||||
|
@ -70,24 +76,37 @@ class LogStash::Outputs::Nagios < LogStash::Outputs::Base
|
|||
# array indexes (host/service combos) and the arrays must be the same
|
||||
# length.
|
||||
|
||||
host = event.fields["nagios_host"]
|
||||
host = event["nagios_host"]
|
||||
if !host
|
||||
@logger.warn("Skipping nagios output; nagios_host field is missing",
|
||||
:missed_event => event)
|
||||
return
|
||||
end
|
||||
|
||||
service = event.fields["nagios_service"]
|
||||
service = event["nagios_service"]
|
||||
if !service
|
||||
@logger.warn("Skipping nagios output; nagios_service field is missing",
|
||||
"missed_event" => event)
|
||||
return
|
||||
end
|
||||
|
||||
annotation = event.fields["nagios_annotation"]
|
||||
level = NAGIOS_CRITICAL
|
||||
if event.fields["nagios_level"] and event.fields["nagios_level"][0].downcase == "warn"
|
||||
level = NAGIOS_WARN
|
||||
annotation = event["nagios_annotation"]
|
||||
level = @nagios_level
|
||||
|
||||
if event["nagios_level"]
|
||||
event_level = [*event["nagios_level"]]
|
||||
case event_level[0].downcase
|
||||
when "ok"
|
||||
level = "0"
|
||||
when "warning"
|
||||
level = "1"
|
||||
when "critical"
|
||||
level = "2"
|
||||
when "unknown"
|
||||
level = "3"
|
||||
else
|
||||
@logger.warn("Invalid Nagios level. Defaulting to CRITICAL", :data => event_level)
|
||||
end
|
||||
end
|
||||
|
||||
cmd = "[#{Time.now.to_i}] PROCESS_SERVICE_CHECK_RESULT;#{host[0]};#{service[0]};#{level};"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue