Innovation
05f798283b
This occurs if someone types `[COMMAND>Node]` without a command. This is fixed by adding checks in `parseMessage` that prevents `runCommand` from being ran if this is the case. |
||
---|---|---|
README.md | ||
sysctl.ini.template | ||
sysctl.py |
twm-sysctl
Sysctl, a bot for reporting the status of the daemons running on its host and other hosts.
Setup
For now, I will only provide a general setup tutorial. Someone who knows about web development should know a bit more about this.
1.) SCNITS - Self-Contained Node Information Transfer Server
What is a SCNITS
Each of my nodes have a PHP-enabled web server intended to let nodes tell other nodes information, which is not accessible from the internet. These servers run on port 9050.
Starting a SCNITS (or something like it)
Sysctl bots use this server. What it cares about (as of now) is the contents of /server/
. Let's pretend you want to track three daemons - matrix
, nginx
, and gitea
. In this case, /server/index.php
would contain the following:
<?php
echo "matrix\n";
echo "nginx\n";
echo "gitea";
?>
That would tell the bot that it needs to check /server/matrix/
, /server/nginx/
, and /server/gitea/
.
Assuming you use systemctl
, ach PHP script in these folders are pretty similar (except nginx, in my case).
Matrix:
<?php
$active = shell_exec("systemctl is-active synapse-matrix.service");
if ($active == "active\n") {
echo 1;
} else {
echo 0;
}
?>
Nginx:
<?php
// Theres no way you'd be reading if Nginx wasn't running.
echo 1;
?>
Gitea:
<?php
$active = shell_exec("systemctl is-active gitea.service");
if ($active == "active\n") {
echo 1;
} else {
echo 0;
}
?>
And so on.
2.) Setting up the bot itself.
Dependencies
First off, this bot requires some dependencies. Install them with pip3
: matrix-nio, urllib3, and ping3.
Matrix-nio is the library I use to communicate with the Matrix server. URLLib3 lets me get webpages. Ping3 pings machines.
Also, this bot has only been tested on Python 3.7. It SHOULD work on version 3.0 and newer, but no guarantees. It is not compatible with Python 2.x.
Actual setup
Now we are ready to set up the bot. First, download sysctl.py
from this repository and place it somewhere. In the same folder, create a new sysctl.ini
file. This file is the configuration file the bot will read on startup.
Information on what to put in your sysctl.ini
file is located in the sysctl.ini.template
file in this repository.
Now, you can run it with python sysctl.py
, or python3.7 sysctl.py
in some cases.
Hold it! We need an account!
Yeah my bad. You must create an account for your bot. I usually do with with Electron.io, a web client for Matrix. Create your account, and use those for the username
and password
fields.
FAQ
Why is the password storage so insecure?
Haha... yeahhh...
It doesn't work!
Please leave an issue, I'd be glad to help you out!