Git Product home page Git Product logo

tngaspar / isitdown-alert Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 2.76 MB

Validates whether or not webpages are reachable periodically. Sends email notifications when unreachable. Integrated with PostgreSQL and webapp Dashboard. Quick deployment with Docker containers.

Home Page: http://isitdown.tgaspar.com

License: Apache License 2.0

Dockerfile 4.88% Python 71.57% JavaScript 16.40% PLpgSQL 7.15%
crontab docker docker-compose email-alert email-alert-for-website gmail-notifier isitdown python website-status yagmail

isitdown-alert's Introduction

Is It Down Alert - Webpage Status Email Alerts

Note: for complex webpage status monitoring needs I would recommend checking out uptime-kuma. Uptime-kuma is an open-source self-hosted monitoring tool.

Validates if webpages are online on a predefined interval. Sends email alerts from gmail account if a page is down. Validation results are stored in a PostgresDB and displayed on a Dashboard built with Flask, Jinja and Chart.js. Quick and simple deployment using Docker containers.

Live example of Dashboard here.

Table of Contents

Features

  • Sends request to website periodically;
  • Current time intervals allowed:
    • every x minutes;
    • every x hours;
    • every x days;
  • Abstracts crontab job creation.
  • User chooses which websites to check as well as the interval for each one by populating webpages.yaml
  • If an http request does not return an expected response status code, an email is sent to a specified email address.
  • Validation results stored in Postgres database.
  • Dashboard website queries database and provides stats and charts to make information available to users.
  • Fast deployment on any system with docker.

Project Components

User created webpages.yaml is read by Cronjobs container and for each of the webpages specified a cronjob is created. On each cronjob execution a history entry is created on a Postgres database table and if webpage was unreachable an email alert is sent. Adminer is a lightweight open source database management tool that may prove useful to easy run queries on database or perform admin operations.

To display and share status of checks performed on website a dashboard website was created. This webapp queries the database and displays the data on an easy to understand format.

Requirements

Installation and Setup

Setting up a Gmail account to use as Sender

Important: Due to security reasons, create a new Gmail account to use as sender. Avoid using this account for other purposes.

After creating a Gmail account, an App Password needs to be created.

  1. 2-Step Verification must be enabled on Google account settings > Security

  2. Create an App Password:

On Select app choose Other (Custom name) and choose any name. Save the password for later use in project parameters.

Setting up the project

  1. Clone the repository:
$ git clone https://github.com/tngaspar/isitdown-alert.git
  1. Create .env file in project root folder with the following parameters:
SENDER_EMAIL=<Sender Gmail created = [email protected]>
APP_PASSWORD=<App Password created for Gmail Account>
RECEIVER_EMAIL=<Email that Receives Alerts = [email protected]>
TIME_ZONE=<Timezone for Email Timestamps. Example: Europe/Amsterdam>

HOST=db
POSTGRESUSER=<username to access postgres db>
POSTGRESPASSWORD=<password to access postgres db>
DATABASE=<database name>

Find a list of available time zones here.

  1. Edit webpages.yaml and add all the webpages to check as well as the corresponding time intervals. This file already contains 2 examples and instructions on how to configure it.

  2. Build and run the container:

$ docker-compose build  # Builds the container
$ docker-compose up -d  # Runs the container

Check if the container is running with the command docker ps.

That's it. The email alerts should now be activated.

Before deploying the final webpage list, I would recommend using an unreachable URL with a small interval to check if emails are being sent.

In a future release, I intend to add a way to track successfull requests to verify that all is up and running and keep a history of websites' downtimes.

Removing Docker container

$ docker-compose stop  # Stops the container
$ docker-compose rm  # Removes the container

Email Alert Example

Emails sent when website is unreachable have the following format:

PostgreSQL Database

Currently the database named cron has the following tables:

cron.dim_webpages:

Column Type
id integer Auto Increment [nextval('dim_webpages_id_seq')]
tag character varying(2000) NULL
url character varying(2000) NULL
interval character varying(255) NULL

Stores webpages for which cronjobs were created and are currently active. This table mirrors the user input data from webpages.yaml.

cron.history:

Column Type
id integer Auto Increment [nextval('history_id_seq')]
request_time timestamptz
tag character varying(2000) NULL
url character varying(2000)
is_up boolean
status_code integer NULL
response_url character varying(2000) NULL

Stores results from validations over time. Creates a new record each time a cron job runs and a http request is made.

Dashboard Webapp

Dashboard that displays data from PostgreSQL database in an accessible format.

Flask used for routing. Jinja Corona Dark template used as base template for UI components. Chart.js used for dashboarding.

The webapp at the moment contains two pages:

Dashboard

High level stats, last 7 day chart and all request chart.

Currently active validations, time between requests and amount of requests previously made.

Latest Request

Table of latest request results. Shows the most recent 100 requests ordered from newest to oldest.

Dependencies

These dependencies may be found in the requirements.txt file and are installed while building docker containers.

For local development and debugging this dependencies are installed using:

$ pip install -r requirements.txt

During development I installed these in a virtualenv. More on python virtual environments here.

(back to top)

isitdown-alert's People

Contributors

tngaspar avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.