Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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