wazuh-ruby-client 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: ded83ec025b9d8642e903ca794ce1993d466effbc2bb022d89350d925a74dde1
4
- data.tar.gz: 377684edb28efde74086e4c3ce1ed1b256d87903bc565686ff22ac054d3bd2e7
3
+ metadata.gz: 15da6e2031a3436d1aa11ec4131497d2d616f3c27d997a92183f4a8e3e94d19e
4
+ data.tar.gz: a47ef14bb2e13720cf96f37942d88d496de56767e4a0a451fddc1cf7df3eb45d
5
5
  SHA512:
6
- metadata.gz: 8e764f47349a4af81238a58b7afb7a0d3ba010d97128882ee9f4ba51778b191b8d7f234cf47522e09f9077a8909759e58608513364a32d7dad3e852aa55a8161
7
- data.tar.gz: 91bbf1387a1c54e4531f95c97443c307af46d8039c39f8d5b37653f616638eb3bdd850a818445e30270dd3dfb71d0ab44739c8c3c04f227966fd93717b44d3a4
6
+ metadata.gz: d8914b3341e3d265defb99a63a8cde65218deb403f0b08eeac95de57f4381cce16b185a86a5c7bd027f1dfe06ee195bee02debe9f2b68f7425432bcf30601e86
7
+ data.tar.gz: ac233ed7ba42fded2d84806fa2517a1517474795cf01940adab08aa5cce8ca9a72008c36d727f6404009f6eaa78cb714162877164df24457acfa5bc917364fb9
data/CHANGELOG.md CHANGED
@@ -0,0 +1,35 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [Unreleased]
9
+
10
+ Bump up to 0.2.0
11
+
12
+ ## [0.2.0] - 2019-02-03
13
+
14
+ ### Adds
15
+
16
+ - `Wazuh::Client#delete_agent`
17
+ - `Wazuh::Client#syscheck_files`
18
+
19
+ ### Changed
20
+
21
+ - `Wazuh::Client#cdb_files` rename to `Wazuh::Client#cdb_files_path`
22
+ - Using sawyer instead of faraday for http client.
23
+ - This can the return vaule to be handle like an object.
24
+
25
+ ```ruby
26
+ > agents = client.all_agents
27
+ > agents.class
28
+ => Array
29
+ > agent = agents.first
30
+ > agent.id
31
+ => "000"
32
+ > agent.os.arch
33
+ => "x86_64"
34
+ ```
35
+
data/README.md CHANGED
@@ -56,7 +56,95 @@ Wazuh.configure do |config|
56
56
  end
57
57
  ```
58
58
 
59
- ## Support API
59
+ ### Global Settings
60
+
61
+ The following global settings are supported via `Wazuh.configure` .
62
+
63
+ | setting | description |
64
+ |:--------|:------------|
65
+ | user_agent | User-Agent |
66
+ | client_cert | Client certificate (if use Client Certificate Authentication) |
67
+ | client_key | Client Key (if use Client Certificate Authentication) |
68
+ | basic_user | Basic Authentication user name |
69
+ | basic_password | Basic Authentication password |
70
+ | verify_ssl | Skip the SSL/TLS verify |
71
+ | logger | loggeer object |
72
+ | endpoint | Wazuh API endpoint URL |
73
+
74
+
75
+ ### Agents
76
+
77
+ Get all agents list.
78
+
79
+ ```ruby
80
+ > client.all_agents
81
+ # => {"error"=>0,
82
+ "data"=>
83
+ {"items"=>
84
+ [{"os"=>
85
+ {"arch"=>"x86_64",
86
+ "codename"=>"Xenial Xerus",
87
+ "major"=>"16",
88
+ "minor"=>"04",
89
+ "name"=>"Ubuntu",
90
+ "platform"=>"ubuntu",
91
+ "uname"=>"Linux |wazuh-manager-master-0 |4.14.138+ |#1 SMP Tue Sep 3 02:58:08 PDT 2019 |x86_64",
92
+ "version"=>"16.04.6 LTS"},
93
+ "status"=>"Active",
94
+ "dateAdd"=>"2020-01-07 16:13:05",
95
+ "ip"=>"127.0.0.1",
96
+ "id"=>"000",
97
+ "registerIP"=>"127.0.0.1",
98
+ "node_name"=>"wazuh-manager-master",
99
+ "manager"=>"wazuh-manager-master-0",
100
+ "name"=>"wazuh-manager-master-0",
101
+ "lastKeepAlive"=>"9999-12-31 23:59:59",
102
+ "version"=>"Wazuh v3.11.1"}],
103
+ ...
104
+ "totalItems"=>5}}
105
+ ```
106
+
107
+ filter by options. (see https://mrtc0.github.io/wazuh-ruby-client/Wazuh/Api/Endpoints/Agents.html#all_agents-instance_method )
108
+
109
+ ```ruby
110
+ # Filter by status is active
111
+ > client.all_agents({ status: 'active' })
112
+ # Filter by agent os.name is ubuntu
113
+ > client.all_agents({ 'os.name' => 'ubuntu' })
114
+ ```
115
+
116
+ ### Syscollector
117
+
118
+ List agent's packages.
119
+
120
+ ```ruby
121
+ > client.packages('000')['data']['items'].map { |package| package['name'] }
122
+ => ["python-apt-common",
123
+ "python-idna",
124
+ "libedit2",
125
+ "libncurses5",
126
+ "libpam-runtime",
127
+ "python3.5",
128
+ "libgsasl7",
129
+ "vim-tiny",
130
+ ...
131
+ ```
132
+
133
+ List agents' processes.
134
+
135
+ ```ruby
136
+ > client.processes('000')['data']['items'].map { |p| p['name'] }
137
+ => ["entrypoint.sh",
138
+ "my_init",
139
+ "syslog-ng",
140
+ "runsvdir",
141
+ "runsv",
142
+ ...
143
+ ```
144
+
145
+ ### Other
146
+
147
+ wazuh-ruby-client is support to all Wazuh API.
60
148
 
61
149
  - [x] Active Response
62
150
  - [x] Agents
@@ -74,6 +162,18 @@ end
74
162
  - [x] Syscheck
75
163
  - [x] Syscollector
76
164
 
165
+ Refer to the document of wazuh-ruby-client and Wazuh API Reference for the list of all available methods.
166
+
167
+ - https://mrtc0.github.io/wazuh-ruby-client/Wazuh/Api/Endpoints.html
168
+ - https://documentation.wazuh.com/3.10/user-manual/api/reference.html
169
+
77
170
  ## Contributing
78
171
 
79
172
  Bug reports and pull requests are welcome on GitHub at https://github.com/mrtc0/wazuh-ruby-client.
173
+
174
+ ## Copyright and License
175
+
176
+ Copyright (c) 2015-2019, [Kohei Morita](https://blog.ssrf.in)
177
+
178
+ This project is licensed under the [MIT License](https://github.com/mrtc0/wazuh-ruby-client/blob/master/LICENSE) .
179
+
@@ -5,26 +5,26 @@ module Wazuh
5
5
  #
6
6
  # Returns a list with the available agents.
7
7
  #
8
- # @option options [offset] :offset
8
+ # @option options [String] :offset
9
9
  # First element to return in the collection.
10
- # @option options [limit] :limit
10
+ # @option options [String] :limit
11
11
  # Maximum number of elements to return.
12
- # @option options [select] :select
12
+ # @option options [String] :select
13
13
  # Select which fields to return (separated by comma).
14
- # @option options [sort] :sort
14
+ # @option options [String] :sort
15
15
  # Sorts the collection by a field or fields (separated by comma). Use +/- at the beginning to list in ascending or descending order.
16
- # @option options [search] :search
16
+ # @option options [String] :search
17
17
  # Looks for elements with the specified string.
18
- # @option options [status] :status
18
+ # @option options [String] :status
19
19
  # Filters by agent status. Use commas to enter multiple statuses.
20
20
  # Allowed values: active, pending, neverconnected, disconnected
21
- # @option options [q] :q
22
- # Query to filter results by. For example q=”status=Active”
23
- # @option options [order_than] :order_than
21
+ # @option options [String] :order_than
24
22
  # Filters out disconnected agents for longer than specified. Time in seconds, ‘[n_days]d’, ‘[n_hours]h’, ‘[n_minutes]m’ or ‘[n_seconds]s’. For never connected agents, uses the register date.
23
+ # @return [Array] Returns Array containing agents
25
24
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-all-agents
26
25
  def all_agents(options = {})
27
- get '/agents', options
26
+ data = get '/agents', options
27
+ data.items
28
28
  end
29
29
 
30
30
  # Returns various information from an agent.
@@ -33,6 +33,7 @@ module Wazuh
33
33
  # ID to agent
34
34
  # @option options [select] :select
35
35
  # List of selected fields separated by commas.
36
+ # @return [Sawyer::Resource] Returns Sawyer::Resource
36
37
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-an-agent
37
38
  def agent(agent_id, options = {})
38
39
  get "/agents/#{agent_id}", options
@@ -44,15 +45,18 @@ module Wazuh
44
45
  # Name to agent
45
46
  # @option options [select] :select
46
47
  # List of selected fields separated by commas.
48
+ # @return [Sawyer::Resource] Returns Sawyer::Resource
47
49
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-an-agent-by-its-name
48
50
  def agent_by_name(agent_name, options = {})
49
51
  get "/agents/name/#{agent_name}", options
50
52
  end
51
53
 
54
+ # Get agent key
52
55
  # Returns the key of an agent.
53
56
  #
54
57
  # @param [String] agent_id
55
58
  # ID to agent
59
+ # @return [String] Returns the key of an agent
56
60
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-agent-key
57
61
  def agent_key(agent_id, options = {})
58
62
  get "/agents/#{agent_id}/key"
@@ -144,13 +148,24 @@ module Wazuh
144
148
  post '/agents', options
145
149
  end
146
150
 
151
+ # Delete an agent
152
+ # Removes an agent.
153
+ #
154
+ # @param [String] agent_id
155
+ # @option options [Bool] purge
156
+ # Delete an agent from the key store. This parameter is only valid if purge is set to no in the manager’s ossec.conf.
157
+ # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#delete-an-agent
158
+ def delete_agent(agent_id, options = {})
159
+ delete "/agents/#{agent_id}", options
160
+ end
161
+
147
162
  # Adds a new agent with name :agent_name. This agent will use ANY as IP.
148
163
  #
149
- # @option options [name] :name
164
+ # @param [String] agent_name
150
165
  # Name to agent
151
166
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#add-agent-quick-method
152
- def add_agent_quick(options = {})
153
- put '/agents', options
167
+ def add_agent_quick(agent_name)
168
+ put "/agents/#{agent_name}"
154
169
  end
155
170
 
156
171
  # Insert an agent with an existing id and key.
@@ -35,7 +35,8 @@ module Wazuh
35
35
  # Filters by final score.
36
36
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-cis-cat-results-from-an-agent
37
37
  def ciscat_result(agent_id, options = {})
38
- get "/ciscat/#{agent_id}/results", options
38
+ data = get "/ciscat/#{agent_id}/results", options
39
+ data.items
39
40
  end
40
41
  end
41
42
  end
@@ -116,7 +116,8 @@ module Wazuh
116
116
  # @option options [category] :category
117
117
  # Filters by category of log
118
118
  def cluster_logs_by_node(node_id, options)
119
- get "/cluster/#{node_id}/logs", options
119
+ data = get "/cluster/#{node_id}/logs", options
120
+ data.items
120
121
  end
121
122
 
122
123
  # Get summary of ossec.log from a specific node in cluster
@@ -141,7 +142,8 @@ module Wazuh
141
142
  # Get nodes info
142
143
  #
143
144
  def nodes(options = {})
144
- get '/cluster/nodes', options
145
+ data = get '/cluster/nodes', options
146
+ data.items
145
147
  end
146
148
 
147
149
  # Restart a specific node in cluster
@@ -23,7 +23,8 @@ module Wazuh
23
23
  # Allowed values: enabled, disabled, all
24
24
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-all-decoders
25
25
  def all_decoders(options = {})
26
- get '/decoders', options
26
+ data = get '/decoders', options
27
+ data.items
27
28
  end
28
29
 
29
30
  # Get all decoders files
@@ -49,7 +50,8 @@ module Wazuh
49
50
  # Name of the decoder file to download.
50
51
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-all-decoders-files
51
52
  def all_decoders_files(options = {})
52
- get '/decoders/files', options
53
+ data = get '/decoders/files', options
54
+ data.items
53
55
  end
54
56
 
55
57
  # Get all parent decoders
@@ -65,7 +67,8 @@ module Wazuh
65
67
  # Looks for elements with the specified string.
66
68
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-all-parent-decoders
67
69
  def all_parent_decoders(options = {})
68
- get '/decoders/parents', options
70
+ data = get '/decoders/parents', options
71
+ data.items
69
72
  end
70
73
 
71
74
  # Get decoders by name
@@ -83,7 +86,8 @@ module Wazuh
83
86
  # Looks for elements with the specified string.
84
87
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-decoders-by-name
85
88
  def decoders_by_name(decoder_name, options = {})
86
- get "/decoders/#{decoder_name}", options
89
+ data = get "/decoders/#{decoder_name}", options
90
+ data.items
87
91
  end
88
92
  end
89
93
  end
@@ -42,7 +42,8 @@ module Wazuh
42
42
  # Filters by board_serial.
43
43
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-hardware-info-of-all-agents
44
44
  def experimental_hardware(options = {})
45
- get '/experimental/syscollector/hardware', options
45
+ data = get '/experimental/syscollector/hardware', options
46
+ data.items
46
47
  end
47
48
 
48
49
  # Get network address info of all agents
@@ -71,7 +72,8 @@ module Wazuh
71
72
  # Filters by netmask.
72
73
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-network-address-info-of-all-agents
73
74
  def experimental_netaddr(options = {})
74
- get '/experimental/syscollector/netaddr', options
75
+ data = get '/experimental/syscollector/netaddr', options
76
+ data.items
75
77
  end
76
78
 
77
79
  # Get network interface info of all agents
@@ -107,7 +109,8 @@ module Wazuh
107
109
  # @option options [rx_dropped] :rx_dropped
108
110
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-network-interface-info-of-all-agents
109
111
  def experimental_netiface(options = {})
110
- get '/experimental/syscollector/netiface', options
112
+ data = get '/experimental/syscollector/netiface', options
113
+ data.items
111
114
  end
112
115
 
113
116
  # Get network protocol info of all agents
@@ -134,7 +137,8 @@ module Wazuh
134
137
  # Filters by dhcp.
135
138
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-network-protocol-info-of-all-agents
136
139
  def experimental_netproto(options = {})
137
- get '/experimental/syscollector/netproto', options
140
+ data = get '/experimental/syscollector/netproto', options
141
+ data.items
138
142
  end
139
143
 
140
144
  # Get os info of all agents
@@ -164,7 +168,8 @@ module Wazuh
164
168
  # Filters by release.
165
169
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-os-info-of-all-agents
166
170
  def experimental_os(options = {})
167
- get '/experimentalsyscollector/os', options
171
+ data = get '/experimentalsyscollector/os', options
172
+ data.items
168
173
  end
169
174
 
170
175
  # Get packages info of all agents
@@ -193,7 +198,8 @@ module Wazuh
193
198
  # Filters by format.
194
199
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-packages-info-of-all-agents
195
200
  def experimental_packages(options = {})
196
- get '/experimental/syscollector/packages', options
201
+ data = get '/experimental/syscollector/packages', options
202
+ data.items
197
203
  end
198
204
 
199
205
  # Get ports info of all agents
@@ -226,7 +232,8 @@ module Wazuh
226
232
  # Filters by state.
227
233
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-ports-info-of-all-agents
228
234
  def experimental_ports(options = {})
229
- get '/experimental/syscollector/ports', options
235
+ data = get '/experimental/syscollector/ports', options
236
+ data.items
230
237
  end
231
238
 
232
239
  # Get processes info of all agents
@@ -273,7 +280,8 @@ module Wazuh
273
280
  # Filters by process suser.
274
281
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-processes-info-of-all-agents
275
282
  def experimental_processes(options = {})
276
- get '/experimental/syscollector/processes', options
283
+ data = get '/experimental/syscollector/processes', options
284
+ data.items
277
285
  end
278
286
 
279
287
  # Get CIS-CAT results
@@ -301,7 +309,8 @@ module Wazuh
301
309
  # @option options [score] :score
302
310
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-cis-cat-results
303
311
  def experimental_ciscat_results(options = {})
304
- get '/experimental/ciscat/results', options
312
+ data = get '/experimental/ciscat/results', options
313
+ data.items
305
314
  end
306
315
  end
307
316
  end
@@ -18,7 +18,8 @@ module Wazuh
18
18
  # Filters by path.
19
19
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-all-lists
20
20
  def cdb_lists(options = {})
21
- get '/lists', options
21
+ data = get '/lists', options
22
+ data.items
22
23
  end
23
24
 
24
25
  # Get paths from all lists
@@ -33,8 +34,9 @@ module Wazuh
33
34
  # @option options [search] :search
34
35
  # Looks for elements with the specified string.
35
36
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-paths-from-all-lists
36
- def cdb_files(options = {})
37
- get '/lists/files', options
37
+ def cdb_files_path(options = {})
38
+ data = get '/lists/files', options
39
+ data.items
38
40
  end
39
41
  end
40
42
  end
@@ -90,7 +90,8 @@ module Wazuh
90
90
  #
91
91
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-ossec-log
92
92
  def manager_log
93
- get '/manager/logs'
93
+ data = get '/manager/logs'
94
+ data.items
94
95
  end
95
96
 
96
97
  # Get summary of ossec.log
@@ -39,7 +39,8 @@ module Wazuh
39
39
  # @option options [search] :search
40
40
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rootcheck-cis-requirements
41
41
  def rootcheck_cis_requirements(agent_id, options = {})
42
- get "/rootcheck/#{agent_id}/cis", options
42
+ data = get "/rootcheck/#{agent_id}/cis", options
43
+ data.items
43
44
  end
44
45
 
45
46
  # Get rootcheck database
@@ -55,7 +56,8 @@ module Wazuh
55
56
  # @option options [status] :status
56
57
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rootcheck-database
57
58
  def rootcheck_database(agent_id, options = {})
58
- get "/rootcheck/#{agent_id}", options
59
+ data = get "/rootcheck/#{agent_id}", options
60
+ data.items
59
61
  end
60
62
 
61
63
  # Get rootcheck pci requirements
@@ -68,7 +70,8 @@ module Wazuh
68
70
  # @option options [search] :search
69
71
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rootcheck-pci-requirements
70
72
  def rootcheck_pic_requirements(agent_id, options = {})
71
- get "/rootcheck/#{agent_id}/pci", options
73
+ data = get "/rootcheck/#{agent_id}/pci", options
74
+ data.items
72
75
  end
73
76
 
74
77
  # Run rootcheck scan in all agents
@@ -7,56 +7,64 @@ module Wazuh
7
7
  #
8
8
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-all-rules
9
9
  def all_rules(options = {})
10
- get '/rules', options
10
+ data = get '/rules', options
11
+ data.items
11
12
  end
12
13
 
13
14
  # Returns the files of all rules.
14
15
  #
15
16
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-files-of-rules
16
17
  def rule_files(options = {})
17
- get '/rules/files', options
18
+ data = get '/rules/files', options
19
+ data.items
18
20
  end
19
21
 
20
22
  # Returns the GDPR requirements of all rules.
21
23
  #
22
24
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rule-gdpr-requirements
23
25
  def gdpr_rules(options = {})
24
- get '/rules/gdpr', options
26
+ data = get '/rules/gdpr', options
27
+ data.items
25
28
  end
26
29
 
27
30
  # Returns the GPG13 requirements of all rules.
28
31
  #
29
32
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rule-gpg13-requirements
30
33
  def gpg13_rules(options = {})
31
- get '/rules/gpg13', options
34
+ data = get '/rules/gpg13', options
35
+ data.items
32
36
  end
33
37
 
34
38
  # Returns the groups of all rules.
35
39
  #
36
40
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rule-groups
37
41
  def rules_groups(options = {})
38
- get '/rules/groups', options
42
+ data = get '/rules/groups', options
43
+ data.items
39
44
  end
40
45
 
41
46
  # Returns the HIPAA requirements of all rules.
42
47
  #
43
48
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rule-hipaa-requirements
44
49
  def hipaa_rules(options = {})
45
- get '/rules/hipaa', options
50
+ data = get '/rules/hipaa', options
51
+ data.items
46
52
  end
47
53
 
48
54
  # Returns the NIST-800-53 requirements of all rules.
49
55
  #
50
56
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rule-nist-800-53-requirements
51
57
  def nist_800_53_rules(options = {})
52
- get '/rules/nist-800-53', options
58
+ data = get '/rules/nist-800-53', options
59
+ data.items
53
60
  end
54
61
 
55
62
  # Returns the PCI requirements of all rules
56
63
  #
57
64
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rule-pci-requirements
58
65
  def pic_rules(options = {})
59
- get '/rules/pci', options
66
+ data = get '/rules/pci', options
67
+ data.items
60
68
  end
61
69
 
62
70
  # Returns the rules with the specified id.
@@ -72,7 +80,8 @@ module Wazuh
72
80
  # Looks for elements with the specified string.
73
81
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-rules-by-id
74
82
  def rule_by_id(rule_id, options = {})
75
- get "/rules/#{rule_id}", options
83
+ data = get "/rules/#{rule_id}", options
84
+ data.items
76
85
  end
77
86
  end
78
87
  end
@@ -39,7 +39,8 @@ module Wazuh
39
39
  # Looks for elements with the specified string.
40
40
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-security-configuration-assessment-sca-checks-database
41
41
  def checks_sca_database(agent_id, policy_id, options = {})
42
- get "/sca/#{agent_id}/checks/#{policy_id}", options
42
+ data = get "/sca/#{agent_id}/checks/#{policy_id}", options
43
+ data.items
43
44
  end
44
45
 
45
46
  # Get security configuration assessment (SCA) database
@@ -65,7 +66,8 @@ module Wazuh
65
66
  # Query to filter results by. This is specially useful to filter by total checks passed, failed or total score (fields pass, fail, score).
66
67
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-security-configuration-assessment-sca-database
67
68
  def sca_database(agent_id, options = {})
68
- get "/sca/#{agent_id}", options
69
+ data = get "/sca/#{agent_id}", options
70
+ data.items
69
71
  end
70
72
  end
71
73
  end
@@ -3,6 +3,40 @@ module Wazuh
3
3
  module Endpoints
4
4
  module Syscheck
5
5
  #
6
+ # Get syscheck files
7
+ # Returns the syscheck files of an agent.
8
+ #
9
+ # @param [String] agent_id
10
+ # @option options [offset] :offset
11
+ # First element to return in the collection.
12
+ # @option options [limit] :limit
13
+ # Maximum number of elements to return.
14
+ # @option options [sort] :sort
15
+ # Sorts the collection by a field or fields (separated by comma). Use +/- at the beginning to list in ascending or descending order.
16
+ # @option options [search] :search
17
+ # Looks for elements with the specified string.
18
+ # @option options [file] :file
19
+ # Filters file by filename.
20
+ # @option options [type] :type
21
+ # Selects type of file. Allowed values: file, registry
22
+ # @option options [summary] :summary
23
+ # Returns a summary grouping by filename. Allowed values: yes, no
24
+ # @option options [select] :select
25
+ # List of selected fields separated by commas.
26
+ # @option options [md5] :md5
27
+ # Returns the files with the specified md5 hash.
28
+ # @option options [sha1] :sha1
29
+ # Returns the files with the specified sha1 hash.
30
+ # @option options [sha256] :sha256
31
+ # Returns the files with the specified sha256 hash.
32
+ # @option options [hash] :hash
33
+ # Returns the files with the specified hash (md5, sha1 or sha256).
34
+ # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-syscheck-files
35
+ def syscheck_files(agent_id, options = {})
36
+ data = get "/syscheck/#{agent_id}"
37
+ data.items
38
+ end
39
+
6
40
  # Clears the syscheck database for the specified agent.
7
41
  #
8
42
  # @param [String] agent_id
@@ -38,7 +38,8 @@ module Wazuh
38
38
  # Filters by netmask.
39
39
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-network-address-info-of-an-agent
40
40
  def netaddr(agent_id, options = {})
41
- get "/syscollector/#{agent_id}/netaddr", options
41
+ data = get "/syscollector/#{agent_id}/netaddr", options
42
+ data.items
42
43
  end
43
44
 
44
45
  # Returns the agent’s network interface info
@@ -74,7 +75,8 @@ module Wazuh
74
75
  # @option options [rx_dropped] :rx_dropped
75
76
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-network-interface-info-of-an-agent
76
77
  def netiface(agent_id, options = {})
77
- get "/syscollector/#{agent_id}/netiface", options
78
+ data = get "/syscollector/#{agent_id}/netiface", options
79
+ data.items
78
80
  end
79
81
 
80
82
  # Returns the agent’s network protocol info.
@@ -100,7 +102,8 @@ module Wazuh
100
102
  # Filters by dhcp.
101
103
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-network-protocol-info-of-an-agent
102
104
  def netproto(agent_id, options = {})
103
- get "/syscollector/#{agent_id}/netproto", options
105
+ data = get "/syscollector/#{agent_id}/netproto", options
106
+ data.items
104
107
  end
105
108
 
106
109
  # Returns the agent’s OS info.
@@ -138,7 +141,8 @@ module Wazuh
138
141
  # Filters by format.
139
142
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-packages-info
140
143
  def packages(agent_id, options = {})
141
- get "/syscollector/#{agent_id}/packages", options
144
+ data = get "/syscollector/#{agent_id}/packages", options
145
+ data.items
142
146
  end
143
147
 
144
148
  # Get ports info of an agent
@@ -171,7 +175,8 @@ module Wazuh
171
175
  # Filters by state.
172
176
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-ports-info-of-an-agent
173
177
  def ports(agent_id, options = {})
174
- get "/syscollector/#{agent_id}/ports", options
178
+ data = get "/syscollector/#{agent_id}/ports", options
179
+ data.items
175
180
  end
176
181
 
177
182
  # Get processes info
@@ -219,7 +224,8 @@ module Wazuh
219
224
  #
220
225
  # @see https://documentation.wazuh.com/3.10/user-manual/api/reference.html#get-processes-info
221
226
  def processes(agent_id, options = {})
222
- get "/syscollector/#{agent_id}/processes", options
227
+ data = get "/syscollector/#{agent_id}/processes", options
228
+ data.items
223
229
  end
224
230
  end
225
231
  end
@@ -1,7 +1,7 @@
1
1
  module Wazuh
2
2
  module Api
3
3
  module Errors
4
- class WazuhError < ::Faraday::Error
4
+ class WazuhError < StandardError
5
5
  attr_reader :response, :message
6
6
 
7
7
  def initialize(message, response = nil)
data/lib/wazuh/client.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Wazuh
2
2
  class Client
3
- include Faraday::Connection
4
- include Faraday::Request
3
+ include Sawyer::Connection
4
+ include Sawyer::Request
5
5
  include Api::Endpoints
6
6
 
7
7
  attr_accessor(*Config::ATTRIBUTES)
@@ -0,0 +1,35 @@
1
+ module Wazuh
2
+ module Sawyer
3
+ module Connection
4
+ private
5
+
6
+ def connection
7
+ options = {
8
+ headers: {
9
+ 'Accept' => 'application/json; charset=utf-8',
10
+ 'Content-Type' => 'application/json'
11
+ },
12
+ ssl: {}
13
+ }
14
+
15
+ options[:headers]['User-Agent'] = user_agent if user_agent
16
+ options[:ssl].merge!({ client_cert: client_cert, client_key: client_key }) if client_cert || client_key
17
+
18
+ if basic_user || basic_password
19
+ authorization_header = "Basic " + Base64.encode64(basic_user + ':' + basic_password).strip
20
+ options[:headers].merge!({'Authorization' => authorization_header})
21
+ end
22
+
23
+ options[:ssl].merge!({ verify: false }) unless verify_ssl
24
+
25
+ opts = {
26
+ :links_parser => ::Sawyer::LinkParsers::Simple.new
27
+ }
28
+
29
+ opts[:faraday] = ::Faraday.new(options)
30
+
31
+ ::Sawyer::Agent.new(endpoint, opts)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Wazuh
3
+ module Sawyer
4
+ module Request
5
+ def get(path, options = {})
6
+ request(:get, path, options)
7
+ end
8
+
9
+ def post(path, options = {})
10
+ request(:post, path, options)
11
+ end
12
+
13
+ def put(path, options = {})
14
+ request(:put, path, options)
15
+ end
16
+
17
+ def delete(path, options = {})
18
+ request(:delete, path, options)
19
+ end
20
+
21
+ private
22
+
23
+ def request(method, path, options)
24
+ response = case method
25
+ when :get, :delete
26
+ connection.call(method, URI::Parser.new.escape(path), nil, {query: options})
27
+ when :post, :put
28
+ data = options unless options.empty?
29
+ connection.call(method, URI::Parser.new.escape(path), data)
30
+ end
31
+
32
+ return response.data.data if response.status == 200 || response.data.error == 0
33
+
34
+ error_message = response.data.message
35
+ raise Wazuh::Api::Errors::WazuhError.new(error_message, response)
36
+ end
37
+ end
38
+ end
39
+ end
data/lib/wazuh/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Wazuh
3
- VERSION = '0.1.2'
3
+ VERSION = '0.2.0'
4
4
  end
@@ -1,3 +1,3 @@
1
1
  module WazuhRubyClient
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,16 +1,15 @@
1
1
  require_relative 'wazuh/version'
2
2
  require_relative 'wazuh/logger'
3
3
 
4
- require 'faraday'
5
- require 'faraday_middleware'
6
4
  require 'json'
7
5
  require 'logger'
8
6
  require 'base64'
7
+ require 'faraday'
8
+ require 'sawyer'
9
9
 
10
10
  require_relative 'wazuh/config'
11
- require_relative 'wazuh/faraday/response/raise_error'
12
- require_relative 'wazuh/faraday/connection'
13
- require_relative 'wazuh/faraday/request'
11
+ require_relative 'wazuh/sawyer/connection'
12
+ require_relative 'wazuh/sawyer/request'
14
13
  require_relative 'wazuh/api/endpoints'
15
14
  require_relative 'wazuh/api/errors/wazuh_error'
16
15
  require_relative 'wazuh/api/error'
@@ -39,7 +39,9 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
40
  spec.add_development_dependency "vcr"
41
41
  spec.add_development_dependency "webmock"
42
+ spec.add_development_dependency "pry"
43
+ spec.add_development_dependency "pry-byebug"
42
44
 
43
- spec.add_dependency 'faraday', '>= 0.9'
44
- spec.add_dependency 'faraday_middleware'
45
+ spec.add_dependency 'faraday'
46
+ spec.add_dependency 'sawyer'
45
47
  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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mrtc0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-25 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,22 +80,50 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: faraday
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
88
116
  - !ruby/object:Gem::Version
89
- version: '0.9'
117
+ version: '0'
90
118
  type: :runtime
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
- version: '0.9'
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: faraday_middleware
126
+ name: sawyer
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -188,14 +216,12 @@ files:
188
216
  - lib/wazuh/api/endpoints/syscheck.rb
189
217
  - lib/wazuh/api/endpoints/syscollector.rb
190
218
  - lib/wazuh/api/error.rb
191
- - lib/wazuh/api/errors/too_many_requests_error.rb
192
219
  - lib/wazuh/api/errors/wazuh_error.rb
193
220
  - lib/wazuh/client.rb
194
221
  - lib/wazuh/config.rb
195
- - lib/wazuh/faraday/connection.rb
196
- - lib/wazuh/faraday/request.rb
197
- - lib/wazuh/faraday/response/raise_error.rb
198
222
  - lib/wazuh/logger.rb
223
+ - lib/wazuh/sawyer/connection.rb
224
+ - lib/wazuh/sawyer/request.rb
199
225
  - lib/wazuh/version.rb
200
226
  - lib/wazuh_ruby_client.rb
201
227
  - wazuh-ruby-client.gemspec
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
- module Wazuh
3
- module Api
4
- module Errors
5
- class TooManyRequestsError < ::Faraday::Error
6
- attr_reader :response
7
-
8
- def initialize(response)
9
- @response = response
10
- end
11
-
12
- def message
13
- "Retry after #{retry_after} seconds"
14
- end
15
-
16
- def retry_after
17
- response.headers['retry-after'].to_i
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,38 +0,0 @@
1
- module Wazuh
2
- module Faraday
3
- module Connection
4
- private
5
-
6
- def connection
7
- options = {
8
- headers: { 'Accept' => 'application/json; charset=utf-8' },
9
- ssl: {}
10
- }
11
-
12
- options[:headers]['User-Agent'] = user_agent if user_agent
13
- # options[:certificate] = certificate if cartificate
14
- # options[:private_key] = private_key if private_key
15
- options[:ssl].merge!({ client_cert: client_cert, client_key: client_key }) if client_cert || client_key
16
-
17
- if basic_user || basic_password
18
- authorization_header = "Basic " + Base64.encode64(basic_user + ':' + basic_password).strip
19
- options[:headers].merge!({'Authorization' => authorization_header})
20
- end
21
-
22
- options[:ssl].merge!({ verify: false }) unless verify_ssl
23
-
24
- # request_options = {}
25
-
26
- ::Faraday::Connection.new(endpoint, options) do |connection|
27
- connection.use ::Faraday::Request::Multipart
28
- connection.use ::Faraday::Request::UrlEncoded
29
- connection.use ::Faraday::Response::RaiseError
30
- connection.use ::Wazuh::Faraday::Response::RaiseError
31
- connection.use ::FaradayMiddleware::ParseJson
32
- connection.response :logger, logger if logger
33
- connection.adapter ::Faraday.default_adapter
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
- module Wazuh
3
- module Faraday
4
- module Request
5
- def get(path, options = {})
6
- request(:get, path, options)
7
- end
8
-
9
- def post(path, options = {})
10
- request(:post, path, options)
11
- end
12
-
13
- def put(path, options = {})
14
- request(:put, path, options)
15
- end
16
-
17
- def delete(path, options = {})
18
- request(:delete, path, options)
19
- end
20
-
21
- private
22
-
23
- def request(method, path, options)
24
- response = connection.send(method) do |request|
25
- case method
26
- when :get, :delete
27
- request.url(path, options)
28
- when :post, :put
29
- request.path = path
30
- request.body = options unless options.empty?
31
- end
32
- request.options.merge!(options.delete(:request)) if options.key?(:request)
33
- end
34
- response.body
35
- end
36
- end
37
- end
38
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
- module Wazuh
3
- module Faraday
4
- module Response
5
- class RaiseError < ::Faraday::Response::Middleware
6
- def on_complete(env)
7
- return if env.status == 200 || env.body['error'] == 0
8
- error_message = env.body['message']
9
- raise Wazuh::Api::Errors::WazuhError.new(error_message, env.response)
10
- end
11
- end
12
- end
13
- end
14
- end