A Python tool to periodically check website availability and content with structured logging.
Project description
Website Monitoring Tool
A Python-based website monitoring tool that periodically checks the availability and content of specified websites, logging detailed structured JSON logs and console output.
Features
- Periodic checks of multiple URLs with user-defined intervals.
- Validates HTTP response status codes.
- Verifies presence of expected content in the response.
- Handles and logs connection errors, timeouts, and HTTP errors.
- Structured logging to console and JSON file with rich metadata.
- Configurable via YAML file.
Project Structure
Project Structure
├── ashar_website_monitor/
│ ├── config/
│ │ └── config.yaml # User input config for URLs and checking period
│ ├── logs/
│ │ └── monitoring_logs.json # JSON log output
│ ├── src/
│ │ ├── logger_config.py # Custom logger setup with JSON formatter
│ │ ├── monitor.py # Monitor class to run periodic checks
│ │ └── website.py # Website class to handle individual site checks
│ ├── __init__.py
│ ├── main.py # Main script to load config and start monitoring
├── tests/
│ ├── test_website.py # Unit tests for Website class
│ └── test_monitor.py # Unit tests for Monitor class
├── .gitignore # Git ignore file
├── pyproject.toml # Pip package setup file
├── requirements.txt # Package requrements
└── README.md # This documentation
---
## Configuration
Create a YAML config file specifying the checking period and URLs to monitor.
Example `config/config.yaml`:
```yaml
checking_period: 7
urls:
- url: "https://www.google.com/"
expected_content: "Google"
- url: "https://www.facebook.com/"
expected_content: "ok pk hello bye"
- url: "https://httpbin.org/status/404"
expected_content: "hello world"
- url: "http://thisdomaindoesnotexist1234567890.com"
expected_content: "anything"
- url: "https://httpbin.org/delay/10"
expected_content: "Delayed"
- url: "htp://invalid-url.com"
expected_content: "test"
- url: "https://httpbin.org/status/500"
expected_content: "internal"
Usage
Pre requisites
- Python 3.7+
- Install dependencies:
pip install -r requirements.txt
Run the monitor
python main.py --config config/config.yaml
Testing
Run all tests with:
PYTHONPATH=./ashar_website_monitor pytest -v tests/
Logging
Logs structured JSON entries containing:
- asctime (timestamp)
- url
- status_code
- response_time
- levelname
- error_type
- message
Logs are written both to console (plain text) and JSON file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ashar_website_monitor-0.1.0.tar.gz.
File metadata
- Download URL: ashar_website_monitor-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14e0eff9ddb9ede676613f047f782f33c0ec7b25ea710f0e1efcf58beb8b6f28
|
|
| MD5 |
481e3945026a11486f8cf92a66f0da15
|
|
| BLAKE2b-256 |
57a722e65e6861c7f48263c6bbf4c757ef330f05c3b77c0bf6e4e55b10280d5b
|
File details
Details for the file ashar_website_monitor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ashar_website_monitor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c1c1c7d0061d3be7952f9b46a4180b57ba90963684e7146942c7d0710994d2d
|
|
| MD5 |
06940d412fbafc3f8e2ba6fbce2d9502
|
|
| BLAKE2b-256 |
018d958e1c2951d1d2e471940a06c338626c344236d41d4a2a18125e9bad8915
|