156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/mongo_request_logger/viewer.rb', line 156
def query_from_terms(terms)
query = {}
errors = []
tags = (terms['tag'] || '').split(',')
if terms['user']
query['user_id'] = terms['user']
end
if terms['error'] == '1'
query['exception'] = {'$ne' => nil}
elsif terms['error'] == '0'
query['exception'] = nil
elsif terms['error']
query['exception.class'] = terms['error']
end
if terms['response']
query['response'] = terms['response'].to_i
end
if terms['ip']
query['ip'] = terms['ip']
end
begin
if terms.search_regex
query["messages"] = Regexp.new(terms.search_regex, Regexp::IGNORECASE)
elsif !terms.search.blank?
query["messages"] = Regexp.new(Regexp.escape(terms.search), Regexp::IGNORECASE)
end
rescue => e
errors << "Error in message regex: #{e.message}"
end
path = terms.path
unless path.blank?
if path.end_with?('$')
query["path"] = path[0...-1]
else
query["path"] = Regexp.new('^' + Regexp.escape(path))
end
end
unless terms['id'].blank?
query["ids"] = terms['id']
end
unless tags.empty?
query["tags"] = {"$all" => tags}
end
[query, errors]
end
|