Skip to content

vincent119/alert-webhooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Alert Webhooks

An efficient AlertManager webhook processing service with multi-platform notifications and multilingual template support.

GitHub License Go Version Build Status Coverage Score GitHub stars GitHub release

๐Ÿ“‹ Table of Contents

๐ŸŒŸ Key Features

  • ๐Ÿ”— AlertManager Integration: Direct webhook processing from AlertManager
  • ๐Ÿ“ฑ Multi-Platform Notifications: Support for Telegram, Slack, and Discord
  • ๐ŸŽฏ Multi-Level Notifications: Support for different alert level group distribution
  • ๐ŸŒ Multilingual Templates: English, Traditional Chinese, Simplified Chinese, Japanese, Korean
  • ๐Ÿ”„ Hot Reload: Dynamic configuration and template reloading without service restart
  • ๐Ÿ” Secure Authentication: HTTP Basic Auth protection
  • ๐Ÿ“‹ Dual Template Modes: Full/Minimal display formats
  • ๐Ÿ“จ Separate Notifications: Firing and resolved alerts sent separately
  • ๐ŸŽจ Custom Templates: Support for custom message templates and formats

๐Ÿš€ Supported Platforms

This service supports alert notifications for the following communication platforms:

๐Ÿ“ฑ Telegram

  • โœ… Support for multiple chat groups
  • โœ… Support for different level notification distribution
  • โœ… Support for bot information queries
  • โœ… Support for custom message formats

๐Ÿ’ฌ Slack

  • โœ… Support for Webhook notifications
  • โœ… Support for channel message sending
  • โœ… Support for custom message formats
  • โœ… Support for attachments and formatted messages

๐ŸŽฎ Discord

  • โœ… Support for server channel notifications
  • โœ… Support for Webhook messages
  • โœ… Support for rich message formats
  • โœ… Support for embedded messages

โšก Quick Start

1. Install Dependencies

go mod download

2. Configuration Setup

# Copy configuration file
cp examples/config.expamle.yaml configs/config.development.yaml

# Edit configuration (set Telegram token and chat IDs)
vim configs/config.development.yaml

3. Start Service

# Development environment
make dev
# or
go run cmd/main.go -e development

# Production environment
make run
# or
go run cmd/main.go -e production

4. Access API Documentation

Open browser: http://localhost:9999/swagger/index.html

๐Ÿ“Š Chat IDs Level Mapping

Chat IDs Level Group Purpose Description
chat_ids0 L0 Information Group General information and status updates
chat_ids1 L1 General Message Group Standard alerts and daily monitoring
chat_ids2 L2 Critical Notification Group Important alerts and critical system notifications
chat_ids3 L3 Emergency Alert Group Emergency events and severe failure notifications
chat_ids4 L4 Testing Group Testing and development environment notifications
chat_ids5 L5 Backup Group Backup and disaster recovery notification group

๐Ÿ“– Documentation

Complete setup and usage guides are available in multiple languages in the documentation directory:

๐ŸŒ Language Selection

๐Ÿ“‹ Quick Links

๐Ÿ”ง Basic Configuration

๐Ÿ“ Template System

๐Ÿ“ฑ Platform Setup Guides

๐Ÿ“š Platform Usage Examples

๐Ÿ› ๏ธ Development

Makefile Commands

make dev              # Start development environment
make build            # Build project
make test             # Run tests
make swagger-generate # Regenerate Swagger documentation
make fmt              # Format code
make lint             # Code quality check

API Endpoints

๐Ÿ“ฑ Telegram API

Method Path Description Authentication
POST /api/v1/telegram/chatid_{level} Send Telegram message โœ… Basic Auth
GET /api/v1/telegram/info Get bot information โœ… Basic Auth

๐Ÿ’ฌ Slack API

Method Path Description Authentication
POST /api/v1/slack/chatid_{level} Send Slack message โœ… Basic Auth
GET /api/v1/slack/info Get Slack info โœ… Basic Auth

๐ŸŽฎ Discord API

Method Path Description Authentication
POST /api/v1/discord/chatid_{level} Send Discord message โœ… Basic Auth
GET /api/v1/discord/info Get Discord info โœ… Basic Auth

๐Ÿ”ง System API

Method Path Description Authentication
GET /api/v1/healthz Health check โŒ
GET /swagger/* API documentation โœ… Basic Auth

AlertManager Integration Example

๐Ÿ“ฑ Telegram Notification Setup

# alertmanager.yml - Telegram Setup
route:
  receiver: "telegram-notifications"

receivers:
  - name: "telegram-notifications"
    webhook_configs:
      - url: "http://localhost:9999/api/v1/telegram/chatid_L0"
        http_config:
          basic_auth:
            username: "admin"
            password: "admin"

๐Ÿ’ฌ Slack Notification Setup

# alertmanager.yml - Slack Setup
route:
  receiver: "slack-notifications"

receivers:
  - name: "slack-notifications"
    webhook_configs:
      - url: "http://localhost:9999/api/v1/slack/chatid_L1"
        http_config:
          basic_auth:
            username: "admin"
            password: "admin"

๐ŸŽฎ Discord Notification Setup

# alertmanager.yml - Discord Setup
route:
  receiver: "discord-notifications"

receivers:
  - name: "discord-notifications"
    webhook_configs:
      - url: "http://localhost:9999/api/v1/discord/chatid_L1"
        http_config:
          basic_auth:
            username: "admin"
            password: "admin"

๐Ÿ”„ Multi-Platform Simultaneous Notifications

# alertmanager.yml - Multi-Platform Setup
route:
  receiver: "multi-platform-notifications"

receivers:
  - name: "multi-platform-notifications"
    webhook_configs:
      # Telegram notification
      - url: "http://localhost:9999/api/v1/telegram/chatid_L2"
        http_config:
          basic_auth:
            username: "admin"
            password: "admin"
      # Slack notification
      - url: "http://localhost:9999/api/v1/slack/chatid_L2"
        http_config:
          basic_auth:
            username: "admin"
            password: "admin"
      # Discord notification
      - url: "http://localhost:9999/api/v1/discord/chatid_L2"
        http_config:
          basic_auth:
            username: "admin"
            password: "admin"

๐Ÿ“„ AlertManager Webhook Sample

The raw_alertmanager.json file in the project root provides a complete Prometheus AlertManager webhook payload sample, including:

๐Ÿ” Sample Content Description

{
  "receiver": "test-telegram-webhook", // Receiver name
  "status": "firing", // Alert status: firing/resolved
  "alerts": [
    // Alert array
    {
      "status": "firing", // Individual alert status
      "labels": {
        // Alert labels
        "alertname": "TEST_Pod_CPU_Usage High", // Alert name
        "env": "uat", // Environment label
        "namespace": "hcgateconsole", // Kubernetes namespace
        "pod": "hcgateconsole-deploy-xxx", // Pod name
        "severity": "test-alert" // Severity level
      },
      "annotations": {
        // Alert annotations
        "summary": "Pod CPU usage exceeds 80%" // Alert summary
      },
      "startsAt": "2022-11-18T08:17:31.745Z", // Alert start time
      "endsAt": "0001-01-01T00:00:00Z", // Alert end time (empty when firing)
      "generatorURL": "http://prometheus...", // Prometheus query link
      "fingerprint": "2da0690c63cf9cd3" // Alert fingerprint ID
    }
  ],
  "groupLabels": {
    // Group labels
    "alertname": "TEST_Pod_CPU_Usage High",
    "env": "uat",
    "severity": "test-alert"
  },
  "commonLabels": {
    // Common labels
    "alertname": "TEST_Pod_CPU_Usage High",
    "env": "uat",
    "severity": "test-alert"
  },
  "commonAnnotations": {}, // Common annotations
  "externalURL": "http://prometheus-alertmanager:9093", // AlertManager external URL
  "version": "4", // AlertManager version
  "groupKey": "...", // Group identification key
  "truncatedAlerts": 0 // Number of truncated alerts
}

๐ŸŽฏ Use Cases

  • Development Testing: Test webhook endpoint functionality
  • Template Development: Reference data for developing custom alert templates
  • Debug Analysis: Analyze webhook structure sent by AlertManager
  • Documentation Reference: Understand complete AlertManager webhook payload format

๐Ÿ“Š Included Alert Types

The sample file contains alerts in two states:

  1. ๐Ÿ”ฅ Firing Alerts (3 alerts)

    • Active alerts for Pod CPU usage exceeding 80%
    • CPU high usage alerts for different Pods
  2. โœ… Resolved Alerts (1 alert)

    • Resolved CPU usage alerts
    • Includes complete start and end times

๐Ÿงช Testing Usage

# Test webhook endpoint using curl
curl -X POST http://localhost:9999/api/v1/telegram/chatid_L4 \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic $(echo -n admin:admin | base64)" \
  -d @raw_alertmanager.json

# Test other platforms
curl -X POST http://localhost:9999/api/v1/slack/chatid_L4 \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic $(echo -n admin:admin | base64)" \
  -d @raw_alertmanager.json

curl -X POST http://localhost:9999/api/v1/discord/chatid_L4 \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic $(echo -n admin:admin | base64)" \
  -d @raw_alertmanager.json

๐Ÿ“ Project Structure

alert-webhooks/
โ”œโ”€โ”€ cmd/                           # Main program entry
โ”‚   โ””โ”€โ”€ main.go                   # Application entry point
โ”œโ”€โ”€ config/                        # Configuration management modules
โ”‚   โ”œโ”€โ”€ app.go                    # Application configuration
โ”‚   โ”œโ”€โ”€ config.go                 # Main configuration file
โ”‚   โ”œโ”€โ”€ discord.go                # Discord configuration
โ”‚   โ”œโ”€โ”€ logger.go                 # Logger configuration
โ”‚   โ”œโ”€โ”€ manager.go                # Configuration manager
โ”‚   โ”œโ”€โ”€ metric.go                 # Monitoring metrics configuration
โ”‚   โ”œโ”€โ”€ slack.go                  # Slack configuration
โ”‚   โ”œโ”€โ”€ telgram.go                # Telegram configuration
โ”‚   โ””โ”€โ”€ webhooks.go               # Webhook configuration
โ”œโ”€โ”€ configs/                       # Configuration file directory
โ”‚   โ”œโ”€โ”€ alert_config.minimal.yaml # Minimal alert configuration
โ”‚   โ”œโ”€โ”€ alert_config.yaml         # Complete alert configuration
โ”‚   โ””โ”€โ”€ config.development.yaml   # Development environment configuration
โ”œโ”€โ”€ docs/                          # Swagger API documentation
โ”‚   โ”œโ”€โ”€ docs.go                   # Documentation generator
โ”‚   โ”œโ”€โ”€ swagger.json              # JSON format API documentation
โ”‚   โ””โ”€โ”€ swagger.yaml              # YAML format API documentation
โ”œโ”€โ”€ documentation/                 # ๐Ÿ“– Project documentation
โ”‚   โ”œโ”€โ”€ en/                       # English documentation
โ”‚   โ”‚   โ”œโ”€โ”€ config_guide.md       # Configuration guide
โ”‚   โ”‚   โ”œโ”€โ”€ discord_setup.md      # Discord setup
โ”‚   โ”‚   โ”œโ”€โ”€ discord_usage.md      # Discord usage examples
โ”‚   โ”‚   โ”œโ”€โ”€ slack_setup.md        # Slack setup
โ”‚   โ”‚   โ”œโ”€โ”€ slack_usage.md        # Slack usage examples
โ”‚   โ”‚   โ”œโ”€โ”€ telegram_setup.md     # Telegram setup
โ”‚   โ”‚   โ”œโ”€โ”€ telegram_usage.md     # Telegram usage examples
โ”‚   โ”‚   โ””โ”€โ”€ template_guide.md     # Template guide
โ”‚   โ””โ”€โ”€ zh/                       # Chinese documentation
โ”‚       โ”œโ”€โ”€ config_guide.md       # Configuration guide
โ”‚       โ”œโ”€โ”€ discord_setup.md      # Discord setup
โ”‚       โ”œโ”€โ”€ discord_usage.md      # Discord usage examples
โ”‚       โ”œโ”€โ”€ slack_setup.md        # Slack setup
โ”‚       โ”œโ”€โ”€ slack_usage.md        # Slack usage examples
โ”‚       โ”œโ”€โ”€ telegram_setup.md     # Telegram setup
โ”‚       โ”œโ”€โ”€ telegram_usage.md     # Telegram usage examples
โ”‚       โ””โ”€โ”€ template_guide.md     # Template guide
โ”œโ”€โ”€ examples/                      # Usage examples
โ”‚   โ”œโ”€โ”€ config_usage.go           # Configuration usage example
โ”‚   โ””โ”€โ”€ config.expamle.yaml       # Configuration example file
โ”œโ”€โ”€ pkg/                          # Core functionality packages
โ”‚   โ”œโ”€โ”€ logcore/                  # Logging core
โ”‚   โ”‚   โ””โ”€โ”€ core.go              # Logging core implementation
โ”‚   โ”œโ”€โ”€ logger/                   # Logging system
โ”‚   โ”‚   โ”œโ”€โ”€ logger.go            # Logger implementation
โ”‚   โ”‚   โ”œโ”€โ”€ middleware.go        # Logging middleware
โ”‚   โ”‚   โ””โ”€โ”€ utils.go             # Logging utility functions
โ”‚   โ”œโ”€โ”€ logutil/                  # Logging utilities
โ”‚   โ”‚   โ””โ”€โ”€ context.go           # Context logging utilities
โ”‚   โ”œโ”€โ”€ middleware/               # HTTP middleware
โ”‚   โ”‚   โ”œโ”€โ”€ basic_auth.go        # Basic authentication middleware
โ”‚   โ”‚   โ”œโ”€โ”€ cors.go              # CORS middleware
โ”‚   โ”‚   โ”œโ”€โ”€ logger.go            # Logging middleware
โ”‚   โ”‚   โ””โ”€โ”€ recovery.go          # Recovery middleware
โ”‚   โ”œโ”€โ”€ notification/             # Notification system
โ”‚   โ”‚   โ”œโ”€โ”€ manager.go           # Notification manager
โ”‚   โ”‚   โ”œโ”€โ”€ providers/           # Notification providers
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ discord.go       # Discord notification implementation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ slack.go         # Slack notification implementation
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ telegram.go      # Telegram notification implementation
โ”‚   โ”‚   โ””โ”€โ”€ types/               # Notification type definitions
โ”‚   โ”‚       โ””โ”€โ”€ types.go         # Notification type structures
โ”‚   โ”œโ”€โ”€ service/                  # Business service layer
โ”‚   โ”‚   โ”œโ”€โ”€ discord.go           # Discord service
โ”‚   โ”‚   โ”œโ”€โ”€ service.go           # Common service interface
โ”‚   โ”‚   โ”œโ”€โ”€ slack.go             # Slack service
โ”‚   โ”‚   โ””โ”€โ”€ telegram.go          # Telegram service
โ”‚   โ”œโ”€โ”€ template/                 # Template engine
โ”‚   โ”‚   โ””โ”€โ”€ engine.go            # Template engine implementation
โ”‚   โ””โ”€โ”€ watcher/                  # File monitoring
โ”‚       โ””โ”€โ”€ config_watcher.go    # Configuration file monitor
โ”œโ”€โ”€ routes/                       # API routing system
โ”‚   โ”œโ”€โ”€ api/                     # API routes
โ”‚   โ”‚   โ””โ”€โ”€ v1/                  # API v1 version
โ”‚   โ”‚       โ”œโ”€โ”€ discord/         # Discord API routes
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ handler.go   # Discord handler
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ routes.go    # Discord route definitions
โ”‚   โ”‚       โ”œโ”€โ”€ slack/           # Slack API routes
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ handler.go   # Slack handler
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ routes.go    # Slack route definitions
โ”‚   โ”‚       โ”œโ”€โ”€ telegram/        # Telegram API routes
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ handler.go   # Telegram handler
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ routes.go    # Telegram route definitions
โ”‚   โ”‚       โ”œโ”€โ”€ healthCheck.go   # Health check endpoint
โ”‚   โ”‚       โ””โ”€โ”€ register.go      # Route registrar
โ”‚   โ””โ”€โ”€ mainRoute.go             # Main route configuration
โ”œโ”€โ”€ scripts/                      # Utility scripts
โ”‚   โ”œโ”€โ”€ fix_swagger_docs.go      # Swagger documentation fix script
โ”‚   โ””โ”€โ”€ regenerate_swagger.sh    # Swagger regeneration script
โ”œโ”€โ”€ templates/                    # Message templates
โ”‚   โ””โ”€โ”€ alerts/                  # Alert templates
โ”‚       โ”œโ”€โ”€ alert_template_eng.tmpl  # English alert template
โ”‚       โ”œโ”€โ”€ alert_template_ja.tmpl   # Japanese alert template
โ”‚       โ”œโ”€โ”€ alert_template_ko.tmpl   # Korean alert template
โ”‚       โ”œโ”€โ”€ alert_template_tw.tmpl   # Traditional Chinese alert template
โ”‚       โ””โ”€โ”€ alert_template_zh.tmpl   # Simplified Chinese alert template
โ”œโ”€โ”€ kubernetes/                   # Kubernetes deployment configuration
โ”‚   โ””โ”€โ”€ deployment-example.yaml  # Deployment example configuration
โ”œโ”€โ”€ docker-compose.yml           # Docker Compose configuration
โ”œโ”€โ”€ docker-compose.dev.yml       # Development environment Docker Compose
โ”œโ”€โ”€ Dockerfile                   # Docker image build file
โ”œโ”€โ”€ Makefile                     # Build and management scripts
โ”œโ”€โ”€ go.mod                       # Go module dependencies
โ”œโ”€โ”€ go.sum                       # Go module checksums
โ”œโ”€โ”€ raw_alertmanager.json        # AlertManager webhook payload sample
โ”œโ”€โ”€ README.md                    # English project documentation
โ””โ”€โ”€ README-zh.md                 # Chinese project documentation

๐ŸŒ Languages

๐Ÿค Contributing

Issues and Pull Requests are welcome to improve this project!

๐Ÿ“„ License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published