From 61ed2159bea502bf0134874a6064e15e518686d2 Mon Sep 17 00:00:00 2001 From: pporcheret Date: Mon, 7 Apr 2025 13:51:23 +0200 Subject: [PATCH] OS and Case minor change --- app.py | 22 ++++++++++++++++++++++ templates/index.html | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 5a7e228..3d35c59 100755 --- a/app.py +++ b/app.py @@ -9,6 +9,12 @@ import json app = Flask(__name__) def get_remote(hostname, port, username, password, local_script_path, remote_script_path): + push_agent(hostname, port, username, password, local_script_path, remote_script_path) + output = pull_agent(hostname, port, username, password, remote_script_path) + return(output) + + +def push_agent(hostname, port, username, password, local_script_path, remote_script_path): ssh = paramiko.SSHClient() try: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) @@ -23,6 +29,22 @@ def get_remote(hostname, port, username, password, local_script_path, remote_scr finally: ssh.close() + +def pull_agent(hostname, port, username, password, remote_script_path): + ssh = paramiko.SSHClient() + try: + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(hostname, port, username, password) + stdin, stdout, stderr = ssh.exec_command(f"python3 {remote_script_path}") + output = stdout.read().decode() + return(output) + + finally: + ssh.close() + + + + def get_boot_time(psboot): boot_time = datetime.fromtimestamp(psboot - 60) return str(boot_time) diff --git a/templates/index.html b/templates/index.html index 05bcabe..d787dc9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -53,7 +53,8 @@ Environnement
-
{{ full['hostname'] }}
+
{{ full['hostname'].capitalize() }}
+
OS : {{ full['os'].capitalize() }}
CPU : {{ full['cpu_number'] }}
vCPU : {{ full['vcpu'] }}
Memory : {{ full['mem_max']}}