Skip to content

Commit

Permalink
Short circuit empty sources, update DB
Browse files Browse the repository at this point in the history
Fixes #134
  • Loading branch information
jakelandis committed Dec 21, 2017
1 parent f6fe313 commit a251675
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.3
- Skip lookup operation if source field contains an empty string
- Update of the GeoIP2 DB

## 5.0.2
- Update gemspec summary

Expand Down
2 changes: 1 addition & 1 deletion logstash-filter-geoip.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-filter-geoip'
s.version = '5.0.2'
s.version = '5.0.3'
s.licenses = ['Apache License (2.0)']
s.summary = "Adds geographical information about an IP address"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
12 changes: 10 additions & 2 deletions spec/filters/geoip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@

it "should set other subfields of 'target' properly" do
expect(event.get("target").to_hash.keys.sort).to eq(["city_name", "ip", "region_name"])
expect(event.get("[target][city_name]")).to eq("Salem")
expect(event.get("[target][region_name]")).to eq("New Hampshire")
expect(event.get("[target][city_name]")).to eq("Watertown")
expect(event.get("[target][region_name]")).to eq("Massachusetts")
end

end
Expand Down Expand Up @@ -183,6 +183,14 @@
sample("ip" => "~") do
expect{ subject }.to_not raise_error
end

sample("ip" => "") do
expect{ subject }.to_not raise_error
end

sample("ip" => " ") do
expect{ subject }.to_not raise_error
end
end

describe "filter method outcomes" do
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/logstash/filters/GeoIPFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,21 @@ public boolean handleEvent(RubyEvent rubyEvent) {
if (input == null) {
return false;
}

String ip;

if (input instanceof List) {
ip = (String) ((List) input).get(0);

} else if (input instanceof String) {
ip = (String) input;
} else {
throw new IllegalArgumentException("Expected input field value to be String or List type");
}

if (ip.trim().isEmpty()){
return false;
}

Map<String, Object> geoData = new HashMap<>();

try {
Expand Down
2 changes: 1 addition & 1 deletion vendor.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"url": "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz",
"sha1": "fe165dab8ed0f2e980fbce81d05f5e120b0b1fa9"
"sha1": "faccb3c92fd5bee0261e6e7640a79c7e37624d16"
},
{
"url": "https://s3.amazonaws.com/download.elasticsearch.org/logstash/maxmind/GeoLite2-ASN.mmdb",
Expand Down

0 comments on commit a251675

Please sign in to comment.