miab 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/miab.rb +157 -128
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbf1ee0a2dd7474a6d8063f6bdf63880f10db17d8edfff2e7e552def3389013a
|
4
|
+
data.tar.gz: e5fb9e2256de496915030beb2d88bfdda3ea63cd42658ff48349cc7fe8f4cd26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611b23b205ff761de613fc5624481aaef5be930b171f9aecae360cc71ca2c9b07dee55260b1ee502659483fab7db657c6ad38f3e6b1619bcd74e3cbcf8860519
|
7
|
+
data.tar.gz: f903b55460325b482a1fe967efeb0ea633be35d4b1afbb6a05c5bc258879f41db791cd4e6b08ccbcfed6e3df2cf6c0e10a25e14d7884a61420a19e35629fb2f2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/miab.rb
CHANGED
@@ -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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
39
|
+
end
|
24
40
|
|
25
|
-
|
41
|
+
# query the available disk space etc.
|
42
|
+
#
|
43
|
+
def disk_space()
|
26
44
|
|
27
|
-
|
28
|
-
|
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
|
-
|
35
|
-
{}
|
36
|
-
end
|
37
|
-
end
|
48
|
+
@results[:disk_usage] = {}
|
38
49
|
|
39
|
-
|
40
|
-
#
|
41
|
-
def cast()
|
50
|
+
a = s.lines.grep(/\/dev\/root/)
|
42
51
|
|
43
|
-
|
52
|
+
puts ('a: ' + a.inspect).debug if @debug
|
44
53
|
|
45
|
-
|
54
|
+
if a.any? then
|
55
|
+
size, used, avail = a[0].split(/ +/).values_at(1,2,3)
|
46
56
|
|
47
|
-
|
48
|
-
|
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
|
-
|
62
|
-
@results[`hostname`.chomp] = {}
|
63
|
-
eval @scroll if @scroll
|
64
|
-
end
|
61
|
+
a2 = s.lines.grep(/\/dev\/sda1/)
|
65
62
|
|
66
|
-
|
67
|
-
@results
|
68
|
-
end
|
63
|
+
puts ('a2: ' + a2.inspect).debug if @debug
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
def date()
|
65
|
+
if a2.any? then
|
66
|
+
size, used, avail = a2[0].split(/ +/).values_at(1,2,3)
|
73
67
|
|
74
|
-
|
75
|
-
|
76
|
-
|
68
|
+
@results[:disk_usage][:sda1] = {size: size, used: used,
|
69
|
+
avail: avail}
|
70
|
+
end
|
77
71
|
|
78
|
-
|
72
|
+
end
|
79
73
|
|
80
|
-
|
81
|
-
#
|
82
|
-
def disk_space()
|
74
|
+
alias df disk_space
|
83
75
|
|
84
|
-
|
85
|
-
|
76
|
+
# find out available memory etc
|
77
|
+
#
|
78
|
+
def memory()
|
86
79
|
|
87
|
-
|
80
|
+
instructions = 'free -h'
|
88
81
|
|
89
|
-
|
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
|
-
|
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
|
-
|
94
|
-
size, used, avail = a[0].split(/ +/).values_at(1,2,3)
|
108
|
+
end
|
95
109
|
|
96
|
-
|
97
|
-
|
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
|
-
|
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
|
-
|
131
|
+
elapsed = nil
|
132
|
+
time = Time.new
|
103
133
|
|
104
|
-
|
105
|
-
size, used, avail = a2[0].split(/ +/).values_at(1,2,3)
|
134
|
+
begin
|
106
135
|
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
154
|
+
def initialize(scroll, domain: nil, target: nil, pwlist: {}, password: nil,
|
155
|
+
user: nil, debug: false)
|
114
156
|
|
115
|
-
|
116
|
-
#
|
117
|
-
def memory()
|
157
|
+
@results = {}
|
118
158
|
|
119
|
-
|
159
|
+
@scroll, @debug = scroll, debug
|
120
160
|
|
121
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
173
|
+
{}
|
145
174
|
end
|
146
|
-
|
147
175
|
end
|
148
176
|
|
149
|
-
#
|
177
|
+
# cast out the thing and hope for the best
|
150
178
|
#
|
151
|
-
def
|
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
|
-
|
158
|
-
|
159
|
-
|
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
|
-
|
171
|
-
|
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
|
-
|
204
|
+
threads.each(&:join)
|
174
205
|
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
-
|
187
|
-
|
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.
|
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-
|
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
|