Skip to content

Latest commit

 

History

History
139 lines (92 loc) · 3.79 KB

File metadata and controls

139 lines (92 loc) · 3.79 KB

About

This is a Telegram bot that sends ad-hock reports about Yandex Cloud expense details and actual billing acount balance.

Getting expense details by folder | Yandex Cloud.

Bot commands

The main bot commands:

Command Description
/balance Show current billing account balance
/daily_report Show today's date actual consumption report
/weekly_report Show last 7 days consumption report
/monthly_report Show last 30 days consumption report

After each /*_report command you will be prompt to select how you want to aggregate data.

The posible ways are:

  1. By Service
  2. By Product

Which means what entity in Yandex Cloud to use in GROUP BY clause.

Show current balance:

balance

Daily report prompt:

daily-report-prompt

Daily report aggregated by product output:

daily-report-by-product-result

Daily report aggregated by service output:

daily-report-by-service-result

The same output will be for each /*_report command.

Local development

Build and run the bot inside docker container.

export IMAGE=yandex-cloud-billing-analysis-bot:dev-1.0.0
docker build -t $IMAGE -f Dockerfile .
docker run --detach --rm \
    --name yandex-cloud-billing-analysis-bot \
    $IMAGE

Get container logs:

docker logs -f yandex-cloud-billing-analysis-bot

Enter into container by root user:

docker exec -it -u root yandex-cloud-billing-analysis-bot /bin/bash

Users authorization

Telegram users that can communicate with this bot should be set via AUTH_USERS env variable in .env file.

For multiple users use this format:

AUTH_USERS=1111,2222,3333,4444

For all required env variables see .env.example.

Deploy

Deploy configurations managed by terraform. You can find it here: https://github.com/leonidgrishenkov/yandex-cloud-infrastructure/tree/main/prod/services/compute-1

Create and use docker context or just ssh into host:

$ docker context create prod-compute-1 --docker "host=ssh://yc-user@leonidgrishenkov.com:51222"
Successfully created context "prod-compute-1"

$ docker context use prod-compute-1
Current context is now "prod-compute-1"

ssh-add ~/.ssh/prod-hosts

Create volume to store bot logs:

docker volume create bot-logs
docker swarm init
cat .yc-sa-auth.json | docker login --username json_key --password-stdin cr.yandex

Add service account auth key into github secrets:

cat .yc-sa-auth.json | jq -c | base64 | pbcopy

TODO

  • Add handler to get report for the particular date
  • Add background job that will send message when balance goes below specified threshold
  • Add report results caching