elastic / elastic/logstash

Official way to add a Gem inside Logstash for use with Ruby Filter?

Open
#7,016 7 comments 7 reactions 0 assignees View on GitHub
discuss packaging plugin manager
Dominant language
Java
Stars
14.9k
Forks
3.5k
Avg merge
19h 14m
Merged PRs (30d)
63

Description

At the moment there is no official way to add a Gem on Logstash to make it available for all plugins. As I didn't want to write my own plugin for this (because there is a lot of boilerplate, releases to do... and I only need 10 lines of ruby) here is what I did.

I added this to the root Gemfile (`/usr/share/logstash/Gemfile`):
```
gem "device_detector", "~> 1.0"
```

I ran this to force Logstash updating the gems:
```
/usr/share/logstash/bin/logstash-plugin update logstash-filter-grok
```

Then I can see my Gem in `/usr/share/logstash/vendor/bundle/jruby/1.9/gems/device_detector-1.0.0/` :+1: and use it inside a **ruby** filter for example:

```
filter {
if [user_agent] =~ /.+/ {
ruby {
init => 'require "device_detector"'
code => 'ua = event.get("user_agent")

client = DeviceDetector.new(ua)

if (client.known?)
event.set("[ua_detect][os][name]", client.os_name)
event.set("[ua_detect][os][version]", client.os_full_version)
event.set("[ua_detect][client][name]", client.name)
event.set("[ua_detect][device][type]", client.device_type)
event.set("[ua_detect][device][model]", client.device_name)
end'
}
}
}
```

It works but it feels like a hack...

- is it supposed to work or is there a better way?
- the bundler update is not exposed and I had to use a `bin/logstash-plugin update` call, maybe it should be added as a proper command in the bin directory?

Thanks!
_This way done with Logstash 5.3.1._

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.