Created
June 29, 2020 12:52
-
-
Save Drowze/d436ff0306846e75bf7f343ee84d66f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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