kanrisuru 0.7.3 → 0.8.3

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: 8235592e090d7f6466a0e78d0d7b4eff7d31a2c47649aadd7cf822df11847642
4
- data.tar.gz: 20c8730f24d486687c1161f0da1dc330bf93ec7f273db14c258cd0a83ce766e8
3
+ metadata.gz: 7986958e7a5a32bb79f6f8cd225b73e996f68329e9adb95c324ad898efaa8bdc
4
+ data.tar.gz: '02279420cd5ff6017234d4058847173f3be44810267e57c59cb2b09be8f9dadc'
5
5
  SHA512:
6
- metadata.gz: f8d141bf32e49bd47acb9adc6d4307264be9b6ee30f83a581f2c033bb662205610d6cdbd495f56d195a91df8bcd5501a4f72bdf681db20bcaf5f5d23527e244a
7
- data.tar.gz: 0a9b31637b3a15cd4928abbcb7e2edcfd925ec9c9f61b008a44e7ef80c39b083b1f16b103281c8b6ed81ea758144dc2ea3eb5b50223a8dbce121fcc868abf453
6
+ metadata.gz: 7fedbd06614d36213c5d7df56c22e1f88ecb5b41732704a02b41eff1272559db3f8dc22eaa1112188cd5b0204f4c81f40e1d7f66689c41ca2d34ef0c125fbd9e
7
+ data.tar.gz: a451f3c5c4cb26ff0bf733371175c99f148ccd9531bcf0366b08d063b4ac495b1fdd3aafe47ff40b4a2cbd9df94b2de3c7dff8e0afa1f9717b3e54271a4ef75b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## Kanrisuru 0.8.3 (August 20, 2021) ##
2
+ * Fix bug with disk usage, `du` command by escaping the awk variables in the command.
3
+ * Update `du` command to execute with shell user.
4
+
5
+ ## Kanrisuru 0.8.2 (August 19, 2021) ##
6
+ * Convert `major` and `minor` device field values to an `integer` in lsblk system module.
7
+
8
+ ## Kanrisuru 0.8.1 (August 19, 2021) ##
9
+ * Fix `nodeps` flag value for `lsblk` command in disk module.
10
+
11
+ ## Kanrisuru 0.8.0 (August 18, 2021) ##
12
+ * Add last / lastb implementation in system core module.
13
+
1
14
  ## Kanrisuru 0.7.3 (August 9, 2021) ##
2
15
  * Fixed bug with zypper remove package, where the package names weren't being added to the linux command.
3
16
  * Test case added to ensure package is removed.
@@ -31,9 +31,9 @@ module Kanrisuru
31
31
 
32
32
  command = Kanrisuru::Command.new('du')
33
33
  command.append_arg('-s', path)
34
- command | "awk '{print $1, $2}'"
34
+ command | "awk '{print \\$1, \\$2}'"
35
35
 
36
- execute(command)
36
+ execute_shell(command)
37
37
 
38
38
  Kanrisuru::Result.new(command) do |cmd|
39
39
  string = cmd.to_s
@@ -144,7 +144,7 @@ module Kanrisuru
144
144
 
145
145
  command.append_flag('-a', all)
146
146
  command.append_flag('-p', paths)
147
- command.append_flag('-p', nodeps)
147
+ command.append_flag('-d', nodeps)
148
148
 
149
149
  command.append_arg('-o', 'NAME,FSTYPE,MAJ:MIN,MOUNTPOINT,SIZE,UUID,RO,RM,OWNER,GROUP,MODE,TYPE')
150
150
  execute(command)
@@ -244,8 +244,8 @@ module Kanrisuru
244
244
  current_device.fs_type = value
245
245
  when 'MAJ:MIN'
246
246
  maj, min = value.split(':')
247
- current_device.maj_dev = maj
248
- current_device.min_dev = min
247
+ current_device.maj_dev = maj ? maj.to_i : nil
248
+ current_device.min_dev = min ? min.to_i : nil
249
249
  when 'MOUNTPOINT'
250
250
  current_device.mount_point = value
251
251
  when 'SIZE'
@@ -281,8 +281,8 @@ module Kanrisuru
281
281
 
282
282
  LsblkDevice.new(
283
283
  device['name'],
284
- maj_min ? maj_min.split(':')[0] : nil,
285
- maj_min ? maj_min.split(':')[1] : nil,
284
+ maj_min ? maj_min.split(':')[0].to_i : nil,
285
+ maj_min ? maj_min.split(':')[1].to_i : nil,
286
286
  device['rm'],
287
287
  device['ro'],
288
288
  device['owner'],
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'date'
4
+ require 'ipaddr'
4
5
 
5
6
  module Kanrisuru
6
7
  module Core
@@ -19,6 +20,7 @@ module Kanrisuru
19
20
  os_define :linux, :kstat
20
21
 
21
22
  os_define :linux, :lsof
23
+ os_define :linux, :last
22
24
 
23
25
  os_define :linux, :uptime
24
26
 
@@ -116,6 +118,19 @@ module Kanrisuru
116
118
  :name
117
119
  )
118
120
 
121
+ SessionDetail = Struct.new(
122
+ :tty,
123
+ :login_at,
124
+ :logout_at,
125
+ :ip_address,
126
+ :success
127
+ )
128
+
129
+ LoginUser = Struct.new(
130
+ :user,
131
+ :sessions
132
+ )
133
+
119
134
  def load_env
120
135
  command = Kanrisuru::Command.new('env')
121
136
  execute_shell(command)
@@ -271,6 +286,65 @@ module Kanrisuru
271
286
  Kanrisuru::Result.new(command, &:to_i)
272
287
  end
273
288
 
289
+ def last(opts = {})
290
+ command =
291
+ if opts[:failed_attempts]
292
+ Kanrisuru::Command.new('lastb')
293
+ else
294
+ Kanrisuru::Command.new('last')
295
+ end
296
+
297
+ command.append_flag('-i')
298
+ command.append_flag('-F')
299
+ command.append_arg('-f', opts[:file])
300
+
301
+ ## Some systems only use 1 space between user and TTY field
302
+ ## Add an additional space in output formatting for simple parsing
303
+ ## logic.
304
+ command | "sed 's/ / /'"
305
+
306
+ execute_shell(command)
307
+
308
+ Kanrisuru::Result.new(command) do |cmd|
309
+ lines = cmd.to_a
310
+
311
+ mapping = {}
312
+
313
+ lines.each do |line|
314
+ next if Kanrisuru::Util.blank?(line)
315
+ next if line.include?('wtmp') || line.include?('btmp')
316
+
317
+ line = line.gsub(' still logged in', '- still logged in') if line.include?('still logged in')
318
+
319
+ values = line.split(/\s{2,}/, 4)
320
+ user = values[0]
321
+ tty = values[1]
322
+ ip = IPAddr.new(values[2])
323
+
324
+ date_range = values[3]
325
+ login, logout = date_range.split(' - ')
326
+
327
+ login = parse_last_date(login) if login
328
+
329
+ logout = parse_last_date(logout) if logout
330
+
331
+ detail = SessionDetail.new
332
+ detail.tty = tty
333
+ detail.ip_address = ip
334
+ detail.login_at = login
335
+ detail.logout_at = logout
336
+
337
+ detail.success = !Kanrisuru::Util.present?(opts[:failed_attemps])
338
+
339
+ mapping[user] = LoginUser.new(user, []) unless mapping.key?(user)
340
+
341
+ mapping[user].sessions << detail
342
+ end
343
+
344
+ mapping.values
345
+ end
346
+ end
347
+
274
348
  def ps(opts = {})
275
349
  group = opts[:group]
276
350
  user = opts[:user]
@@ -567,6 +641,19 @@ module Kanrisuru
567
641
  line.split(char, 2)[1]
568
642
  end
569
643
 
644
+ def parse_last_date(string)
645
+ tokens = string.split
646
+
647
+ return if tokens.length < 4
648
+
649
+ month_abbr = tokens[1]
650
+ day = tokens[2]
651
+ timestamp = tokens[3]
652
+ year = tokens[4]
653
+
654
+ DateTime.parse("#{day} #{month_abbr} #{year} #{timestamp}")
655
+ end
656
+
570
657
  def parse_policy_abbr(value)
571
658
  case value
572
659
  when '-'
@@ -713,7 +713,7 @@ module Kanrisuru
713
713
  zypper_repos_opt(command, opts)
714
714
  zypper_package_type_opt(command, opts)
715
715
  zypper_solver_opts(command, opts)
716
-
716
+
717
717
  packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
718
718
  command << packages
719
719
 
@@ -159,7 +159,6 @@ module Kanrisuru
159
159
  os_method_names.each do |method_name|
160
160
  if namespace
161
161
  namespace_class.class_eval do
162
-
163
162
  define_method method_name do |*args, &block|
164
163
  unbound_method = nil
165
164
 
@@ -193,7 +192,7 @@ module Kanrisuru
193
192
  else
194
193
  define_method method_name do |*args, &block|
195
194
  unbound_method = nil
196
-
195
+
197
196
  host = self
198
197
  os_method_cache = host.instance_variable_get(:@os_method_cache) || {}
199
198
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.7.3'
4
+ VERSION = '0.8.3'
5
5
  end
@@ -65,6 +65,13 @@ RSpec.describe Kanrisuru::Core::Disk do
65
65
  expect(result[0].path).to eq("#{host_json['home']}/.bashrc")
66
66
  end
67
67
 
68
+ it 'gets disk usage root' do
69
+ host.su('root')
70
+ result = host.du(path: '/etc')
71
+ expect(result).to be_success
72
+ expect(result[0].path).to eq("/etc")
73
+ end
74
+
68
75
  it 'gets disk free for system' do
69
76
  expect(host.df.data).to be_instance_of(Array)
70
77
  expect(host.df(inodes: true).data).to be_instance_of(Array)
@@ -96,6 +96,21 @@ RSpec.describe Kanrisuru::Core::System do
96
96
  expect(result.cpus.length).to eq(host.cpu.cores)
97
97
  end
98
98
 
99
+ it 'gets login details' do
100
+ host.su('root')
101
+
102
+ result = host.last
103
+ expect(result).to be_success
104
+ end
105
+
106
+ it 'gets failed login attempts' do
107
+ host.su('root')
108
+
109
+ result = host.last(failed_attempts: true)
110
+ puts result.data
111
+ expect(result).to be_success
112
+ end
113
+
99
114
  it 'gets process details' do
100
115
  result = host.ps
101
116
 
@@ -162,10 +162,10 @@ RSpec.describe Kanrisuru::OsPackage do
162
162
 
163
163
  expect(cluster).to respond_to(:output)
164
164
  expect(cluster.output).to eq([
165
- {:host=>"ubuntu-host", :result=>"debian"},
166
- {:host=>"centos-host", :result=>"fedora"},
167
- {:host=>"opensuse-host", :result=>"sles"}
168
- ])
165
+ { host: 'ubuntu-host', result: 'debian' },
166
+ { host: 'centos-host', result: 'fedora' },
167
+ { host: 'opensuse-host', result: 'sles' }
168
+ ])
169
169
 
170
170
  expect(host1).to respond_to(:alias)
171
171
  expect(host2).to respond_to(:alias)
@@ -180,10 +180,10 @@ RSpec.describe Kanrisuru::OsPackage do
180
180
  expect(cluster).to respond_to(:alias)
181
181
  expect(cluster.alias).to respond_to(:output)
182
182
  expect(cluster.alias.output).to eq([
183
- {:host=>"ubuntu-host", :result=>"debian"},
184
- {:host=>"centos-host", :result=>"fedora"},
185
- {:host=>"opensuse-host", :result=>"sles"}
186
- ])
183
+ { host: 'ubuntu-host', result: 'debian' },
184
+ { host: 'centos-host', result: 'fedora' },
185
+ { host: 'opensuse-host', result: 'sles' }
186
+ ])
187
187
 
188
188
  host1.disconnect
189
189
  host2.disconnect
@@ -86,5 +86,17 @@ RSpec.describe Kanrisuru::Core::System do
86
86
  :inode,
87
87
  :name
88
88
  )
89
+ expect(Kanrisuru::Core::System::SessionDetail.new).to respond_to(
90
+ :tty,
91
+ :login_at,
92
+ :logout_at,
93
+ :ip_address,
94
+ :success
95
+ )
96
+
97
+ expect(Kanrisuru::Core::System::LoginUser.new).to respond_to(
98
+ :user,
99
+ :sessions
100
+ )
89
101
  end
90
102
  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.7.3
4
+ version: 0.8.3
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-08-09 00:00:00.000000000 Z
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec