[REF]Uptime now uses Python config file
Because of env limit with cronie on OL8
This commit is contained in:
parent
067c64cfd9
commit
b53a107471
@ -4,6 +4,7 @@ MAINTAINER Yaltik - Fabien Bourgeois <fabien@yaltik.com>
|
|||||||
RUN dnf -y install cronie python3 python3-requests
|
RUN dnf -y install cronie python3 python3-requests
|
||||||
|
|
||||||
COPY check.py ./
|
COPY check.py ./
|
||||||
|
COPY config.py ./
|
||||||
COPY crontab ./
|
COPY crontab ./
|
||||||
COPY launch.sh ./
|
COPY launch.sh ./
|
||||||
|
|
||||||
|
@ -2,23 +2,12 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Uptime check, at the moment HTTPS only domains
|
Uptime check, at the moment HTTPS only domains
|
||||||
Usage of own healthchecks.io instance and ENV
|
Usage of own healthchecks.io instance and config file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from os import environ
|
|
||||||
from requests import get, post
|
from requests import get, post
|
||||||
|
from config import HC_ROOT, CONFIG
|
||||||
|
|
||||||
hc_root = environ.get('HC_ROOT', '')
|
|
||||||
# HOSTS are in form hostname|uuid:hostname2|uuid...
|
|
||||||
hosts = environ.get('HOSTS', '').split(':')
|
|
||||||
# Domains are in form of example.org,example.net:hostname.org:another.net
|
|
||||||
domains = environ.get('DOMAINS', '').split(':')
|
|
||||||
|
|
||||||
config = {}
|
|
||||||
for host in zip(hosts, domains):
|
|
||||||
host_data = host[0].split('|')
|
|
||||||
config[host_data[0]] = {'url': '%s/ping/%s' % (hc_root, host_data[1]),
|
|
||||||
'domains': host[1].split(',')}
|
|
||||||
|
|
||||||
def check_domain(domain):
|
def check_domain(domain):
|
||||||
try:
|
try:
|
||||||
@ -35,13 +24,14 @@ def ping_with_info(url, fail=False, data=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Ping failed: %s" % e)
|
print("Ping failed: %s" % e)
|
||||||
|
|
||||||
for host, settings in config.items():
|
for check_item in CONFIG:
|
||||||
print('Checking %s : %s' % (', '.join(settings['domains']), host))
|
print('Checking %s : %s' % (check_item['host'], ', '.join(check_item['domains'])))
|
||||||
fail = False
|
fail = False
|
||||||
data = []
|
data = []
|
||||||
for domain in settings['domains']:
|
for domain in check_item['domains']:
|
||||||
status = check_domain(domain)
|
status = check_domain(domain)
|
||||||
if not fail and status != 200:
|
if not fail and status != 200:
|
||||||
fail = True
|
fail = True
|
||||||
data.append('%s : %s' % (domain, status))
|
data.append('%s : %s' % (domain, status))
|
||||||
ping_with_info(settings['url'], fail=fail, data='\n'.join(data))
|
url = '%s/ping/%s' % (HC_ROOT, check_item['uuid'])
|
||||||
|
ping_with_info(url, fail=fail, data='\n'.join(data))
|
||||||
|
10
uptime/check/config.py
Normal file
10
uptime/check/config.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Configuration file
|
||||||
|
"""
|
||||||
|
|
||||||
|
HC_ROOT = 'https://hc.yaltik.net'
|
||||||
|
CONFIG = [{'host': 'server_name',
|
||||||
|
'uuid': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||||
|
'domains': ['www.example.com', 'beta.example.com', 'another.sample.net']}]
|
@ -1,4 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
printenv >> /etc/environment
|
|
||||||
crontab ./crontab && touch /var/log/cron.log && crond && tail -f /var/log/cron.log
|
crontab ./crontab && touch /var/log/cron.log && crond && tail -f /var/log/cron.log
|
||||||
|
Loading…
x
Reference in New Issue
Block a user