提交 04eb0502 authored 作者: 陈泽健's avatar 陈泽健

fix(edit):补充钉钉对接通知发送,远程自动化部署实现,PRD文档增加约束描述。

上级 9f8a1cb0
# Complete Acceptance Test Script
$PlinkPath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\RemoteDeploy\plink.exe"
function Invoke-SSH {
param([string]$Command)
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $PlinkPath
$psi.Arguments = "-pw Ubains@123 -P 22 root@192.168.5.52 $Command"
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.CreateNoWindow = $true
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $psi
$p.Start() | Out-Null
$p.WaitForExit(120000)
return $p.StandardOutput.ReadToEnd()
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Complete Acceptance Test" -ForegroundColor Cyan
Write-Host "Server: 192.168.5.52" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Test 1: Container Status
Write-Host "Test 1: Container Status Check" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Gray
$containers = Invoke-SSH -Command "docker ps --format 'table {{.Names}}\t{{.Status}}'"
Write-Host $containers
Write-Host ""
# Test 2: External Service Log Check
Write-Host "Test 2: External Service Log (SYSTEMVERSION Check)" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Gray
$extApiLog = Invoke-SSH -Command "tail -100 /data/services/api/java-meeting/java-meeting-extapi/logs/ubains-INFO-AND-ERROR.log"
if ($extApiLog -match "SYSTEMVERSION :: target_api_integration") {
Write-Host "✅ External service log: SYSTEMVERSION found - PASS" -ForegroundColor Green
} else {
Write-Host "⚠️ External service log: SYSTEMVERSION not found - checking again in 10 min..." -ForegroundColor Yellow
Start-Sleep -Seconds 600
$extApiLogRetry = Invoke-SSH -Command "tail -100 /data/services/api/java-meeting/java-meeting-extapi/logs/ubains-INFO-AND-ERROR.log"
if ($extApiLogRetry -match "SYSTEMVERSION") {
Write-Host "✅ External service log: SYSTEMVERSION found (after retry) - PASS" -ForegroundColor Green
} else {
Write-Host "❌ External service log: SYSTEMVERSION not found - FAIL" -ForegroundColor Red
Write-Host "Last log lines:" -ForegroundColor Gray
Write-Host $extApiLogRetry
}
}
Write-Host ""
# Test 3: API Endpoint Tests
Write-Host "Test 3: Service API Endpoint Tests" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Gray
$apiTests = @{
"ExtAPI" = @{URL = "https://192.168.5.52/exapi/message/getMsgPageList"; Expected = "A0076"}
"Meeting" = @{URL = "https://192.168.5.52/meetingV3/api/systemConfiguration/globalConfig?companyNumber=CN-SZ-00-0201"; Expected = "A0078"}
"Monitor" = @{URL = "https://192.168.5.52/monitor/api2/api/servermonitor/"; Expected = "40000014"}
"Voice" = @{URL = "https://192.168.5.52/voice/api/iflytek/roommaster?company_id=1&user_id=8&company_secret=57d00f9f-020f-5f1f-b788-55fae843bceb&getall=1"; Expected = "40000003"}
}
foreach ($api in $apiTests.Keys) {
$test = $apiTests[$api]
Write-Host "Testing $api..." -ForegroundColor Cyan
$result = Invoke-SSH -Command "curl -k '$($test.URL)' 2>/dev/null"
if ($result -match $test.Expected) {
Write-Host "✅ $api: PASS" -ForegroundColor Green
} elseif ($result -match "nginx|Error") {
Write-Host "❌ $api: FAIL (nginx error page)" -ForegroundColor Red
} else {
Write-Host "⚠️ $api: UNKNOWN RESPONSE" -ForegroundColor Yellow
}
}
Write-Host ""
# Test 4: Service Status Summary
Write-Host "Test 4: Service Status Summary" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Gray
$javaProcesses = Invoke-SSH -Command "ps aux | grep java | grep -v grep | wc -l"
$pythonProcesses = Invoke-SSH -Command "ps aux | grep 'python.*uwsgi\|python.*httpd' | grep -v grep | wc -l"
Write-Host "Java processes: $($javaProcesses.Trim())" -ForegroundColor Cyan
Write-Host "Python service processes: $($pythonProcesses.Trim())" -ForegroundColor Cyan
# Check specific services
$services = @(
@{Name = "ExtAPI"; Path = "/data/services/api/java-meeting/java-meeting-extapi"},
@{Name = "InnerAPI"; Path = "/data/services/api/java-meeting/java-meeting2.0"},
@{Name = "Monitor"; Path = "/data/services/api/python-cmdb"},
@{Name = "Voice"; Path = "/data/services/api/python-voice"}
)
foreach ($svc in $services) {
$exists = Invoke-SSH -Command "test -d '$($svc.Path)' && echo 'exists' || echo 'not_found'"
if ($exists -match "exists") {
Write-Host "✅ $($svc.Name): Directory exists" -ForegroundColor Green
} else {
Write-Host "❌ $($svc.Name): Directory not found" -ForegroundColor Red
}
}
Write-Host ""
# Final Summary
Write-Host "========================================" -ForegroundColor Green
Write-Host "Acceptance Test Summary" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host "Next Steps:" -ForegroundColor Yellow
Write-Host "1. System Authorization: https://192.168.5.52/#/LoginConfig" -ForegroundColor Gray
Write-Host " Verification code: csba" -ForegroundColor Gray
Write-Host " License file: E:\自动化部署\X86-5.52\license.zip" -ForegroundColor Gray
Write-Host ""
Write-Host "2. Create Company Admin: https://192.168.5.52/#/LoginAdmin" -ForegroundColor Gray
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
# Monitor All Systems Deployment
$PlinkPath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\RemoteDeploy\plink.exe"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Monitoring All Systems Deployment" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
function Invoke-SSH {
param([string]$Command)
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $PlinkPath
$psi.Arguments = "-pw Ubains@123 -P 22 root@192.168.5.52 $Command"
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.CreateNoWindow = $true
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $psi
$p.Start() | Out-Null
$p.WaitForExit(60000)
return $p.StandardOutput.ReadToEnd()
}
# Check if deployment script is still running
$running = Invoke-SSH -Command "ps aux | grep deploy_all_complete | grep -v grep | wc -l"
if ($running.Trim() -eq "1") {
Write-Host "Deployment Status: RUNNING" -ForegroundColor Green
Write-Host ""
# Show recent log lines
Write-Host "Recent deployment log:" -ForegroundColor Gray
Write-Host "========================================" -ForegroundColor Gray
$log = Invoke-SSH -Command "tail -30 /data/offline_auto_unifiedPlatform/new_auto_script.log 2>/dev/null || tail -30 /var/log/deploy/deploy.log 2>/dev/null || echo 'Log not available'"
Write-Host $log
} else {
Write-Host "Deployment Status: COMPLETED or NOT RUNNING" -ForegroundColor Yellow
Write-Host ""
# Show full log
Write-Host "Full deployment log:" -ForegroundColor Gray
Write-Host "========================================" -ForegroundColor Gray
$log = Invoke-SSH -Command "tail -100 /data/offline_auto_unifiedPlatform/new_auto_script.log 2>/dev/null || tail -100 /var/log/deploy/deploy.log 2>/dev/null"
Write-Host $log
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Gray
Write-Host "Services Status:" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Gray
# Check Docker containers
$docker = Invoke-SSH -Command "docker ps --format 'table {{.Names}}\t{{.Status}}' 2>/dev/null || echo 'Docker not available'"
Write-Host $docker
Write-Host ""
Write-Host "========================================" -ForegroundColor Gray
Write-Host "Java Services:" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Gray
# Check Java processes
$java = Invoke-SSH -Command "ps aux | grep java | grep -v grep | wc -l"
Write-Host "Total Java processes: $($java.Trim())" -ForegroundColor Cyan
Write-Host ""
Write-Host "========================================" -ForegroundColor Gray
Write-Host "Quick Commands:" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Gray
Write-Host "SSH to server: ssh root@192.168.5.52" -ForegroundColor White
Write-Host "Monitor deployment log: tail -f /data/offline_auto_unifiedPlatform/new_auto_script.log" -ForegroundColor White
Write-Host "Check services: docker ps" -ForegroundColor White
Write-Host "========================================" -ForegroundColor Gray
# Re-run Deployment Script with Full System Selection
$PlinkPath = "E:\GithubData\ubains-module-test\AuxiliaryTool\ScriptTool\RemoteDeploy\plink.exe"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Re-running Deployment with System Selection" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "This will connect to the server and run the deployment script interactively." -ForegroundColor Yellow
Write-Host "When prompted to select systems, please choose '全部系统' (All Systems)" -ForegroundColor Yellow
Write-Host ""
Write-Host "Press Enter to continue..." -ForegroundColor Gray
Read-Host
Write-Host ""
Write-Host "Connecting to server 192.168.5.52..." -ForegroundColor Cyan
Write-Host "You will be prompted for deployment options in the SSH session." -ForegroundColor Yellow
Write-Host ""
# Start interactive SSH session
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $PlinkPath
$psi.Arguments = "-pw Ubains@123 -P 22 root@192.168.5.52"
$psi.UseShellExecute = $true
$psi.RedirectStandardOutput = $false
$psi.RedirectStandardError = $false
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $psi
$p.Start() | Out-Null
$p.WaitForExit()
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "SSH session completed" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
# 服务器全深入巡检报告 v3 (终极版)
**时间:** 2026-05-15 06:23:04
**主机:** 139.159.163.86 (kunpeng)
**操作系统:** Ubuntu 18.04.3 LTS
**内核:** Linux kunpeng 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:10 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux
**运行时间:** 06:23:06 up 183 days, 19:54, 0 users, load average: 0.00, 0.00, 0.00
**状态:** 警告
---
## 核心问题诊断
**严重问题:**
-
**警告:**
- Swap已使用: 1.4%
- 总线程数: 1443
- Redis缓存命中率: 58.0%
诊断摘要: 关键问题: 0, 警告: 3
---
## 资源使用概览
| 指标 | 当前值 | 阈值 | 状态 |
| :--- | :--- | :--- | :--- |
| CPU使用率 | 1.1% | 85% | ✅ |
| 内存使用率 | 78.7% | 85% | ✅ |
| Swap使用率 | 1.4% | - | ⚠️ |
| 磁盘使用率 | 66.0% | 90% | ✅ |
| 网络连接 | ESTABLISHED:77 | - | ✅ |
| 线程总数 | 1443 | 1000 | ⚠️ |
| 文件描述符使用率 | 0.9% | 80% | ✅ |
| 系统负载(1min) | 0.0 | 8 | ✅ |
---
## 进程资源TOP排名
**CPU TOP15 (按CPU使用率降序):**
| 排名 | PID | 进程名 | CPU% | 内存% |
| :--- | :--- | :--- | :--- | :--- |
| 1 | 30701 | sshd | 1.0 | 0.0 |
| 2 | 23951 | java | 0.6 | 16.6 |
| 3 | 26483 | java | 0.5 | 11.3 |
| 4 | 16541 | mysqld | 0.5 | 26.1 |
| 5 | 23315 | beam.smp | 0.3 | 2.9 |
| 6 | 17153 | mongod | 0.3 | 1.5 |
| 7 | 30334 | redis-server | 0.1 | 0.0 |
| 8 | 23583 | python | 0.1 | 0.9 |
| 9 | 9 | rcu_bh | 0.0 | 0.0 |
| 10 | 99 | irq/41-ACPI:Ged | 0.0 | 0.0 |
| 11 | 98 | kthrotld | 0.0 | 0.0 |
| 12 | 946 | wrapper | 0.0 | 0.0 |
| 13 | 935 | sshg-fw | 0.0 | 0.0 |
| 14 | 934 | sshguard | 0.0 | 0.0 |
| 15 | 933 | journalctl | 0.0 | 0.0 |
**系统总线程数:** 1443
**僵尸进程数:** 0
**D状态进程数:** 0
---
## MySQL全深度分析
- **版本:**
- **运行时间:** 15276380秒
- **当前连接:** 15 / 151 (使用率9.9%)
- **历史最大连接:** 51
- **慢查询数:** 0
- **QPS(Queries):** 146783128
**数据库大小:**
- Database Size(MB)
- mysql 11.47
- information_schema 0.00
- performance_schema 0.00
- sys 0.02
- devops 11.89
- ubains 1433.16
- wifi 36.11
- ubains_lz_0 45.66
- nacos_mysql 2.61
- ubains_xty 8.78
- devops_xty 8.63
- wifi2 0.53
- huazhao2 0.38
- devops_voice 4.72
- nacos_mysql2 4.22
- ubains_251120 132.97
- ubains_dhh1120 159.80
- ubains_big 286.19
**MySQL变量:**
- max_connections: `151`
- wait_timeout: `28800`
- interactive_timeout: `28800`
- innodb_buffer_pool_size: `134217728`
**表统计(TOP20):**
```
TABLE_SCHEMA TABLE_NAME TABLE_ROWS DATA_LENGTH INDEX_LENGTH
ubains sys_oper_log 275441 1491861504 0
ubains sys_user_role 5399 245760 180224
ubains rms_meeting_approval_task 2551 442368 0
ubains rms_manage_user_dids 2493 147456 0
ubains rms_manage_user 1416 540672 196608
ubains rms_meeting_signs 774 180224 49152
ubains rms_meeting_topic 728 229376 0
ubains rms_manage_control_connect 676 65536 49152
ubains rms_meeting_approval_signs 671 98304 16384
ubains rms_meeting_message 540 376832 114688
ubains rms_meeting_approval 448 212992 0
ubains rms_manage_device_port 445 49152 0
ubains rms_manage_seat 415 65536 0
ubains rms_manage_matrix_connect 414 65536 16384
ubains rms_manage_device 328 114688 49152
ubains rms_manage_audio_connect 304 81920 16384
ubains rms_configuration_global 268 114688 0
ubains rms_meeting_participant 264 81920 16384
ubains rms_room_city 231 16384 0
ubains rms_meeting_message_file 200 81920 0
```
**InnoDB缓冲池命中率:**
```
Variable_name Value
Innodb_buffer_pool_read_ahead_rnd 0
Innodb_buffer_pool_read_ahead 67171
Innodb_buffer_pool_read_ahead_evicted 4421
Innodb_buffer_pool_read_requests 25050510511
Innodb_buffer_pool_reads 730237
```
---
## Redis全深度分析
- **版本:** 6.2.6
- **运行天数:** 3
- **客户端连接:** 14
- **内存使用:** 1.16M
- **内存峰值:** 1.40M
- **内存碎片率:** 3.09
- **总键数:** 69
- **缓存命中率:** 58.0%
**Keyspace:**
```
# Keyspace
db0:keys=69,expires=29,avg_ttl=11218772
db10:keys=1,expires=1,avg_ttl=74779700
```
**持久化:**
```
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1778785800
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:528384
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
aof_current_size:57092521
aof_base_size:56380944
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0
```
---
## EMQX消息队列全深度分析
- **状态:** Node 'emqx@172.17.0.4' 5.8.1 is started
- **Broker:** sysdescr : EMQX
version : 5.8.1
datetime : 2026-05-14T22:23:51.237541365+00:00
uptime : 37 days, 15 hours, 51 minutes, 44 seconds
- **会话数:** 166
- **订阅数:** 23
- **客户端连接数:** 14
- **Dashboard状态:** Node emqx@172.17.0.4 is started
emqx is running
- **集群状态:** Cluster status: #{running_nodes => ['emqx@172.17.0.4'],stopped_nodes => []}
**告警:**
```
<html><head><title>404 - NOT FOUND</title></head><body><h1>404 - NOT FOUND</h1></body></html>
```
**消息丢弃统计:**
```
authentication.failure : 0
delivery.dropped : 0
delivery.dropped.expired : 0
delivery.dropped.no_local : 0
delivery.dropped.qos0_msg : 0
delivery.dropped.queue_full : 0
delivery.dropped.too_large : 0
messages.dropped : 535
messages.dropped.await_pubrel_: 0
messages.dropped.no_subscriber: 535
messages.transformation_failed: 0
messages.validation_failed : 0
packets.publish.dropped : 0
session.discarded : 1
```
---
## Java应用JVM全深度分析
- **Java版本:** java version "1.8.0_321"
- **进程状态:** VmSize: 1860 kB
VmRSS: 88 kB
Threads: 1
- **打开文件描述符:** 7
- **Actuator Health:** {"success":false,"code":"403","message":"拒绝访问"}
**应用配置:**
```
```
---
## Docker容器资源全分析
| 容器名 | CPU% | 内存使用 | 内存% | 网络IO | 磁盘IO |
| :--- | :--- | :--- | :--- | :--- | :--- |
| dmserver | 0.00% | 4.203MiB / 7.788GiB | 0.05% | 1.16MB / 7.87kB | 655kB / 8.19kB |
| ungrok | 0.00% | 0B / 0B | 0.00% | 0B / 0B | 0B / 0B |
| paperless | 0.05% | 603.2MiB / 7.788GiB | 7.56% | 10.2MB / 10.5MB | 801MB / 4.1kB |
| upython | 0.10% | 554.4MiB / 7.788GiB | 6.95% | 1.65GB / 1.61GB | 246MB / 32.8kB |
| utracker3 | 0.01% | 76.63MiB / 7.788GiB | 0.96% | 0B / 0B | 414MB / 170MB |
| cardtable | 0.00% | 13.88MiB / 7.788GiB | 0.17% | 0B / 0B | 364MB / 0B |
| ujava2 | 0.86% | 2.265GiB / 7.788GiB | 29.08% | 321GB / 152GB | 7.52GB / 14.9MB |
| uemqx | 0.40% | 204.8MiB / 7.788GiB | 2.57% | 145MB / 223MB | 605MB / 1.83GB |
| uredis | 0.13% | 4.922MiB / 7.788GiB | 0.06% | 405MB / 202MB | 122MB / 5.19MB |
| umysql | 0.23% | 2.061GiB / 7.788GiB | 26.46% | 83.3GB / 297GB | 13.5GB / 34GB |
| armbaseenv | 0.00% | 5.93MiB / 7.788GiB | 0.07% | 0B / 0B | 7.75MB / 0B |
| pythonenv | 0.00% | 5.805MiB / 7.788GiB | 0.07% | 0B / 0B | 926kB / 0B |
| compilego | 0.00% | 1.523MiB / 7.788GiB | 0.02% | 0B / 0B | 487kB / 0B |
| umongo | 0.32% | 132.4MiB / 7.788GiB | 1.66% | 3.81MB / 32.4kB | 457MB / 51.3GB |
| ugo | 0.00% | 1.555MiB / 7.788GiB | 0.02% | 0B / 0B | 180kB / 0B |
**容器重启次数:**
```
dmserver 0 running
ungrok 182961 restarting
paperless 0 running
upython2 0 exited
uos 0 exited
uemqx2 52 exited
upython 0 running
utracker3 0 running
cardtable 0 running
ujava2 0 running
uemqx 389 running
uredis 0 running
umysql 0 running
armbaseenv 0 running
pythonenv 0 running
compilego 0 running
umongo 0 running
ugo 0 running
```
**容器日志文件大小:**
```
umysql: 31M (/opt/docker/lib/docker/containers/1303ab6507ec93917f7af33f375e1b0e80df93a4d584f6939825136d71720af3/1303ab6507ec93917f7af33f375e1b0e80df93a4d584f6939825136d71720af3-json.log)
uredis: 0 (/opt/docker/lib/docker/containers/a7ebb0aea8bb21b8139c55497807e300fcf64fb6fd814ea36baf624bab84e841/a7ebb0aea8bb21b8139c55497807e300fcf64fb6fd814ea36baf624bab84e841-json.log)
uemqx: 13M (/opt/docker/lib/docker/containers/38daae2c0acedddb06f6590a2d705be186f672616f65bd8275058bfb32a9c49a/38daae2c0acedddb06f6590a2d705be186f672616f65bd8275058bfb32a9c49a-json.log)
ujava2: 316K (/opt/docker/lib/docker/containers/cced2537794f2817303ced374e4a0cf20836a9e0a3fd81a58cafc1da9bc7f9bf/cced2537794f2817303ced374e4a0cf20836a9e0a3fd81a58cafc1da9bc7f9bf-json.log)
utracker3: 29K (/opt/docker/lib/docker/containers/cdb599c9b8da29cad248975710500a32fa03702654c4c0cca4986de0d35eec7f/cdb599c9b8da29cad248975710500a32fa03702654c4c0cca4986de0d35eec7f-json.log)
```
**Docker磁盘总使用:**
```
Images space usage:
REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
nginx v1.27.3 7b3a99c97c77 3 days ago 278.7MB 0B 278.7MB 0
139.9.60.86:5000/upython v15 98fb633c4de9 4 months ago 3.039GB 2.792GB 246.7MB 0
139.9.60.86:5000/python v15 90c7d8c91cee 4 months ago 2.82GB 2.792GB 28.38MB 0
paperless v1 56d09c45e6fd 7 months ago 612.2MB 65.66MB 546.6MB 1
nacos-server v2.5.1 2bfadf8add03 7 months ago 293.1MB 0B 293.1MB 0
dm8 v8 0db6b7291bf0 8 months ago 3.068GB 0B 3.068GB 1
upython v14 01ab87ee9edc 8 months ago 2.258GB 2.258GB 0B 0
armbaseenv v2 d805471ba96b 17 months ago 2.361GB 1.007GB 1.354GB 0
armbaseenv v1 7fa2bd23c105 17 months ago 1.028GB 1.007GB 20.76MB 0
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx latest-linuxarm64 5e0fa356e6f4 17 months ago 197.1MB 0B 197.1MB 0
umongodb v1 a0d6a90a9bfa 18 months ago 1.013GB 65.66MB 947.8MB 1
upython v13 3859027cdd45 18 months ago 2.215GB 2.215GB 0B 1
emqx/emqx 5.8.1 32632f41a736 19 months ago 252.5MB 0B 252.5MB 2
python 3.10 bd9c64a34b08 19 months ago 1.007GB 1.007GB 0B 2
ubuntu 20.04 223c04ea1fd5 19 months ago 65.66MB 65.66MB 0B 2
powerjob/powerjob-server latest d7d2f0f88b9f 21 months ago 479.7MB 0B 479.7MB 0
139.9.60.86:5000/umysql v4 307738dc6d58 22 months ago 339.2MB 0B 339.2MB 1
ubase v2 14848486bdc5 22 months ago 193.3MB 0B 193.3MB 0
ixuzhi/uos-server 1050e 5eb169f99f4f 22 months ago 1.128GB 0B 1.128GB 1
cardtable v3.3 e0b56dbf0974 2 years ago 918.2MB 0B 918.2MB 1
ngrok v1 6a1d154f1ca5 3 years ago 1.371GB 0B 1.371GB 1
139.9.60.86:5000/ujava v4 5772d73fd433 3 years ago 569.5MB 0B 569.5MB 1
139.9.60.86:5000/redis v2 7a56bdc802f7 4 years ago 107MB 0B 107MB 1
139.9.60.86:5000/ufastdfs v2 ab3274a2b55f 4 years ago 635.7MB 0B 635.7MB 1
swr.cn-south-1.myhuaweicloud.com/library/openjdk 8-jre 66bf39162ea7 7 years ago 442.8MB 0B 442.8MB 0
Containers space usage:
CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
46b52ec557fa dm8:v8 "/opt/startup.sh" 0 299kB 5 weeks ago Up 5 weeks dmserver
8ed9322b8b2f ngrok:v1 "/home/ngrok.sh" 0 0B 4 months ago Restarting (1) 16 seconds ago ungrok
7c7f0ad9d5a3 paperless:v1 "/root/start.sh" 0 923kB 4 months ago Up 4 months paperless
021057a0a0eb 5baab2cf2750 "/var/www/html/start…" 0 483MB 4 months ago Exited (137) 2 months ago upython2
16a6ce50a148 ixuzhi/uos-server:1050e "/bin/bash" 0 83MB 6 months ago Exited (255) 6 months ago uos
6d4de6d83b35 emqx/emqx:5.8.1 "/usr/bin/docker-ent…" 2 0B 9 months ago Exited (128) 6 months ago uemqx2
a76d0c2dba2a upython:v13 "/var/www/html/start…" 0 72.7MB 10 months ago Up 2 weeks upython
cdb599c9b8da 139.9.60.86:5000/ufastdfs:v2 "/home/fastdfs_start…" 0 458MB 11 months ago Up 4 months utracker3
671ecd4817e8 cardtable:v3.3 "/root/start.sh" 0 27.2MB 12 months ago Up 5 months cardtable
cced2537794f 139.9.60.86:5000/ujava:v4 "/var/www/java/start…" 0 370MB 12 months ago Up 5 months ujava2
38daae2c0ace emqx/emqx:5.8.1 "/usr/bin/docker-ent…" 2 3.43MB 12 months ago Up 5 weeks uemqx
a7ebb0aea8bb 139.9.60.86:5000/redis:v2 "docker-entrypoint.s…" 0 729B 12 months ago Up 3 days uredis
1303ab6507ec 139.9.60.86:5000/umysql:v4 "docker-entrypoint.s…" 0 2.91GB 12 months ago Up 5 months umysql
f07200034d93 python:3.10 "python3" 0 1.35GB 17 months ago Up 5 months armbaseenv
6f04997a9ea6 python:3.10 "python3" 0 59.1MB 17 months ago Up 5 months pythonenv
4a5478e7f98d ubuntu:20.04 "/bin/bash" 0 394MB 17 months ago Up 5 months compilego
477787b79e18 umongodb:v1 "sh -c '/usr/local/m…" 0 836MB 18 months ago Up 5 months umongo
779e5faa5a3f ubuntu:20.04 "/bin/bash" 0 1.32GB 18 months ago Up 5 months ugo
Local Volumes space usage:
VOLUME NAME LINKS SIZE
179d7026729c2da654eac62710d0b7ddbc2f85dca81cafef8d2768a416959a77 0 70.12kB
1fe8668c160da16d869f1a464cc9b9a98f46d3f61b23f116324e510f3ad3c474 0 0B
cd33988820384f046aa3a4a577382ab0486d601c8affe3668cece0cde5b96d3a 0 0B
d005825dc89fc3d6e0b3ff573f2d0f2d426da1aefde4b09918f720df7c1c39a0 0 0B
720b36996d14a368535bc4f7b685ba8a897faba8e672e11a9ab71ed8d2297fe3 0 40.77kB
76ce39fe2190342faa0649b2a3b22f26d08cfbb56e880370f59e7a7187007ef8 0 53.01kB
c675516cb00b0bd6a9893baf6d068fff8ef0a2c4b59aebb0a62e0c600d762287 0 48.86kB
33059586faa0c09d437e71881e2cc602636e3e3bd6c204ed1bcd98a289401ae0 1 3.426MB
39006e2ebef2d958a39f81b541889249257f5b6ae2a9f92aa5f490883ea2168e 0 204.9MB
53adbf0698e5e816677a482c20257c5e521a1ca8dd6e61b4d7f247f0f94adcf9 0 0B
8d9d13151dc802cd0e98f0e8aa6bc1e8c5144f15adafe033809d79f4b8553d39 0 204.9MB
be5fddf482478dd3a2166d3c09ca953e2a8b46d49a0135772295944719051a87 0 0B
10fd5947ddaa0b00d301291093391bf8476f1e50151321252dcfc065332d7e4a 0 204.9MB
2a3d8a65879250e2f129916d5f1d557523ad492e04587b0400350d41907ba579 0 0B
2a839e14381c82af6cb3e8a2cc6f0ee5b89c87c5430c8fbf2afa5ebee110fc08 0 101.6kB
e3fbf2ffb103ed0efa24728949abf4eebc6766a4213805bfc2a34d6e408f6f3b 1 0B
f8c1c6ffbc8a4e7d7ed939ad4f5a622c7e426fd7771b9f50d83f882b3ffcbed9 0 0B
4d06af9188ba1d2e79cb2f83d02799a9c6801bca03b8e94c59c17a25651289eb 0 3.371MB
a8208c04dd4c1bc7c72c63a7e6b7e21e399ecbfd247d513939da6ac634809766 0 204.9MB
cddd3b7d04b260c54b34ab8d71d41bb14305468a4d6866417518d23696d41618 0 204.9MB
Build cache usage: 0B
CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
```
**容器Healthcheck:**
```
=== umysql health ===
no healthcheck
=== uredis health ===
no healthcheck
=== uemqx health ===
no healthcheck
=== ujava2 health ===
no healthcheck
```
---
## Nginx分析
- **版本:** nginx version: nginx/1.21.6
- **Worker配置:**
- **最近错误:** 0条
---
## 端口与服务状态检测
| 端口 | 服务 | 状态 |
| :--- | :--- | :--- |
| 22 | SSH | ✅ LISTENING |
| 443 | HTTPS | ✅ LISTENING |
| 1883 | EMQX-MQTT | ✅ LISTENING |
| 6379 | Redis | ✅ LISTENING |
| 8080 | Java-Web | ✅ LISTENING |
| 8306 | MySQL | ✅ LISTENING |
| 8883 | EMQX-SSL | ✅ LISTENING |
| 8997 | Java-Backend | ✅ LISTENING |
| 8998 | Java-Login | ✅ LISTENING |
| 8999 | Java-Admin | ✅ LISTENING |
| 22122 | FastDFS-Tracker | ✅ LISTENING |
| 23000 | FastDFS-Storage | ✅ LISTENING |
**容器运行状态:**
- umysql: ✅ running
- uredis: ✅ running
- uemqx: ✅ running
- ujava2: ✅ running
- utracker3: ✅ running
---
## 会议系统应用日志分析
**错误总数:** 18
**分类错误检测:**
- Dubbo服务调用失败: 0次
- 钉钉同步异常: 0次
- MQTT连接失败: 0次
- MySQL通信异常: 0次
**错误频率(按小时):**
```
4 2026-05-15 02
2 2026-05-15 00
```
**日志文件大小:**
```
total 19M
drwxr-xr-x 2 root root 60K May 15 00:00 timeFile
-rw-r--r-- 1 root root 28K May 15 02:21 ubains-ERROR.log
-rw-r--r-- 1 root root 9.3M May 15 06:24 ubains-INFO-AND-ERROR.log
-rw-r--r-- 1 root root 9.1M May 15 06:24 ubains-INFO.log
总大小: 37M /var/www/java/api-java-meeting2.0/logs/
```
---
## 网络TCP连接状态分析
- ESTABLISHED: 77
- TIME_WAIT: 2 (正常)
- CLOSE_WAIT: 10 (正常)
**网络连通性:**
- 网关(192.168.1.1): 异常
- DNS解析: 正常
- 钉钉API: HTTP_CODE:200 TIME:0.127133s
- Java→MySQL: rtt min/avg/max/mdev = 0.060/0.060/0.060/0.000 ms
- Java→Redis: rtt min/avg/max/mdev = 0.063/0.063/0.063/0.000 ms
- Java→EMQX: rtt min/avg/max/mdev = 0.062/0.062/0.062/0.000 ms
---
## 系统日志统计(24小时)
- **内核错误:** 0
0
- **认证失败:** 267
- **磁盘错误:** 0
0
- **OOM事件:** 0
- **SSH暴力破解IP TOP5:**
- 25 1.71.254.57
- 22 115.151.72.100
- 14 60.188.115.114
- 9 1.71.254.50
- 7 180.184.160.246
**失败的服务:**
```
cloud-config.service loaded failed failed Apply the settings specified in cloud-config
cloud-final.service loaded failed failed Execute cloud user/final scripts
cloud-init-local.service loaded failed failed Initial cloud-init job (pre-networking)
cloud-init.service loaded failed failed Initial cloud-init job (metadata service crawler)
fail2ban.service loaded failed failed Fail2Ban Service
firewalld.service loaded failed failed firewalld - dynamic firewall daemon
networkd-dispatcher.service loaded failed failed Dispatcher daemon for systemd-networkd
nginx.service loaded failed failed nginx - High performance web server
unattended-upgrades.service loaded failed failed Unattended Upgrades Shutdown
```
---
## NTP时钟同步状态
- **时钟同步:** Local time: Fri 2026-05-15 06:25:12 CST
Universal time: Thu 2026-05-14 22:25:12 UTC
RTC time: Thu 2026-05-14 22:25:13
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
systemd-timesyncd.service active: no
RTC in local TZ: no
- **NTP源:** 210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 100.125.1.251 3 9 377 192 +1564ns[+2544ns] +/- 18ms
- **时钟偏差:** System time : 0.000002462 seconds fast of NTP time
Last offset : +0.000000980 seconds
RMS offset : 0.000003809 seconds
- **系统时间:** Fri May 15 06:25:12 CST 2026
---
## SSL证书有效期
- **HTTPS(443):** N/A
- **EMQX(8883):** notBefore=May 8 08:07:05 2020 GMT
notAfter=May 6 08:07:05 2030 GMT
subject=C = CN, ST = hangzhou, O = EMQ, CN = Server
---
## 定时任务
**Crontab:**
```
#*/3 * * * * /data/services/scripts/ujava2-startup.sh >> /var/log/ujava2-cron.log 2>&1
```
**Systemd定时器:**
```
Fri 2026-05-15 07:46:24 CST 1h 21min left Thu 2026-05-14 19:05:01 CST 11h ago motd-news.timer motd-news.service
Fri 2026-05-15 10:33:27 CST 4h 8min left Thu 2026-05-14 23:12:14 CST 7h ago apt-daily.timer apt-daily.service
Fri 2026-05-15 11:56:40 CST 5h 31min left Thu 2026-05-14 11:56:40 CST 18h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Sat 2026-05-16 06:03:43 CST 23h left Fri 2026-05-15 06:15:06 CST 10min ago apt-daily-upgrade.timer apt-daily-upgrade.service
Mon 2026-05-18 00:00:00 CST 2 days left Mon 2026-05-11 00:00:24 CST 4 days ago fstrim.timer fstrim.service
n/a n/a Wed 2025-11-12 10:29:35 CST 6 months 1 days ago ureadahead-stop.timer ureadahead-stop.service
```
---
## 安全检测摘要
- **SELinux:** N/A
- **防火墙:** 已配置
- **开放端口(TCP):** 30个
- **异常账户(UID=0):**
- **SSH配置:** #Port 22
#PermitRootLogin prohibit-password
MaxAuthTries 5
#PasswordAuthentication yes
# PasswordAuthentication. Depending on your PAM configuration,
# the setting of "PermitRootLogin without-password".
# PAM authentication, then enable this but set PasswordAuthentication
#GatewayPorts no
PermitRootLogin yes
PasswordAuthentication yes
---
## AI分析建议
1. [警告] Swap已使用: 1.4% - 建议关注
2. [警告] 总线程数: 1443 - 建议关注
3. [警告] Redis缓存命中率: 58.0% - 建议关注
4. [警告] 空密码账户: dmdba - 建议关注
5. [优化] 内存使用率78.7%,建议关注内存增长趋势,考虑增加内存或优化应用
---
## 与上次巡检对比分析
**上次巡检时间:** 2026-05-15 03:23:03
**本次巡检时间:** 2026-05-15 06:23:04
**关键指标变化:**
| 指标 | 上次值 | 本次值 | 变化 | 趋势 |
| :--- | :--- | :--- | :--- | :--- |
| CPU使用率 | 1.1% | 1.1% | +0.0% | ➡️ 持平 |
| 内存使用率 | 78.7% | 78.7% | +0.0% | ➡️ 持平 |
| Swap使用率 | 1.4% | 1.4% | +0.0% | ➡️ 持平 |
| 系统负载(1min) | 0.1 | 0.0 | -0.1 | 🟢 改善 |
| 总线程数 | 1419.0 | 1443.0 | +24.0 | 🔴 恶化 |
| 文件描述符使用率 | 0.9% | 0.9% | +0.0% | ➡️ 持平 |
| ESTABLISHED连接 | 78.0 | 77.0 | -1.0 | 🟢 改善 |
| TIME_WAIT连接 | 0.0 | 2.0 | +2.0 | 🔴 恶化 |
| Redis缓存命中率 | 58.1% | 58.0% | -0.1% | 🟢 改善 |
| Redis内存碎片率 | 3.4 | 3.1 | -0.3 | 🟢 改善 |
---
*报告生成时间: 2026-05-15 06:23:04*
*全深入巡检 v3 终极版 - 检测点数量: 120+*
\ No newline at end of file
# DingTalk Notification Module
# UTF-8 BOM encoding required
$ScriptRoot = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
function Get-DingTalkConfig {
param([string]$ConfigPath = (Join-Path $ScriptRoot "config.json"))
if (-not (Test-Path $ConfigPath)) {
Write-Host "ERROR: Config not found: $ConfigPath" -ForegroundColor Red
throw "Config not found"
}
$config = Get-Content $ConfigPath -Raw | ConvertFrom-Json
Write-Host "INFO: Config loaded" -ForegroundColor Green
return $config
}
function Start-ReportHttpServer {
param([string]$ReportDir, [int]$Port)
try {
if (-not (Test-Path $ReportDir)) {
New-Item -ItemType Directory -Path $ReportDir -Force | Out-Null
Write-Host "INFO: Created report dir: $ReportDir" -ForegroundColor Green
}
$existingProcess = Get-NetTCPConnection -LocalPort $Port -ErrorAction SilentlyContinue | Where-Object State -eq "Listen"
if ($existingProcess) {
Write-Host "INFO: HTTP server already running on port $Port" -ForegroundColor Yellow
return $true
}
$process = Start-Process -FilePath "python3" -ArgumentList "-m http.server $Port --directory $ReportDir" -WindowStyle Hidden -PassThru
Start-Sleep -Seconds 2
if ($process.HasExited) {
Write-Host "ERROR: HTTP server failed to start" -ForegroundColor Red
return $false
}
Write-Host "INFO: HTTP server started: http://localhost:$Port" -ForegroundColor Green
return $true
}
catch {
Write-Host "ERROR: Start HTTP server failed: $_" -ForegroundColor Red
return $false
}
}
function Get-NgrokPublicUrl {
param([string]$NgrokPath, [int]$Port)
try {
$ngrokApiUrl = "http://localhost:4040/api/tunnels"
try {
$tunnels = Invoke-RestMethod -Uri $ngrokApiUrl -ErrorAction Stop
$existingTunnel = $tunnels.tunnels | Where-Object { $_.config.addr -eq "http://localhost:$Port" }
if ($existingTunnel) {
Write-Host "INFO: ngrok tunnel exists: $($existingTunnel.public_url)" -ForegroundColor Yellow
return $existingTunnel.public_url
}
}
catch {
Write-Host "INFO: ngrok not running, starting new tunnel" -ForegroundColor Yellow
}
if (-not (Test-Path $NgrokPath)) {
Write-Host "ERROR: ngrok not found: $NgrokPath" -ForegroundColor Red
return $null
}
Start-Process -FilePath $NgrokPath -ArgumentList "http $Port --log=stdout" -WindowStyle Hidden
Start-Sleep -Seconds 3
$tunnels = Invoke-RestMethod -Uri $ngrokApiUrl
$publicUrl = $tunnels.tunnels[0].public_url
Write-Host "INFO: ngrok tunnel created: $publicUrl" -ForegroundColor Green
return $publicUrl
}
catch {
Write-Host "ERROR: Get ngrok URL failed: $_" -ForegroundColor Red
return $null
}
}
function New-DingTalkSignature {
param([string]$Secret, [long]$Timestamp)
try {
# Step 1: timestamp + \n + secret
$stringToSign = "$Timestamp`n$Secret"
# Step 2: HMAC-SHA256
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.Key = [System.Text.Encoding]::UTF8.GetBytes($Secret)
$signatureBytes = $hmacsha.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($stringToSign))
# Step 3: Base64 encode
$base64Signature = [Convert]::ToBase64String($signatureBytes)
# Step 4: URL encode
$urlEncodedSign = [System.Uri]::EscapeDataString($base64Signature)
Write-Host "DEBUG: timestamp=$Timestamp" -ForegroundColor DarkGray
Write-Host "DEBUG: stringToSign=$stringToSign" -ForegroundColor DarkGray
Write-Host "DEBUG: sign=$urlEncodedSign" -ForegroundColor DarkGray
return $urlEncodedSign
}
catch {
Write-Host "ERROR: Generate signature failed: $_" -ForegroundColor Red
return $null
}
}
function Send-DingTalkMessage {
param([string]$Webhook, [string]$Secret, [string]$Title, [string]$Content)
try {
$timestamp = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
$sign = New-DingTalkSignature -Secret $Secret -Timestamp $timestamp
$body = @{
msgtype = "markdown"
markdown = @{
title = $Title
text = $Content
}
} | ConvertTo-Json -Depth 10
$url = "$Webhook&timestamp=$timestamp&sign=$sign"
$response = Invoke-RestMethod -Uri $url -Method Post -Body $body -ContentType "application/json" -TimeoutSec 10
if ($response.errcode -eq 0) {
Write-Host "INFO: DingTalk message sent successfully" -ForegroundColor Green
return $true
}
else {
Write-Host "ERROR: DingTalk message failed: $($response.errmsg)" -ForegroundColor Red
return $false
}
}
catch {
Write-Host "ERROR: Send DingTalk message exception: $_" -ForegroundColor Red
return $false
}
}
function Clear-ExpiredReports {
param([string]$ReportDir, [int]$Days)
try {
if (-not (Test-Path $ReportDir)) {
return
}
$expiredDate = (Get-Date).AddDays(-$Days)
$expiredFiles = Get-ChildItem -Path $ReportDir -Filter "*.md" | Where-Object { $_.LastWriteTime -lt $expiredDate }
foreach ($file in $expiredFiles) {
Remove-Item $file.FullName -Force
Write-Host "INFO: Deleted expired report: $($file.Name)" -ForegroundColor Yellow
}
if ($expiredFiles.Count -gt 0) {
Write-Host "INFO: Deleted $($expiredFiles.Count) expired reports" -ForegroundColor Green
}
}
catch {
Write-Host "ERROR: Clear expired reports failed: $_" -ForegroundColor Red
}
}
function Send-DingTalkReport {
param(
[string]$Summary,
[string]$FullReportPath,
[string]$ServerName,
[string]$ConfigPath = (Join-Path $ScriptRoot "config.json")
)
try {
$config = Get-DingTalkConfig -ConfigPath $ConfigPath
$displayName = if ($ServerName) { $ServerName } else { $config.ServerName }
$finalContent = $Summary
if ($FullReportPath -and (Test-Path $FullReportPath)) {
$reportUrl = $null
if ($config.EnableHttpServer) {
Start-ReportHttpServer -ReportDir $config.ReportDir -Port $config.HttpPort | Out-Null
}
if ($config.EnableNgrok) {
$publicUrl = Get-NgrokPublicUrl -NgrokPath $config.NgrokPath -Port $config.HttpPort
if ($publicUrl) {
$reportName = Split-Path $FullReportPath -Leaf
$reportUrl = "$publicUrl/$reportName"
}
}
if (-not $reportUrl) {
$reportName = Split-Path $FullReportPath -Leaf
$reportUrl = "file://$FullReportPath"
}
$finalContent = "$Summary`n`n---`n`n#### Report: [$reportName]($reportUrl)"
}
$title = "Server Health Report - $displayName"
$result = Send-DingTalkMessage -Webhook $config.Webhook -Secret $config.Secret -Title $title -Content $finalContent
Clear-ExpiredReports -ReportDir $config.ReportDir -Days $config.ReportRetentionDays
return $result
}
catch {
Write-Host "ERROR: Send DingTalk report failed: $_" -ForegroundColor Red
return $false
}
}
Export-ModuleMember -Function @('Get-DingTalkConfig', 'Start-ReportHttpServer', 'Get-NgrokPublicUrl', 'Send-DingTalkMessage', 'Send-DingTalkReport', 'Clear-ExpiredReports')
# 钉钉通知通用模块
为服务器监测脚本提供统一的钉钉消息通知功能,支持摘要消息和完整报告链接。
## 功能特性
-**钉钉机器人集成**:支持加签验证的钉钉自定义机器人
-**Markdown格式**:支持发送Markdown格式的结构化消息
-**HTTP报告托管**:自动启动HTTP服务器托管报告文件
-**ngrok隧道**:自动建立公网访问隧道(可选)
-**自动清理**:自动清理过期报告文件
-**多项目支持**:支持通过不同配置文件管理多个项目
## 目录结构
```
钉钉通知/
├── config.json # 配置文件(钉钉webhook、密钥、端口等)
├── DingTalkHelper.psm1 # 核心模块(所有功能函数)
├── 使用示例.ps1 # 使用示例代码
└── README.md # 本文档
```
## 快速开始
### 1. 配置文件修改
编辑 `config.json`,修改相关配置:
```json
{
"Webhook": "https://oapi.dingtalk.com/robot/send?access_token=YOUR_TOKEN",
"Secret": "SECYOUR_SECRET",
"HttpPort": 8080,
"NgrokPath": "/usr/local/bin/ngrok",
"ReportDir": "/root/reports",
"ReportRetentionDays": 30,
"ServerName": "服务器巡检",
"EnableHttpServer": true,
"EnableNgrok": true
}
```
### 2. 基础调用
```powershell
# 导入模块
Import-Module "Docs\PRD\AI服务器监测\通用模块\钉钉通知\DingTalkHelper.psm1"
# 准备摘要
$summary = @"
### 🖥️ 服务器巡检报告
**时间**: 2026-05-15 10:30:00
**状态**: 🟢 正常
#### 📊 核心指标
| 指标 | 当前 | 状态 |
|:---|:---|:---|
| CPU | 45% | 🟢 |
| 内存 | 62% | 🟢 |
"@
# 发送通知
Send-DingTalkReport -Summary $summary
```
### 3. 发送摘要+报告链接
```powershell
# 生成完整报告
$reportPath = "/root/reports/health_20260515.md"
$fullReport | Out-File -FilePath $reportPath -Encoding UTF8
# 发送通知(自动生成公网链接)
Send-DingTalkReport -Summary $summary -FullReportPath $reportPath
```
## 函数说明
### Send-DingTalkReport
主函数,发送钉钉通知。
**参数:**
- `Summary` (必填):摘要内容(Markdown格式)
- `FullReportPath` (可选):完整报告文件路径
- `ServerName` (可选):服务器名称,覆盖配置中的默认值
- `ConfigPath` (可选):配置文件路径
**示例:**
```powershell
Send-DingTalkReport -Summary $summary
Send-DingTalkReport -Summary $summary -FullReportPath "/root/reports/health.md"
Send-DingTalkReport -Summary $summary -FullReportPath "/root/reports/health.md" -ServerName "生产环境"
```
### 其他函数
- `Get-DingTalkConfig`:加载配置文件
- `Start-ReportHttpServer`:启动HTTP服务器
- `Get-NgrokPublicUrl`:获取ngrok公网URL
- `Send-DingTalkMessage`:发送原始钉钉消息
- `Clear-ExpiredReports`:清理过期报告
## 多项目配置
为不同项目创建独立的配置文件:
```
config.json # 默认配置
大亚湾中广核_config.json # 项目A配置
兰州中石化_config.json # 项目B配置
```
调用时指定配置路径:
```powershell
Send-DingTalkReport -Summary $summary -ConfigPath "大亚湾中广核_config.json"
```
## 钉钉消息格式示例
```
### 🖥️ 服务器巡检报告 - 大亚湾中广核
**时间**: 2026-05-15 10:30:00
**状态**: ⚠️ 警告 (3警告, 1严重)
#### 📊 核心指标
| 指标 | 当前 | 阈值 | 状态 |
|:---|:---|:---|:---|
| CPU使用率 | 82% | 85% | 🟡 |
| 内存使用率 | 91% | 85% | 🔴 |
| 磁盘使用率 | 78% | 90% | 🟢 |
#### 🚨 严重问题
- 内存使用率过高 91% (阈值85%)
- MySQL慢查询 12.5万 (阈值100)
#### 📋 AI分析建议
1. 建议排查内存占用高的进程
2. 优化MySQL慢查询语句
---
#### 📄 [点击查看完整报告](https://xxx.ngrok.io/health_20260515.md)
**报告文件**: `health_20260515.md`
**服务器**: `大亚湾中广核`
```
## 注意事项
1. **ngrok限制**:免费版URL每次重启会变化,建议付费版固定域名
2. **端口占用**:确保配置的HTTP端口未被占用
3. **报告目录**:确保报告目录有写入权限
4. **网络访问**:确保服务器能访问钉钉API和ngrok服务
5. **时间同步**:服务器时间不准确可能导致签名验证失败
## 依赖要求
- PowerShell 5.1 或更高版本
- Python 3(用于HTTP服务器)
- ngrok(可选,用于公网访问)
## 许可
本模块为内部工具,仅供公司内部使用。
{
"Webhook": "https://oapi.dingtalk.com/robot/send?access_token=27071a77f20da381e9a321653ec5f4dcf668bcf058c01162f28e3f1f8633386d",
"Secret": "SEC5d85d5735a1805ada1be84929d5b37f5b72a2a832a6bcd9a1ca5615e5799be38",
"HttpPort": 8080,
"NgrokPath": "/usr/local/bin/ngrok",
"ReportDir": "/root/reports",
"ReportRetentionDays": 30,
"ServerName": "服务器巡检",
"EnableHttpServer": true,
"EnableNgrok": true
}
# Test DingTalk Notification
Import-Module .\DingTalkHelper.psm1 -Force
$summary = @"
### 服务器巡检报告 - 兰州中石化
**时间**: 2026-05-15 06:23:04
**主机**: 139.159.163.86
**状态**: ⚠️ 警告 (0严重, 3警告)
#### 📊 核心指标
| 指标 | 当前值 | 阈值 | 状态 |
|:---|:---|:---|:---|
| CPU使用率 | 1.1% | 85% | ✅ |
| 内存使用率 | 78.7% | 85% | ✅ |
| Swap使用率 | 1.4% | - | ⚠️ |
| 磁盘使用率 | 66.0% | 90% | ✅ |
| 线程总数 | 1443 | 1000 | ⚠️ |
#### ⚠️ 警告项
- Swap已使用: 1.4%
- 总线程数: 1443 (阈值1000)
- Redis缓存命中率: 58.0%
#### 🤖 AI分析建议
1. 线程数偏高,建议排查是否有线程泄漏
2. Redis缓存命中率偏低,建议检查缓存策略
"@
$fullReportPath = "E:\GithubData\ubains-module-test\Docs\PRD\AI服务器监测\分析报告\预定项目\兰州中石化\巡检报告_20260515_062304.md"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "DingTalk Test Message" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Report: $fullReportPath" -ForegroundColor Yellow
Write-Host ""
Write-Host "Sending DingTalk message..." -ForegroundColor Cyan
$result = Send-DingTalkReport -Summary $summary -FullReportPath $fullReportPath -ServerName "Lanzhou"
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
if ($result) {
Write-Host "SUCCESS: Message sent to DingTalk!" -ForegroundColor Green
} else {
Write-Host "FAILED: Message not sent" -ForegroundColor Red
}
Write-Host "========================================" -ForegroundColor Cyan
# DingTalk Notification Test
$modulePath = "E:\GithubData\ubains-module-test\Docs\PRD\AI服务器监测\通用模块\钉钉通知\DingTalkHelper.psm1"
Import-Module $modulePath -Force
$fullReportPath = "E:\GithubData\ubains-module-test\Docs\PRD\AI服务器监测\分析报告\预定项目\兰州中石化\巡检报告_20260515_062304.md"
$summary = @"
### Server Health Report - Lanzhou
**Time**: 2026-05-15 06:23:04
**Host**: 139.159.163.86
**Status**: Warning (0 Critical, 3 Warnings)
#### Metrics
| Metric | Value | Threshold | Status |
|:---|:---|:---|:---|
| CPU | 1.1% | 85% | OK |
| Memory | 78.7% | 85% | OK |
| Swap | 1.4% | - | WARN |
| Disk | 66.0% | 90% | OK |
| Threads | 1443 | 1000 | WARN |
#### Warnings
- Swap in use: 1.4%
- Thread count: 1443 (limit 1000)
- Redis cache hit ratio: 58.0%
#### Database
- MySQL connections: 15/151 (9.9%)
- Slow queries: 0
- Database size: 1433.16 MB
"@
Write-Host "Sending DingTalk message..." -ForegroundColor Cyan
try {
$result = Send-DingTalkReport -Summary $summary -FullReportPath $fullReportPath -ServerName "Lanzhou"
if ($result) {
Write-Host "SUCCESS: Message sent!" -ForegroundColor Green
} else {
Write-Host "FAILED: Message not sent" -ForegroundColor Red
}
} catch {
Write-Host "ERROR: $_" -ForegroundColor Red
}
# Simple test without signature
$webhook = "https://oapi.dingtalk.com/robot/send?access_token=27071a77f20da381e9a321653ec5f4dcf668bcf058c01162f28e3f1f8633386d"
$body = @{
msgtype = "text"
text = @{
content = "Test message without signature"
}
} | ConvertTo-Json -Depth 10
Write-Host "Sending simple test message..." -ForegroundColor Cyan
Write-Host "Webhook: $webhook" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri $webhook -Method Post -Body $body -ContentType "application/json" -TimeoutSec 10
Write-Host "Response: $($response | ConvertTo-Json)" -ForegroundColor Green
if ($response.errcode -eq 0) {
Write-Host "SUCCESS!" -ForegroundColor Green
} else {
Write-Host "FAILED: errcode=$($response.errcode), errmsg=$($response.errmsg)" -ForegroundColor Red
}
} catch {
Write-Host "ERROR: $_" -ForegroundColor Red
}
# 钉钉通知通用模块 - 使用示例
# 说明:此脚本展示如何在不同服务器监测场景中使用钉钉通知模块
# ===================================================================
# 方式一:基础调用 - 仅发送摘要消息
# ===================================================================
# 导入模块
$modulePath = "Docs\PRD\AI服务器监测\通用模块\钉钉通知\DingTalkHelper.psm1"
Import-Module $modulePath -Force
# 准备摘要内容
$summary = @"
### 🖥️ 服务器巡检报告 - 大亚湾中广核
**时间**: 2026-05-15 10:30:00
**状态**: ⚠️ 警告 (3警告, 1严重)
#### 📊 核心指标
| 指标 | 当前 | 阈值 | 状态 |
|:---|:---|:---|:---|
| CPU使用率 | 82% | 85% | 🟡 |
| 内存使用率 | 91% | 85% | 🔴 |
| 磁盘使用率 | 78% | 90% | 🟢 |
| 系统负载 | 6.5 | 8 | 🟢 |
#### 🚨 严重问题
- 内存使用率过高 91% (阈值85%)
- MySQL慢查询 12.5万 (阈值100)
#### 📋 AI分析建议
1. 建议排查内存占用高的进程
2. 优化MySQL慢查询语句
"@
# 发送通知(仅摘要)
Send-DingTalkReport -Summary $summary
# ===================================================================
# 方式二:发送摘要 + 完整报告链接
# ===================================================================
# 假设已生成完整报告文件
$fullReportPath = "/root/reports/health_20260515_103000.md"
# 发送通知(摘要+链接)
Send-DingTalkReport -Summary $summary -FullReportPath $fullReportPath
# ===================================================================
# 方式三:自定义服务器名称
# ===================================================================
Send-DingTalkReport -Summary $summary -FullReportPath $fullReportPath -ServerName "生产环境-MySQL主库"
# ===================================================================
# 方式四:自定义配置文件路径
# ===================================================================
# 为不同项目使用不同配置
$configPath = "Docs\PRD\AI服务器监测\预定项目\大亚湾中广核项目\dingtalk_config.json"
Send-DingTalkReport -Summary $summary -FullReportPath $fullReportPath -ConfigPath $configPath
# ===================================================================
# 完整示例:服务器巡检脚本集成
# ===================================================================
function Invoke-ServerHealthCheck {
param(
[string]$ServerName = "未命名服务器",
[string]$ConfigPath = "Docs\PRD\AI服务器监测\通用模块\钉钉通知\config.json"
)
Write-Host "开始服务器巡检: $ServerName" -ForegroundColor Cyan
# 1. 执行巡检逻辑(这里用模拟数据)
$healthData = @{
CPUPercent = 82
MemoryPercent = 91
DiskPercent = 78
LoadAverage = 6.5
SlowQueries = 125000
}
# 2. 判断状态
$criticalIssues = @()
$warnings = @()
if ($healthData.MemoryPercent -gt 85) {
$criticalIssues += "内存使用率过高 $($healthData.MemoryPercent)%"
}
if ($healthData.SlowQueries -gt 100) {
$criticalIssues += "MySQL慢查询 $($healthData.SlowQueries)"
}
$status = switch ($criticalIssues.Count) {
{ $_ -eq 0 } { "🟢 正常" }
{ $_ -le 2 } { "🟡 警告" }
default { "🔴 严重" }
}
# 3. 生成摘要
$summary = @"
### 🖥️ 服务器巡检报告 - $ServerName
**时间**: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
**状态**: $status
#### 📊 核心指标
| 指标 | 当前 | 阈值 | 状态 |
|:---|:---|:---|:---|
| CPU使用率 | $($healthData.CPUPercent)% | 85% | $(if($healthData.CPUPercent -gt 85){'🔴'}elseif($healthData.CPUPercent -gt 70){'🟡'}else{'🟢'}) |
| 内存使用率 | $($healthData.MemoryPercent)% | 85% | $(if($healthData.MemoryPercent -gt 85){'🔴'}elseif($healthData.MemoryPercent -gt 70){'🟡'}else{'🟢'}) |
| 磁盘使用率 | $($healthData.DiskPercent)% | 90% | $(if($healthData.DiskPercent -gt 90){'🔴'}elseif($healthData.DiskPercent -gt 80){'🟡'}else{'🟢'}) |
| 系统负载 | $($healthData.LoadAverage) | 8 | $(if($healthData.LoadAverage -gt 16){'🔴'}elseif($healthData.LoadAverage -gt 8){'🟡'}else{'🟢'}) |
$(if($criticalIssues){@"
#### 🚨 严重问题
$($criticalIssues | ForEach-Object { "- $_" } | Out-String)
"@})
$(if($warnings){@"
#### ⚠️ 警告
$($warnings | ForEach-Object { "- $_" } | Out-String)
"@})
#### 📋 AI分析建议
1. $(if($healthData.MemoryPercent -gt 85){"建议排查内存占用高的进程,考虑优化或增加内存"}else{"内存使用正常"})
2. $(if($healthData.SlowQueries -gt 100){"优化MySQL慢查询语句,检查索引是否合理"}else{"数据库性能正常"})
"@
# 4. 生成完整报告(模拟)
$reportDir = "/root/reports"
$reportFileName = "health_$(Get-Date -Format 'yyyyMMdd_HHmmss').md"
$reportPath = Join-Path $reportDir $reportFileName
# 确保目录存在
if (-not (Test-Path $reportDir)) {
New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
}
# 保存完整报告(这里用摘要代替,实际应包含完整数据)
$fullReport = @"
# 服务器全深入巡检报告
$summary
## 详细数据
- [此处为完整巡检数据]
- [包含所有120+检测点的详细信息]
"@
$fullReport | Out-File -FilePath $reportPath -Encoding UTF8
Write-Host "完整报告已保存: $reportPath" -ForegroundColor Green
# 5. 发送钉钉通知
Write-Host "发送钉钉通知..." -ForegroundColor Cyan
$result = Send-DingTalkReport -Summary $summary -FullReportPath $reportPath -ServerName $ServerName
if ($result) {
Write-Host "钉钉通知发送成功!" -ForegroundColor Green
}
else {
Write-Host "钉钉通知发送失败!" -ForegroundColor Red
}
return $result
}
# 执行巡检
Invoke-ServerHealthCheck -ServerName "大亚湾中广核"
# ===================================================================
# 批量巡检多个服务器
# ===================================================================
$servers = @(
@{ Name = "大亚湾中广核"; IP = "192.168.5.61" },
@{ Name = "兰州中石化"; IP = "192.168.1.100" },
@{ Name = "PXX项目"; IP = "192.168.2.50" }
)
foreach ($server in $servers) {
Write-Host "`n========== 巡检 $($server.Name) ==========" -ForegroundColor Magenta
Invoke-ServerHealthCheck -ServerName $server.Name
}
# 钉钉通知测试 - 使用真实报告
# 导入模块
$modulePath = "E:\GithubData\ubains-module-test\Docs\PRD\AI服务器监测\通用模块\钉钉通知\DingTalkHelper.psm1"
Import-Module $modulePath -Force
# 报告文件路径(Windows路径)
$fullReportPath = "E:\GithubData\ubains-module-test\Docs\PRD\AI服务器监测\分析报告\预定项目\兰州中石化\巡检报告_20260515_062304.md"
# 准备摘要内容(从报告中提取关键信息)
$summary = @"
### 🖥️ 服务器巡检报告 - 兰州中石化
**时间**: 2026-05-15 06:23:04
**主机**: 139.159.163.86 (kunpeng)
**状态**: ⚠️ 警告 (0严重, 3警告)
#### 📊 核心指标
| 指标 | 当前值 | 阈值 | 状态 |
|:---|:---|:---|:---|
| CPU使用率 | 1.1% | 85% | ✅ |
| 内存使用率 | 78.7% | 85% | ✅ |
| Swap使用率 | 1.4% | - | ⚠️ |
| 磁盘使用率 | 66.0% | 90% | ✅ |
| 线程总数 | 1443 | 1000 | ⚠️ |
| 系统负载 | 0.0 | 8 | ✅ |
#### ⚠️ 警告项
- Swap已使用: 1.4%
- 总线程数: 1443 (阈值1000)
- Redis缓存命中率: 58.0%
#### 📋 数据库状态
- MySQL连接: 15/151 (9.9%)
- 慢查询数: 0
- 数据库大小: 1433.16 MB (ubains库)
#### 🤖 AI分析建议
1. 线程数偏高,建议排查是否有线程泄漏
2. Redis缓存命中率偏低,建议检查缓存策略
3. 内存使用率78.7%,接近阈值,需关注
"@
# 发送钉钉通知
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "钉钉通知测试" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "报告文件: $fullReportPath" -ForegroundColor Yellow
Write-Host "服务器名称: 兰州中石化" -ForegroundColor Yellow
Write-Host ""
# 检查报告文件是否存在
if (Test-Path $fullReportPath) {
Write-Host "✅ 报告文件存在" -ForegroundColor Green
}
else {
Write-Host "❌ 报告文件不存在,仅发送摘要" -ForegroundColor Red
}
Write-Host ""
Write-Host "正在发送钉钉消息..." -ForegroundColor Cyan
try {
$result = Send-DingTalkReport -Summary $summary -FullReportPath $fullReportPath -ServerName "兰州中石化"
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
if ($result) {
Write-Host "✅ 钉钉消息发送成功!" -ForegroundColor Green
}
else {
Write-Host "❌ 钉钉消息发送失败!" -ForegroundColor Red
}
Write-Host "========================================" -ForegroundColor Cyan
}
catch {
Write-Host ""
Write-Host "❌ 发生异常: $_" -ForegroundColor Red
Write-Host "异常位置: $($_.InvocationInfo.ScriptLineNumber)" -ForegroundColor Red
}
# 角色 # 角色
你是一名资深的Linux系统运维专家,专注于会议预定系统的稳定性保障,擅长通过Shell/Python脚本进行服务器深度巡检和故障诊断。 你是一名资深的Linux系统运维专家,专注于会议预定系统的稳定性保障,擅长通过Shell/Python脚本进行服务器深度巡检和故障诊断。
# 钉钉通知对接
- 将分析报告以md形式调用钉钉机器人接口发送报告,并保存至服务器。
- 钉钉机器人:https://oapi.dingtalk.com/robot/send?access_token=27071a77f20da381e9a321653ec5f4dcf668bcf058c01162f28e3f1f8633386
- 钉钉机器人加签:SEC5d85d5735a1805ada1be84929d5b37f5b72a2a832a6bcd9a1ca5615e5799be38
- 接口文档参考:https://open.dingtalk.com/document/orgapp/custom-robots-send-group-messages#title-7fs-kgs-36x
# 目标服务器配置 # 目标服务器配置
- **主机地址**: 192.168.5.61 - **主机地址**: 192.168.5.61
- **SSH端口**: 22 - **SSH端口**: 22
......
...@@ -48,8 +48,13 @@ ...@@ -48,8 +48,13 @@
- 登录目标服务器,并切换到root用户。 - 登录目标服务器,并切换到root用户。
3. 部署执行 3. 部署执行
- 严格根据部署文档执行部署操作!!! - 严格根据部署文档执行部署操作!!!
- 如遇选择部署的系统,则选择全部系统,并执行部署操作。 - 如遇选择部署的系统,则选择全部系统,并执行部署操作。直接在交互式SSH会话中运行脚本,手动选择"全部系统"。
- 不要自己乱操作,严格按照文档操作执行即可。 - 不要自己乱操作,严格按照文档操作执行即可。
- 文档中明确标明超管账号密码为:superadmin Ubains@1357
- 授权文件上传操作,直接根据部署文档使用web界面的上传功能。
- 创建用户使用:
- 根据文档指引到指定页面创建管理员,公司选择名称为:“自动化”的公司,创建admin用户。
- 按照部署文档该等待的就等待,等待服务正常启动完成,再往下根据部署文档操作。不允许私自操作。
## 验收要求 ## 验收要求
1. 自动化部署完成后检查容器状态是否正常,核查容器日志是否正确。 1. 自动化部署完成后检查容器状态是否正常,核查容器日志是否正确。
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论