You got a job as a system administrator in a small office. Your responsibilities include monitoring the health of multiple sites. You have successfully set up a server status mail notification from the hosting, but it turned out that this is not enough. And you decide to develop a small application in Python so that it sends you messages in case any of the sites becomes unavailable for any reason.
- The application performs all necessary checks
- The application works offline, informs when there is no Internet access
- The application performs input checks
- The application performs all necessary checks every hour
Name | Description |
---|---|
checker | All main program code |
checker/units | Custom errors, handlers and csv file readers |
checker/units/controller.py | Single site request handler |
checker/units/exceptions.py | Custom errors |
checker/__init__.py | Main project initialization file |
checker/config.py | Application configuration (regular expressions, log formats, etc.) |
checker/display.py | Web part of the application, responsible for outputting data to the console |
app.py | Code (in some cases an example) that performs the function of deploying an application |
requirements.txt | Libraries required to use the application |
Dockerfile | Docker application image |
run.sh | a bash script that deploys and executes a docker container if docker is available (otherwise, the library is installed and the app.py starts working) |
.
├── checker
│ ├── units
│ │ ├── __init__.py
│ │ ├── controller.py
│ │ ├── exceptions.py
│ │ ├── exceptions.py
│ │ └── reader.py
│ ├── __init__.py
│ ├── config.py
│ ├── display.py
│ └── sitestatuschecker.py
├── app.py
├── run.sh
├── README.md
├── .gitignore
├── Dockerfile
├── LICENCE.md
├── .dockerignore
└── requirements.txt
Bash scripts are almost everywhere (even in windows, sort of...)
When testing with this script, I managed to run the program on both Unix and Windows.
Run command:
bash run.sh
The script checks for the presence of docker on the computer and, depending on the result, launches 2 options:
- Build and run the docker image
- Installing all the necessary libraries from the requirements.txt, running the app.py python script
The entire code of the script can be found here
Docker is an open platform for developing, delivering and operating applications. Docker is designed to get your applications up and running faster. With Docker, you can decouple your application from your infrastructure and treat your infrastructure as a managed application. Docker helps you deploy your code faster, test faster, deploy applications faster, and reduce the time between coding and running code. Docker does this with a lightweight container virtualization platform, using processes and utilities to help manage and host your applications.
At its core, Docker allows you to run almost any application safely isolated in a container. Secure isolation allows you to run many containers on the same host at the same time. The lightweight nature of the container, which runs without the overhead of a hypervisor, allows you to get more out of your hardware.
- install docker on your computer
- run docker (it is important that it starts completely)
- Enter the command in the console
docker build --no-cache -t sitestatuschecker . && docker run -it sitestatuschecker
- Wait for the end of the program build
- Everything is ready to use!
It is very important that the python version >= 3.10, otherwise the application will not work
It is also possible to run through a regular python
- In the console from the project directory, write the command
pip3 install -r requirements.txt
- Wait for all libraries to be installed and send the command to the console from the bot directory
python3 app.py
- Everything is ready to use!
SSCException # Basic custom error
├── CSVReaderException # Error while reading file
│ ├── DataInvalidFormat # Error in data format from .csv file
│ └── FileInvalidFormat # Critical file reading error (wrong extension, etc.)
├── CheckerException # More warning than error (no access to IP address, TCP or HTTPS ports closed, etc.)
└── InternetConnectionError # Internet connection error
[2023-03-12 18:12:58] [INFO]: Enter filename (csv): test.csv
[2023-03-12 18:13:01] [INFO]: Ignore errors in csv? (Y/N): y
[2023-03-12 18:13:02] [INFO]: Print errors? (Y/N): y
[2023-03-12 18:13:02] [INFO]: Worker created
[2023-03-12 18:13:02] [INFO]: Check starting...
[2023-03-12 18:13:02] [ERROR]: host must be not None
[2023-03-12 18:13:02] [INFO]: continue...
[2023-04-11 21:57:18] [INFO]: host: localhost | ip: 127.0.0.1 | RTT: 0.285 ms | port: ??? | multy ip: False
[2023-04-11 21:57:26] [INFO]: host: yandex.ru | ip: 5.255.255.77 | RTT: 50.284 ms | port: 443 | status: Opened | multy ip: True | ssl: valid cert
[2023-04-11 21:57:26] [INFO]: host: yandex.ru | ip: 77.88.55.60 | RTT: 55.647 ms | port: 443 | status: Opened | multy ip: True | ssl: valid cert
[2023-04-11 21:57:26] [INFO]: host: yandex.ru | ip: 5.255.255.70 | RTT: 54.540 ms | port: 443 | status: Opened | multy ip: True | ssl: valid cert
[2023-04-11 21:57:26] [INFO]: host: yandex.ru | ip: 77.88.55.88 | RTT: 55.607 ms | port: 443 | status: Opened | multy ip: True | ssl: valid cert
[2023-04-11 21:57:32] [INFO]: host: last.fm | ip: 34.96.123.111 | RTT: 66.948 ms | port: 80 | status: Opened | multy ip: False
[2023-04-11 21:57:32] [INFO]: host: last.fm | ip: 34.96.123.111 | RTT: 68.951 ms | port: 443 | status: Opened | multy ip: False | ssl: valid cert
[2023-04-11 21:57:36] [WARNING]: ip is not success (140.82.112.3)
[2023-04-11 21:57:38] [WARNING]: cant get host name by address
[2023-04-11 21:57:43] [INFO]: host: d1ffic00lt.com | ip: 31.31.198.35 | RTT: 46.597 ms | port: 443 | status: Opened | multy ip: False | ssl: INVALID cert
[2023-04-11 21:57:43] [INFO]: Check completed!