Skip to content

Instantly share code, notes, and snippets.

Avatar

Ry Biesemeyer yaauie

View GitHub Profile
View noisy-proxy.rb
require 'time' # Time#iso8601
# A NoisyProxy will log all method calls on the wrapped object and their results to the given IO.
# It will optionally _infect_ any object returned by the real method.
class NoisyProxy < BasicObject
def initialize(inner, infect:false, io:$stderr)
@inner = inner
@infect = infect
@io = io
end
View USAGE.md

Suppose you had events with the following structure:

{
  "books": [
    {"author":"Alice",  "title":"Fields" },
    {"author":"Bob",    "title":"Oceans" },
    {"author":"Connie", "title":"Rivers" },
    {"author":"Connie", "title":"Lakes"  },
    {"author":"David",  "title":"Streams"},
@yaauie
yaauie / USAGE.md
Created Mar 3, 2021
Logstash script for ruby filter plugin to destructively merge two array fields
View USAGE.md

This script has three parameters:

  • source: a field reference to the source array
  • target: a field reference to the target array
  • coerce: (optional: default false) when encountering non-array values in either source or target fields, setting coerce => true causes these fields to first be converted to a single-entry array.
filter {
@yaauie
yaauie / logstash-codec-csv.auto-flush-on-evict.patch
Created Dec 21, 2020
Patch Logstash CSV Codec 1.0.0 to ensure the Logstash File Input re-detects column names per file
View logstash-codec-csv.auto-flush-on-evict.patch
diff --git a/lib/logstash/codecs/csv.rb b/lib/logstash/codecs/csv.rb
index 07d6416..66cd6ed 100644
--- a/lib/logstash/codecs/csv.rb
+++ b/lib/logstash/codecs/csv.rb
@@ -133,12 +133,19 @@ class LogStash::Codecs::CSV < LogStash::Codecs::Base
rescue CSV::MalformedCSVError => e
@logger.error("CSV parse failure. Falling back to plain-text", :error => e, :data => data)
yield LogStash::Event.new("message" => data, "tags" => ["_csvparsefailure"])
end
end
@yaauie
yaauie / downcase-field-names.logstash-filter-ruby.rb
Created Oct 14, 2020
A script for a Logstash Ruby Filter to transform field names to all lowercase
View downcase-field-names.logstash-filter-ruby.rb
###############################################################################
# downcase-field-names.logstash-filter-ruby.rb
# ---------------------------------
# A script for a Logstash Ruby Filter to transform field names to all lowercase
###############################################################################
#
# Copyright 2020 Ry Biesemeyer
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
View stringify-timestamp.logstash-filter-ruby.rb
###############################################################################
# stringify-timestamp.logstash-filter-ruby.rb
# ---------------------------------
# A script for a Logstash Ruby Filter to stringify logstash timestamps using
# ISO-8601.
###############################################################################
#
# Copyright 2020 Ry Biesemeyer
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@yaauie
yaauie / ecs-complaint-host-geoip.conf
Created Jul 22, 2020
Example remapping the fields output by GeoIP filter for a host ip to ECS's host geo fields, as identified in the ECS compatibility mode issue https://github.com/logstash-plugins/logstash-filter-geoip/issues/163#issuecomment-592177677
View ecs-complaint-host-geoip.conf
filter {
geoip {
source => "[host][ip]"
target => "[@metadata][host_geoip]"
}
if [@metadata][host_geoip] {
mutate {
copy => {
"[@metadata][host_geoip][city_name]" => "[host][geo][city_name]"
"[@metadata][host_geoip][country_name]" => "[host][geo][country_name]"
@yaauie
yaauie / tag-when-fields-over-threshold.logstash-filter-ruby.rb
Last active Jun 1, 2020
Logstash: tag when field count over threshold
View tag-when-fields-over-threshold.logstash-filter-ruby.rb
###############################################################################
# tag-when-fields-over-threshold.logstash-filter-ruby.rb
# ---------------------------------
# A script for a Logstash Ruby Filter to tag an event when it has "too many"
# fields, with a configurable threshold.
###############################################################################
#
# Copyright 2020 Ry Biesemeyer
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
View replace-subset.logstash-filter-ruby.rb
###############################################################################
# replace-subset.logstash-filter-ruby.rb
# ---------------------------------
# A script for a Logstash Ruby Filter to replace an event's contents with a
# subset that exists as an object in a field.
###############################################################################
#
# Copyright 2020 Ry Biesemeyer
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@yaauie
yaauie / delete-emtpy-nodes.logstash-filter-ruby.rb
Last active Jul 28, 2020
A script for a Logstash Ruby Filter to delete empty nodes from an event; by default, crawls the entire event recursively, but it can be configured to limit the scope.
View delete-emtpy-nodes.logstash-filter-ruby.rb
###############################################################################
# delete-emtpy-nodes.logstash-filter-ruby.rb
# ---------------------------------
# A script for a Logstash Ruby Filter to delete empty nodes from an event; by
# default, crawls the entire event recursively, but it can be configured to
# limit the scope.
###############################################################################
#
# Copyright 2018 Ry Biesemeyer
#