Last active
January 18, 2020 14:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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