super-test 1.0.9
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 +7 -0
- data/CHANGE.txt +9 -0
- data/README.txt +13 -0
- data/bin/idb +19 -0
- data/bin/ii +113 -0
- data/bin/istart_mock +36 -0
- data/bin/istop_mock +16 -0
- data/bin/kk +181 -0
- data/bin/rubyatp +42 -0
- data/bin/start_mock +36 -0
- data/bin/stop_mock +16 -0
- data/bin/xgo +45 -0
- data/conf/conf.rb +11 -0
- data/conf/db03.yml +31 -0
- data/conf/db13.yml +37 -0
- data/conf/db19.yml +33 -0
- data/conf/online.yml +32 -0
- data/conf/super_test.yml +40 -0
- data/conf/system.yml +26 -0
- data/conf/sz00.yml +31 -0
- data/conf/sz06.yml +34 -0
- data/conf/wise00.yml +11 -0
- data/data/case.house +0 -0
- data/data/char.house +0 -0
- data/data/images/Bluehills.jpg +0 -0
- data/data/images/Sunset.jpg +0 -0
- data/data/images/Waterlilies.jpg +0 -0
- data/data/images/Winter.jpg +0 -0
- data/data/query.house +18595 -0
- data/data/user.house +8 -0
- data/lib/action/module/check_action.rb +58 -0
- data/lib/action/module/cnnt_action.rb +161 -0
- data/lib/action/module/datacenter_action.rb +48 -0
- data/lib/action/module/http_pack_helper.rb +163 -0
- data/lib/action/module/httpserver_action.rb +297 -0
- data/lib/action/module/inc.rb +21 -0
- data/lib/action/module/mcpack_action.rb +57 -0
- data/lib/action/module/sql_action.rb +84 -0
- data/lib/action/module/ssh_action.rb +37 -0
- data/lib/action/system/user_action.rb +180 -0
- data/lib/common/appium_helper.rb +217 -0
- data/lib/common/atp_helper.rb +74 -0
- data/lib/common/atp_report.rb +344 -0
- data/lib/common/data_house.rb +405 -0
- data/lib/common/data_model.rb +87 -0
- data/lib/common/http/assert_helper.rb +343 -0
- data/lib/common/http/fix_hpricot.rb +118 -0
- data/lib/common/http/html_helper.rb +362 -0
- data/lib/common/http/http_helper.rb +469 -0
- data/lib/common/http/multipart.rb +81 -0
- data/lib/common/isandbox_helper.rb +195 -0
- data/lib/common/json_helper.rb +43 -0
- data/lib/common/mock_helper.rb +168 -0
- data/lib/common/mtop_helper.rb +141 -0
- data/lib/common/myconf_helper.rb +49 -0
- data/lib/common/mylog_helper.rb +77 -0
- data/lib/common/pairwise.rb +121 -0
- data/lib/common/query_house.rb +89 -0
- data/lib/common/report_helper.rb +97 -0
- data/lib/common/robot_helper.rb +85 -0
- data/lib/common/socket/check.rb +325 -0
- data/lib/common/socket/conf_modifier.rb +149 -0
- data/lib/common/socket/context.rb +55 -0
- data/lib/common/socket/data.rb +392 -0
- data/lib/common/socket/data_helper.rb +41 -0
- data/lib/common/socket/env.rb +317 -0
- data/lib/common/socket/inc.rb +24 -0
- data/lib/common/socket/log.rb +213 -0
- data/lib/common/socket/log4s.rb +58 -0
- data/lib/common/socket/log_helper.rb +332 -0
- data/lib/common/socket/my_sql.rb +77 -0
- data/lib/common/socket/net.rb +74 -0
- data/lib/common/socket/network.rb +115 -0
- data/lib/common/socket/rlib/conf_modifier.rb +130 -0
- data/lib/common/socket/rlib/data_helper.rb +33 -0
- data/lib/common/socket/rlib/log_helper.rb +303 -0
- data/lib/common/socket/rlib/process_helper.rb +91 -0
- data/lib/common/socket/stub.rb +276 -0
- data/lib/common/socket/util.rb +266 -0
- data/lib/patterns/inc.rb +10 -0
- data/lib/patterns/mc_base_pattern.rb +474 -0
- data/lib/patterns/some_pattern.rb +145 -0
- data/lib/super_test.rb +114 -0
- data/log/super_test.log +0 -0
- data/log/super_test.log.wf +0 -0
- data/test/cover_me.rb +6 -0
- data/tool/jenny +0 -0
- data/tool/mcsend/mcsend2 +0 -0
- data/tool/mcsend/mcsend2_shead +0 -0
- data/tool/mcserver/conf/mcserver.conf +77 -0
- data/tool/mcserver/conf/mcserverauthip +17 -0
- data/tool/mcserver/mcserver +0 -0
- data/tool/mcserver/mcserver_trans +0 -0
- data/tool/mysql +0 -0
- data/tool/net/mcsend/mcsend +0 -0
- data/tool/net/mcsend/mcsend_trans +0 -0
- data/tool/net/mcsend/nshead.data +7 -0
- data/tool/net/mcsend/res_nshead.data +7 -0
- data/tool/net/my_client/my_client +0 -0
- data/tool/net/tsclient/client.tcl +205 -0
- data/tool/others/kk +190 -0
- data/tool/others/rubyatp +42 -0
- data/tool/others/supertest_install.sh +34 -0
- data/tool/trip/idb +0 -0
- data/tool/ts-agent/nshead.bft +12 -0
- data/tool/ts-agent/server.conf +10 -0
- data/tool/ts-agent/server.tcl +376 -0
- metadata +275 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '../')
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
# coding: utf-8
|
4
|
+
|
5
|
+
#require 'log4s'
|
6
|
+
|
7
|
+
class DataHelper
|
8
|
+
# === 功能:
|
9
|
+
# 验证文件是否存在
|
10
|
+
# === Example:
|
11
|
+
# DataHelper.file_exist? file_path
|
12
|
+
def self.file_exist? file_path
|
13
|
+
return File.exists? file_path
|
14
|
+
end
|
15
|
+
|
16
|
+
# === 功能:
|
17
|
+
# 获取文件的大小
|
18
|
+
# === Example:
|
19
|
+
# DataHelper.file_size? file_path
|
20
|
+
def self.file_size? file_path
|
21
|
+
return File.size? file_path
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
if __FILE__ == $0
|
27
|
+
if ARGV.length > 0 then
|
28
|
+
case ARGV[0]
|
29
|
+
when 'file_exist?'
|
30
|
+
file_path = ARGV[1]
|
31
|
+
puts DataHelper.file_exist? file_path
|
32
|
+
|
33
|
+
when 'file_size?'
|
34
|
+
file_path = ARGV[1]
|
35
|
+
puts DataHelper.file_size? file_path
|
36
|
+
|
37
|
+
# else
|
38
|
+
# puts 'DataHelper: bad method name? #{ARGV[0]}'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), './rlib/')
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '.')
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
# coding: utf-8
|
5
|
+
|
6
|
+
require 'conf_modifier'
|
7
|
+
require 'process_helper'
|
8
|
+
require 'util'
|
9
|
+
require 'net/ssh'
|
10
|
+
require 'net/scp'
|
11
|
+
|
12
|
+
#============================================================
|
13
|
+
# This class supply enviroment related local/remote operation
|
14
|
+
# e.g. modify configration, operate process...
|
15
|
+
# Author:: chenjie
|
16
|
+
# Data:: 2009-4-30
|
17
|
+
#============================================================
|
18
|
+
|
19
|
+
module Env
|
20
|
+
#=====================================#
|
21
|
+
# CONF RELATED
|
22
|
+
#=====================================#
|
23
|
+
|
24
|
+
# ===功能
|
25
|
+
# 修改配置文件
|
26
|
+
# ===参数
|
27
|
+
# - host host ip(example: 127.0.0.1 stands for localhost)
|
28
|
+
# - conf_path 配置文件路径
|
29
|
+
# - key 欲修改的key
|
30
|
+
# - new_value 新的value值
|
31
|
+
# ===example
|
32
|
+
# modify_conf_single "name", newname
|
33
|
+
def modify_conf_single host=HOST, user=USERNAME, password=PASSWORD, conf_path=CONFPATH, key, new_value
|
34
|
+
if Util.is_localhost? host
|
35
|
+
cm = ConfModifier.new conf_path
|
36
|
+
cm.modify key, new_value
|
37
|
+
cm.writeconf
|
38
|
+
else
|
39
|
+
#lib_path = Util.get_lib_path host
|
40
|
+
#cmd_str = "cd #{lib_path} && ruby conf_modifier.rb modify_conf_single #{conf_path} #{key} #{new_value.to_s}"
|
41
|
+
#Util.exe_ssh_cmd! host, cmd_str, user, password
|
42
|
+
Util.change_in_local(host, conf_path, user, password) { | local_path |
|
43
|
+
cm = ConfModifier.new local_path
|
44
|
+
cm.modify key, new_value
|
45
|
+
cm.writeconf
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# ===功能
|
51
|
+
# 修改配置文件
|
52
|
+
# ===参数
|
53
|
+
# - host
|
54
|
+
# - conf_path
|
55
|
+
# - hash 欲修改的配置hash
|
56
|
+
# ===example
|
57
|
+
# hh = {"name"=>newname, "path"=>newpath}
|
58
|
+
# modify_conf hh
|
59
|
+
def modify_conf host=HOST, user=USERNAME, password=PASSWORD, conf_path=CONFPATH, hash
|
60
|
+
if Util.is_localhost? host
|
61
|
+
cm = ConfModifier.new conf_path
|
62
|
+
cm.modifyall hash
|
63
|
+
cm.writeconf
|
64
|
+
else
|
65
|
+
hash.each{|k,v|
|
66
|
+
Env.modify_conf_single host, user, password, conf_path, k, v
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# ===功能
|
73
|
+
# 获取配置文件的value
|
74
|
+
# ===参数
|
75
|
+
# - host
|
76
|
+
# - conf_path
|
77
|
+
# - key
|
78
|
+
# return if key existed, return conf value string; if not, return empty string ""
|
79
|
+
#
|
80
|
+
# === Example:
|
81
|
+
# get_conf "name"
|
82
|
+
#
|
83
|
+
# === 检查的方法:
|
84
|
+
# assert_body pattern
|
85
|
+
def get_conf host=HOST, user=USERNAME, password=PASSWORD, conf_path=CONFPATH, key
|
86
|
+
if Util.is_localhost? host
|
87
|
+
cm = ConfModifier.new conf_path
|
88
|
+
ret = cm.get_conf key
|
89
|
+
Context.set("IOBODY", ret)
|
90
|
+
return ret
|
91
|
+
else
|
92
|
+
#lib_path = Util.get_lib_path host
|
93
|
+
#cmd_str = "cd #{lib_path} && ruby conf_modifier.rb get_conf #{conf_path} #{key}"
|
94
|
+
#value = Util.exe_ssh_cmd! host, cmd_str, user, password
|
95
|
+
#Context.set("IOBODY", value)
|
96
|
+
#return value
|
97
|
+
Util.change_in_local(host, conf_path, user, password) { | local_path |
|
98
|
+
cm = ConfModifier.new local_path
|
99
|
+
ret = cm.get_conf key
|
100
|
+
Context.set("IOBODY", ret)
|
101
|
+
}
|
102
|
+
return ret
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# === 功能
|
107
|
+
# 备份配置
|
108
|
+
# === 参数
|
109
|
+
# @param host
|
110
|
+
# @param conf_path
|
111
|
+
# @param conf_name
|
112
|
+
# @param context_key the value of context_key is the bak name for conf
|
113
|
+
# @author tangweimin
|
114
|
+
# === Example:
|
115
|
+
# bak_conf "conf1"
|
116
|
+
def bak_conf host=HOST, user=USERNAME, password=PASSWORD, conf_path=CONFPATH, context_key
|
117
|
+
conf_dir=`dirname #{conf_path}`
|
118
|
+
conf_name=`basename #{conf_path}`
|
119
|
+
conf_dir.chop!
|
120
|
+
conf_name.chop!
|
121
|
+
now = Time.now.to_datetime
|
122
|
+
bak_cmd = "cd #{conf_dir} && cp #{conf_name} #{conf_name}.#{now}"
|
123
|
+
if Util.is_localhost? host
|
124
|
+
system "#{bak_cmd}"
|
125
|
+
else
|
126
|
+
Util.exe_ssh_cmd! host, bak_cmd, user, password
|
127
|
+
end
|
128
|
+
Context.set "#{context_key}", "#{conf_name}.#{now}"
|
129
|
+
$log.debug "bak conf which context key is #{context_key}"
|
130
|
+
end
|
131
|
+
|
132
|
+
# === 功能:
|
133
|
+
# 恢复配置
|
134
|
+
# === 参数
|
135
|
+
# @param host
|
136
|
+
# @param conf_path
|
137
|
+
# @param conf_name
|
138
|
+
# @param context_key the value of context_key is the bak name for conf
|
139
|
+
# @author tangweimin
|
140
|
+
# === Example:
|
141
|
+
# recover_conf "conf1"
|
142
|
+
def recover_conf host=HOST, user=USERNAME, password=PASSWORD, conf_path=CONFPATH, context_key
|
143
|
+
conf_dir=`dirname #{conf_path}`
|
144
|
+
conf_name=`basename #{conf_path}`
|
145
|
+
conf_dir.chop!
|
146
|
+
conf_name.chop!
|
147
|
+
bak_conf = Context.get "#{context_key}"
|
148
|
+
recover_cmd = "cd #{conf_dir} && mv #{bak_conf} #{conf_name}"
|
149
|
+
if Util.is_localhost?(host) then
|
150
|
+
system "#{recover_cmd}"
|
151
|
+
else
|
152
|
+
Util.exe_ssh_cmd! host, recover_cmd, user, password
|
153
|
+
end
|
154
|
+
Context.delete "#{context_key}"
|
155
|
+
$log.debug "Recover conf which context key is #{context_key}."
|
156
|
+
end
|
157
|
+
|
158
|
+
# === 功能:
|
159
|
+
# 拷贝配置
|
160
|
+
# ===参数
|
161
|
+
# @param host
|
162
|
+
# @param source_conf
|
163
|
+
# @param target_conf
|
164
|
+
# @author tangweimin
|
165
|
+
# === Example:
|
166
|
+
# copy_conf "/home/space/space/conf/conf1", "/home/space/space/conf/conf2"
|
167
|
+
def copy_conf host=HOST, user=USERNAME, password=PASSWORD, source_conf, target_conf
|
168
|
+
copy_cmd = "cp #{source_conf} #{target_conf}"
|
169
|
+
if Util.is_localhost?(host) then
|
170
|
+
system "#{copy_cmd}"
|
171
|
+
else
|
172
|
+
Util.exe_ssh_cmd! host, copy_cmd, user, password
|
173
|
+
end
|
174
|
+
$log.debug "Copy conf from #{source_conf} to #{target_conf}."
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
#=====================================#
|
179
|
+
#PROCESS RELATED
|
180
|
+
#=====================================#
|
181
|
+
|
182
|
+
# ===功能
|
183
|
+
# 启动模块进程, 运用脚本
|
184
|
+
# ===参数
|
185
|
+
# - host
|
186
|
+
# - module_name module name, e.g.: appui
|
187
|
+
# - script_path default "/home/space/space"
|
188
|
+
# - script_name default "loadspace.sh"
|
189
|
+
# return true/false
|
190
|
+
#
|
191
|
+
# === Example
|
192
|
+
#
|
193
|
+
# start_process '10.241.14.56', 'mlstar', '/home/space/mlstar/'
|
194
|
+
def start_process host, module_name, super_path="/home/space/space/", child_path="./bin/", user=USERNAME, password=PASSWORD
|
195
|
+
|
196
|
+
if Util.is_localhost? host
|
197
|
+
`killall -9 #{module_name}`
|
198
|
+
`cd #{super_path}; nohup #{child_path}#{module_name} >/dev/null 2>&1 &`
|
199
|
+
else
|
200
|
+
cmd_str = "killall -9 #{module_name};cd #{super_path}; nohup #{child_path}#{module_name} >/dev/null 2>&1 &"
|
201
|
+
Util.exe_ssh_cmd! host, cmd_str, user, password
|
202
|
+
end
|
203
|
+
|
204
|
+
sleep 2
|
205
|
+
value = is_process_running? host, module_name, user, password
|
206
|
+
return value
|
207
|
+
end
|
208
|
+
|
209
|
+
# ===功能
|
210
|
+
# kill模块进程
|
211
|
+
# execute killall to kill a process, if the process is supervised, then it will restart
|
212
|
+
# ===参数
|
213
|
+
# - host
|
214
|
+
# - module_name
|
215
|
+
# ===example
|
216
|
+
# kill_process host, "friend"
|
217
|
+
def kill_process host, module_name, user=USERNAME, password=PASSWORD
|
218
|
+
if Util.is_localhost?(host) then
|
219
|
+
`killall -9 #{module_name}`
|
220
|
+
else
|
221
|
+
cmd_str = "killall -9 #{module_name}"
|
222
|
+
Util.exe_ssh_cmd! host, cmd_str, user, password
|
223
|
+
end
|
224
|
+
sleep 1
|
225
|
+
end
|
226
|
+
|
227
|
+
# === 功能
|
228
|
+
# 检查模块是否启动
|
229
|
+
# return true/false
|
230
|
+
# === example
|
231
|
+
# is_process_running? host, "friend"
|
232
|
+
def is_process_running? host, module_name, user=USERNAME, password=PASSWORD
|
233
|
+
if Util.is_localhost?(host) then
|
234
|
+
value = `pstree | grep #{module_name} | wc -l`
|
235
|
+
if value.to_i > 0 then
|
236
|
+
return true
|
237
|
+
else
|
238
|
+
return false
|
239
|
+
end
|
240
|
+
else
|
241
|
+
cmd_str = "pstree | grep #{module_name} | wc -l"
|
242
|
+
value = Util.exe_ssh_cmd! host, cmd_str, user, password
|
243
|
+
if value.to_i > 0 then
|
244
|
+
return true
|
245
|
+
else
|
246
|
+
return false
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
# ===功能
|
252
|
+
# 获取模块进程线程数
|
253
|
+
# ===参数
|
254
|
+
# - host
|
255
|
+
# - module_name
|
256
|
+
# return thead number or 0(process not running)
|
257
|
+
# ===example
|
258
|
+
# get_thread_num host, "friend"
|
259
|
+
def get_thread_num host, module_name, user=USERNAME, password=PASSWORD
|
260
|
+
if Util.is_localhost? host
|
261
|
+
str = `pstree | grep #{module_name}`
|
262
|
+
mdata = str.scan /.*---(\d+).*/
|
263
|
+
if mdata.size > 0 then
|
264
|
+
return mdata[0][0].to_i
|
265
|
+
else
|
266
|
+
return 0
|
267
|
+
end
|
268
|
+
else
|
269
|
+
cmd_str = "pstree | grep #{module_name}"
|
270
|
+
str = Util.exe_ssh_cmd! host, cmd_str, user, password
|
271
|
+
mdata = str.scan /.*---(\d+).*/
|
272
|
+
if mdata.size > 0 then
|
273
|
+
return mdata[0][0].to_i
|
274
|
+
else
|
275
|
+
return 0
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
if __FILE__ == $0
|
285
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '.')
|
286
|
+
require 'test/unit'
|
287
|
+
require 'env'
|
288
|
+
class EnvTest < Test::Unit::TestCase
|
289
|
+
include Env
|
290
|
+
def no_test_start_process_remote
|
291
|
+
start_process '10.81.14.45', 'mlcommitui', '/home/space/mlcommitui/'
|
292
|
+
end
|
293
|
+
|
294
|
+
def no_test_get_local_ip
|
295
|
+
puts Util.get_local_ip
|
296
|
+
end
|
297
|
+
|
298
|
+
def no_test_modify_conf_single
|
299
|
+
value1 = get_conf '10.81.11.32', "#{TEST_ROOT}env/simple.conf", 'a'
|
300
|
+
puts value1
|
301
|
+
modify_conf_single '10.81.11.32', "#{TEST_ROOT}env/simple.conf", 'a', "#{value1}1"
|
302
|
+
value2 = get_conf '10.81.11.32', "#{TEST_ROOT}env/simple.conf", 'a'
|
303
|
+
puts value2
|
304
|
+
end
|
305
|
+
|
306
|
+
def no_test_get_thread_num
|
307
|
+
num = get_thread_num '10.81.14.45', 'mlstar'
|
308
|
+
puts num
|
309
|
+
end
|
310
|
+
|
311
|
+
def no_test_kill_process
|
312
|
+
kill_process '10.81.14.45', 'mlstar'
|
313
|
+
puts is_process_running? '10.81.14.45', 'mlstar'
|
314
|
+
puts start_process '10.81.14.45', 'mlstar', '/home/space/mlstar/'
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '../../conf/')
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '.')
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
#coding: utf-8
|
5
|
+
|
6
|
+
#require 'dbi'
|
7
|
+
require 'conf'
|
8
|
+
require 'env'
|
9
|
+
require 'network'
|
10
|
+
require 'data'
|
11
|
+
require 'my_sql'
|
12
|
+
require 'stub'
|
13
|
+
require 'log'
|
14
|
+
require 'context'
|
15
|
+
require 'check'
|
16
|
+
require 'test/unit'
|
17
|
+
|
18
|
+
include Env
|
19
|
+
include Network
|
20
|
+
include DATA
|
21
|
+
include Log
|
22
|
+
include Check
|
23
|
+
include MY_SQL
|
24
|
+
include Stub
|
@@ -0,0 +1,213 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), './rlib/')
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '.')
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
# coding: utf-8
|
5
|
+
require 'log_helper'
|
6
|
+
require 'util'
|
7
|
+
require 'context'
|
8
|
+
#============================================================
|
9
|
+
# 这个类是日志相关服务的顶层接口,提供本机/远程数据相服务
|
10
|
+
# e.g. monitor log, get match times, get match values...
|
11
|
+
# Author:: chenjie
|
12
|
+
# Data:: 2009-4-30
|
13
|
+
#============================================================
|
14
|
+
module Log
|
15
|
+
include DATA
|
16
|
+
|
17
|
+
# ===功能
|
18
|
+
# 在使用以下所有函数前使用
|
19
|
+
# 注意:一次只能monitor一个日志文件.
|
20
|
+
# monitor the log file and record the lines into context
|
21
|
+
# ===参数
|
22
|
+
# - host the remote host ip, nil means the log is on localhost
|
23
|
+
# - log_path
|
24
|
+
# - log_name
|
25
|
+
# return the lines of the log; -1 if the log not exist
|
26
|
+
# ===example
|
27
|
+
# monitor_log host, logpath, "log1"
|
28
|
+
def monitor_log host, log_path, log_name, user=USERNAME, password=PASSWORD
|
29
|
+
lines=0
|
30
|
+
log_pathname = "#{log_path}/#{log_name}"
|
31
|
+
# 为了解决日志文件过大导致的性能问题,首先将日志清空
|
32
|
+
if Util.is_localhost? host
|
33
|
+
`> #{log_pathname}`
|
34
|
+
lines = LogHelper.get_lines log_path, log_name
|
35
|
+
else
|
36
|
+
#lib_path = Util.get_lib_path host
|
37
|
+
#cmd_str = "cd #{lib_path} && ruby log_helper.rb get_lines #{log_path} #{log_name}"
|
38
|
+
#lines = Util.exe_ssh_cmd!(host, cmd_str).to_i
|
39
|
+
cmd_str = "> #{log_pathname}"
|
40
|
+
Util.exe_ssh_cmd!(host, cmd_str, user, password)
|
41
|
+
Util.change_in_local(host, "#{log_pathname}", user, password){ | local_path |
|
42
|
+
lines = LogHelper.get_lines File.dirname(local_path), File.basename(local_path)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
#record in context
|
47
|
+
Context.set("#{host}:#{log_path}:#{log_name}", lines)
|
48
|
+
end
|
49
|
+
|
50
|
+
# ===功能
|
51
|
+
# 监控被测模块日志
|
52
|
+
# 简化版方法,减少参数传递
|
53
|
+
# 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
|
54
|
+
# ===example
|
55
|
+
# _monitor_log
|
56
|
+
def _monitor_log
|
57
|
+
monitor_log IP, LOG_PATH, LOG, USERNAME, PASSWORD
|
58
|
+
end
|
59
|
+
|
60
|
+
# === 功能
|
61
|
+
# 监控被测模块异常日志
|
62
|
+
# 简化版方法,减少参数传递
|
63
|
+
# 约束: helper中必须定义 IP, PORT, LOG_PATH, LOG, WFLOG等变量
|
64
|
+
# ===example
|
65
|
+
# _monitor_wflog
|
66
|
+
def _monitor_wflog
|
67
|
+
monitor_log IP, LOG_PATH, WFLOG, USERNAME, PASSWORD
|
68
|
+
end
|
69
|
+
|
70
|
+
# === 功能:
|
71
|
+
# 是否有新的log日志产生
|
72
|
+
# === Example:
|
73
|
+
# has_new_log? "127.0.0.1", "/home/space/space/log/", "log1"
|
74
|
+
def has_new_log? host, log_path, log_name, user=USERNAME, password=PASSWORD
|
75
|
+
log_pathname = "#{log_path}/#{log_name}"
|
76
|
+
last_lines = Context.get "#{host}:#{log_path}:#{log_name}"
|
77
|
+
|
78
|
+
lines = 0
|
79
|
+
if Util.is_localhost? host
|
80
|
+
lines = LogHelper.get_lines log_path, log_name
|
81
|
+
else
|
82
|
+
#lib_path = Util.get_lib_path host
|
83
|
+
#cmd_str = "cd #{lib_path} && ruby log_helper.rb get_lines #{log_path} #{log_name}"
|
84
|
+
#lines = Util.exe_ssh_cmd!(host, cmd_str).to_i
|
85
|
+
Util.change_in_local(host, "#{log_pathname}", user, password){ | local_path |
|
86
|
+
lines = LogHelper.get_lines File.dirname(local_path), File.basename(local_path)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
if lines == last_lines then
|
91
|
+
return false
|
92
|
+
elsif lines > last_lines then
|
93
|
+
return true
|
94
|
+
else
|
95
|
+
raise "params error: lines is more than last lines"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# ===功能
|
100
|
+
# get the match times with the giving log level and regex pattern
|
101
|
+
# ===参数
|
102
|
+
# - host the remote host ip, nil means the log is on localhost
|
103
|
+
# - log_path
|
104
|
+
# - log_name
|
105
|
+
# - log_level an array whoes value from ["DEBUG", "NOTICE", "WARNING", "FATAL"]; nil for all levels
|
106
|
+
# - pattern a string or a regex pattern
|
107
|
+
#
|
108
|
+
# return int, the match times with the giving log level and regex pattern
|
109
|
+
# ===example
|
110
|
+
# get_match_times host, logpath, "log1", ["DEBUG"], "time"
|
111
|
+
def get_match_times host, log_path, log_name, log_level, pattern, user=USERNAME, password=PASSWORD
|
112
|
+
log_pathname = "#{log_path}/#{log_name}"
|
113
|
+
start_lines = Context.get("#{host}:#{log_path}:#{log_name}") + 1
|
114
|
+
lines = 0
|
115
|
+
if Util.is_localhost? host
|
116
|
+
return LogHelper.get_match_times log_path, log_name, start_lines, log_level, pattern
|
117
|
+
else
|
118
|
+
#level_code = LogHelper.level_encode log_level
|
119
|
+
#lib_path = Util.get_lib_path host
|
120
|
+
#cmd_str = "cd #{lib_path} && ruby log_helper.rb get_match_times #{log_path} #{log_name} #{start_lines} #{level_code} #{pattern}"
|
121
|
+
#times = Util.exe_ssh_cmd! host, cmd_str
|
122
|
+
#return times.to_i
|
123
|
+
Util.change_in_local(host, "#{log_pathname}", user, password){ | local_path |
|
124
|
+
lines = LogHelper.get_match_times File.dirname(local_path), File.basename(local_path), start_lines, log_level, pattern
|
125
|
+
}
|
126
|
+
return lines
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# === 功能:
|
131
|
+
# get the match lines with the giving log level and regex pattern
|
132
|
+
# === Example:
|
133
|
+
# get_match_lines host, "/home/space/space/log/", "log1",
|
134
|
+
def get_match_lines host, log_path, log_name, log_level, pattern, user=USERNAME, password=PASSWORD
|
135
|
+
log_pathname = "#{log_path}/#{log_name}"
|
136
|
+
start_lines = Context.get("#{host}:#{log_path}:#{log_name}") + 1
|
137
|
+
lines = []
|
138
|
+
if Util.is_localhost? host
|
139
|
+
return LogHelper.get_match_lines log_path, log_name, start_lines, log_level, pattern
|
140
|
+
else
|
141
|
+
#level_code = LogHelper.level_encode log_level
|
142
|
+
#lib_path = Util.get_lib_path host
|
143
|
+
#cmd_str = "cd #{lib_path} && ruby log_helper.rb get_match_lines #{log_path} #{log_name} #{start_lines} #{level_code} #{pattern}"
|
144
|
+
#lines = Util.exe_ssh_cmd! host, cmd_str
|
145
|
+
#return lines
|
146
|
+
Util.change_in_local(host, "#{log_pathname}", user, password){ | local_path |
|
147
|
+
lines = LogHelper.get_match_lines File.dirname(local_path), File.basename(local_path), start_lines, log_level, pattern
|
148
|
+
}
|
149
|
+
return lines
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# ===功能
|
154
|
+
# get the match values with the giving log level and regex pattern
|
155
|
+
# ===参数
|
156
|
+
# - log_path
|
157
|
+
# - log_name
|
158
|
+
# - last_lines the lines read from tail to head
|
159
|
+
# - log_level an array whoes value from ["DEBUG", "NOTICE", "WARNING", "FATAL"]; nil for all levels
|
160
|
+
# - pattern a string or a regex pattern
|
161
|
+
# - return an array contains the match values with the giving log level and regex pattern
|
162
|
+
# ===example
|
163
|
+
# get_match_values host, logpath, "log1", ["DEBUG", "WARNING"], "time"
|
164
|
+
def get_match_values host, log_path, log_name, log_level, pattern, user=USERNAME, password=PASSWORD
|
165
|
+
log_pathname = "#{log_path}/#{log_name}"
|
166
|
+
start_lines = Context.get("#{host}:#{log_path}:#{log_name}") + 1
|
167
|
+
lines = []
|
168
|
+
if Util.is_localhost? host
|
169
|
+
return LogHelper.get_match_values log_path, log_name, start_lines, log_level, pattern
|
170
|
+
else
|
171
|
+
#level_code = LogHelper.level_encode log_level
|
172
|
+
#lib_path = Util.get_lib_path host
|
173
|
+
#cmd_str = "cd #{lib_path} && ruby log_helper.rb get_match_values #{log_path} #{log_name} #{start_lines} #{level_code} #{pattern}"
|
174
|
+
#values = Util.exe_ssh_cmd! host, cmd_str
|
175
|
+
#return values
|
176
|
+
Util.change_in_local(host, "#{log_pathname}", user, password){ | local_path |
|
177
|
+
lines = LogHelper.get_match_values File.dirname(local_path), File.basename(local_path), start_lines, log_level, pattern
|
178
|
+
}
|
179
|
+
return lines
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# ===功能
|
184
|
+
# get the first match value, nil if no match found
|
185
|
+
# ===参数
|
186
|
+
# - log_path
|
187
|
+
# - log_name
|
188
|
+
# - last_lines the lines read from tail to head
|
189
|
+
# - log_level an array whoes value from ["DEBUG", "NOTICE", "WARNING", "FATAL"]; nil for all levels
|
190
|
+
# - pattern a string or a regex pattern
|
191
|
+
# return a string firstly matches the pattern
|
192
|
+
# ===example
|
193
|
+
# get_match_value host, logpath, "log1", ["DEBUG"], "time"
|
194
|
+
def get_match_value host, log_path, log_name, log_level, pattern, user=USERNAME, password=PASSWORD
|
195
|
+
log_pathname = "#{log_path}/#{log_name}"
|
196
|
+
start_lines = Context.get("#{host}:#{log_path}:#{log_name}") + 1
|
197
|
+
lines = nil
|
198
|
+
if Util.is_localhost? host
|
199
|
+
return LogHelper.get_match_value log_path, log_name, start_lines, log_level, pattern
|
200
|
+
else
|
201
|
+
#level_code = LogHelper.level_encode log_level
|
202
|
+
#lib_path = Util.get_lib_path host
|
203
|
+
#cmd_str = "cd #{lib_path} && ruby log_helper.rb get_match_value #{log_path} #{log_name} #{start_lines} #{level_code} #{pattern}"
|
204
|
+
#value = Util.exe_ssh_cmd! host, cmd_str
|
205
|
+
#return value
|
206
|
+
Util.change_in_local(host, "#{log_pathname}", user, password){ | local_path |
|
207
|
+
lines = LogHelper.get_match_value File.dirname(local_path), File.basename(local_path), start_lines, log_level, pattern
|
208
|
+
}
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|