| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | |
| 7 | "github.com/sylvinus/agent-vm/internal/diagnostics" |
| 8 | "github.com/sylvinus/agent-vm/internal/usererror" |
| 9 | ) |
| 10 | |
| 11 | |
| 12 | |
| 13 | func incompleteExitSamples(hostIP string, hostErr error, terminal networkObservation, terminalErr error, browser networkObservation, browserErr error) string { |
| 14 | var missing []string |
| 15 | for _, sample := range []struct { |
| 16 | name string |
| 17 | observation networkObservation |
| 18 | err error |
| 19 | }{ |
| 20 | {"宿主", networkObservation{Status: 200, IP: hostIP}, hostErr}, |
| 21 | {"虚拟机终端", terminal, terminalErr}, |
| 22 | {"浏览器", browser, browserErr}, |
| 23 | } { |
| 24 | var reason string |
| 25 | switch { |
| 26 | case sample.err != nil: |
| 27 | reason = diagnostics.Redact(usererror.Display("读取采样", sample.err, "请重新检测。").Error()) |
| 28 | case sample.observation.Status == 0: |
| 29 | reason = "没有收到检测通道的响应" |
| 30 | case sample.observation.Status != 200: |
| 31 | reason = fmt.Sprintf("检测通道返回 HTTP %d,未取得出口地址", sample.observation.Status) |
| 32 | case sample.observation.IP == "": |
| 33 | reason = "检测通道没有返回出口地址" |
| 34 | } |
| 35 | if reason != "" { |
| 36 | missing = append(missing, sample.name+":"+reason) |
| 37 | } |
| 38 | } |
| 39 | if len(missing) == 0 { |
| 40 | return "" |
| 41 | } |
| 42 | return "出口采样不完整,无法确认配置范围(" + strings.Join(missing, ";") + ")" |
| 43 | } |