diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4589964 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmk_container_running"] + path = cmk_container_running + url = https://github.com/Margu86/cmk_container_running diff --git a/README.md b/README.md index a26f2db..6210fb1 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,18 @@ ## Usage ### PSONO-Health -1. Clone the recent version to your psono server. +1. Clone the recent version to your psono server into the folder (/usr/lib/check_mk/local/) 2. Edit the Script and set the URL to yours. -3. Copy the edited Script into the Check_MK folder `cp psono-healthcheck.py /usr/lib/check_mk_agent/local/` -4. Set the execution permission `chmod +x /usr/lib/check_mk_agent/local/psono-healthcheck.py` -5. Got to your Check_MK WATO and search for new services -6. Finished - You should now have a working service named psono-health +3. Set the execution permission `chmod +x /usr/lib/check_mk_agent/local/check-psono/psono-healthcheck.py` +4. Create symbolic link to the python file `ln -s /usr/lib/check_mk/local/check-psono/psono-healthcheck.py /usr/lib/check_mk/local/psono-healthcheck.py` +6. Go to your Check_MK WATO and search for new services +7. Finished - You should now have a working service named psono-health ### Docker Checks To also Check the Docker Containers you need pip and the docker-py library installed. -If you got that you can uncomment the import for docker and the for-loop. +If you got that you can uncomment the Lines 4,5,7,9 and 10. Make shure the Containers you want to check are in the CONTAINER_NAMES list, remove if you don't have all of them on your server. +Also male shure you synchronised the Submodule (`git submodule update --init --recursive`). ## Returncodes 0 ->OK (http request returns 200 and json contains "healthy":true for db_read, db_sync and time_sync) diff --git a/cmk_container_running b/cmk_container_running new file mode 160000 index 0000000..0e4f660 --- /dev/null +++ b/cmk_container_running @@ -0,0 +1 @@ +Subproject commit 0e4f6609f6b389d3d5ecd680e89a4295f688c2ca diff --git a/psono-healthcheck.py b/psono-healthcheck.py old mode 100644 new mode 100755 index e48407e..37c8d52 --- a/psono-healthcheck.py +++ b/psono-healthcheck.py @@ -1,31 +1,14 @@ #!/usr/bin/python3 -import urllib.request, os, json -#import docker +import urllib.request, sys, os, json +#sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/cmk_container_running") +#import containercheck -DOCKER_CLIENT = docker.from_env() -RUNNING = 'running' -CONTAINER_NAMES = ['psono-server', 'psono-client', 'psono-admin-client'] - - -def is_running(container_name): - container = DOCKER_CLIENT.containers.get(container_name) - container_state = container.attrs['State'] - container_is_running = container_state['Status'] == RUNNING - return container_is_running - -def cmk_message(container_name): - if(is_running): - printstr = '0 "{}" - Running'.format(container_name) - print(printstr) - else: - printstr = '2 "{}" - not Running'.format(container_name) - print(printstr) - - -#for c in CONTAINER_NAMES: - #cmk_message(c) +#CONTAINER_NAMES = ['psono-server', 'psono-client', 'psono-admin-client'] +#for container in CONTAINER_NAMES: + #print(containercheck.cmk_message(container)) + try: healthcheck = urllib.request.urlopen("https://sub.dom.tld/server/healthcheck/") status = healthcheck.read().decode('utf-8')