diff options
author | Ian <ViViDboarder@gmail.com> | 2019-07-26 00:38:31 -0700 |
---|---|---|
committer | Paul Emm. Katsoulakis <34388743+paulkatsoulakis@users.noreply.github.com> | 2019-07-26 10:38:31 +0300 |
commit | e2e20dad1fc29dcd6bd76b6dc50c80045d0a2956 (patch) | |
tree | c706201dacebc4381e6aefc3ee0b46fcc644e3e4 /collectors/cgroups.plugin | |
parent | ca5c1836cec65904362289572708e2f3d871e1dc (diff) |
Safer container names (#6441)
* Allow building without pushing
This enables easier local testing
* Refactor fetching Docker container names to be safer
Fixes #5680
* Wrap shell variable with quotes
And change spaces to tabs
* Make cgroup-name quieter
* Make DOCKER_USR overridable
* Update documentation to explain safe usage
* Remove recommended image for docker socket proxy
* Add capability to pass in a privileged GID
* Fix some documentation typos
* Update documentation to remove socket reference and clean up wording
Diffstat (limited to 'collectors/cgroups.plugin')
-rwxr-xr-x | collectors/cgroups.plugin/cgroup-name.sh.in | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/collectors/cgroups.plugin/cgroup-name.sh.in b/collectors/cgroups.plugin/cgroup-name.sh.in index 48f523885b..784c06042d 100755 --- a/collectors/cgroups.plugin/cgroup-name.sh.in +++ b/collectors/cgroups.plugin/cgroup-name.sh.in @@ -53,18 +53,25 @@ function docker_get_name_classic() { } function docker_get_name_api() { - local id="${1}" - if [ ! -S "${DOCKER_HOST}" ]; then - warning "Can't find ${DOCKER_HOST}" + local path="/containers/${1}/json" + if [ -z "${DOCKER_HOST}" ]; then + warning "No DOCKER_HOST is set" return 1 fi if ! command -v jq >/dev/null 2>&1; then 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" return 1 fi - - info "Running API command: /containers/${id}/json" - JSON=$(echo -e "GET /containers/${id}/json HTTP/1.0\\r\\n" | nc -U "${DOCKER_HOST}" | grep '^{.*') + if [ -S "${DOCKER_HOST}" ]; then + info "Running API command: curl --unix-socket ${DOCKER_HOST} http://localhost${path}" + JSON=$(curl -sS --unix-socket "${DOCKER_HOST}" "http://localhost${path}") + elif [ "${DOCKER_HOST}" == "/var/run/docker.sock" ]; then + warning "Docker socket was not found at ${DOCKER_HOST}" + return 1 + else + info "Running API command: curl ${DOCKER_HOST}${path}" + JSON=$(curl -sS "${DOCKER_HOST}${path}") + fi NAME=$(echo "$JSON" | jq -r .Name,.Config.Hostname | grep -v null | head -n1 | sed 's|^/||') return 0 } |