From 2db64ed6edec7bca757efb8801de3d1b3989b30c Mon Sep 17 00:00:00 2001 From: Dirk Uys Date: Fri, 2 Jul 2021 14:37:26 +0200 Subject: [PATCH] Update monitor role to run a daily check for running containers --- roles/knight-rabbitmq/tasks/main.yml | 16 ---------------- roles/learningcircles-app/files/robots.txt | 2 -- roles/monitor/files/p2pu-netwell/checks.py | 19 +++++++++++++++++++ .../files/p2pu-netwell/requirements.txt | 2 ++ roles/monitor/tasks/main.yml | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) delete mode 100644 roles/knight-rabbitmq/tasks/main.yml delete mode 100644 roles/learningcircles-app/files/robots.txt diff --git a/roles/knight-rabbitmq/tasks/main.yml b/roles/knight-rabbitmq/tasks/main.yml deleted file mode 100644 index 1c3be96..0000000 --- a/roles/knight-rabbitmq/tasks/main.yml +++ /dev/null @@ -1,16 +0,0 @@ -# This role install a rabbitmq server - ---- -- name: RabbitMQ docker container - docker: - docker_api_version: 1.23 - name: knight-rabbitmq - hostname: knight-rabbitmq - image: rabbitmq:3 - pull: always - state: reloaded - restart_policy: always - volumes: - - "/var/p2pu/volumes/knight-rabbitmq:/var/lib/rabbitmq" - env: - RABBITMQ_NODENAME: "knight-rabbitmq" diff --git a/roles/learningcircles-app/files/robots.txt b/roles/learningcircles-app/files/robots.txt deleted file mode 100644 index 09c37fe..0000000 --- a/roles/learningcircles-app/files/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -user-agent: * -allow: / diff --git a/roles/monitor/files/p2pu-netwell/checks.py b/roles/monitor/files/p2pu-netwell/checks.py index 8e7eb50..88c94ad 100644 --- a/roles/monitor/files/p2pu-netwell/checks.py +++ b/roles/monitor/files/p2pu-netwell/checks.py @@ -12,3 +12,22 @@ Path('/').free_space(gb=2) #Path('/var/log/syslog').modified_within(hours=1) #Repo('/home/deploy/src/project').is_clean() + +import docker +import os +DOMAIN = os.environ.get('DOMAIN') +client = docker.from_env() +containers = [c.name for c in client.containers.list()] +expected_container = [ + 'p2pu-nginx', + f'{DOMAIN}-celerybeat', + f'{DOMAIN}-celery', + f'{DOMAIN}', + 'nginx-letsencrypt-companion', + 'learningcircles-rabbitmq', + 'p2pu-postgres', + 'fluentd', +] +for c in expected_container: + oknotok = "OK" if c in containers else "ERROR" + print(f'Checking that docker container {c} is running: {oknotok}') diff --git a/roles/monitor/files/p2pu-netwell/requirements.txt b/roles/monitor/files/p2pu-netwell/requirements.txt index 06d010f..276a5c6 100644 --- a/roles/monitor/files/p2pu-netwell/requirements.txt +++ b/roles/monitor/files/p2pu-netwell/requirements.txt @@ -1,8 +1,10 @@ certifi==2020.6.20 chardet==3.0.4 +docker==5.0.0 idna==2.10 netwell==0.4.0 python-dateutil==2.8.1 requests==2.24.0 six==1.15.0 urllib3==1.25.10 +websocket-client==1.1.0 diff --git a/roles/monitor/tasks/main.yml b/roles/monitor/tasks/main.yml index ccc2f03..61482e2 100644 --- a/roles/monitor/tasks/main.yml +++ b/roles/monitor/tasks/main.yml @@ -30,4 +30,4 @@ name: "check dirs" minute: "0" hour: "2" - job: "docker run --rm -t --env-file /usr/local/etc/p2pu-netwell.env p2pu/netwell-mailer" + job: "docker run -v /var/run/docker.sock:/var/run/docker.sock:ro --rm -t --env-file /usr/local/etc/p2pu-netwell.env p2pu/netwell-mailer"