This project is a server monitoring and maintenance management API developed using FastAPI. The API tracks server statuses via ping and port checks and manages maintenance modes. Additionally, it can send notifications using Discord Webhook integration.
First, install all dependencies by running:
pip install -r requirements.txtFor PostreSQL database, first log in to the database
sudo -u postgres psqlAfter logging in to the database, create a table and database user user
CREATE DATABASE monitoring_db;
CREATE USER user WITH ENCRYPTED PASSWORD ‘password’;
GRANT ALL PRIVILEGES ON DATABASE monitoring_db TO user;
After creating the user, update it in main.py:
DATABASE_URL = ‘postgresql://user:password@localhost/monitoring_db’Translated with DeepL.com (free version)
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadEndpoint: POST /auth/register/
{
"username": "testuser",
"password": "TestPassword123"
}Endpoint: POST /auth/login/
{
"username": "testuser",
"password": "TestPassword123"
}📌 Response:
{
"access_token": "your_jwt_token_here",
"token_type": "bearer"
}📌 Copy the access_token and use it in other API requests with Authorization: Bearer {TOKEN}.
Endpoint: POST /servers/
{
"name": "Test Server",
"ip_address": "192.168.1.100",
"snmp_community": "public"
}Endpoint: GET /ping/{ip_address}
curl -X GET "http://localhost:8000/ping/192.168.1.100"📌 Response:
{
"ip": "192.168.1.100",
"status": "UP",
"response_time": 10.5
}Endpoint: GET /port-check/{ip_address}/{port}
curl -X GET "http://localhost:8000/port-check/192.168.1.100/22"Endpoint: POST /maintenance/
{
"server_id": 1,
"description": "Updating OS"
}Endpoint: GET /maintenance/
curl -X GET "http://localhost:8000/maintenance/"Endpoint: PATCH /maintenance/{maintenance_id}
curl -X PATCH "http://localhost:8000/maintenance/1"- Fork the project.
- Create a branch for new features.
- Develop and test your code.
- Submit a Pull Request (PR) to contribute.
This project is licensed under the MIT License.