Remote bot on machines to auto collect data *
- collect data
- execute triggers
Setup
Recommended way is to use a virtual-env like:
# please use python3.9 or higher
python3.9 -m venv /var/lib/sre-bot
. /var/lib/sre-bot/bin/activate
pip install wheel
pip install sre-bot
# to install systemd service
sre install
Completion for user root in bash
Per default ubuntu deactivates ~/.bashrc bash-completion. Uncomment the lines please.
First steps
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/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
- call http://address:port/trigger/mymachine/restart and a msg with topic "mymachine/restart" is sent
- useful together with zabbix
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;
}
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
Metadata
Release files for sre-bot 0.1.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sre-bot-0.1.15.tar.gz | 11.5 kB | Without provenance | Details for sre-bot-0.1.15.tar.gz |
Release files / sre-bot-0.1.15.tar.gz
| Download URL | sre-bot-0.1.15.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d99f025b3b873986509ff12c579d4831cef64f440c5e37c5b56ac8f117e88b67
|
|
BLAKE2b-256 checksum How to use checksums |
14b68c08b7d59197b0b6dabff4607dcf6b48f7c7dd552364bcd28d9d899f5217
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for sre-bot 0.1.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.