151 lines
2.7 KiB
Markdown
151 lines
2.7 KiB
Markdown
# Screenshot
|
|
|
|
![ScreenShot](./image/Pymonit.PNG)
|
|
|
|
# Install
|
|
|
|
For Debian 12 (and more...)
|
|
|
|
On server :
|
|
```bash
|
|
apt install python3-flask python3-paramiko python3-psutil
|
|
```
|
|
|
|
On nodes :
|
|
```bash
|
|
apt install python3-psutil
|
|
```
|
|
|
|
For Debian < 12
|
|
```bash
|
|
pip3 install psutil flask paramiko
|
|
```
|
|
|
|
On nodes :
|
|
```bash
|
|
pip3 install psutil
|
|
```
|
|
If you prefer (recommended), you can run in an python env
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
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 :
|
|
```bash
|
|
ssh-keygen -b 2048 -t rsa
|
|
```
|
|
|
|
And push the public key in your clients :
|
|
|
|
```bash
|
|
ssh-copy-id -i <home_user>/.ssh/id_rsa.pub <user>@<client>
|
|
```
|
|
|
|
## Configuration on application
|
|
|
|
You have to report these info on the application :
|
|
|
|
```bash
|
|
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.
|
|
|
|
```bash
|
|
class ssh_conf:
|
|
port = 22
|
|
username = '<user>'
|
|
password ='<password>'
|
|
```
|
|
|
|
|
|
## Flask configuration
|
|
Configure the flask configuration according to your needs (port,host,...)
|
|
```bash
|
|
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 :
|
|
|
|
```bash
|
|
pip3 install pyopenssl
|
|
```
|
|
|
|
## Path configuration
|
|
```bash
|
|
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 :
|
|
|
|
```bash
|
|
[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 :
|
|
|
|
```bash
|
|
|
|
cp ./monit.service /etc/systemd/system/
|
|
|
|
```
|
|
|
|
Then you can start it :
|
|
```bash
|
|
systemctl start monit.service
|
|
```
|
|
To get it automaticaly start with your system:
|
|
```bash
|
|
systemctl enable monit.service
|
|
```
|