This Python script uses Tkinter and Paramiko to monitor and manage services on multiple remote hosts via SSH. It allows adding hosts and services dynamically, checks service statuses, and provides an interface to restart services if needed. The GUI displays real-time status updates and logs activities for easy monitoring.
- Service Monitoring: Monitor the status of specified services (e.g., MySQL) on multiple hosts.
- SSH Connectivity: Establish SSH connections to remote hosts for executing commands.
- Dynamic Configuration: Easily add new hosts and services through the GUI.
- Auto Refresh: Automatically refresh the status of services on each host.
- Logging: View logs of service status checks and actions taken.
- Python 3.x
paramiko
library for SSH connectionstkinter
library for the GUIPyinstaller
library for generate the .exe
> pip install paramiko tk
> pip install pyinstaller --user
-
Setup:
- Ensure
hosts.json
andservices.json
files are present in the same directory as the script. These files store host credentials and services to monitor, respectively. - Populate
hosts.json
with host details in the format:[ { "code": "host_code", "hostname": "hostname_or_ip", "username": "ssh_username", "password": "ssh_password" } ]
- Populate
services.json
with an array of service names to monitor.
- Ensure
-
Running the Script:
- Execute the script
to launch the GUI.
> python service_monitor.py
- The GUI consists of two tabs: Monitor Services and Add Hosts and Services.
- Execute the script
-
Monitor Services Tab:
- Displays host status and service availability.
- Allows refreshing status and reconnecting services.
-
Add Hosts and Services Tab:
- Facilitates adding new hosts and services dynamically.
To build an executable (service_monitor.exe
) using PyInstaller, use the following command in your terminal:
pyinstaller --onefile --add-data "hosts.json;." --add-data "services.json;." --windowed --clean -- icon=iconfinder-server2-4417099_116631.ico service_monitor.py
- SSH Connectivity: Ensure the script can connect to the specified hosts via SSH. Verify SSH keys or password access as required.
- Error Handling: The script includes basic error handling for SSH connections and service checks.
- Threading: Uses threading to manage multiple host checks concurrently within the GUI.
- If hosts or services are not loading correctly, ensure:
hosts.json
andservices.json
files are correctly formatted and located.- Python environment has necessary permissions and dependencies installed.