Skip to content

Small utility to check whether or not a given endpoint is up. Supports multiple notification channels

License

Notifications You must be signed in to change notification settings

mirgj/go-service-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-service-check

Small utility to check whether or not a given endpoint is up. Supports multiple notification channels

  • console
  • SMTP
  • SendGrid

Configuration

Based on the notification channel that you want to use to send notifications you're required to set the following ENV variables to make it work:

Console

No configuration required

SMTP

The following ENV are required:

SMTP_SERVER=<hostname of the SMTP server>
SMTP_USER=<SMTP username>
SMTP_PASSWORD=<SMTP user's password>
SMTP_PORT=25 <or any other in case>

SendGrid

The following ENV are required:

SENDGRID_API_KEY=<send grid API Key (secret)>

Service to be checked

The utility uses a db.json which needs to have the following structure to:

{
  "sites": [
    {
      "url": "https://google.com",
      "name": "Google",
      "delay": 5,
      "notifier": "console"
    }
  ]
}

The array contains a structure with the following fields:

  • url: URL and/or API endpoint to check (a GET HTTP request will be performed to verify the service availability)
  • name: Service name to be used as alias for the given URL
  • delay: Defines the seconds between one ping and another
  • notifier: Define the type of notifier to be used (allowed values: console, sendgrid, smtp)

In case the notifier is sendgrid or smtp the following options are required on the specific element with the given notifier:

{
  "options": {
    "from": "from@email.com",
    "to": "to@email.com",
    "body": "{{name}} ({{url}}) was not reachable the last {{delay}} seconds!",
    "subject": "{{name}} is down!"
  }
}

The body and subject can contain the following placeholder that will be replaced with the actual value:

  • {{url}}: replaced with the service URL
  • {{delay}}: replaced with the configured delay
  • {{name}}: replaced with the service name

Full configuration file

Example of a configuration file with all the given options:

{
  "sites": [
    {
      "url": "https://google.com",
      "name": "Google",
      "delay": 5,
      "notifier": "console"
    },
    {
      "url": "https://facebook.com",
      "name": "Facebook",
      "delay": 5,
      "notifier": "sendgrid",
      "options": {
        "from": "from@email.com",
        "to": "to@email.com",
        "body": "{{name}} ({{url}}) was not reachable the last {{delay}} seconds!",
        "subject": "{{name}} is down!"
      }
    },
    {
      "url": "https://stackoverflow.com",
      "name": "Stackoverflow",
      "delay": 5,
      "notifier": "smtp",
      "options": {
        "from": "from@email.com",
        "to": "to@email.com",
        "body": "{{name}} ({{url}}) was not reachable the last {{delay}} seconds!",
        "subject": "{{name}} is down!"
      }
    }
  ]
}

About

Small utility to check whether or not a given endpoint is up. Supports multiple notification channels

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages