pporcheret f3cb525fed | ||
---|---|---|
templates | ||
README.md | ||
agent.py | ||
app.py | ||
config.py | ||
monit.service |
README.md
Install
For Debian 12 (and more...)
On server :
apt install python3-flask python3-paramiko python3-psutil
On nodes :
apt install python3-psutil
For Debian < 12
pip3 install psutil flask paramiko
On nodes :
pip3 install psutil
If you prefer (recommended), you can run in an python env
apt install python3-venv
python3 -m venv Pymonit
. /Pymonit/bin/activate
pip3 install psutil flask paramiko
Configuration
Clients
Add your client in the python list client:
client = ['192.168.0.1','server.local','server.mydns']
Generate keys for connection
Becarrefull, avoid using a root user to start application and connect to client. Use a dedicated user.
On server, generate a pair of key :
ssh-keygen -b 2048 -t rsa
And push the public key in your clients :
ssh-copy-id -i <home_user>/.ssh/id_rsa.pub <user>@<client>
Configuration on application
You have to report these info on the application :
class ssh_conf:
port = 22
username = '<user>'
password ='<home_user>/.ssh/id_rsa.pub'
For testing purpose, but still not recommended, you can use a password in configuration file.
class ssh_conf:
port = 22
username = '<user>'
password ='<password>'
Flask configuration
Configure the flask configuration according to your needs (port,host,...)
class flask_conf:
port = 8090
host = "0.0.0.0"
thread = False
debug = False
reloader = False
ssl = 'adhoc'
NB: the parameter ssl = 'adhoc' will activate the HTTPS with a self certificate. If you get an error, you should add this package :
pip3 install pyopenssl
Path configuration
class paths :
basedir = os.path.abspath(os.path.dirname(__file__))
agent_path = basedir+'/agent.py'
remote_path = '/var/tmp/script.py'
remote_path : the location where the agent will be pushed and execute. Take care that your used is able to write and execute in this location.
Systemctl (optional)
To easy start, stop and restart application, you can use the monit.service template.
Replace the path according to your system in :
[Unit]
Description= Monit service
After=multi-user.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 /application/path/app.py
[Install]
WantedBy=multi-user.target
Copy the file in your systemd folder :
cp ./monit.service /etc/systemd/system/
Then you can start it :
systemctl start monit.service
To get it automaticaly start with your system:
systemctl enable monit.service