graylogapi 0.0.1 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e18820f8c12cdbb4ee2ca5abbbae9cf243602a1
4
- data.tar.gz: a3f0359c7e296e882ada520d468b5d545330df68
3
+ metadata.gz: 683d85c513cb5ae61865a46e6df25f4c32059b4c
4
+ data.tar.gz: f26183d5c0741ed649760e09412d1fca673b3563
5
5
  SHA512:
6
- metadata.gz: 9c158262bfbe63f1dd4cc625cf9a06b430c7e09b14501774cce47cc38c9920398aa519ff9c7e50a3b3f2ecd8954fe42cd4309ca5dbc2a4a542b5461e47aaad48
7
- data.tar.gz: 35abed6db071d0d21ef7095d6d34569bf3a119b9bbf584b4239ad4bed580440a2f3398db1274d58a024a1ba885d1c0f96269c4a55651c8b34b11cb5b0b6dd1a8
6
+ metadata.gz: 5678337ae29a5d47027778b9a330730649725b95cbc75b475b35299e8cfda2edca90fb803136626f4cbf7ae0d5f4cada4b85544474db88c140d35af9dd7192e6
7
+ data.tar.gz: 860e06d3ffb7822c1d1b2bf32be4d571612b4a69cf57eba518753740c4c7b929f4568499f63b9f6f351737d9dc6f9c7424d7eb245eeee047773a97eafabad4de
data/README.md CHANGED
@@ -10,30 +10,65 @@ Ruby gem for working with [Graylog](https://www.graylog.org/) via the [Graylog R
10
10
 
11
11
  ## Installation
12
12
 
13
- gem install zabbixapi
13
+ gem install graylogapi
14
+ ## Dependencies
15
+
16
+ - net/http
17
+ - json
18
+
19
+ ## Graylog documentation
20
+
21
+ - [Graylog Homepage][Graylog]
22
+ - [Graylog API docs][GraylogAPI]
23
+
24
+ [Graylog]: https://www.graylog.org/
25
+ [GraylogAPI]: http://docs.graylog.org/en/2.2/pages/configuration/rest_api.html?highlight=API
14
26
 
15
27
  ## Usage
16
28
 
17
29
  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.
30
+ 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
31
 
20
32
  ### get Input by id
21
33
 
22
34
  graylogapi = Graylog.new('http://localhost:9000/api', 'username', 'password')
23
35
  graylogapi.system.inputs.by_id('5947d3840b5712166af25009')
24
36
 
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
+ ## Supported methods
38
+
39
+ * **Alerts**: Manage stream alerts for all streams
40
+ * recent(params) — Get the most recent alarms of all streams.
41
+ * paginated(params) — Get alarms of all streams, filtered by specifying limit and offset parameters.
42
+ * by_id(id, params) — Get an alert by ID.
43
+ * **Streams**: Manage streams
44
+ * all — Get a list of all streams.
45
+ * create(params) Create a stream.
46
+ * enabled — Get a list of all enabled streams.
47
+ * by_id — Get a single stream.
48
+ * update(id, params) — Update a stream.
49
+ * delete(id) — Delete a stream.
50
+ * clone(id, params) — Clone a stream.
51
+ * pause(id) — Pause a stream.
52
+ * resume(id) — Resume a stream.
53
+ * **System**: System informatino of this node.
54
+ * overview — Get system overview.
55
+ * jvm — Get JVM information.
56
+ * thread_dump — Get a thread dump.
57
+ * **System/Cluster**: Node discovery
58
+ * node — Infromation about this node.
59
+ * nodes — List all active nodes in this cluster.
60
+ * node_by_id — Infromation about a node.
61
+ * **System/IndexSets**: Index sets
62
+ * all — Get a list of all index sets.
63
+ * create(params) — Create index set.
64
+ * by_id(id) — Get index set by id.
65
+ * delete(id) — Delete index set.
66
+ * **System/Inputs**: Message inputs
67
+ * all — Get all inputs.
68
+ * by_id(id, params) — Get information of a single input on this node.
69
+ * create(params) — Launch input on this node.
70
+ * update(params) — Update input on this node.
71
+ * delete(id) — Terminate input on this node.
37
72
 
38
73
  ## Copyright
39
74
 
@@ -42,4 +77,3 @@ Copytight (c) 2017 Andrey Aleksandrov
42
77
  See [LICENSE][] for details.
43
78
 
44
79
  [license]: LICENSE.md
45
-
@@ -6,15 +6,15 @@ class GraylogAPI
6
6
  end
7
7
 
8
8
  def recent(options = {})
9
- @client.get('/streams/alerts', options)
9
+ @client.json_request(:get, '/streams/alerts', options)
10
10
  end
11
11
 
12
12
  def paginated(options = {})
13
- @client.get('/streams/alerts/paginated', options)
13
+ @client.json_reuqest(:get, '/streams/alerts/paginated', options)
14
14
  end
15
15
 
16
16
  def by_id(id, options = {})
17
- @client.get("/streams/alerts/#{id}", options)
17
+ @client.json_request(:get, "/streams/alerts/#{id}", options)
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+
3
+ class GraylogAPI
4
+ class Client
5
+ # Response of a http request
6
+ class Response
7
+ attr_accessor :code, :body
8
+
9
+ # Initialize object of response
10
+ #
11
+ # @param http_response [HTTP]
12
+ # @return GraylogAPI::Client::Response
13
+ def initialize(http_response)
14
+ self.body = parse_body(http_response.body)
15
+ self.code = http_response.code.to_i
16
+ end
17
+
18
+ def [](key)
19
+ body[key]
20
+ end
21
+
22
+ def keys
23
+ body.keys
24
+ end
25
+
26
+ def success?
27
+ (200..299).cover? code
28
+ end
29
+
30
+ def fail?
31
+ (400..599).cover? code
32
+ end
33
+
34
+ private
35
+
36
+ def parse_body(body)
37
+ if body.nil? || body.empty?
38
+ {}
39
+ else
40
+ begin
41
+ JSON.parse(body)
42
+ rescue
43
+ body
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,10 +1,17 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
- require 'json'
3
+ require 'graylogapi/client/response'
4
4
 
5
5
  class GraylogAPI
6
6
  # The client is the entry point to the api
7
7
  class Client
8
+ METHODS = {
9
+ delete: Net::HTTP::Delete,
10
+ get: Net::HTTP::Get,
11
+ post: Net::HTTP::Post,
12
+ put: Net::HTTP::Put
13
+ }.freeze
14
+
8
15
  # @return options of object [Hash]
9
16
  attr_reader :options
10
17
 
@@ -18,95 +25,35 @@ class GraylogAPI
18
25
  @http = Net::HTTP.new(uri.host, uri.port)
19
26
  end
20
27
 
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
28
+ # Make request to the API
40
29
  #
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
-
30
+ # @param method [Symbol] can be :get, :post, :delete, :put
31
+ # @param path [String] url
32
+ # @param params [Hash] request params
33
+ # @return Struct
59
34
  def json_request(method, path, params = {})
60
- request = method("#{method}_request").call(path, params)
35
+ request = request(method, path, params)
61
36
  request.basic_auth(options[:user], options[:pass])
62
37
  request.add_field('Content-Type', 'application/json')
63
38
  response = @http.request(request)
64
39
 
65
- response_struct(response)
40
+ Response.new(response)
66
41
  rescue
67
42
  response
68
43
  end
69
44
 
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
45
+ private
77
46
 
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
47
+ def request(method, path, params = {})
48
+ case method
49
+ when :get, :delete
50
+ full_path = [options[:base_url] + path, URI.encode_www_form(params)]
51
+ METHODS[method].new(full_path.join('?'))
52
+ when :post, :put
53
+ req = METHODS[method].new(options[:base_url] + path)
54
+ req.body = params.to_json
55
+ req
87
56
  end
88
57
  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
58
  end
112
59
  end
@@ -0,0 +1,44 @@
1
+ class GraylogAPI
2
+ # class for manage streams
3
+ class Streams
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def all
9
+ @client.json_request(:get, '/streams')
10
+ end
11
+
12
+ def create(params = {})
13
+ @client.json_request(:post, '/streams', params)
14
+ end
15
+
16
+ def enabled
17
+ @client.json_request(:get, '/streams/enabled')
18
+ end
19
+
20
+ def by_id(id)
21
+ @client.json_request(:get, "/streams/#{id}")
22
+ end
23
+
24
+ def update(id, params = {})
25
+ @client.json_request(:put, "/streams/#{id}", params)
26
+ end
27
+
28
+ def delete(id, params = {})
29
+ @client.json_request(:delete, "/streams/#{id}", params)
30
+ end
31
+
32
+ def clone(id, params = {})
33
+ @client.json_request(:post, "/streams/#{id}/clone", params)
34
+ end
35
+
36
+ def pause(id)
37
+ @client.json_request(:post, "/streams/#{id}/pause")
38
+ end
39
+
40
+ def resume(id)
41
+ @client.json_request(:post, "/streams/#{id}/resume")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ class GraylogAPI
2
+ class System
3
+ # class for get system information of a node
4
+ class Cluster
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def node
10
+ @client.json_request(:get, '/system/cluster/node')
11
+ end
12
+
13
+ def nodes
14
+ @client.json_request(:get, '/system/cluster/nodes')
15
+ end
16
+
17
+ def node_by_id(id)
18
+ @client.json_request(:get, "/system/cluster/nodes/#{id}")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ class GraylogAPI
2
+ class System
3
+ # class for manage System/IndexSets
4
+ class IndexSets
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def all
10
+ @client.json_request(:get, '/system/indices/index_sets')
11
+ end
12
+
13
+ def create(params)
14
+ @client.json_request(:post, '/system/indices/index_sets', params)
15
+ end
16
+
17
+ def by_id(id)
18
+ @client.json_request(:get, "/system/indices/index_sets/#{id}")
19
+ end
20
+
21
+ def delete(id)
22
+ @client.json_request(:delete, "/system/indices/index_sets/#{id}")
23
+ end
24
+ end
25
+ end
26
+ end
@@ -10,14 +10,14 @@ class GraylogAPI
10
10
  #
11
11
  # @return [Struct]
12
12
  def all
13
- @client.get('/system/inputs')
13
+ @client.json_request(:get, '/system/inputs')
14
14
  end
15
15
 
16
16
  # get input by input id
17
17
  #
18
18
  # @return [Struct]
19
19
  def by_id(id)
20
- @client.get("/system/inputs/#{id}")
20
+ @client.json_request(:get, "/system/inputs/#{id}")
21
21
  end
22
22
 
23
23
  # create input
@@ -25,7 +25,7 @@ class GraylogAPI
25
25
  # @param params [Hash]
26
26
  # @return [Struct]
27
27
  def create(params = {})
28
- @client.post('/system/inputs', params)
28
+ @client.json_request(:post, '/system/inputs', params)
29
29
  end
30
30
 
31
31
  # update input
@@ -33,7 +33,7 @@ class GraylogAPI
33
33
  # @param params [Hash]
34
34
  # @return [Struct]
35
35
  def update(id, params = {})
36
- @client.put("/system/inputs/#{id}", params)
36
+ @client.json_request(:put, "/system/inputs/#{id}", params)
37
37
  end
38
38
 
39
39
  # delete input
@@ -41,7 +41,7 @@ class GraylogAPI
41
41
  # @param params [Hash]
42
42
  # @return [Struct]
43
43
  def delete(id, params = {})
44
- @client.delete("/system/inputs/#{id}", params)
44
+ @client.json_request(:delete, "/system/inputs/#{id}", params)
45
45
  end
46
46
  end
47
47
  end
@@ -1,3 +1,5 @@
1
+ require 'graylogapi/system/cluster'
2
+ require 'graylogapi/system/index_sets'
1
3
  require 'graylogapi/system/inputs'
2
4
 
3
5
  class GraylogAPI
@@ -7,11 +9,31 @@ class GraylogAPI
7
9
  @client = client
8
10
  end
9
11
 
12
+ def overview
13
+ @client.json_request(:get, '/system')
14
+ end
15
+
16
+ def jvm
17
+ @client.json_request(:get, '/system/jvm')
18
+ end
19
+
20
+ def thread_dump
21
+ @client.json_request(:get, '/system/threaddump')
22
+ end
23
+
10
24
  # object for manage System/Inputs
11
25
  #
12
26
  # @return GraylogAPI::System::Inputs
13
27
  def inputs
14
28
  @inputs ||= Inputs.new(@client)
15
29
  end
30
+
31
+ def index_sets
32
+ @index_sets ||= IndexSets.new(@client)
33
+ end
34
+
35
+ def cluster
36
+ @cluster ||= Cluster.new(@client)
37
+ end
16
38
  end
17
39
  end
@@ -1,3 +1,3 @@
1
1
  class GraylogAPI
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/lib/graylogapi.rb CHANGED
@@ -2,8 +2,9 @@ libdir = File.dirname(__FILE__)
2
2
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
3
 
4
4
  require 'graylogapi/version'
5
- require 'graylogapi/client'
6
5
  require 'graylogapi/alerts'
6
+ require 'graylogapi/client'
7
+ require 'graylogapi/streams'
7
8
  require 'graylogapi/system'
8
9
 
9
10
  # class for work with graylog api
@@ -28,4 +29,9 @@ class GraylogAPI
28
29
  def system
29
30
  @system ||= System.new(@client)
30
31
  end
32
+
33
+ # @return [GraylogAPI::Streams]
34
+ def streams
35
+ @streams ||= Streams.new(@client)
36
+ end
31
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graylogapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Aleksandrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-19 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Allows you to work with graylog api from ruby
14
14
  email:
@@ -23,7 +23,11 @@ files:
23
23
  - lib/graylogapi.rb
24
24
  - lib/graylogapi/alerts.rb
25
25
  - lib/graylogapi/client.rb
26
+ - lib/graylogapi/client/response.rb
27
+ - lib/graylogapi/streams.rb
26
28
  - lib/graylogapi/system.rb
29
+ - lib/graylogapi/system/cluster.rb
30
+ - lib/graylogapi/system/index_sets.rb
27
31
  - lib/graylogapi/system/inputs.rb
28
32
  - lib/graylogapi/version.rb
29
33
  homepage: https://github.com/postgred/graylogapi