Skip to content

Latest commit

 

History

History

mftp-doctor

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

MFTP Doctor

mftp-doctor.py periodically monitors the latest runtime logs of mftp.py. Analyses the logs and looks for errors. On encountering any errors it sends a notification to configured e-mail and ntfy topic, both done utilising ntfy.

Table of Contents

Using docker

To set up a local instance of the application using docker, follow the steps below.

Prerequisites

The following requirements are to be satisfied for the project to function properly:

(back to top)

Installation

  1. Get the docker image

    You can get the docker image from either docker-hub or by buiilding it locally:

    • Pull from docker-hub
      sudo docker pull metakgporg/mftp-doctor
    • Build from Dockerfile
      • Clone the repository and cd into it
        git clone https://github.com/metakgp/mftp
        cd mftp/mftp-doctor
      • Build the image
        sudo docker build -t metakgporg/mftp-doctor .
  2. Create a directory which will contain your env.py, name it as doctor_config

  3. Follow the steps to configure env variables

(back to top)

Usage

Docker Compose

It is mandatory to provide the following env variable before the docker-compose command.

  • DOCTOR_CONFIG: Absolute path to doctor_config directory
sudo DOCTOR_CONFIG=/path/to/doctor_config docker-compose up -d

(back to top)

Docker Command

This container requires access to hosts' docker.sock to check logs of mftp container running on host and the env.py file:

sudo docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /path/to/doctor_config/env.py:/mftp-doctor/env.py \
--name mftp-doctor \
metakgporg/mftp-doctor

(back to top)

As a cronjob

It is also possible to run these docker containers as a cronjob:

  • With Docker Compose
    • Provide --cron as the DOCTOR_MODE env variable. For example:
      sudo DOCTOR_CONFIG=/path/to/doctor_config DOCTOR_MODE=--cron docker-compose up -d
  • With Docker Command
    • Append --cron at the end of this commands, as follows:
        sudo docker run -d \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /path/to/doctor_config/env.py:/mftp-doctor/env.py \
        --name mftp-doctor \
        metakgporg/mftp-doctor --cron
  • Add the updated command with desired cron expression into your cronjob using crontab -e

(back to top)

Without using docker

To set up a local instance of the application without using docker, follow the steps below.

Prerequisites

The following requirements are to be satisfied for the project to function properly:

  • python3 >=python3.10
    sudo apt update
    sudo apt install python3

(back to top)

Installation

Now that the environment has been set up and configured to properly compile and run the project, the next step is to download and configure the project locally on your system.

  1. Clone the repository

    git clone https://github.com/metakgp/mftp
    cd mftp/mftp-doctor
  2. Install required dependencies

    pip3 install -r requirements.txt
  3. Configuring environment variables

    • Copy env.example.py as env.py. It looks like this:
      TOPIC_URL = "https://ntfy.sh/metakgp-mftp" # NTFY topic to send doctors' notifications on
      EMAIL = "abc@xyz.com" # Email to send doctors' notifications on

      You can read about you can learn about ntfy from their docs: https://docs.ntfy.sh/

    • Update the values inside the double quotes ("). DO NOT CHANGE VAR NAMES.

(back to top)

Usage

It is straight forward to use this script, just run it using supported version of python interpreter:

python3 mftp-doctor.py

It is also possible to bypass the continuous loop - which executes the code after every 2 minutes - using the --cron argument:

python3 mftp-doctor.py --cron

(back to top)