Skip to content

Commit d8520d7

Browse files
committed
Update.
1 parent f2a9991 commit d8520d7

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

resource/template/theme-default/home.html

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,22 +385,40 @@
385385
// 确保i是字符串并转为小写
386386
i = (i || "").toString().toLowerCase();
387387

388-
// 使用对象映射代替switch语句
388+
// 使用对象映射代替switch语句,包含更多虚拟化平台的优雅显示
389389
const virMapping = {
390390
"kvm": "KVM",
391-
"openvz": "OpenVZ",
391+
"openvz": "OpenVZ",
392392
"lxc": "LXC",
393393
"xen": "Xen",
394-
"vbox": "vBox",
394+
"vbox": "VirtualBox",
395+
"virtualbox": "VirtualBox",
395396
"rkt": "RKT",
396397
"docker": "Docker",
397398
"vmware": "VMware",
399+
"vmware-esxi": "VMware ESXi",
398400
"linux-vserver": "VServer",
399-
"hyperv": "Hyperv"
401+
"hyperv": "Hyper-V",
402+
"hyper-v": "Hyper-V",
403+
"microsoft": "Hyper-V",
404+
"qemu": "QEMU",
405+
"parallels": "Parallels",
406+
"bhyve": "bhyve",
407+
"jail": "FreeBSD Jail",
408+
"zone": "Solaris Zone",
409+
"wsl": "WSL",
410+
"podman": "Podman",
411+
"containerd": "containerd",
412+
"systemd-nspawn": "systemd-nspawn"
400413
};
401414

402-
// 如果在映射中找到匹配项,返回对应的值,否则返回原始输入
403-
return virMapping[i] || i;
415+
// 如果在映射中找到匹配项,返回对应的值,否则返回首字母大写的原始输入
416+
if (virMapping[i]) {
417+
return virMapping[i];
418+
}
419+
420+
// 如果没有找到映射,将首字母大写返回
421+
return i.charAt(0).toUpperCase() + i.slice(1);
404422
}
405423
function clearString(i) {
406424
if (i != null && i != "") {

service/singleton/api.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,35 @@ func (m *MonitorAPIService) GetMonitorHistories(query map[string]any) *MonitorIn
387387
for _, history := range monitorHistories {
388388
infos, ok := resultMap[history.MonitorID]
389389
if !ok {
390+
// 安全检查:确保monitor和server存在
391+
var monitorName string
392+
var serverName string
393+
394+
// 检查ServiceSentinelShared和monitors是否存在
395+
if ServiceSentinelShared != nil && ServiceSentinelShared.monitors != nil {
396+
if monitor, exists := ServiceSentinelShared.monitors[history.MonitorID]; exists && monitor != nil {
397+
monitorName = monitor.Name
398+
} else {
399+
monitorName = "Unknown Monitor"
400+
}
401+
} else {
402+
monitorName = "Unknown Monitor"
403+
}
404+
405+
// 检查ServerList中是否存在该服务器
406+
ServerLock.RLock()
407+
if server, exists := ServerList[history.ServerID]; exists && server != nil {
408+
serverName = server.Name
409+
} else {
410+
serverName = "Unknown Server"
411+
}
412+
ServerLock.RUnlock()
413+
390414
infos = &MonitorInfo{
391415
MonitorID: history.MonitorID,
392416
ServerID: history.ServerID,
393-
MonitorName: ServiceSentinelShared.monitors[history.MonitorID].Name,
394-
ServerName: ServerList[history.ServerID].Name,
417+
MonitorName: monitorName,
418+
ServerName: serverName,
395419
}
396420
resultMap[history.MonitorID] = infos
397421
sortedMonitorIDs = append(sortedMonitorIDs, history.MonitorID)

0 commit comments

Comments
 (0)