Skip to content

Instantly share code, notes, and snippets.

@Programie
Last active January 18, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Programie/501ea716c44579f3d747feaca334dacc to your computer and use it in GitHub Desktop.
Save Programie/501ea716c44579f3d747feaca334dacc to your computer and use it in GitHub Desktop.
Local Check_MK check to check whether Docker container images are up to date
#! /usr/bin/env python3
import docker
client = docker.from_env()
containers = client.containers.list(all=True)
outdated_containers = []
for container in containers:
container_image = container.image
container_image_tag = container_image.attrs["RepoTags"][0]
container_image_digest = container_image.attrs["RepoDigests"][0].split("@")[-1]
repo_image = client.images.get_registry_data(name=container_image_tag)
if container_image_digest != repo_image.id:
outdated_containers.append(container)
if outdated_containers:
check_state = 1
message = "Found {} outdated containers\\n{}".format(len(outdated_containers), "\\n".join(sorted([container.name for container in outdated_containers])))
else:
check_state = 0
message = "All containers are up to date"
print("{} Docker_Container_Updates containers={}|outdated={} {}".format(check_state, len(containers), len(outdated_containers), message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment