Coder Social home page Coder Social logo

rhardih / pong Goto Github PK

View Code? Open in Web Editor NEW
96.0 2.0 7.0 121 KB

Basic uptime monitoring system, with email alerts and/or push notifications

License: MIT License

Dockerfile 0.74% Ruby 71.94% JavaScript 2.07% CSS 1.19% HTML 22.20% Shell 1.60% SCSS 0.27%
rails rails5 uptime-monitor docker docker-compose mailgun telegram-bot-api telegram telegram-bot uptime

pong's Introduction

Pong

Build Status

A minimal availability monitoring system with email alerts and push notifications.

Requirements

Pong is a dockerized Rails application run via docker-compose, so both a host running docker and a client with compose are required.

Configuration

Notifications

EMail

By default Pong uses mailgun as delivery method for ActionMailer. There's no specific reason other than easy integration via mailgun-ruby, and because they have a free plan with more than enough monthly sends for the purpose of occasional email alerts.

Since the free plan doesn't allow ad-hoc delivery, it's necessary to add the alert receiver as an Authorized Recipient in the mailgun account settings.

The application expects the following environment variables, either added in the default compose file, or added in the .env file.

MAILGUN_API_KEY
MAILGUN_DOMAIN
EMAIL_SENDER
EMAIL_RECEIVER

The sender is set as as default from address for all alerts, and the receiver is the target address for all alert mailings.

For now Pong only supports a single global receiver.

Push (via Telegram)

Pong supports push notifications, via direct chat messages over Telegram. This requires creating a dedicated Telegram bot and corresponding API key.

Here's the necessary steps:

   
1. Open the application, search for botfather and start a chat. Start chat
2. Create a new bot by issuing the /newbot command. Create new bot
3. Go through the naming steps. Any name will do, but you'll need it shortly, so make it something you can remember. Once done, you'll be given a token to access the HTTP API.

4. Copy the API key into the the .env file for Pong.

5. We need the id, of the chat we're going to use for notifications. Pong includes a rake task, that runs the bot and replies with the id when a chat is started. Run this before the next step:

$ docker-compose run web bin/rake telegram:run
Copy api key
6. Next open a chat with the newly created bot. Here you need the name you chose in step 3. Open bot chat
7. Upon joining the chat with the bot, you will be given the chat id we need.

8. Copy the chat id into the .env file, as you did with the api key and you're all set. Now Pong will send you notifications via this chat.
Get chat id

Docker image

For easier deployment, Pong is packaged as a fully self-contained docker image in production mode. A default image build is available on the dockerhub, but a custom or self built image can be used by setting the corresponding environment variable:

PROD_IMAGE=rhardih/pong:latest

Run

Bring up all compose services with:

docker-compose up -d

Database creation & initialization

docker-compose run web bin/rake db:create
docker-compose run web bin/rake db:migrate

How to run the test suite

This app uses the default minitest framework.

In development mode, a test compose service with a spring preloaded environment is added for running tests faster.

To run all tests:

docker-compose exec test bin/rake test

To run specific test:

docker-compose exec test bin/rake test TEST=test/jobs/request_job_test.rb

Services

The default application stack, as can also be seen in docker-compose.yml, consists of the following components:

  • Database server running PostgreSQL.
  • Key value store running redis.
  • A worker instance, running a resque worker.
  • A static job scheduler running resque-scheduler.
  • Default Puma web server.

Development

Aside from the services listed above, these are added for local development:

  • A test instance, with a preloaded spring environment.
  • A MailCatcher instance.

Deployment instructions

Assuming the production host is reachable and running docker, setting the following should be enough to let compose do deploys:

DOCKER_HOST=tcp://<url-or-ip-of-remote-host>:2376
DOCKER_TLS_VERIFY=1

Then adding reference to the production config:

docker-compose -f docker-compose.yml -f production.yml up -d

Remember to create and initialize the database as well.

System design notes

Check

In order to somewhat alleviate spurious alert triggerings, when a request for a check fails, it is put into an intermediate state of limbo. If a set number of subsequent request attempts are still failing, the check will then be marked as being down

Below is transition diagram illustrating how the status of a Check changes:

Check status

One thing to note, is that when a check is either in limbo or is down, its interval is disregarded, and a request is triggered every time the queue job is running, which is roughly once every minute.

pong's People

Contributors

dependabot[bot] avatar rhardih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pong's Issues

Alternative notification services

As mentioned on Reddit, it would be nice to be able to integrate this with other services or APIs instead of (or as well as) email.

For example I would personally like to use it with a Telegram bot (as it's free, compared to a premium iOS push notification service such as IFTTT/Zapier + Pushover).

Typically you would create a Telegram bot by interacting with "BotFather" in the Telegram app. This will get you a BOT_API_KEY so that you can send message as the bot. You will also need a CHAT_ID so that you can send messages to yourself from the bot.

Example API call:

https://api.telegram.org/bot<BOT_API_KEY>/sendMessage?chat_id=<CHAT_ID>&text=<MESSAGE_CONTENT"

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.