Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
U
ubains-module-test
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
郑晓兵
ubains-module-test
Commits
cc80a433
提交
cc80a433
authored
12月 23, 2024
作者:
陈泽健
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
补充对于服务器状态的监测,并体现在报告中做判断。
上级
c5937a0c
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
142 行增加
和
61 行删除
+142
-61
Mqtt_Send.py
预定系统/Base/Mqtt_Send.py
+1
-1
base.py
预定系统/Base/base.py
+52
-17
README.md
预定系统/README.md
+3
-2
01服务器状态监测.py
预定系统/cases/展厅巡检/07服务器监测/01服务器状态监测.py
+32
-0
__st__.py
预定系统/cases/展厅巡检/07服务器监测/__st__.py
+36
-0
test.py
预定系统/cases/展厅巡检/test.py
+18
-41
没有找到文件。
预定系统/Base/Mqtt_Send.py
浏览文件 @
cc80a433
...
...
@@ -395,7 +395,7 @@ class Mqtt:
"startTime"
:
config
[
'startTime'
],
"endTime"
:
config
[
'endTime'
],
"companyNumber"
:
config
[
'companyNumber'
],
"participantList"
:
[
"
zhangsan"
,
"LaoYang"
,
"zhaoliu"
,
"DuoTangMaLaBan"
,
"czj"
,
"czj2"
,
"CJZ3"
,
"CZJ4
"
]
"participantList"
:
[
"
JiaoJiao"
,
"JiaYu"
,
"DuiFangZhengZaiZhangTouFa"
,
"DuoTangMaLaBan
"
]
}]
})
...
...
预定系统/Base/base.py
浏览文件 @
cc80a433
...
...
@@ -701,19 +701,54 @@ def single_click_and_drag(source_element_locator, target_element_locator, wd):
except
Exception
as
e
:
logging
.
error
(
f
"发生未知错误: {e}"
)
def
get_current_window_index
(
wd
):
current_handle
=
wd
.
current_window_handle
handles
=
wd
.
window_handles
return
handles
.
index
(
current_handle
)
def
switch_to_next_window
(
wd
):
current_index
=
get_current_window_index
(
wd
)
handles
=
wd
.
window_handles
next_index
=
(
current_index
+
1
)
%
len
(
handles
)
wd
.
switch_to
.
window
(
handles
[
next_index
])
def
switch_to_previous_window
(
wd
):
current_index
=
get_current_window_index
(
wd
)
handles
=
wd
.
window_handles
previous_index
=
(
current_index
-
1
)
%
len
(
handles
)
wd
.
switch_to
.
window
(
handles
[
previous_index
])
\ No newline at end of file
import
requests
import
os
import
chardet
from
urllib3.exceptions
import
InsecureRequestWarning
# 禁用 InsecureRequestWarning 警告
requests
.
packages
.
urllib3
.
disable_warnings
(
category
=
InsecureRequestWarning
)
def
fetch_and_parse_check_txt
(
url
,
save_path
,
extract_info
):
"""
获取check.txt文件并解析指定信息
:param url: check.txt文件的URL
:param save_path: 文件保存路径
:param extract_info: 需要提取的信息列表,例如 ['[m]ysql', '[r]edis', '[f]dfs_storaged', '[f]dfs_tracker', '[e]mqx', 'ubains-meeting-api-1.0-SNAPSHOT.jar', 'ubains-meeting-inner-api-1.0-SNAPSHOT.jar', 'uwsgi']
:return: 提取的信息字典
"""
try
:
# 发送HTTPS请求获取文件内容
response
=
requests
.
get
(
url
,
verify
=
False
)
# verify=False 忽略SSL证书验证,生产环境不推荐
response
.
raise_for_status
()
# 如果响应状态码不是200,抛出异常
# 检测文件编码
detected_encoding
=
chardet
.
detect
(
response
.
content
)[
'encoding'
]
print
(
f
"检测到的编码: {detected_encoding}"
)
# 如果检测到的编码为空或不准确,可以手动指定编码
if
not
detected_encoding
or
detected_encoding
==
'ascii'
:
detected_encoding
=
'utf-8'
# 假设文件编码为 utf-8
# 将响应内容解码为字符串
content
=
response
.
content
.
decode
(
detected_encoding
)
# 将文件内容保存到指定目录
with
open
(
save_path
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
file
.
write
(
content
)
# 解析文件内容
parsed_info
=
{}
for
line
in
content
.
split
(
'
\n
'
):
for
info
in
extract_info
:
if
info
in
line
:
service_name
=
info
service_status
=
line
.
split
(
info
,
1
)[
1
]
.
strip
()
parsed_info
[
service_name
]
=
service_status
return
parsed_info
except
requests
.
exceptions
.
RequestException
as
e
:
print
(
f
"请求错误: {e}"
)
return
None
\ No newline at end of file
预定系统/README.md
浏览文件 @
cc80a433
...
...
@@ -122,4 +122,5 @@
-
补充讯飞、运维以及统一平台的巡检流程,并整合展厅巡检目录的执行初始化文件。
-
补充统一平台的软终端入会流程,完善统一平台的会控巡检流程。
25.
2024-12-23
-
调整富创项目的MQTT消息体,补充参会人数据推送。处理展厅巡检的时间格式问题。
\ No newline at end of file
-
调整富创项目的MQTT消息体,补充参会人数据推送。处理展厅巡检的时间格式问题。
-
补充对于服务器状态的监测,并体现在报告中做判断。
\ No newline at end of file
预定系统/cases/展厅巡检/07服务器监测/01服务器状态监测.py
0 → 100644
浏览文件 @
cc80a433
import
sys
import
os
# 获取当前脚本的绝对路径
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
# 构建预定系统的绝对路径
预定系统
_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
current_dir
,
'..'
,
'..'
,
'..'
,
'..'
))
# 添加路径
sys
.
path
.
append
(
预定系统
_path
)
# 导入模块
from
预定系统
.
Base
.
base
import
*
class
Server_monitoring_0001
:
tags
=
[
'展厅巡检'
,
'服务器状态巡检'
]
def
teststeps
(
self
):
i
=
0
# 使用示例
url
=
"https://192.168.5.218:8443/media/file/check.txt"
save_path
=
"check.txt"
extract_info
=
[
'[m]ysql'
,
'[r]edis'
,
'[f]dfs_storaged'
,
'[f]dfs_tracker'
,
'[e]mqx'
,
'ubains-meeting-api-1.0-SNAPSHOT.jar'
,
'ubains-meeting-inner-api-1.0-SNAPSHOT.jar'
,
'uwsgi'
]
info
=
fetch_and_parse_check_txt
(
url
,
save_path
,
extract_info
)
if
info
:
for
key
,
value
in
info
.
items
():
STEP
(
i
+
1
,
f
"服务器{key} 服务状态巡检"
)
INFO
(
f
"监测到{key} 服务的状态:{value}"
)
CHECK_POINT
(
f
"{key}服务的状态是否正常"
,
value
==
"服务正常"
)
else
:
INFO
(
"无法获取或解析文件内容"
)
\ No newline at end of file
预定系统/cases/展厅巡检/07服务器监测/__st__.py
0 → 100644
浏览文件 @
cc80a433
import
sys
import
os
from
time
import
sleep
# 获取当前脚本的绝对路径
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
# 构建预定系统的绝对路径
预定系统
_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
current_dir
,
'..'
,
'..'
,
'..'
))
# 添加路径
sys
.
path
.
append
(
预定系统
_path
)
# 导入模块
try
:
from
预定系统
.
Base
.
base
import
*
except
ModuleNotFoundError
as
e
:
print
(
f
"ModuleNotFoundError: {e}"
)
print
(
"尝试使用绝对路径导入"
)
from
预定系统
.
Base
.
base
import
*
def
suite_setup
():
STEP
(
1
,
"初始化浏览器"
)
login_exhibit_url
=
'http://192.168.5.200:38083/#/login'
browser_init
(
login_exhibit_url
)
wd
=
GSTORE
[
'wd'
]
STEP
(
2
,
"登录系统"
)
safe_send_keys
((
By
.
XPATH
,
"//input[@placeholder='手机号/用户名/邮箱']"
),
"admin@czj"
,
wd
)
safe_send_keys
((
By
.
XPATH
,
"//input[@placeholder='密码']"
),
"Ubains@54321"
,
wd
)
safe_send_keys
((
By
.
XPATH
,
"//input[@placeholder='图形验证']"
),
"csba"
,
wd
)
safe_click
((
By
.
XPATH
,
"//span[@class='el-checkbox__inner']"
),
wd
)
sleep
(
2
)
safe_click
((
By
.
XPATH
,
"//div[@id='pane-1']//div//span[contains(text(),'登录')]"
),
wd
)
sleep
(
2
)
def
suite_teardown
():
browser_quit
()
\ No newline at end of file
预定系统/cases/展厅巡检/test.py
浏览文件 @
cc80a433
import
os
import
requests
import
chardet
from
urllib3.exceptions
import
InsecureRequestWarning
# 禁用 InsecureRequestWarning 警告
requests
.
packages
.
urllib3
.
disable_warnings
(
category
=
InsecureRequestWarning
)
def
download_file
(
url
,
save_directory
,
filename
):
# 确保保存目录存在
if
not
os
.
path
.
exists
(
save_directory
):
os
.
makedirs
(
save_directory
)
# 构建完整的本地文件路径
local_filepath
=
os
.
path
.
join
(
save_directory
,
filename
)
try
:
# 发送HTTP GET请求以获取文件数据
response
=
requests
.
get
(
url
,
verify
=
False
)
# 禁用SSL验证
# 检查响应状态码是否为200(OK)
if
response
.
status_code
==
200
:
# 自动检测文件编码
detected_encoding
=
chardet
.
detect
(
response
.
content
)[
'encoding'
]
print
(
f
"检测到的编码: {detected_encoding}"
)
# 将响应内容解码为字符串
content
=
response
.
content
.
decode
(
detected_encoding
)
# 打开本地文件以文本写入模式,并将响应内容写入文件
with
open
(
local_filepath
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
content
)
print
(
f
"文件已成功下载并保存为 {local_filepath}"
)
else
:
print
(
f
"无法下载文件,状态码: {response.status_code}"
)
except
requests
.
exceptions
.
RequestException
as
e
:
print
(
f
"请求过程中出现错误: {e}"
)
from
预定系统
.
Base
.
base
import
fetch_and_parse_check_txt
if
__name__
==
"__main__"
:
# 使用示例
# url = "https://192.168.5.218:8443/media/file/check.txt"
# save_directory = r"D:\GithubData\自动化\ubains-module-test\预定系统\reports" # 指定保存目录
# filename = "check.txt"
# download_file(url, save_directory, filename)
# 使用示例
url
=
"https://192.168.5.218:8443/media/file/check.txt"
save_directory
=
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports"
# 指定保存目录
filename
=
"check.txt"
download_file
(
url
,
save_directory
,
filename
)
\ No newline at end of file
save_path
=
"check.txt"
extract_info
=
[
'[m]ysql'
,
'[r]edis'
,
'[f]dfs_storaged'
,
'[f]dfs_tracker'
,
'[e]mqx'
,
'ubains-meeting-api-1.0-SNAPSHOT.jar'
,
'ubains-meeting-inner-api-1.0-SNAPSHOT.jar'
,
'uwsgi'
]
info
=
fetch_and_parse_check_txt
(
url
,
save_path
,
extract_info
)
if
info
:
for
key
,
value
in
info
.
items
():
print
(
f
"{key} 服务的状态是 {value}"
)
else
:
print
(
"无法获取或解析文件内容"
)
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论