Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "logstash/namespace"
- require "logstash/outputs/base"
- # The Xymon output is used for sending check results to xymon server via the
- # xymon command line
- #
- # For this output to work, your event must have the following fields:
- #
- # * "xymon_host" (the host configured in xymon host.cfg)
- # * "xymon_check" (the check name)
- # * "xymon_color" (color result of check)
- #
- # The easiest way to use this output is with the grep filter.
- # Presumably, you only want certain events matching a given pattern
- # to sends events to xymon server, so use grep to match and also to add the required
- # fields.
- #
- # In this example i use input gelf, the java app use gelfj library, i set
- # originHost to fqdn hostname and facility to java app name.
- #
- # input {
- # gelf {
- # type => "gelf"
- # tags => "gelf"
- # }
- # }
- #
- # filter {
- # grep {
- # tags => "gelf"
- # match => [ "level", "3" ]
- # drop => "false"
- # add_tag => "send-to-xymon"
- # add_field => [
- # "xymon_host", "%{host}",
- # "xymon_check", "%{facility}_log}",
- # "xymon_color", "red"
- # ]
- # }
- # }
- #
- # output {
- # xymon {
- # tags => "send-to-xymon"
- # # specify the hostname or ip of your xymon server
- # # (defaults to localhost)
- # server => "localhost"
- #
- # # specify the port to connect to xymon server (default 1984)
- # port => "1984"
- #
- # # specify the path to xymon bin
- # xymon_bin => "/home/xymon/client/bin/xymon"
- # }
- # }
- #
- class LogStash::Outputs::Xymon < LogStash::Outputs::Base
- config_name "xymon"
- plugin_status "experimental"
- config :server, :validate => :string, :default => "localhost"
- config :port, :validate => :number, :default => 1984
- config :xymon_bin, :validate => :string, :default => "/home/xymon/client/bin/xymon"
- public
- def register
- # nothing to do
- end # def register
- public
- def receive(event)
- return unless output?(event)
- if !File.exists?(@xymon_bin)
- @logger.warn("Skipping xymon output; xymon_bin file is missing",
- :xymon_bin => @xymon_bin, :missed_event => event)
- return
- end
- host = event.fields["xymon_host"]
- if !host
- @logger.warn("Skipping xymon output; xymon_host field is missing",
- :missed_event => event)
- return
- end
- check = event.fields["xymon_check"]
- if !check
- @logger.warn("Skipping xymon output; xymon_check field is missing",
- :missed_event => event)
- return
- end
- color = event.fields["xymon_color"]
- if !color
- @logger.warn("Skipping xymon output; xymon_color field is missing",
- :missed_event => event)
- return
- end
- host = host[0].gsub(/\./, ",")
- xmsg = event.message
- xmsg = xmsg.gsub("\n", "")
- xmsg = xmsg.gsub(/"/, "\\\"")
- cmd = "#{@xymon_bin} #{@server}:#{@port} \"status #{host}.#{check[0]} #{color[0]} #{Time.now}
- #{xmsg} \""
- @logger.debug("Running xymon command", :command => cmd)
- begin
- system(cmd)
- rescue => e
- @logger.warn("Skipping xymon output; error calling xymon_bin",
- :command => cmd, :missed_event => event,
- :exception => e, :backtrace => e.backtrace)
- end
- end # def receive
- end # class LogStash::Outputs::xymon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement