Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cmk_container_running"]
path = cmk_container_running
url = https://github.com/Margu86/cmk_container_running
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmk_container_running
Submodule cmk_container_running added at 0e4f66
31 changes: 7 additions & 24 deletions psono-healthcheck.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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')
Expand Down