Skip to main content

Data collector / executor - Site Reliability Framework

Project description

Remote bot on machines to auto collect data *

  • collect data
  • execute triggers

Setup

Recommended way is to use a virtual-env like:

python3 -m venv /var/lib/sre-bot
. /var/lib/sre-bot/bin/activate
pip install wheel
pip install sre-bot

First steps

sre install-service
sre add-bot-path ./bots
sre new test-bot.py

/etc/sre/sre.conf

{
    "bots-paths": [
        "/home/sre/autobots/bots",
        "/home/sre/autobots/test-bots"
    ],
    "broker": {
        "ip": "address of mqtt broker",
        "port": 1883, # optional
    },
    "name": "myhost1",
    "log_level": "error"
    "log_file": "/var/log/sre/.log",
    # used for webhook trigger
    "http_address": "0.0.0.0",
    "http_port": 8520,
}

Making a new bot

  • sre new my-bot1
HOSTNAME = "my-virtual-host1"   # optional otherwise configured default host
SCHEDULERS = ["*/10 * * * * *"] # optional - used when run is given up to seconds

def run(client):
    # requires SCHEDULERS!
    client.publish('house/bulb5', payload='off', qos=2)

def on_message(client, msg, payload=None):
    if '/restart/machine1' in msg.topic:
        ...

Calling a webhook

Example: Zabbix Trigger

Setup Zabbix

// Insert this in the script section of mediatype webhook
try {
    Zabbix.Log(4, 'Autobot webhook: ' + value);
    var params = JSON.parse(value),
        req = new CurlHttpRequest(),
        resp;
    if (params.HTTPProxy) {
        req.setProxy(params.HTTPProxy);
    }
    req.AddHeader('Content-Type: application/html');
    resp = req.Post(params.URL, JSON.stringify(params));
    if (req.Status() != 200) {
        throw 'Response code: ' + req.Status();
    }
    return true;
}
catch (error) {
    Zabbix.Log(3, error);
    throw 'Failed with error: ' + error;
}

image image image image image

Make a new bot

import json

def on_message(client, msg, payload=None):
    if 'trigger/zabbix' in msg.topic:
        data = json.loads(msg.payload.decode('utf-8'))
        if data.get('OPDATA') == 'restart_queuejobs' and data.get("ERROR") == "1":
            client.publish("restart_queuejobs")

Example: Setup Mosquitto for mqtt with docker

version: '3'
services:
  mosquitto:
      image: eclipse-mosquitto:1.6
      ports:
        - 1883:1883
      restart: unless-stopped

install directly

pip3 install git+https://github.com/marcwimmer/sre-bot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sre-bot-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

File details

Details for the file sre-bot-0.1.0.tar.gz.

File metadata

  • Download URL: sre-bot-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.7

File hashes

Hashes for sre-bot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dbccfe795cb149a96929b13d74af00acd1f5f91ea86f6d788aff73de53ce9121
MD5 2cbd34a37bf9d09f5ea8fd76cf442a44
BLAKE2b-256 017dc7617333de26ceaf1937533e20a8833b2efd909a5aff806c86a740747a4b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page