mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 17:21:13 +01:00
A container that uses another container's network (a download client behind a VPN container) has no network attachments and no published ports of its own, so Pulse showed it with no network at all and nothing said where its traffic went. On a real Unraid host three containers looked like that. The agent already inspects every container. It now reports the runtime's network mode as the runtime wrote it: bridge, host, none, a network name, or container:<id>. The server keeps it trimmed and bounded on the container model, the app-container resource and the frontend types. A report without it stays empty, which means not reported and never "no network". Nothing reads the field yet. The infrastructure map will use it to draw a container next to the one whose network it uses.
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package monitoring
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// maxDockerNetworkModeLength bounds a reported container network mode. The
|
|
// longest value a runtime writes itself is "container:" and a 64-character
|
|
// ID. A network name can be longer, and Docker caps none, so anything past
|
|
// this is dropped instead of stored.
|
|
const maxDockerNetworkModeLength = 255
|
|
|
|
// dockerNetworkModeFromReport keeps the runtime's network mode as the agent
|
|
// sent it. The value is the runtime's own word for how a container is
|
|
// networked (bridge, host, none, a network name, or container:<id> when it
|
|
// uses another container's network), so it is trimmed and bounded but never
|
|
// rewritten: a network name is case-sensitive, and a container reference only
|
|
// means something while it still matches a reported container ID. An empty
|
|
// result means the mode is not known, which is what an older agent sends.
|
|
func dockerNetworkModeFromReport(mode string) string {
|
|
mode = strings.TrimSpace(mode)
|
|
if mode == "" || len(mode) > maxDockerNetworkModeLength {
|
|
return ""
|
|
}
|
|
if strings.IndexFunc(mode, unicode.IsControl) >= 0 {
|
|
return ""
|
|
}
|
|
return mode
|
|
}
|