DEV Community

Nico Martin
Nico Martin

Posted on

Uptime Slackbot: Getting Started

TLDR: the whole source code for this project is on GitHub:

For several years I have been using UptimeRobot, a service that monitors the availability of my site and sends me a message in a Slack channel when the site is down. Until the end of 2022, this worked great with my free plan. However, after an adjustment to the pricing structure, Slack integration is now only available on the "Solo." Plan.

Of course I understand that the operation of the platform has to be financed and yes, $84 per year is quite reasonable. But for my private projects this is not really worth it.
Moreover, it should be quite easy to build such a monitoring system yourself, right?

So what do I need exactely. I need a service that requests a Website every five minutes. If the request has a status code of 300 or higher, its concidered as "down". If lower than 300 it is "up".
"Down" should send me a notification. Furthermore it should recheck every 2 seconds and notify me again when the site is back up. So far so good.

Let's take the individual parts apart.

  1. I need a reliable service that executes the requests and attempts retries when a request fails.
  2. I need a database that tracks the attempts.
  3. I need to set up a messaging system through slack.

So far so good. I was able to answer the first fundamental question very quickly. No, I do not want to be responsible for hosting an application myself, for which high availability is absolutely necessary. So it had to be a cloud provider. And a quick comparison of the developer experience immediately led me to Firebase.
With Cloud Functions I have an easy way to execute certain tasks in time intervals and with the Firestore Database I have a highly available database to store the status of my requests.

Initialize Firebase

The setup in Firebase is pretty simple.
Communicationis handled by firebase-tools, which is best installed globally right away:

npm install -g firebase-tools
Enter fullscreen mode Exit fullscreen mode

After that you can go to your project folder and install some dependencies:

npm install firebase-functions@latest firebase-admin@latest --save
Enter fullscreen mode Exit fullscreen mode

The initial setup can then be completed with the following steps:

  1. Run npx firebase login, this allows you to login via the browser
  2. npx firebase init firestore this will initialize your project. I guess you will need to create a new project if you haven't created the project already.
  3. npx firebase init functions now you can set up the cloud functions for the same project before. You will also be asked if you want to use TypeScript or JavaScript. In this example, I choose TypeScript.
  4. As the last step, all dependencies will be installed for you together with the whole folder structure.
  5. Additionally I have installed prettier for automatic code formatting in the functions folder: npm install prettier eslint-config-prettier --save-dev. To make the setup work exactly the same as in my example I recommend to compare your eslint and typescript configuration with mine.

And with that we are ready to start with the implementation. More about this in the second part.

Top comments (0)