@cryptotaxi247 / netdata-1 / commits / fa5c84a61

netdata/collectors/cgroups.plugin: When jq not available, prompt the user he may have to install jq (#5848)

* netdata/collectors/cgroups.plugin: When jq not available, pop a warning to let the user know he might have to install jq. We still support him with alternative way of retrieving the docker name, but there may be cases the user prefers the API approach * netdata/collectors/cgroups.plugin: Missed one more jq call to handle

Paul Emm. Katsoulakis committed Apr 17, 2019 at 16:47 UTC fa5c84a61874b14a3d1a7a6dd9de424a55105f23
1 file changed +16 -6
collectors/cgroups.plugin/cgroup-name.sh.in
+16 -6
@@ -58,6 +58,11 @@ function docker_get_name_api() {
58 warning "Can't find ${DOCKER_HOST}"
59 return 1
60 fi
61 + if ! command -v jq >/dev/null 2>&1; then
62 + warning "Can't find jq command line tool. jq is required for netdata to retrieve docker container name using ${DOCKER_HOST} API, falling back to docker ps"
63 + return 1
64 + fi
65 +
66 info "Running API command: /containers/${id}/json"
67 JSON=$(echo -e "GET /containers/${id}/json HTTP/1.0\\r\\n" | nc -U "${DOCKER_HOST}" | grep '^{.*')
68 NAME=$(echo "$JSON" | jq -r .Name,.Config.Hostname | grep -v null | head -n1 | sed 's|^/||')
@@ -71,12 +76,17 @@ function k8s_get_name() {
76 id="${1##*/}"
77 fi
78 KUBE_TOKEN="$(</var/run/secrets/kubernetes.io/serviceaccount/token)"
74 - NAME="$(
75 -curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" "https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/pods" |
76 -jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_\(.status.containerStatuses[0].name) \(.status.containerStatuses[0].containerID)"' |
77 -grep "$id" |
78 -cut -d' ' -f1
79 -)"
79 + if command -v jq >/dev/null 2>&1; then
80 + NAME="$(
81 + curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" "https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/pods" |
82 + jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_\(.status.containerStatuses[0].name) \(.status.containerStatuses[0].containerID)"' |
83 + grep "$id" |
84 + cut -d' ' -f1
85 + )"
86 + else
87 + warning "jq command not available, k8s_get_name() cannot execute. Please install jq should you wish for k8s to be fully functional"
88 + fi
89 +
90 if [ -z "${NAME}" ]; then
91 warning "cannot find the name of k8s pod with containerID '${id}'. Setting name to ${id} and disabling it"
92 NAME="${id}"