Magesh Ravi

Magesh Ravi

Artist | Techie | Entrepreneur

Using Telegram to get notified about my internet downtime

My team has been working fully remote since 2019, even before COVID-19 pandemic started. Part of our daily routine is to connect to a computer in my office remotely. So, my office's internet connection must be stable at all times. But over the past few months, there have been frequent disconnections throughout the day. I don't know what the problem is, but every time the network goes down, I call up my service provider. Then it's fixed within minutes.

If one of my team members cannot connect to the computer, then I have to ensure the office's network is down before I call up the service provider. Because sometimes the fault could be with the client's connection.

I wanted to hack a solution that would monitor my office's internet connection and notify my team every time the network goes down (and then up).

The solution consists of three components,

  1. Client
  2. Logger
  3. Monitor

The client is a simple bash script running in my old raspberry pi connected to my office network. It sends an HTTP POST request to the logger (protected by an API key and secret) every 2 minutes. If the office's network goes down, the client won't be able to reach out to the logger. A CRON job runs the client every 2 minutes.

The logger is a Python Flask application running in a webserver. It receives the POST request from the client, validates the API key and secret, then creates a timestamped entry in the SQLite database.

The monitor is a stand-alone python script in the webserver that checks the timestamp of the most recent record in the SQLite database. If the timestamp is older than 2 minutes, then it sends out an alerting message through a telegram bot. A CRON job runs the monitoring script every 2 minutes.

infographic internet monitor

You can find the source code for this project with instructions to set up at https://github.com/mageshravi/internet-monitor.

I referred to this article to send messages through a Telegram bot.

Last updated: Nov. 5, 2023, 6:17 p.m.