I am adding the field of a device to the pipeline(because I don't want to query It every time and the name should not change) and I'm changing the "host" field to "host.ip"
Let's say this is what I get from SNMP walk input.
ruby {
code => '
a = []
event.to_hash.each { |k, v|
if k =~ /^iso\.org\.dod\.internet\.mgmt\.mib-2\.interfaces\.ifTable\.ifEntry\.ifSpeed\.\d+$/
matches = k.scan(/(\d+)$/)
a << { "cisco.device.interface.number" => matches[0][0], "cisco.device.interface.speed" => v }
end
}
if a != []
event.set("someField", a)
end
'
}
I tried your code and this is the output I got back(I have removed the part on interface number because I will later add interface name so I don't need the number)
event.remove(k) did the work thanks!
I have tried to edit your code to achieve what I think is what I need.
I have made the below change
code => '
a = []
event.to_hash.each { |k, v|
if k =~ /^.*?ifSpeed\.\d+$/
matches = k.scan(/(\d+)$/)
a << { "speed" => v }
event.remove(k)
end
if k =~ /^.*?ifName\.\d+$/
matches = k.scan(/(\d+)$/)
a << { "name" => v }
event.remove(k)
end
}
if a != []
event.set("cisco.device.interface", a)
end
'
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.