kanrisuru 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +2 -0
- data/kanrisuru.gemspec +2 -1
- data/lib/kanrisuru/core/system.rb +77 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/system_spec.rb +9 -3
- data/spec/unit/core/system_spec.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a02ab5fbc9ef38c054d2c336b630e9a48c209a393044056a2262dec3a00d373
|
4
|
+
data.tar.gz: 80d925b3b5b3c884a9bea23b81423607130f021da7fc55ad2bc5f8bfbb8ab245
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be886466d7bd57cf325d84dc5d254a7c7c638f3cbafe328b875426c95ceb81c6d2b38564a390d8a7f9f42831a514f9bdc5ec0c0d0201166776aed389bcab590f
|
7
|
+
data.tar.gz: f72ecffd89742fd13df20362044f1618ef45618ba3eaf58c4d688a7b0fe31682b052effd28f60d5bc6e2dbd90dbe33394827d304e456b3ccba2608a9c8d5d17e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## Kanrisuru 0.6.0 (August 1, 2021) ##
|
2
|
+
* Add lsof implementation in system core module
|
3
|
+
* Fix changelog formatting
|
4
|
+
* Add changelog url to gemspec
|
5
|
+
|
1
6
|
## Kanrisuru 0.5.2 (July 30, 2021) ##
|
2
7
|
* Add changelog documentation
|
3
8
|
* Update documentation table with new tested core module
|
@@ -78,7 +83,7 @@
|
|
78
83
|
## Kanrisuru 0.2.1 (June 16, 2021) ##
|
79
84
|
* Add first working release on rubygems.org
|
80
85
|
|
81
|
-
## Kanrisuru 0.2.0 (June 16, 2021) [YANKED]##
|
86
|
+
## Kanrisuru 0.2.0 (June 16, 2021) [YANKED] ##
|
82
87
|
|
83
88
|
## Kanrisuru 0.1.0 (December 12, 2020) ##
|
84
89
|
* Initialize repository, start working on project.
|
data/README.md
CHANGED
@@ -81,6 +81,8 @@ cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', r
|
|
81
81
|
| Get CPU Info | cpu_info | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
82
82
|
| Get CPU architecture | lscpu | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
83
83
|
| Get kernel stastics | kernel_statistics | cat /proc/stat | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
84
|
+
| Get hardware BIOS info | dmi | dmidecode | core | https://linux.die.net/man/8/dmidecode | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
85
|
+
| Get open file details for processes | lsof | lsof | core | https://linux.die.net/man/8/lsof | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
84
86
|
| Get Load Average | load_average | cat /proc/load_avg | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
85
87
|
| Get RAM Available | free | cat /proc/meminfo | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
86
88
|
| Get list of processes | ps | ps | core | https://linux.die.net/man/1/ps | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
data/kanrisuru.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |gem|
|
|
27
27
|
gem.require_paths = ['lib']
|
28
28
|
|
29
29
|
gem.metadata = {
|
30
|
-
'source_code_uri' => 'https://github.com/avamia/kanrisuru/'
|
30
|
+
'source_code_uri' => 'https://github.com/avamia/kanrisuru/',
|
31
|
+
'changelog_uri' => 'https://github.com/avamia/kanrisuru/blob/main/CHANGELOG.md'
|
31
32
|
}
|
32
33
|
end
|
@@ -16,6 +16,9 @@ module Kanrisuru
|
|
16
16
|
os_define :linux, :kill
|
17
17
|
|
18
18
|
os_define :linux, :kernel_statistics
|
19
|
+
os_define :linux, :kstat
|
20
|
+
|
21
|
+
os_define :linux, :lsof
|
19
22
|
|
20
23
|
os_define :linux, :uptime
|
21
24
|
|
@@ -101,6 +104,18 @@ module Kanrisuru
|
|
101
104
|
|
102
105
|
UserLoggedIn = Struct.new(:user, :tty, :ip, :login, :idle, :jcpu, :pcpu, :command)
|
103
106
|
|
107
|
+
OpenFile = Struct.new(
|
108
|
+
:command,
|
109
|
+
:pid,
|
110
|
+
:uid,
|
111
|
+
:file_descriptor,
|
112
|
+
:type,
|
113
|
+
:device,
|
114
|
+
:size,
|
115
|
+
:inode,
|
116
|
+
:name
|
117
|
+
)
|
118
|
+
|
104
119
|
def load_env
|
105
120
|
command = Kanrisuru::Command.new('env')
|
106
121
|
execute_shell(command)
|
@@ -305,6 +320,64 @@ module Kanrisuru
|
|
305
320
|
Kanrisuru::Result.new(command)
|
306
321
|
end
|
307
322
|
|
323
|
+
def lsof(opts = {})
|
324
|
+
command = Kanrisuru::Command.new('lsof -F pcuftDsin')
|
325
|
+
|
326
|
+
execute_shell(command)
|
327
|
+
Kanrisuru::Result.new(command) do |cmd|
|
328
|
+
lines = cmd.to_a
|
329
|
+
|
330
|
+
current_row = nil
|
331
|
+
current_pid = nil
|
332
|
+
current_user = nil
|
333
|
+
current_command = nil
|
334
|
+
|
335
|
+
rows = []
|
336
|
+
|
337
|
+
lines.each do |line|
|
338
|
+
case line
|
339
|
+
when /^p/
|
340
|
+
current_pid = parse_lsof(line, 'p').to_i
|
341
|
+
when /^c/
|
342
|
+
current_command = parse_lsof(line, 'c')
|
343
|
+
when /^u/
|
344
|
+
current_user = parse_lsof(line, 'u').to_i
|
345
|
+
when /^f/
|
346
|
+
if current_row
|
347
|
+
rows << current_row
|
348
|
+
end
|
349
|
+
|
350
|
+
current_row = OpenFile.new
|
351
|
+
current_row.pid = current_pid
|
352
|
+
current_row.command = current_command
|
353
|
+
current_row.uid = current_user
|
354
|
+
|
355
|
+
current_row.file_descriptor = parse_lsof(line, 'f')
|
356
|
+
when /^t/
|
357
|
+
current_row.type = parse_lsof(line, 't')
|
358
|
+
when /^D/
|
359
|
+
current_row.device = parse_lsof(line, 'D')
|
360
|
+
when /^s/
|
361
|
+
current_row.size = parse_lsof(line, 's').to_i
|
362
|
+
when /^i/
|
363
|
+
current_row.inode = parse_lsof(line, 'i').to_i
|
364
|
+
when /^n/
|
365
|
+
current_row.name = parse_lsof(line, 'n')
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
if current_row
|
370
|
+
rows << current_row
|
371
|
+
end
|
372
|
+
|
373
|
+
rows
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
def kstat
|
378
|
+
kernel_statistics
|
379
|
+
end
|
380
|
+
|
308
381
|
def kernel_statistics
|
309
382
|
command = Kanrisuru::Command.new('cat /proc/stat')
|
310
383
|
|
@@ -494,6 +567,10 @@ module Kanrisuru
|
|
494
567
|
|
495
568
|
private
|
496
569
|
|
570
|
+
def parse_lsof(line, char)
|
571
|
+
line.split(char, 2)[1]
|
572
|
+
end
|
573
|
+
|
497
574
|
def parse_policy_abbr(value)
|
498
575
|
case value
|
499
576
|
when '-'
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -26,14 +26,20 @@ RSpec.describe Kanrisuru::Core::System do
|
|
26
26
|
|
27
27
|
it 'gets environment variables' do
|
28
28
|
result = host.load_env
|
29
|
-
|
30
|
-
expect(result.success?).to be(true)
|
29
|
+
expect(result).to be_success
|
31
30
|
expect(result.data).to be_instance_of(Hash)
|
32
31
|
end
|
33
32
|
|
33
|
+
it 'gets open files' do
|
34
|
+
host.su('root')
|
35
|
+
result = host.lsof
|
36
|
+
expect(result).to be_success
|
37
|
+
expect(result.data).to be_instance_of(Array)
|
38
|
+
end
|
39
|
+
|
34
40
|
it 'gets uptime' do
|
35
41
|
result = host.uptime
|
36
|
-
expect(result
|
42
|
+
expect(result).to be_success
|
37
43
|
|
38
44
|
expect(result).to respond_to(
|
39
45
|
:boot_time, :uptime, :seconds,
|
@@ -75,5 +75,16 @@ RSpec.describe Kanrisuru::Core::System do
|
|
75
75
|
expect(Kanrisuru::Core::System::UserLoggedIn.new).to respond_to(
|
76
76
|
:user, :tty, :ip, :login, :idle, :jcpu, :pcpu, :command
|
77
77
|
)
|
78
|
+
expect(Kanrisuru::Core::System::OpenFile.new).to respond_to(
|
79
|
+
:command,
|
80
|
+
:pid,
|
81
|
+
:uid,
|
82
|
+
:file_descriptor,
|
83
|
+
:type,
|
84
|
+
:device,
|
85
|
+
:size,
|
86
|
+
:inode,
|
87
|
+
:name
|
88
|
+
)
|
78
89
|
end
|
79
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanrisuru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Mammina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -226,6 +226,7 @@ licenses:
|
|
226
226
|
- MIT
|
227
227
|
metadata:
|
228
228
|
source_code_uri: https://github.com/avamia/kanrisuru/
|
229
|
+
changelog_uri: https://github.com/avamia/kanrisuru/blob/main/CHANGELOG.md
|
229
230
|
post_install_message:
|
230
231
|
rdoc_options: []
|
231
232
|
require_paths:
|