@cryptotaxi247 / netdata-1 / commits / e8c171cf5

fix "lsns: unknown column" logging in cgroup-network-helper script (#11687)

Ilya Mashchenko committed Oct 21, 2021 at 10:12 UTC e8c171cf5d03de6ae131a970e0221fbb34be6c52
1 file changed +10 -7
collectors/cgroups.plugin/cgroup-network-helper.sh
+10 -7
@@ -76,7 +76,7 @@ debug() {
76
77 pid=
78 cgroup=
79 -while [ ! -z "${1}" ]
79 +while [ -n "${1}" ]
80 do
81 case "${1}" in
82 --cgroup) cgroup="${2}"; shift 1;;
@@ -164,7 +164,7 @@ virsh_find_all_interfaces_for_cgroup() {
164 # shellcheck disable=SC2230
165 virsh="$(which virsh 2>/dev/null || command -v virsh 2>/dev/null)"
166
167 - if [ ! -z "${virsh}" ]
167 + if [ -n "${virsh}" ]
168 then
169 local d
170 d="$(virsh_cgroup_to_domain_name "${c}")"
@@ -172,7 +172,7 @@ virsh_find_all_interfaces_for_cgroup() {
172 # e.g.: vm01\x2dweb => vm01-web (https://github.com/netdata/netdata/issues/11088#issuecomment-832618149)
173 d="$(printf '%b' "${d}")"
174
175 - if [ ! -z "${d}" ]
175 + if [ -n "${d}" ]
176 then
177 debug "running: virsh domiflist ${d}; to find the network interfaces"
178
@@ -203,8 +203,11 @@ netnsid_find_all_interfaces_for_pid() {
203 local pid="${1}"
204 [ -z "${pid}" ] && return 1
205
206 - local nsid=$(lsns -t net -p ${pid} -o NETNSID -nr)
207 - [ -z "${nsid}" -o "${nsid}" = "unassigned" ] && return 1
206 + local nsid
207 + nsid=$(lsns -t net -p "${pid}" -o NETNSID -nr 2>/dev/null)
208 + if [ -z "${nsid}" ] || [ "${nsid}" = "unassigned" ]; then
209 + return 1
210 + fi
211
212 set_source "netnsid"
213 ip link show |\
@@ -234,14 +237,14 @@ netnsid_find_all_interfaces_for_cgroup() {
237 find_all_interfaces_of_pid_or_cgroup() {
238 local p="${1}" c="${2}" # the pid and the cgroup path
239
237 - if [ ! -z "${pid}" ]
240 + if [ -n "${pid}" ]
241 then
242 # we have been called with a pid
243
244 proc_pid_fdinfo_iff "${p}"
245 netnsid_find_all_interfaces_for_pid "${p}"
246
244 - elif [ ! -z "${c}" ]
247 + elif [ -n "${c}" ]
248 then
249 # we have been called with a cgroup
250