Open t3easy opened 2 years ago
Here what I did so far as a first quick but working solution:
ARG ICINGA2_VERSION==2.13.5
ARG DOCKER_VERSION=20.10
FROM docker:${DOCKER_VERSION} as docker-cli
# Icinga 2
FROM icinga/icinga2:${ICINGA2_VERSION} as icinga2
USER root
COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker
RUN set -eux; \
groupadd -g 999 docker; \
usermod -aG docker icinga;
USER icinga
services:
icinga2:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
object CheckCommand "by_docker" {
import "plugin-check-command"
command = [ "/usr/local/bin/docker" ]
arguments += {
docker_command = {
order = 10
required = true
skip_key = true
value = {{
if (macro("$by_docker_run$")) {
return "run"
} else {
return "exec"
}
}}
}
docker_container = {
description = "The container in that the command will be executed"
order = 20
required = true
skip_key = true
value = "$by_docker_container$"
}
docker_container_command = {
description = "The command that will be executed in the container"
order = 30
required = true
skip_key = true
value = "$by_docker_container_command$"
}
docker_container_command_arguments = {
description = "The arguments for the command that will be executed in the container"
order = 40
skip_key = true
value = "$by_docker_container_command_arguments$"
}
}
}
template Service "Icingacli by Docker" {
check_command = "by_docker"
check_interval = 1m
retry_interval = 30s
vars.by_docker_container = "monitoring-icingaweb2-1"
vars.by_docker_container_command = "/usr/local/bin/icingacli"
}
Maybe a Phar of the icingacli plus configuration deployed to the Icinga container. But I don't know if creating the Phar works that easily.
Originally posted by @lippserd in https://github.com/lippserd/docker-compose-icinga/issues/17#issuecomment-1172136693
I just had an idea how to run such tests. As there is a
by_ssh
command, that runs commands on a remote server by ssh, we could implement aby_docker
command that can run check commands inside an existing container bydocker exec icingaweb icingacli ...
or by creating a new container with a custom check commanddocker run --rm check_xy_image
.Therefore the docker cli in the icinga2 image and the docker socket of the host of the icinga2 service or a ssh/tls DOCKERHOST is required.
Its not perfect for all hosting environments but the best solution for common.