lib/logstash/outputs/opennms.rb in logstash-output-opennms-0.1.0 vs lib/logstash/outputs/opennms.rb in logstash-output-opennms-0.1.1
- old
+ new
@@ -7,26 +7,12 @@
# The OpenNMS output is used to send an event (xml document) to an OpenNMS
# server. The event `@timestamp` will automatically be associated with the
# OpenNMS item data.
#
-# Each "host" is an identifier, and each item is associated with that host.
-# Items are typed on the OpenNMS side. You can send numbers as strings and
-# OpenNMS will Do The Right Thing.
-#
-# In the OpenNMS UI, ensure that your hostname matches the value referenced by
-# `opennms_host`. Create the item with the key as it appears in the field
-# referenced by `opennms_key`. In the item configuration window, ensure that the
-# type dropdown is set to OpenNMS Trapper. Also be sure to set the type of
-# information that OpenNMS should expect for this item.
-#
-# This plugin does not currently send in batches. While it is possible to do
-# so, this is not supported. Be careful not to flood your OpenNMS server with
-# too many events per second.
-#
-# NOTE: This plugin will log a warning if a necessary field is missing. It will
-# not attempt to resend if OpenNMS is down, but will log an error message.
+# NOTE: This plugin will log a warning if a necessary field is missing. It
+# will not attempt to resend if OpenNMS is down, but will log an error message.
class LogStash::Outputs::OpenNMS < LogStash::Outputs::Base
config_name "opennms"
concurrency :single
@@ -54,19 +40,19 @@
# the @metadata field.
config :opennms_event_interface, :validate => :string
# The field name which holds the OpenNMS ... This can be a sub-field of
# the @metadata field.
- config :opennms_event_uei, :validate => :string, :default => "uei.opennms.org/logstash"
+ config :opennms_event_uei, :validate => :string, :default => "uei.opennms.org/elastic/logstash/generic/state/1"
# The field name which holds the OpenNMS ... This can be a sub-field of
# the @metadata field.
config :opennms_event_origin, :validate => :string, :default => "None"
# The field name which holds the OpenNMS ... This can be a sub-field of
# the @metadata field.
- config :opennms_event_severity, :validate => :number, :required => true, :default => 4
+ config :opennms_event_severity, :validate => :string, :required => true, :default => "Warning"
# The field name which holds the OpenNMS ... This can be a sub-field of
# the @metadata field.
config :opennms_event_source, :validate => :string, :default => "logstash"
@@ -79,10 +65,14 @@
config :opennms_event_logmsg, :validate => :string, :default => "None"
# This directive cannot be used in conjunction with the single-value directives
# `opennms_key` and `opennms_value`.
config :opennms_event_parms, :validate => :hash
+
+ # The field name which holds the OpenNMS ... This can be a sub-field of
+ # the @metadata field.
+ config :opennms_event_parms_order, :validate => :array
public
def register
if !@opennms_key.nil? && !@multi_value.nil?
@logger.warn("Cannot use multi_value in conjunction with opennms_key/opennms_value. Ignoring opennms_key.")
@@ -139,18 +129,20 @@
public
def validate_props(event,props,found)
props.each do |props_key,props_value|
if props_value.is_a?(::Hash)
found[props_key] = validate_props(event,props_value,{})
- else
+ elsif props_value.is_a?(::Array)
+ found[props_key]=props_value
+ else
if !event.get(props_value)
- @logger.warn("Field referenced by #{props_value} is missing")
- found[props_key] = props_value.empty? ? "n/a" : props_value
- else
- found[props_key]=event.get(props_value)
- end
- end
+ @logger.warn("Field referenced by #{props_value} is missing")
+ found[props_key] = props_value.empty? ? "n/a" : props_value
+ else
+ found[props_key]=event.get(props_value)
+ end
+ end
end
found
end # def validate_props
# Build XML event document
@@ -160,24 +152,26 @@
event_doc += "<events>"
event_doc += "<event>"
event_doc += "<uei>" + message['uei'] + "</uei>"
event_doc += "<source>" + message['source'] + "</source>"
event_doc += "<nodeid>" + message['nodeid'] + "</nodeid>" if !message['nodeid'].empty?
- event_doc += "<time>" + Time.now.strftime("%A %d %B %Y %H:%M:%S o'clock GMT") + "</time>"
+ event_doc += "<time>" + Time.now.strftime("%A, %d %B %Y %H:%M:%S o'clock GMT") + "</time>"
event_doc += "<host>" + message['origin'] + "</host>"
event_doc += "<interface>" + message['interface'] + "</interface>" if !message['interface'].empty?
event_doc += "<service>" + message ['service'] + "</service>" if !message['service'].empty?
event_doc += "<parms>"
- message['parms'].each do |parm_name, parm_value|
+ #message['parms'].each do |parm_name, parm_value|
+ message['parms_order'].each do |parm_name|
+ parm_value = message['parms'][parm_name]
next if parm_name == 'severity'
event_doc += "<parm>"
event_doc += "<parmName><![CDATA[" + parm_name + "]]></parmName>"
event_doc += "<value type=\"string\" encoding=\"text\"><![CDATA[" + parm_value + "]]></value>"
event_doc += "</parm>"
end
event_doc += "</parms>"
- event_doc += "<descr>" + message['description'] + "</descr>" if !message['description'].empty?
+ #event_doc += "<descr>" + message['description'] + "</descr>" if !message['description'].empty?
event_doc += "<logmsg>" + message['logmsg'] + "</logmsg>" if !message['logmsg'].empty?
event_doc += "<severity>" + message['severity'] + "</severity>"
event_doc += "</event>"
event_doc += "</events>"
event_doc += "</log>"
@@ -231,11 +225,12 @@
'severity' => @opennms_event_severity.to_s,
'source' => @opennms_event_source.to_s,
'description' => @opennms_event_description.to_s,
'logmsg' => @opennms_event_logmsg.to_s,
'parms' => @opennms_event_parms,
+ 'parms_order' => @opennms_event_parms_order
}
-
+
message = validate_props(event,message_map,{})
#message['parms'].each do |k,v|
# @logger.debug("Hash: " + k + " => " + v)
#end
\ No newline at end of file