wazuh-ruby-client 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5378e67cd9073d90868662fe577ddafdbbd774f5813ae4883646fb1573804ef
4
- data.tar.gz: 475ab3b706db3da28ba4bf80f1234e2d3ebe37f5e94d73c5cef98e87f51fd2f5
3
+ metadata.gz: 657652b05f675dd6fbe1ddb5e81adb03ef185d0eae786ffdfd30421ee975fcec
4
+ data.tar.gz: '0948eea68b62f1d1f66eb74e058edcd4ef3200cfb2eeca8b45c51cd782983ec3'
5
5
  SHA512:
6
- metadata.gz: b5cdd839f283f03626900446db96eb040ba368664c1110a3f04bb4e31468f7e9f01cba0382006c79f074a9c14dcfed2344e2d302010d780b2dcfe8e237ac4273
7
- data.tar.gz: d6443f7b6f466542b8e705b18318fef5444ec8309afa3631db0188391013955496b8c5ad04a88efdf1dc49391c648dea5523e8ffe9441f00064f85ff8e0b8bad
6
+ metadata.gz: 1f0718c22e673a282d6849dc5d9829f440357d34d5fd891bf6e42f43cb99ba8cbec019736d192b162901d6bf6fac1e7c3ecc30a1a42db11cbcc14ff3b9155132
7
+ data.tar.gz: 45151ead99511c81f03fd944415a0d8098613a0cadf601bfa04ccaf58cee504d7e88ce6e97bd531fa7a4917cf5603f3e7a0367a7d21e624fd9618b7d0fcaae12
data/.rubocop.yml ADDED
@@ -0,0 +1,59 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.6
7
+ DisplayCopNames: true
8
+ DisabledByDefault: true
9
+ Exclude:
10
+ - 'vendor/**/*'
11
+ - 'bin/bundle'
12
+
13
+ Style/HashSyntax:
14
+ Enabled: true
15
+
16
+ Layout/EmptyLines:
17
+ Enabled: true
18
+
19
+ Layout/TrailingEmptyLines:
20
+ Enabled: true
21
+
22
+ Layout/TrailingWhitespace:
23
+ Enabled: true
24
+
25
+ Style/MethodDefParentheses:
26
+ Enabled: true
27
+
28
+ # Generated by gry
29
+
30
+ Layout/AccessModifierIndentation:
31
+ EnforcedStyle: indent
32
+ Enabled: true
33
+
34
+ Layout/CaseIndentation:
35
+ EnforcedStyle: end
36
+ Enabled: true
37
+
38
+ Style/Encoding:
39
+ Enabled: true
40
+
41
+ Style/For:
42
+ EnforcedStyle: each
43
+ Enabled: true
44
+
45
+ Style/FrozenStringLiteralComment:
46
+ EnforcedStyle: never
47
+ Enabled: false
48
+
49
+ Layout/MultilineHashBraceLayout:
50
+ EnforcedStyle: symmetrical
51
+ Enabled: true
52
+
53
+ Style/NumericLiteralPrefix:
54
+ EnforcedOctalStyle: zero_only
55
+ Enabled: true
56
+
57
+ Style/StabbyLambdaParentheses:
58
+ EnforcedStyle: require_parentheses
59
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ Supports v4 Cluster API.
11
+
12
+ - [Supports v4 Cluster API by mrtc0 · Pull Request #36 · mrtc0/wazuh-ruby-client](https://github.com/mrtc0/wazuh-ruby-client/pull/36)
13
+
10
14
  ## [0.3.4]
11
15
 
12
16
  Support Vulnerability API.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
7
7
 
8
8
  task :doc do
9
9
  sh %{yardoc 'lib/**/*.rb' --output docs}
@@ -4,7 +4,7 @@ module Wazuh
4
4
  module Agents
5
5
  #
6
6
  # Returns a list with the available agents.
7
- #
7
+ #
8
8
  # @option options [String] :offset
9
9
  # First element to return in the collection.
10
10
  # @option options [String] :limit
@@ -21,7 +21,7 @@ module Wazuh
21
21
  end
22
22
 
23
23
  # Get last rootcheck scan
24
- # Returns the timestamp of the last rootcheck scan.
24
+ # Returns the timestamp of the last rootcheck scan.
25
25
  #
26
26
  # @param [String] agent_id
27
27
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-last-rootcheck-scan
@@ -15,7 +15,7 @@ module Wazuh
15
15
  # Filters by policy description
16
16
  # @option options [rationale] :rationale
17
17
  # Filters by rationale
18
- # @option options [remediation] :remediation
18
+ # @option options [remediation] :remediation
19
19
  # Filters by remediation
20
20
  # @option options [file] :file
21
21
  # Filters by file
@@ -216,7 +216,7 @@ module Wazuh
216
216
  # Filters by process sgroup.
217
217
  # @option options [suser] :suser
218
218
  # Filters by process suser.
219
- #
219
+ #
220
220
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-processes-info
221
221
  def processes(agent_id, options = {})
222
222
  offset_request('get', "/syscollector/#{agent_id}/processes", options)
@@ -4,6 +4,133 @@ module Wazuh
4
4
  module V4
5
5
  module Cluster
6
6
  include ::Wazuh::Api::Endpoints::Cluster
7
+
8
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_cluster_node
9
+ def local_node_info(options = {})
10
+ offset_request('get', '/cluster/local/info', options)
11
+ end
12
+
13
+ alias_method :get_cluster_node, :local_node_info
14
+
15
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_cluster_nodes
16
+ def nodes_info(options = {})
17
+ offset_request('get', '/cluster/nodes', options)
18
+ end
19
+
20
+ alias_method :get_cluster_nodes, :nodes_info
21
+
22
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_healthcheck
23
+ def nodes_healthcheck(options = {})
24
+ offset_request('get', '/cluster/healthcheck', options)
25
+ end
26
+
27
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_status
28
+ def cluster_status(options = {})
29
+ get '/cluster/status', options
30
+ end
31
+
32
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_config
33
+ def local_node_config(options = {})
34
+ offset_request('get', '/cluster/local/config', options)
35
+ end
36
+
37
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_api_config
38
+ def nodes_api_config(options = {})
39
+ offset_request('get', '/cluster/api/config', options)
40
+ end
41
+
42
+ alias_method :get_api_config, :nodes_api_config
43
+
44
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_status_node
45
+ def node_status(node_id, options = {})
46
+ offset_request('get', "/cluster/#{node_id}/status", options)
47
+ end
48
+
49
+ alias_method :get_status_node, :node_status
50
+
51
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_info_node
52
+ def node_info(node_id, options = {})
53
+ offset_request('get', "/cluster/#{node_id}/info", options)
54
+ end
55
+
56
+ alias_method :get_info_node, :node_info
57
+
58
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_configuration_node
59
+ def node_config(node_id, options = {})
60
+ offset_request('get', "/cluster/#{node_id}/configuration", options)
61
+ end
62
+
63
+ alias_method :get_configuration_node, :node_config
64
+
65
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_stats_node
66
+ def node_stats(node_id, options = {})
67
+ offset_request('get', "/cluster/#{node_id}/stats", options)
68
+ end
69
+
70
+ alias_method :get_stats_node, :node_stats
71
+
72
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_stats_hourly_node
73
+ def node_stats_hour(node_id, options = {})
74
+ offset_request('get', "/cluster/#{node_id}/stats/hourly", options)
75
+ end
76
+
77
+ alias_method :get_stats_hourly_node, :node_stats_hour
78
+
79
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_stats_weekly_node
80
+ def node_stats_week(node_id, options = {})
81
+ offset_request('get', "/cluster/#{node_id}/stats/weekly", options)
82
+ end
83
+
84
+ alias_method :get_stats_weekly_node, :node_stats_week
85
+
86
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_stats_analysisd_node
87
+ def node_stats_analysisd(node_id, options = {})
88
+ offset_request('get', "/cluster/#{node_id}/stats/analysisd", options)
89
+ end
90
+
91
+ alias_method :get_stats_analysisd_node, :node_stats_analysisd
92
+
93
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_stats_remoted_node
94
+ def node_stats_remoted(node_id, options = {})
95
+ offset_request('get', "/cluster/#{node_id}/stats/remoted", options)
96
+ end
97
+
98
+ alias_method :get_stats_remoted_node, :node_stats_remoted
99
+
100
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_log_node
101
+ def node_logs(node_id, options = {})
102
+ offset_request('get', "/cluster/#{node_id}/logs", options)
103
+ end
104
+
105
+ alias_method :get_log_node, :node_logs
106
+
107
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_log_summary_node
108
+ def node_logs_summary(node_id, options = {})
109
+ offset_request('get', "/cluster/#{node_id}/logs/summary", options)
110
+ end
111
+
112
+ alias_method :get_log_summary_node, :node_logs_summary
113
+
114
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.put_restart
115
+ def restart_nodes(options = {})
116
+ offset_request('put', "/cluster/restart", options)
117
+ end
118
+
119
+ alias_method :put_restart, :restart_nodes
120
+
121
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_conf_validation
122
+ def check_nodes_config(options = {})
123
+ offset_request('get', "/cluster/configuration/validationj", options)
124
+ end
125
+
126
+ alias_method :get_conf_validation, :check_nodes_config
127
+
128
+ # https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.cluster_controller.get_node_config
129
+ def node_active_configuration(node_id, component, configuration, options = {})
130
+ offset_request('get', "/cluster/#{node_id}/configuration/#{component}/#{configuration}", options)
131
+ end
132
+
133
+ alias_method :get_node_config, :node_active_configuration
7
134
  end
8
135
  end
9
136
  end
data/lib/wazuh/client.rb CHANGED
@@ -31,4 +31,3 @@ module Wazuh
31
31
  end
32
32
  end
33
33
  end
34
-
@@ -18,7 +18,7 @@ module Wazuh
18
18
  options[:ssl].merge!({ verify: false }) unless verify_ssl
19
19
 
20
20
  opts = {
21
- :links_parser => ::Sawyer::LinkParsers::Simple.new
21
+ links_parser: ::Sawyer::LinkParsers::Simple.new
22
22
  }
23
23
 
24
24
  case api_version
@@ -2,49 +2,55 @@
2
2
  module Wazuh
3
3
  module Sawyer
4
4
  module Request
5
+ MAX_ITEM_NUM = 500
6
+
5
7
  def get(path, options = {})
6
- request(:get, path, options)
8
+ request(:get, path, options).data
7
9
  end
8
10
 
9
11
  def post(path, options = {})
10
- request(:post, path, options)
12
+ request(:post, path, options).data
11
13
  end
12
14
 
13
15
  def put(path, options = {})
14
- request(:put, path, options)
16
+ request(:put, path, options).data
15
17
  end
16
18
 
17
19
  def delete(path, options = {})
18
- request(:delete, path, options)
20
+ request(:delete, path, options).data
19
21
  end
20
22
 
23
+ # The response format is different for v3 and v4.
24
+ # In v3, it is a camel case like `totalItems` and `items`,
25
+ # but in v4, it is snake case like total_affected_items.
26
+ # offset_request will fill this gap.
27
+ # This function is used if there are `affected_items` or `items` in the response.
21
28
  def offset_request(method, path, options = {})
22
29
  items = []
23
30
  data = send(method, path, options)
24
31
  total_items = api_version == 3 ? data.totalItems : data.total_affected_items
25
- 0.step(total_items, 500) { |offset|
32
+ 0.step(total_items, MAX_ITEM_NUM) do |offset|
26
33
  options[:offset] = offset
27
34
  d = send(method, path, options)
28
35
  _items = api_version == 3 ? data.items : d.affected_items
29
36
  items.concat(_items)
30
- }
37
+ end
31
38
 
32
39
  items
33
40
  end
34
41
 
35
-
36
42
  private
37
43
 
38
44
  def request(method, path, options, query_options={})
39
45
  response = case method
40
- when :get, :delete
41
- connection.call(method, URI::Parser.new.escape(path), nil, {query: options})
42
- when :post, :put
43
- data = options unless options.empty?
44
- connection.call(method, URI::Parser.new.escape(path), data, {query: query_options})
45
- end
46
-
47
- return response.data.data if response.status == 200
46
+ when :get, :delete
47
+ connection.call(method, URI::Parser.new.escape(path), nil, {query: options})
48
+ when :post, :put
49
+ data = options unless options.empty?
50
+ connection.call(method, URI::Parser.new.escape(path), data, {query: query_options})
51
+ end
52
+
53
+ return response.data if response.status == 200
48
54
 
49
55
  raise Wazuh::Api::Errors::WazuhError.new(response.body, response)
50
56
  end
data/lib/wazuh/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Wazuh
3
- VERSION = '0.3.4'
3
+ VERSION = '0.3.5'
4
4
  end
@@ -1,3 +1,3 @@
1
1
  module WazuhRubyClient
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wazuh-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - mrtc0
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-03 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -189,7 +189,7 @@ files:
189
189
  - ".github/workflows/rspec-ci.yml"
190
190
  - ".gitignore"
191
191
  - ".rspec"
192
- - ".travis.yml"
192
+ - ".rubocop.yml"
193
193
  - CHANGELOG.md
194
194
  - Gemfile
195
195
  - LICENSE
@@ -306,7 +306,7 @@ metadata:
306
306
  homepage_uri: https://github.com/mrtc0/wazuh-ruby-client
307
307
  source_code_uri: https://github.com/mrtc0/wazuh-ruby-client
308
308
  changelog_uri: https://github.com/mrtc0/wazuh-ruby-client/blob/master/CHANGELOG.md
309
- post_install_message:
309
+ post_install_message:
310
310
  rdoc_options: []
311
311
  require_paths:
312
312
  - lib
@@ -322,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
322
  version: '0'
323
323
  requirements: []
324
324
  rubygems_version: 3.1.4
325
- signing_key:
325
+ signing_key:
326
326
  specification_version: 4
327
327
  summary: Wazuh API client for Ruby
328
328
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.17.3