Skip to content

Simple internet outages monitor with slack notification on reconnection

License

Notifications You must be signed in to change notification settings

abhijitWakchaure/internet-outages-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Internet Outages Monitor

Simple internet outages monitor in golang with slack notification on reconnection

Goal

Run the program in background (daemon) and monitor the internet connection status after set interval. In the event of disconnection the program should notify using a notifier (for now it supports slack only, PR's welcome)

Prerequisites

This program depends on the nc (or netcat) utility. Most of the OS today have this utility pre-installed, but just to be sure you can check this by running following command:

nc -dzw1 google.com 443

Installation

Step 1: Create Slack App

  1. Go to https://api.slack.com/apps and Create New App using From Scratch

  2. Under Add features and functionality choose Incoming Webhooks and turn on the Activate Incoming Webhooks option

  3. Create a new webhook URL for your app by clicking the button Add New Webhook to Workspace

  4. Grant the permission to post in any channel of your choosing and copy the webhook URL. It should look like this:

    https://hooks.slack.com/services/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
    
  5. Export the webhook URL as SLACK_WEBHOOK_URL using command:

    export SLACK_WEBHOOK_URL=<your slack webhook URL>
  6. To test if your slack app is working correctly you can use the following command to send Hello, World! message to your channel:

    curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' <your slack webhook URL>

    You should see the ok as output and your slack channel should receive the Hello, World! message.

Step 2: Configure the environment variables

This program uses the following env variables. Set them according to your needs.

Variable Name Required Default Value Summary
SLACK_WEBHOOK_URL Yes N/A The webhook URL for your slack app from Step 1
NC_DOMAIN No google.com Domain you want to use to check internet connection
NC_PORT No 443 Port you want to use for netcat
SLACK_NOTIFY_ON_REGISTER No true If true you will get a message Slack Notifier registered everytime the program starts
TICK_INTERVAL No 30s Interval between two internet checks. e.g. 15s, 1m etc

If you prefer using .env files instead of exporting individual variable, here is a sample .env file:

TICK_INTERVAL=30s
NC_DOMAIN=google.com
NC_PORT=443
SLACK_NOTIFY_ON_REGISTER=true
SLACK_WEBHOOK_URL=<your slack webhook URL>

To use the .env file don't forget to source it using command:

source .env

Step 3: Run the program

You can run the program by downloading the binary from latest release or if you have Go (golang) installed you can directly download the source code and run using following command:

go run .

About

Simple internet outages monitor with slack notification on reconnection

Resources

License

Stars

Watchers

Forks

Packages

No packages published