Skip to content

atareao/den

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

project-logo

DEN

Amplify events, empower notifications, elevate observability.

license last-commit repo-top-language repo-language-count


Table of Contents

Overview

A Docker Event Notification

A very simple app in a Docker to notificate docker events with some Messaging services as,

  • Telegram
  • Mattermost
  • Discord
  • ZincObeserve
  • Matrix
  • Rabbitmq
  • Mosquitto

Avoid container monitoring

if monitorize_always=true all container are monitorized except has those who has the label es.atareao.den.monitorize=false. But if monitorize_always=false only container with the label es.atareao.den.monitorize=true will be monitorized.

So if you set es.atareao.den.monitorize=false the container never will be monitorized, also if monitorize_always=true

docker run --label es.atareao.den.monitorize=false --rm hello-world

If you want, only some contaniers will be monitorized, you mast set monitorize_always=false, and set es.atareao.den.monitorize=true, in those containers you want monitorize.

By the moment, only container have this attribute. I think in next version I can implement this feature for other Docker objects.

Configuration

settings:
  # if `monitorize_always=true` all container are monitorized except has the
  # label `es.atareao.den.monitorize=false`
  # if `monitorize_always=false` only container with the following label
  # `es.atareao.den.monitorize=true` will be monitorized
  monitorize_always: true

objects:
  #  https://docs.docker.com/engine/reference/commandline/events/
  - name: container
    monitorize: true
    # attach, commit, copy, create, destroy, detach, die, exec_create,
    # exec_detach, exec_die, exec_start, export, health_status, kill, oom,
    # pause, rename, resize, restart, start, stop, top, unpause, update
    events:
      - name: 'health_status: unhealthy'
        message: "πŸ“¦πŸ€’ Container unhealty
            DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            Hostname: {{hostname}}\n
            Container: {{container}}\n
            Image: {{image}}"
      - name: destroy
        message: "πŸ“¦πŸ’₯ Destroyed container\n
            DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            Hostname: {{hostname}}\n
            Container: {{container}}\n
            Image: {{image}}"
      - name: stop
        message: "πŸ“¦βœ‹ Stopped container
            DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            Hostname: **{{hostname}}**\n
            Container: **{{container}}**\n
            Image: **{{image}}**"
      - name: start
        message: "πŸ“¦πŸ Started container\n
            DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            Hostname: **{{hostname}}**\n
            Container: **{{container}}**\n
            Image: **{{image}}**"
      - name: create
        message: "### πŸ“¦πŸ†• Created container\n
            * DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            * Hostname: **{{hostname}}**\n
            * Container: **{{container}}**\n
            * Image: **{{image}}**"
      - name: die
        message: "πŸ“¦β˜ οΈ  Died container\n
            DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            Hostname: {{hostname}}\n
            Container: {{container}}\n
            Image: {{image}}"
  - name: image
    monitorize: true
    # delete, import, load, pull, push, save, tag, untag
    events:
      - name: delete
        message: Deleted image
  - name: plugin
    monitorize: false
    # enable, disable, install, remove
    events: []
  - name: volume
    monitorize: true
    # create, destroy, mount, unmount
    events:
      - name: destroy
        message: "πŸ₯ƒπŸ’₯ Volume destroyed
            DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            Hostname: {{hostname}}\n
            Volume: {{volume}}"
      - name: create
        message: "πŸ₯ƒπŸ†• Volume created \n
            DateTime: {{now | date(format='%H:%M:%S %d-%m-%Y', timezone='Europe/Madrid')}}\n
            Hostname: {{hostname}}\n
            Volume: {{volume}}"
  - name: network
    monitorize: true
    # create, connect, destroy, disconnect, remove
    events:
      - name: destroy
        message: "πŸ•ΈοΈπŸ’₯ Network destroyed\n
            DateTime: {{ timestamp|datetimeformat(format='iso') }}\n
            Hostname: {{hostname}}\n
            Network: {{network}}"
  - name: daemon
    monitorize: false
    # reload
    events: []
  - name: service
    monitorize: false
    # create, remove, update
    events: []
  - name: node
    monitorize: false
    # create, remove, update
    events: []
  - name: secret
    monitorize: false
    # create, remove, update
    events: []
  - name: config
    monitorize: false
    # create, remove, update
    events: []

publishers: ## Available publishers
  - service: slack
    enabled: false
    config:
      url: https://hooks.slack.com/services/<your_uuid>
  - service: discord
    enabled: false
    config:
      url: https://discordapp.com/api/webhooks/<your_uuid>
  - service: mattermost
    enabled: false
    config:
      url: https://mm.tusitio.como
      token: xxxxxxxxxxxxxxxxxxxx
      channel_id: xxxxxxxxxxxxxxxxxxx
  - service: telegram
    enabled: false
    config:
      url: https://api.telegram.org
      token:
      chat_id:
  - service: zinc
    enabled: true
    config:
      url: https://zincobserve.tusitio.como
      token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      index: docker
  - service: matrix
    enabled: false
    config:
      url: matrix.tusitio.como
      token: xxxxxxxxxxxxxxxxxxxxxxxxxxx
      room: "!xxxxxxxxxxxxxxxxxxxxxxxx"
  - service: mosquitto
    enabled: true
    config:
      user: guest
      password: guest
      host: localhost
      port: 1883
      topic: bonzo/dog
  - service: rabbitmq
    enabled: false
    config:
      user: guest
      password: guest
      host: localhost
      port: 5672
      queue: docker

Docker compose

If you want to use DEN with Docker Compose, this is an example,

services:
  den:
    image: atareao/den:latest
    container_name: den
    init: true
    restart: unless-stopped
    hostname: co1
    environment:
        RUST_LOG: debug
    volumes:
      - ./config.yml:/app/config.yml
      - /var/run/docker.sock:/var/run/docker.sock

Features

Feature Description
βš™οΈ Architecture The project utilizes a containerized architecture with Docker, enabling efficient deployment and scalability.
πŸ”© Code Quality The codebase maintains high quality standards with clear logic and adherence to Rust best practices.
πŸ“„ Documentation The project offers comprehensive documentation, detailing setup instructions, configuration, and usage guidelines.
πŸ”Œ Integrations Key integrations include Docker for containerization and various messaging platforms for notifications.
🧩 Modularity The codebase is structured in a modular fashion, promoting code reusability and ease of maintenance.
πŸ§ͺ Testing Testing frameworks and tools are not explicitly mentioned in the details provided for the project.
⚑️ Performance The project aims to achieve efficiency and speed through its Rust implementation and Docker-based deployment.
πŸ›‘οΈ Security Security measures may include Docker security features and access control mechanisms for monitoring configurations.
πŸ“¦ Dependencies Key dependencies include tokio, reqwest, serde for efficient Rust development, and various Docker-related packages.
πŸš€ Scalability The use of Docker and a containerized approach suggests good potential for scalability to handle increased loads.

Repository Structure

└── den/
    β”œβ”€β”€ Cargo.toml
    β”œβ”€β”€ Dockerfile
    β”œβ”€β”€ LICENSE
    β”œβ”€β”€ README.md
    β”œβ”€β”€ config.sample.yml
    β”œβ”€β”€ docker-compose.yml
    β”œβ”€β”€ entrypoint.sh
    β”œβ”€β”€ run.sh
    └── src
        β”œβ”€β”€ config.rs
        β”œβ”€β”€ error.rs
        β”œβ”€β”€ filters.rs
        β”œβ”€β”€ main.rs
        β”œβ”€β”€ object.rs
        └── publisher.rs

Modules

.
File Summary
run.sh Initiate containerized Den service using run.sh to facilitate environment setup with necessary configurations and components.
docker-compose.yml Defines Docker service configuration for den image with restart policy, logging level, and volume mounts in the repository architecture.
Cargo.toml Implements dependencies in Cargo.toml for den project, managing packages like tokio, reqwest, serde for efficient Rust development.
Dockerfile Builds a Rust application container using multi-stage Docker within the repositorys den' directory. Inherits required dependencies and sets up a compact Alpine-based image for deployment. Simplifies the distribution process by managing build artifacts efficiently.
config.sample.yml Defines monitoring settings for various Docker objects with customizable event messages. Specifies publishers for notifications via Slack, Discord, Mattermost, Telegram, Zinc, Matrix, Mosquitto, and RabbitMQ, enhancing observability in the comprehensive Den repository architecture.
entrypoint.sh Initialize user and group, set ownership, and execute commands securely for the Den project through the entrypoint shell script.
src
File Summary
main.rs Processes Docker events based on configuration, extracting relevant information and sending messages to enabled publishers. Loads configuration, initializes Docker, and listens for events. Logs event details, handles monitorization logic, and triggers message posting.
error.rs Defines a custom error struct with a message, implementing display and error traits for the repositorys error handling.
filters.rs Implements a datetime formatting filter for Unix timestamps or ISO 8601 strings. Parses dates and times with timezone support. Takes formatting and timezone as arguments, defaults from context variables.
object.rs Defines Docker event and object structs with parsing logic for event message templates and rendering based on event type. Handles different event scenarios with contextual data and filtering rules from the parent repositorys architecture.
publisher.rs Implements publisher services for various platforms, enabling message posting via RabbitMQ, MQTT, Zinc, Telegram, and Mattermost. Posts messages utilizing specific configurations for each platform.
config.rs Ability to check if monitoring is always enabled.

Getting Started

System Requirements:

  • Rust: version x.y.z

Installation

From source

  1. Clone the den repository:
$ git clone https://github.com/atareao/den
  1. Change to the project directory:
$ cd den
  1. Install the dependencies:
$ cargo build

Usage

From source

Run den using the command below:

$ cargo run

Tests

Run the test suite using the command below:

$ cargo test

Project Roadmap

  • β–Ί INSERT-TASK-1
  • β–Ί INSERT-TASK-2
  • β–Ί ...

Contributing

Contributions are welcome! Here are several ways you can contribute:

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/atareao/den
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
  6. Push to github: Push the changes to your forked repository.
    git push origin new-feature-x
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph


License

This project is protected under the SELECT-A-LICENSE License. For more details, refer to the LICENSE file.


Acknowledgments

  • List any resources, contributors, inspiration, etc. here.

Return


About

A simple Docker Event Notification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published