Skip to content

MinaMamdouh2/uptime-monitoring-server

Repository files navigation

Uptime Monitoring RESTful API serve

An uptime monitoring RESTful API server that allows authenticated users to monitor URLs, and get detailed uptime reports about their availability, average response time, and total uptime/downtime.

Prerequisites

  • Before you can run this app, you need to have the following installed on your system:
    • Node.js
    • Docker
  • Getting started
    • Clone this repository to your local machine: git clone https://github.com/MinaMamdouh2/uptime-monitoring-server.git
    • Navigate to the project directory: cd uptime-monitoring-server
    • Install the app's dependencies: npm install
    • Create a .env file in the project root as .env.example
  • Running the app with npm start
    • To run the app using npm start, use the following command: npm start
    • This will start the app on the port specified in your .env file.
  • Running the app with Docker
    • Set NODE_ENV in the .env file to production
    • Build the Docker image: docker-compose build
    • Start the container: docker-compose up
    • This will start the app inside a Docker container on the port specified in your .env file.
    • Stopping the app: docker-compose down
  • Running tests
    • Before running the tests, make sure that the app is running with npm start.
    • To run the tests, use the following command: npm run tests
    • Note:- After running the tests the database will be cleared.

System Overview

Authentication system

alt text

  • User Creation Process
    • A user sends a post request to the server with an email and password; an email with a JWT token is sent to him, and he uses this token to verify his email.
    • You can resend the verification email through this API.
      • API used:
    • Role Authorization flow:
      • Each user can be assigned a role "user" or "admin", by default all users created are assigned to "user" role.
      • Users can only create URL checks & generate reports
    • Admins can only get users & delete users
      • APIs used:
        • PROTECTED GET: {{URL}}/users
        • PROTECTED GET: {{URL}}/users/:id
        • PROTECTED DELETE: {{URL}}/users/:id
    • Each user must login to use any URL checks CRUDs or Reports CRUDs
      • API used: {{URL}}/auth/login --> body: {"email": "[email protected]", "password": "@Test1234"}
        • This API returns jwtToken which must be set in Authorization Bearer Token Protected APIs.

URL Checks

alt text

  • URL Check Creation Proccess
    • A user creates a URL check, which is then sent to the monitor URL function, which pings the server on an interval basis.
      • The check status is only considered available if only the server responds with status code 2XX otherwise it is considered down
      • If URL check consists of assert.statusCode, if the server response's status != assert.statusCode; it is considered down
      • An email with a down notification is sent to the user's email upon exceeding the check threshold
      • An email with an available notification is sent to the user's email upon exceeding the check threshold & comes back available
      • The URL check is terminated if the check or the user who created it has been deleted
        • APIs used: -PROTECTED POST: {{URL}}/checks --> body: {"name": "check1", "url":"localhost", "protocol": "HTTP", "port": 5000, "path": "/api", "threshold": 3, "ignoreSSL": false,"assert":{ "statusCode": 200}, "webhook": "http://localhost:5000/webhook", "httpHeaders":{ "post":{"header1": 1}}}
          • PROTECTED POST: {{URL}}/checks --> To check for basic authentication --> body:{"name": "check2","url":"httpbin.org/basic-auth/foo/bar","protocol": "http", "tags": ["localhost", "my enviroment"], "authentication":{ "username": "foo","password": "bar"},"ignoreSSL": false}
          • PROTECTED POST: {{URL}}/checks --> To check ignore broken/expired SSL certificates --> body:{ "name": "check71", "url":"expired.badssl.com", "protocol": "HTTPS", "tags": ["trial3"], "threshold": 3, "ignoreSSL": true, "webhook": "http://localhost:5000/webhook", "httpHeaders":{ "post":{ "header1": 1}}}
          • PROTECTED GET: {{URL}}/checks/:id
          • PROTECTED GET: {{URL}}/checks?page=1&limit=10&tags=localhost&tags=dev&tags=production
          • PROTECTED PUT: {{URL}}/checks/:id
          • PROTECTED DELETE: {{URL}}/checks/:id

Reports

  • A user can obtain a detailed report for a single URL check or a group of URL checks.
    • APIs used:
      • PROTECTED GET: {{URL}}/reports/:id?page=1&limit=10
      • PROTECTED GET: {{URL}}/reports/?page=1&limit=10&tags=env&tags=dev

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published