miab 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/miab.rb +157 -128
  5. metadata +2 -2
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6911c70d764bfa7d9de2c494403828fbc38c4ffeb85fe7a26db923a898b678b
4
- data.tar.gz: 0426ee0f211bc6f7f379acfedb468bb0e6930740e725ef0272b450ba9afc08bb
3
+ metadata.gz: bbf1ee0a2dd7474a6d8063f6bdf63880f10db17d8edfff2e7e552def3389013a
4
+ data.tar.gz: e5fb9e2256de496915030beb2d88bfdda3ea63cd42658ff48349cc7fe8f4cd26
5
5
  SHA512:
6
- metadata.gz: 11d6a71ba658ce25b2b3648b4b2587b3d8912bb5053c3bc9f1a39eafe5127f0e9a97dedde121ee63eec9aa49de7a327fff076159ff94524cf2a1b60b43ef6c4e
7
- data.tar.gz: 2ca3773b2c9a3c8acf3fba76ae8fc076d788dccfb4cab21cd163cc1c3c2de16cb733e15453409d3f16772fe7646c765ff59799634d83277741e3a3ce60a3f024
6
+ metadata.gz: 611b23b205ff761de613fc5624481aaef5be930b171f9aecae360cc71ca2c9b07dee55260b1ee502659483fab7db657c6ad38f3e6b1619bcd74e3cbcf8860519
7
+ data.tar.gz: f903b55460325b482a1fe967efeb0ea633be35d4b1afbb6a05c5bc258879f41db791cd4e6b08ccbcfed6e3df2cf6c0e10a25e14d7884a61420a19e35629fb2f2
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -12,179 +12,208 @@ require 'resolv'
12
12
 
13
13
  class Miab
14
14
  using ColouredText
15
+
16
+ class Session
17
+
18
+ def initialize( host, ssh=nil, debug: false)
19
+ @ssh, @host, @debug = ssh, host, debug
20
+ @results = {}
21
+ end
22
+
23
+ def exec(s)
24
+ eval s
25
+ @results
26
+ end
27
+
28
+ protected
29
+
30
+ # return the local date and time
31
+ #
32
+ def date()
15
33
 
16
- def initialize(scroll, domain: nil, target: nil, pwlist: {}, password: nil,
17
- user: nil, debug: false)
18
-
19
- @results = {}
20
-
21
- @scroll, @debug = scroll, debug
34
+ instructions = 'date'
35
+ r = @ssh ? @ssh.exec!(instructions) : `#{instructions}`
36
+ puts 'r: ' + r.inspect if @debug
37
+ @results[:date] = r.chomp
22
38
 
23
- @nodes = if target then
39
+ end
24
40
 
25
- target = [target] if target.is_a? String
41
+ # query the available disk space etc.
42
+ #
43
+ def disk_space()
26
44
 
27
- target.inject({}) do |r,x|
28
- host = domain ? x + '.' + domain : x
29
- passwd = pwlist[x] || password
30
- userhost = user ? user + '@' + host : host
31
- r.merge({userhost => passwd})
32
- end
45
+ instructions = 'df -h'
46
+ r = @ssh ? @ssh.exec!(instructions) : `#{instructions}`
33
47
 
34
- else
35
- {}
36
- end
37
- end
48
+ @results[:disk_usage] = {}
38
49
 
39
- # cast out the thing and hope for the best
40
- #
41
- def cast()
50
+ a = s.lines.grep(/\/dev\/root/)
42
51
 
43
- if @nodes.any? then
52
+ puts ('a: ' + a.inspect).debug if @debug
44
53
 
45
- @nodes.each do |raw_host, password|
54
+ if a.any? then
55
+ size, used, avail = a[0].split(/ +/).values_at(1,2,3)
46
56
 
47
- host, user = raw_host.split(/@/,2).reverse
48
- @host = host
49
- @results[host] = {}
50
-
51
- begin
52
- @ssh = Net::SSH.start( host, user, password: password)
53
- eval @scroll
54
- @ssh.close
55
- rescue
56
- @results[host] = nil
57
- end
58
-
57
+ @results[:disk_usage][:root] = {size: size, used: used,
58
+ avail: avail}
59
59
  end
60
60
 
61
- else
62
- @results[`hostname`.chomp] = {}
63
- eval @scroll if @scroll
64
- end
61
+ a2 = s.lines.grep(/\/dev\/sda1/)
65
62
 
66
- @scroll = nil
67
- @results
68
- end
63
+ puts ('a2: ' + a2.inspect).debug if @debug
69
64
 
70
- # return the local date and time
71
- #
72
- def date()
65
+ if a2.any? then
66
+ size, used, avail = a2[0].split(/ +/).values_at(1,2,3)
73
67
 
74
- instructions = 'date'
75
- r = @ssh ? @ssh.exec!(instructions) : system(instructions)
76
- @results[@host][:date] = r.chomp
68
+ @results[:disk_usage][:sda1] = {size: size, used: used,
69
+ avail: avail}
70
+ end
77
71
 
78
- end
72
+ end
79
73
 
80
- # query the available disk space etc.
81
- #
82
- def disk_space()
74
+ alias df disk_space
83
75
 
84
- instructions = 'df -h'
85
- s = @ssh ? @ssh.exec!(instructions) : system(instructions)
76
+ # find out available memory etc
77
+ #
78
+ def memory()
86
79
 
87
- @results[@host][:disk_usage] = {}
80
+ instructions = 'free -h'
88
81
 
89
- a = s.lines.grep(/\/dev\/root/)
82
+ puts ('instructions: ' + instructions.inspect).debug if @debug
83
+ r = @ssh ? @ssh.exec!(instructions) : `#{instructions}`
84
+ puts ('memory: ' + r.inspect).debug if @debug
85
+ a = r.lines
86
+ total, used, avail = a[1].split.values_at(1,2,-1)
87
+ @results[:memory] = {total: total, used: used, available: avail}
90
88
 
91
- puts ('a: ' + a.inspect).debug if @debug
89
+ end
90
+
91
+ # query the ping time
92
+ #
93
+ def ping()
94
+
95
+ ip = Resolv.getaddress(@host)
96
+ puts ('ip: ' + ip.inspect).debug if @debug
97
+ valid = pingecho(ip)
98
+ puts ('valid: ' + valid.inspect).debug if @debug
99
+
100
+ @results[:ping] = if valid then
101
+ a = [valid]
102
+ 4.times {sleep 0.01; a << pingecho(ip)}
103
+ (a.min * 1000).round(3)
104
+ else
105
+ nil
106
+ end
92
107
 
93
- if a.any? then
94
- size, used, avail = a[0].split(/ +/).values_at(1,2,3)
108
+ end
95
109
 
96
- @results[@host][:disk_usage][:root] = {size: size, used: used,
97
- avail: avail}
110
+ # query the path of the current working directory
111
+ #
112
+ def pwd()
113
+ instructions = 'pwd'
114
+ r = @ssh ? @ssh.exec!(instructions) : `#{instructions}`
115
+ @results[:pwd] = r.chomp
98
116
  end
99
117
 
100
- a2 = s.lines.grep(/\/dev\/sda1/)
118
+ # query the CPU temperature
119
+ #
120
+ def temperature()
121
+ instructions = 'cat /sys/class/thermal/thermal_zone0/temp'
122
+ r = @ssh ? @ssh.exec!(instructions) : `#{instructions}`
123
+ @results[:temperature] = r.chomp
124
+ end
125
+
126
+ private
127
+
128
+
129
+ def pingecho(host, timeout=5, service="echo")
101
130
 
102
- puts ('a2: ' + a2.inspect).debug if @debug
131
+ elapsed = nil
132
+ time = Time.new
103
133
 
104
- if a2.any? then
105
- size, used, avail = a2[0].split(/ +/).values_at(1,2,3)
134
+ begin
106
135
 
107
- @results[@host][:disk_usage][:sda1] = {size: size, used: used,
108
- avail: avail}
109
- end
136
+ Timeout.timeout(timeout) do
137
+ s = TCPSocket.new(host, service)
138
+ s.close
139
+ end
110
140
 
141
+ rescue Errno::ECONNREFUSED
142
+ return Time.now - time
143
+ rescue Timeout::Error, StandardError
144
+ return false
145
+ end
146
+
147
+ # it should not reach this far
148
+ return true
149
+ end
150
+
151
+
111
152
  end
112
153
 
113
- alias df disk_space
154
+ def initialize(scroll, domain: nil, target: nil, pwlist: {}, password: nil,
155
+ user: nil, debug: false)
114
156
 
115
- # find out available memory etc
116
- #
117
- def memory()
157
+ @results = {}
118
158
 
119
- instructions = 'free -h'
159
+ @scroll, @debug = scroll, debug
120
160
 
121
- puts ('instructions: ' + instructions.inspect).debug if @debug
122
- r = @ssh ? @ssh.exec!(instructions) : system(instructions)
123
- puts ('memory: ' + r.inspect).debug if @debug
124
- a = r.lines
125
- total, used, avail = a[1].split.values_at(1,2,-1)
126
- @results[@host][:memory] = {total: total, used: used, available: avail}
161
+ @nodes = if target then
127
162
 
128
- end
129
-
130
- # query the ping time
131
- #
132
- def ping()
163
+ target = [target] if target.is_a? String
164
+
165
+ target.inject({}) do |r,x|
166
+ host = domain ? x + '.' + domain : x
167
+ passwd = pwlist[x] || password
168
+ userhost = user ? user + '@' + host : host
169
+ r.merge({userhost => passwd})
170
+ end
133
171
 
134
- ip = Resolv.getaddress(@host)
135
- puts ('ip: ' + ip.inspect).debug if @debug
136
- valid = pingecho(ip)
137
- puts ('valid: ' + valid.inspect).debug if @debug
138
-
139
- @results[@host][:ping] = if valid then
140
- a = [valid]
141
- 4.times {sleep 0.01; a << pingecho(ip)}
142
- (a.min * 1000).round(3)
143
172
  else
144
- nil
173
+ {}
145
174
  end
146
-
147
175
  end
148
176
 
149
- # query the path of the current working directory
177
+ # cast out the thing and hope for the best
150
178
  #
151
- def pwd()
152
- instructions = 'pwd'
153
- r = @ssh ? @ssh.exec!(instructions) : system(instructions)
154
- @results[@host][:pwd] = r.chomp
155
- end
179
+ def cast()
156
180
 
157
- # query the CPU temperature
158
- #
159
- def temperature()
160
- instructions = 'cat /sys/class/thermal/thermal_zone0/temp'
161
- r = @ssh ? @ssh.exec!(instructions) : system(instructions)
162
- @results[@host][:temperature] = r.chomp
163
- end
164
-
165
- private
166
-
167
-
168
- def pingecho(host, timeout=5, service="echo")
181
+ if @nodes.any? then
182
+
183
+ threads = []
169
184
 
170
- elapsed = nil
171
- time = Time.new
185
+ @nodes.each do |raw_host, password|
186
+
187
+ host, user = raw_host.split(/@/,2).reverse
188
+ @results[host] = {}
189
+
190
+ threads << Thread.new do
191
+ begin
192
+ puts ('host: ' + host.inspect).debug if @debug
193
+ ssh = Net::SSH.start( host, user, password: password)
194
+ @results[host] = Session.new(host, ssh, debug: @debug).exec @scroll
195
+ ssh.close
196
+ puts (host + ' result: ' + @results[host].inspect).debug if @debug
197
+ rescue
198
+ @results[host] = nil
199
+ end
200
+ end
201
+
202
+ end
172
203
 
173
- begin
204
+ threads.each(&:join)
174
205
 
175
- Timeout.timeout(timeout) do
176
- s = TCPSocket.new(host, service)
177
- s.close
206
+ else
207
+
208
+ if @scroll then
209
+ host = `hostname`.chomp
210
+ @results[host] = Session.new(host, debug: @debug).exec(@scroll)
178
211
  end
179
-
180
- rescue Errno::ECONNREFUSED
181
- return Time.now - time
182
- rescue Timeout::Error, StandardError
183
- return false
212
+
184
213
  end
185
-
186
- # it should not reach this far
187
- return true
188
- end
214
+
215
+ @scroll = nil
216
+ @results
217
+ end
189
218
 
190
219
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  9irKsAp/hZt3dTbQOtnSlc9XREZZdegwOgu1FEqBqviNIn9R28OR237HExiWXwmw
36
36
  HDTFIjk8XBqTunABuFUgr4qx
37
37
  -----END CERTIFICATE-----
38
- date: 2019-09-14 00:00:00.000000000 Z
38
+ date: 2019-09-16 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: net-ssh
metadata.gz.sig CHANGED
Binary file