Skip to content

Instantly share code, notes, and snippets.

@Drowze
Created June 29, 2020 12:52
Show Gist options
  • Save Drowze/d436ff0306846e75bf7f343ee84d66f2 to your computer and use it in GitHub Desktop.
Save Drowze/d436ff0306846e75bf7f343ee84d66f2 to your computer and use it in GitHub Desktop.
require 'bundler/inline'
require 'minitest/autorun'
gemfile do
source 'https://rubygems.org'
gem 'http'
end
require 'http'
require 'cgi'
require 'json'
class GraylogClient
def initialize(options = {})
@host = options[:host]
@user = options[:user]
@pass = options[:pass]
end
def get(endpoint, params)
HTTP.use(:auto_inflate).accept(:json).basic_auth(user: @user, pass: @pass)
.get(@host + endpoint, params: params).then(&JSON.method(:parse))
end
def search_relative(query:, range: 604800, fields: ['message'])
params = { query: CGI.escape(query), range: range, fields: fields.join(',') }
get('/search/universal/relative', params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment