2025-09-28 11:00:40 +00:00
2025-09-28 11:00:40 +00:00

بسم الله الرحمن الرحيم

API Development with Monitoring

Objective:
Build a demo API (e.g., for a store, booking system, or any domain of your choice) with 6-7 documented endpoints, implement logging, monitor errors via a Bash script, and automate API requests.


Part 1: API Implementation

Requirements:

  1. Framework: Use any backend framework (e.g., Flask, Django, Express, Spring Boot).
  2. Endpoints:
    • Include 6-7 RESTful endpoints (e.g., GET /items, POST /order, PUT /update).
    • Implement basic CRUD operations.
  3. Documentation:
    • Document all endpoints using Swagger/OpenAPI.
  4. Logging:
    • Configure the API to log all output (requests, errors, etc.) to a file (e.g., api.log).

Part 2: Log Monitoring with Bash

Requirements:

  1. Script: Write a Bash script (monitor.sh) that:
    • Continuously reads the API log file (api.log).
    • Detects HTTP error codes (e.g., 4XX, 5XX) or unusual patterns (e.g., "failed", "timeout").
  2. Alerting:
    • On error detection, the script must:
      • Capture server metadata (IP, CPU/RAM usage, disk space) using commands like df, free, top.
      • Send a JSON payload to a Ghaymah endpoint (URL provided later) via curl. Example payload:
        {
          "error": "500 Internal Server Error",
          "timestamp": "2023-11-15T12:00:00Z",
          "message": "db not connected",
          "server_metrics": {
            "ip": "192.168.1.1",
            "cpu_usage": "75%",
            "ram_available": "2GB",
            "disk_space": "50GB"
          }
        }
        

Part 3: API Automation Testing

Requirements:

  1. Script: Write a second Bash script (test_api.sh) to automate API requests:
    • Send GET, POST, PUT, DELETE requests to your endpoints.
    • Include payloads for POST/PUT (e.g., adding a new item).
    • Log responses to a file (test_results.log).
الوصف
لا يوجد وصف
اقرأني 26 KiB