Skip to content

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Service Monitor Telegram Bot

Telegram bot for monitoring the availability of network services.
· Report Bug · Request Feature

About The Project

Monitoring the availability of network services is an important task for any project. At the same time, it is not always necessary to deploy universal solutions like Prometheus, a fairly simple solution. It is for such cases that this bot was created.

The bot will allow you to monitor the availability of HTTP(S) and TCP services and notify Telegram about changes in their status.

The project is in the MVP stage.

(back to top)

Built With

  • Golang

(back to top)

Getting Started

Follow the instructions below to run a bot using Docker.

Prerequisites

To run a bot, it is enough to have Docker or another environment for running containers.

Installation

  1. Register a new bot and get a token for it: https://core.telegram.org/bots/features#creating-a-new-bot
  2. Create a channel or group to which notifications will be sent
  3. Add the bot to the channel/group as an administrator with the ability to send messages
  4. Copy the configuration file config.example.yml to your working directory as config.yml
  5. Make changes to the configuration file:
  6. Run the docker container: docker run -d -v "$(pwd)/config.yml:/app/config.yml:ro" --name tgbot capcom6/service-monitor-tgbot:latest

Note: By default, the service list is read from the same YAML file (file storage backend). To use Redis or another backend, see the Storage Backends section and set the storage.dsn field or STORAGE__DSN environment variable.

(back to top)

Usage

Messages Template System

The bot uses a flexible template system for customizing notification messages. Templates support Go template syntax and can be customized in the configuration file under the messages section.

Available templates:

Template Variables Description
online Name - name of the service
ChangedAt - when the service entered this state
Duration - how long the service has been in this state
message when a service goes "online"
offline Name - name of the service
Error - error message
ChangedAt - when the service entered this state
Duration - how long the service has been in this state
message when a service goes "offline"
services_list . - list of all services:
Name - name of the service
State - state of the service
Error - error message
ChangedAt - when the service entered this state
Duration - how long the service has been in this state
message with a list of all services

Commands

The bot supports the following commands:

  • /status - Get the current status of all monitored services

(back to top)

Storage Backends

The bot supports pluggable storage backends for loading the list of monitored services. The backend is selected via DSN in the storage.dsn config field (or STORAGE__DSN environment variable).

Scheme Backend Use Case
file YAML file (default) Simple setups, static configs
redis Redis key Dynamic service lists, distributed management

File DSN format: file:///path/to/services.yml

Redis DSN format: redis://[[user]:pass@]host:port[/db][?key=<key>&channel=<channel>]

Default key: service-monitor:services, default channel: service-monitor:reload.

Examples

HTTP service monitoring example

services:
  - name: Google
    initialDelaySeconds: 5
    periodSeconds: 10
    timeoutSeconds: 1
    successThreshold: 1
    failureThreshold: 3
    httpGet:
      scheme: https
      host: google.com
      path: /
      port: 443
      httpHeaders:
        - name: X-Header
          value: value

HTTP Alert

TCP service monitoring example

services:
  - name: MySQL
    initialDelaySeconds: 5
    periodSeconds: 10
    timeoutSeconds: 1
    successThreshold: 1
    failureThreshold: 3
    tcpSocket:
      host: localhost
      port: 3306

TCP Alert

(back to top)

Roadmap

  • Add Changelog
  • Add the ability to change the text of messages
  • Send notifications to multiple channels/groups
  • Display event time in notifications
  • Online/offline time count
  • Active bot mode
    • Request current state of services
    • SLA report
    • The event log
  • Separation of bot and monitoring service
  • Dynamic list of services
  • Service discovery
  • Resource groups

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the Apache-2.0 license. See LICENSE.txt for more information.

(back to top)

Contact

Project Link: https://github.com/capcom6/service-monitor-tgbot

(back to top)

About

Telegram bot for monitoring network services

Topics

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages