graylogapi 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +45 -0
- data/graylogapi.gemspec +21 -0
- data/lib/graylogapi/alerts.rb +20 -0
- data/lib/graylogapi/client.rb +112 -0
- data/lib/graylogapi/system/inputs.rb +48 -0
- data/lib/graylogapi/system.rb +17 -0
- data/lib/graylogapi/version.rb +3 -0
- data/lib/graylogapi.rb +31 -0
- metadata +53 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2e18820f8c12cdbb4ee2ca5abbbae9cf243602a1
|
|
4
|
+
data.tar.gz: a3f0359c7e296e882ada520d468b5d545330df68
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9c158262bfbe63f1dd4cc625cf9a06b430c7e09b14501774cce47cc38c9920398aa519ff9c7e50a3b3f2ecd8954fe42cd4309ca5dbc2a4a542b5461e47aaad48
|
|
7
|
+
data.tar.gz: 35abed6db071d0d21ef7095d6d34569bf3a119b9bbf584b4239ad4bed580440a2f3398db1274d58a024a1ba885d1c0f96269c4a55651c8b34b11cb5b0b6dd1a8
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Andrey Aleksandrov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# GraylogAPI
|
|
2
|
+
|
|
3
|
+
[][gem]
|
|
4
|
+
[][travis]
|
|
5
|
+
|
|
6
|
+
[gem]: https://rubygems.org/gems/graylogapi
|
|
7
|
+
[travis]: https://travis-ci.org/postgred/graylogapi
|
|
8
|
+
|
|
9
|
+
Ruby gem for working with [Graylog](https://www.graylog.org/) via the [Graylog REST API](http://docs.graylog.org/en/2.2/pages/configuration/rest_api.html?highlight=API)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
gem install zabbixapi
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Structure of gem looks like Graylog REST Api or navigation menu in UI.
|
|
18
|
+
For example, you can find **Inputs* in *System/Inputs* in the UI and you can find *Inputs* in `GraylogAPI.new(...).system.inputs` in the gem.
|
|
19
|
+
|
|
20
|
+
### get Input by id
|
|
21
|
+
|
|
22
|
+
graylogapi = Graylog.new('http://localhost:9000/api', 'username', 'password')
|
|
23
|
+
graylogapi.system.inputs.by_id('5947d3840b5712166af25009')
|
|
24
|
+
|
|
25
|
+
## Dependencies
|
|
26
|
+
|
|
27
|
+
* net/http
|
|
28
|
+
* json
|
|
29
|
+
|
|
30
|
+
## Graylog documentation
|
|
31
|
+
|
|
32
|
+
* [Graylog Homepage][Graylog]
|
|
33
|
+
* [Graylog API docs][GraylogAPI]
|
|
34
|
+
|
|
35
|
+
[Graylog]: https://www.graylog.org/
|
|
36
|
+
[GraylogAPI]: http://docs.graylog.org/en/2.2/pages/configuration/rest_api.html?highlight=API
|
|
37
|
+
|
|
38
|
+
## Copyright
|
|
39
|
+
|
|
40
|
+
Copytight (c) 2017 Andrey Aleksandrov
|
|
41
|
+
|
|
42
|
+
See [LICENSE][] for details.
|
|
43
|
+
|
|
44
|
+
[license]: LICENSE.md
|
|
45
|
+
|
data/graylogapi.gemspec
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'graylogapi/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'graylogapi'
|
|
9
|
+
spec.version = GraylogAPI::VERSION
|
|
10
|
+
spec.authors = ['Andrey Aleksandrov']
|
|
11
|
+
spec.email = ['postgred@gmail.com']
|
|
12
|
+
spec.license = 'MIT'
|
|
13
|
+
|
|
14
|
+
spec.summary = 'Ruby gem for working with Graylog API'
|
|
15
|
+
spec.description = 'Allows you to work with graylog api from ruby'
|
|
16
|
+
spec.homepage = 'https://github.com/postgred/graylogapi'
|
|
17
|
+
|
|
18
|
+
spec.files = ['README.md', 'graylogapi.gemspec', 'LICENSE'] +
|
|
19
|
+
Dir['lib/**/*.rb']
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class GraylogAPI
|
|
2
|
+
# class for manage stream alerts for all streams
|
|
3
|
+
class Alerts
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def recent(options = {})
|
|
9
|
+
@client.get('/streams/alerts', options)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def paginated(options = {})
|
|
13
|
+
@client.get('/streams/alerts/paginated', options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def by_id(id, options = {})
|
|
17
|
+
@client.get("/streams/alerts/#{id}", options)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
class GraylogAPI
|
|
6
|
+
# The client is the entry point to the api
|
|
7
|
+
class Client
|
|
8
|
+
# @return options of object [Hash]
|
|
9
|
+
attr_reader :options
|
|
10
|
+
|
|
11
|
+
# Initializes a new Client object
|
|
12
|
+
#
|
|
13
|
+
# @param options [Hash]
|
|
14
|
+
# @return [GraylogAPI::Client]
|
|
15
|
+
def initialize(options = {})
|
|
16
|
+
@options = options
|
|
17
|
+
uri = URI.parse(options[:base_url])
|
|
18
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Make get request to url
|
|
22
|
+
#
|
|
23
|
+
# @param url [String]
|
|
24
|
+
# @param params [Hash]
|
|
25
|
+
# @return [Struct]
|
|
26
|
+
def get(url, params = {})
|
|
27
|
+
json_request(:get, url, params)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Make post request to url
|
|
31
|
+
#
|
|
32
|
+
# @param url [String]
|
|
33
|
+
# @param params [Hash]
|
|
34
|
+
# @return [Struct]
|
|
35
|
+
def post(url, params = {})
|
|
36
|
+
json_request(:post, url, params)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Make post request to url
|
|
40
|
+
#
|
|
41
|
+
# @param url [String]
|
|
42
|
+
# @param params [Hash]
|
|
43
|
+
# @return [Struct]
|
|
44
|
+
def put(url, params = {})
|
|
45
|
+
json_request(:put, url, params)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Make post request to url
|
|
49
|
+
#
|
|
50
|
+
# @param url [String]
|
|
51
|
+
# @param params [Hash]
|
|
52
|
+
# @return [Struct]
|
|
53
|
+
def delete(url, params = {})
|
|
54
|
+
json_request(:delete, url, params)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def json_request(method, path, params = {})
|
|
60
|
+
request = method("#{method}_request").call(path, params)
|
|
61
|
+
request.basic_auth(options[:user], options[:pass])
|
|
62
|
+
request.add_field('Content-Type', 'application/json')
|
|
63
|
+
response = @http.request(request)
|
|
64
|
+
|
|
65
|
+
response_struct(response)
|
|
66
|
+
rescue
|
|
67
|
+
response
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def response_struct(response)
|
|
71
|
+
struct = Struct.new(:code, :body)
|
|
72
|
+
|
|
73
|
+
code = response.code.to_i
|
|
74
|
+
body = parse_body(response.body)
|
|
75
|
+
struct.new(code, body)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def parse_body(body)
|
|
79
|
+
if body.nil? || body.empty?
|
|
80
|
+
{}
|
|
81
|
+
else
|
|
82
|
+
begin
|
|
83
|
+
JSON.parse(body)
|
|
84
|
+
rescue
|
|
85
|
+
body
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def get_request(path, params = {})
|
|
91
|
+
full_path = [options[:base_url] + path, URI.encode_www_form(params)]
|
|
92
|
+
Net::HTTP::Get.new(full_path.join('?'))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def post_request(path, params = {})
|
|
96
|
+
req = Net::HTTP::Post.new(options[:base_url] + path)
|
|
97
|
+
req.body = params.to_json
|
|
98
|
+
req
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def put_request(path, params = {})
|
|
102
|
+
req = Net::HTTP::Put.new(options[:base_url] + path)
|
|
103
|
+
req.body = params.to_json
|
|
104
|
+
req
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def delete_request(path, params = {})
|
|
108
|
+
full_path = [options[:base_url] + path, URI.encode_www_form(params)]
|
|
109
|
+
Net::HTTP::Delete.new(full_path.join('?'))
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class GraylogAPI
|
|
2
|
+
class System
|
|
3
|
+
# class for manage inputs
|
|
4
|
+
class Inputs
|
|
5
|
+
def initialize(client)
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# get all inputs
|
|
10
|
+
#
|
|
11
|
+
# @return [Struct]
|
|
12
|
+
def all
|
|
13
|
+
@client.get('/system/inputs')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# get input by input id
|
|
17
|
+
#
|
|
18
|
+
# @return [Struct]
|
|
19
|
+
def by_id(id)
|
|
20
|
+
@client.get("/system/inputs/#{id}")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# create input
|
|
24
|
+
#
|
|
25
|
+
# @param params [Hash]
|
|
26
|
+
# @return [Struct]
|
|
27
|
+
def create(params = {})
|
|
28
|
+
@client.post('/system/inputs', params)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# update input
|
|
32
|
+
#
|
|
33
|
+
# @param params [Hash]
|
|
34
|
+
# @return [Struct]
|
|
35
|
+
def update(id, params = {})
|
|
36
|
+
@client.put("/system/inputs/#{id}", params)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# delete input
|
|
40
|
+
#
|
|
41
|
+
# @param params [Hash]
|
|
42
|
+
# @return [Struct]
|
|
43
|
+
def delete(id, params = {})
|
|
44
|
+
@client.delete("/system/inputs/#{id}", params)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'graylogapi/system/inputs'
|
|
2
|
+
|
|
3
|
+
class GraylogAPI
|
|
4
|
+
# class for manage system
|
|
5
|
+
class System
|
|
6
|
+
def initialize(client)
|
|
7
|
+
@client = client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# object for manage System/Inputs
|
|
11
|
+
#
|
|
12
|
+
# @return GraylogAPI::System::Inputs
|
|
13
|
+
def inputs
|
|
14
|
+
@inputs ||= Inputs.new(@client)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/graylogapi.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
3
|
+
|
|
4
|
+
require 'graylogapi/version'
|
|
5
|
+
require 'graylogapi/client'
|
|
6
|
+
require 'graylogapi/alerts'
|
|
7
|
+
require 'graylogapi/system'
|
|
8
|
+
|
|
9
|
+
# class for work with graylog api
|
|
10
|
+
class GraylogAPI
|
|
11
|
+
# @return [GraylogAPI::Client]
|
|
12
|
+
attr_reader :client
|
|
13
|
+
|
|
14
|
+
# Initializes a new GraylogAPI object
|
|
15
|
+
#
|
|
16
|
+
# @param options [Hash]
|
|
17
|
+
# @return [GraylogAPI]
|
|
18
|
+
def initialize(options = {})
|
|
19
|
+
@client = Client.new(options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @return [GraylogAPI::Alerts]
|
|
23
|
+
def alerts
|
|
24
|
+
@alerts ||= Alerts.new(@client)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @return [GraylogAPI::System]
|
|
28
|
+
def system
|
|
29
|
+
@system ||= System.new(@client)
|
|
30
|
+
end
|
|
31
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: graylogapi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrey Aleksandrov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-06-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Allows you to work with graylog api from ruby
|
|
14
|
+
email:
|
|
15
|
+
- postgred@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- graylogapi.gemspec
|
|
23
|
+
- lib/graylogapi.rb
|
|
24
|
+
- lib/graylogapi/alerts.rb
|
|
25
|
+
- lib/graylogapi/client.rb
|
|
26
|
+
- lib/graylogapi/system.rb
|
|
27
|
+
- lib/graylogapi/system/inputs.rb
|
|
28
|
+
- lib/graylogapi/version.rb
|
|
29
|
+
homepage: https://github.com/postgred/graylogapi
|
|
30
|
+
licenses:
|
|
31
|
+
- MIT
|
|
32
|
+
metadata: {}
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubyforge_project:
|
|
49
|
+
rubygems_version: 2.6.11
|
|
50
|
+
signing_key:
|
|
51
|
+
specification_version: 4
|
|
52
|
+
summary: Ruby gem for working with Graylog API
|
|
53
|
+
test_files: []
|