Giter VIP home page Giter VIP logo

smsc-balance-exporter's Introduction

Balance exporter for https://smsc.ru service

The smsc balance exporter for prometheus allows exporting balance for smsc gateway

How it works

Exporter querying balance every hour (by default) and store it value in memory. When prometheus make request, exporter retrieve balance value from memory for make response.

Configuration

You must set environment variables:

  • SMSC_LOGIN - your login
  • SMSC_PASSWORD - your password

Command-line flags

  • listen-address - the address to listen on for HTTP requests. (Default: 0.0.0.0:9601)
  • interval - the interval (in seconds) for querying balance. (Default: 3600)
  • retry-interval - the interval (in seconds) for load balance when errors. (Default: 10)
  • retry-limit - the count of tries when error. (Default: 10)

Running

Running with docker

docker run \
    -e SMSC_LOGIN=<your-login> \
    -e SMSC_PASSWORD=<your-password> \
    -p 9601:9601 \
    --restart=unless-stopped \
    --name smsc-balance-exporter \
    -d \
    xxxcoltxxx/smsc-balance-exporter

Running with docker-compose

Create configuration file. For example, file named docker-compose.yaml:

version: "3"

services:
  smsc-balance-exporter:
    image: xxxcoltxxx/smsc-balance-exporter
    restart: unless-stopped
    environment:
      SMSC_LOGIN: <your-login>
      SMSC_PASSWORD: <your-password>
    ports:
      - 9601:9601

Run exporter:

docker-compose up -d

Show service logs:

docker-compose logs -f smsc-balance-exporter

Running with systemctl

Set variables you need:

SMSC_EXPORTER_VERSION=v0.1.3-beta.3
SMSC_EXPORTER_PLATFORM=linux
SMSC_EXPORTER_ARCH=amd64
SMSC_LOGIN=<your_login>
SMSC_PASSWORD=<your_password>

Download release:

wget https://github.com/xxxcoltxxx/smsc-balance-exporter/releases/download/${SMSC_EXPORTER_VERSION}/smsc_balance_exporter_${SMSC_EXPORTER_VERSION}_${SMSC_EXPORTER_PLATFORM}_${SMSC_EXPORTER_ARCH}.tar.gz
tar xvzf smsc_balance_exporter_${SMSC_EXPORTER_VERSION}_${SMSC_EXPORTER_PLATFORM}_${SMSC_EXPORTER_ARCH}.tar.gz
mv ./smsc_balance_exporter_${SMSC_EXPORTER_VERSION}_${SMSC_EXPORTER_PLATFORM}_${SMSC_EXPORTER_ARCH} /usr/local/bin/smsc_balance_exporter

Add service to systemctl. For example, file named /etc/systemd/system/smsc_balance_exporter.service:

[Unit]
Description=Smsc Balance Exporter
Wants=network-online.target
After=network-online.target

[Service]
Environment="SMSC_LOGIN=${SMSC_LOGIN}"
Environment="SMSC_PASSWORD=${SMSC_PASSWORD}"
Type=simple
ExecStart=/usr/local/bin/smsc_balance_exporter

[Install]
WantedBy=multi-user.target

Reload systemctl configuration and restart service

systemctl daemon-reload
systemctl restart smsc_balance_exporter

Show service status:

systemctl status smsc_balance_exporter

Show service logs:

journalctl -fu smsc_balance_exporter

Example configs

Example grafana config

Import dashboard from https://grafana.com/dashboards/9752 or use examples/grafana.json Grafana Panel

Example prometheus config

examples/prometheus.yaml

  - job_name: 'smsc_balance'
    scrape_interval: 1m
    static_configs:
      - targets:
        - '10.10.0.10:9601'

Example alert rules for prometheus

examples/prometheus-alert.rules

- name: balance
  rules:

  - alert: sms_balance
    expr: sum(balance_smsc) <= 2000
    for: 1s
    labels:
      severity: critical
    annotations:
      summary: "sms balance is {{ .Value }} RUB"
      description: "Top up the balance: https://smsc.ru/payment/"

smsc-balance-exporter's People

Contributors

alikhil avatar xxxcoltxxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

smsc-balance-exporter's Issues

Possible credentials leak in logs

Here is a log I get when started exporter:

2018/12/06 11:41:32 Starting Smsc balance exporter (version=, branch=, revision=)
2018/12/06 11:41:32 Build context (go=go1.11.2, user=, date=)
2018/12/06 11:41:34 Request error: Get https://smsc.ru/sys/balance.php?fmt=3&login=<my-login>&psw=<mypassword>: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) 
2018/12/06 11:41:34 Error fetching balance: Get https://smsc.ru/sys/balance.php?fmt=3&login=<my-login>&psw=<my-password>: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
2018/12/06 11:41:34 Error fetching balance: unexpected end of JSON input
2018/12/06 11:41:34 Cannot parse balance: strconv.ParseFloat: parsing "": invalid syntax

As you see, there is a real credentials in the log which is not very secure.

As possible solution credentials in error message can be substitued by certain placeholder before printing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.