diff --git a/Dockerfile b/Dockerfile index 17cce14..e8a8bed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# For more information, please refer to https://aka.ms/vscode-docker-python FROM python:3.8-slim-buster # Keeps Python from generating .pyc files in the container @@ -7,7 +6,6 @@ ENV PYTHONDONTWRITEBYTECODE 1 # Turns off buffering for easier container logging ENV PYTHONUNBUFFERED 1 -# Install pip requirements ADD requirements.txt . RUN python -m pip install -r requirements.txt @@ -15,13 +13,11 @@ WORKDIR /app COPY alertify.py /app COPY src /app/src -# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights RUN useradd appuser && chown -R appuser /app USER appuser EXPOSE 8080 -# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug CMD ["python", "alertify.py"] HEALTHCHECK --interval=30s --timeout=3s --retries=1 \ diff --git a/alertify.py b/alertify.py index 82acbc7..1579446 100644 --- a/alertify.py +++ b/alertify.py @@ -56,8 +56,6 @@ if __name__ == '__main__': args = parse_cli() - logging.info('Version: %s', alertify.__version__) - # forwarder = alertify.Alertify(args.config) forwarder = alertify.Alertify() @@ -69,6 +67,8 @@ if __name__ == '__main__': # Invert the sense of 'healthy' for Unix CLI usage return not forwarder.healthcheck.report() + logging.info('Version: %s', alertify.__version__) + if forwarder.config.verbose: logging.debug('Parsed config:') for key, val in forwarder.config.items(): diff --git a/src/alertify/gotify.py b/src/alertify/gotify.py index 9738aa2..f298b35 100644 --- a/src/alertify/gotify.py +++ b/src/alertify/gotify.py @@ -4,6 +4,7 @@ Module to handle communication with the Gotify server import http.client import json import logging +import socket class Gotify: @@ -35,8 +36,8 @@ class Gotify: try: self.api.request(method, url, body=body, headers=headers) response = self.api.getresponse() - except ConnectionRefusedError as error: - logging.error(error) + except (ConnectionRefusedError, socket.gaierror) as error: + logging.error('Connection error: %s', error) return { 'status': error.errno, 'reason': error.strerror, @@ -52,7 +53,7 @@ class Gotify: try: resp_obj['json'] = json.loads(rawbody.decode()) except json.decoder.JSONDecodeError as error: - logging.error(error) + logging.error('Could not parse JSON: %s', error) logging.debug('Returned from Gotify:\n%s', json.dumps(resp_obj, indent=2)) logging.debug('Status: %s, Reason: %s', resp_obj['status'], resp_obj['reason'])