98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/logstash/filters/greynoise.rb', line 98
def filter(event)
valid = nil
begin
IPAddr.new(event.sprintf(ip))
rescue ArgumentError => e
valid = e
end
if valid
@logger.error("Invalid IP address, skipping", :ip => event.sprintf(ip), :event => event.to_hash)
event.tag(@tag_on_failure)
return
end
if @hit_cache
gn_result = @hit_cache[event.sprintf(ip)]
if gn_result
event.set(@target, gn_result)
filter_matched(event)
return
end
end
begin
gn_result = lookup_ip(event.sprintf(ip), event.sprintf(key), @full_context)
unless gn_result.nil?
if @hit_cache
@hit_cache[event.sprintf(ip)] = gn_result
end
event.set(@target, gn_result)
filter_matched(event)
end
rescue InvalidAPIKey => _
@logger.error("unauthorized - check API key")
event.tag(@tag_on_auth_failure)
end
end
|