Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,28 +3,46 @@ import paramiko
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
def test_antena_remota(ip, usuario, password):
|
| 6 |
-
"""
|
| 7 |
-
Conecta a UNA antena remota y obtiene m茅tricas REALES
|
| 8 |
-
"""
|
| 9 |
try:
|
| 10 |
-
# 1. Conexi贸n SSH
|
| 11 |
ssh = paramiko.SSHClient()
|
| 12 |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
| 13 |
ssh.connect(ip, username=usuario, password=password, timeout=10)
|
| 14 |
|
| 15 |
-
# 2. Comandos para m茅tricas REALES
|
| 16 |
-
print("Ejecutando comandos en el equipo...")
|
| 17 |
-
|
| 18 |
-
# Comando principal para obtener todas las m茅tricas
|
| 19 |
stdin, stdout, stderr = ssh.exec_command("mca-status")
|
| 20 |
mca_output = stdout.read().decode()
|
| 21 |
-
|
| 22 |
ssh.close()
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
def test_antena_remota(ip, usuario, password):
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
|
|
|
| 7 |
ssh = paramiko.SSHClient()
|
| 8 |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
| 9 |
ssh.connect(ip, username=usuario, password=password, timeout=10)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
stdin, stdout, stderr = ssh.exec_command("mca-status")
|
| 12 |
mca_output = stdout.read().decode()
|
|
|
|
| 13 |
ssh.close()
|
| 14 |
|
| 15 |
+
resultado = f"# TEST EXITOSO - {ip}\n\n"
|
| 16 |
+
resultado += "## METRICAS OBTENIDAS:\n"
|
| 17 |
+
resultado += f"```\n{mca_output[:800]}\n```\n\n"
|
| 18 |
+
resultado += f"**Hora:** {time.strftime('%H:%M:%S')}"
|
| 19 |
+
|
| 20 |
+
return resultado
|
| 21 |
+
|
| 22 |
+
except Exception as e:
|
| 23 |
+
error_msg = f"# ERROR DE CONEXION\n\n"
|
| 24 |
+
error_msg += f"**IP:** {ip}\n"
|
| 25 |
+
error_msg += f"**Error:** {str(e)}\n"
|
| 26 |
+
error_msg += f"**Hora:** {time.strftime('%H:%M:%S')}"
|
| 27 |
+
return error_msg
|
| 28 |
|
| 29 |
+
with gr.Blocks(title="Test Ubiquiti") as demo:
|
| 30 |
+
gr.Markdown("# Test Antena Ubiquiti")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
ip_input = gr.Textbox(label="IP del Equipo", placeholder="192.168.1.20")
|
| 35 |
+
usuario_input = gr.Textbox(label="Usuario", value="ubnt")
|
| 36 |
+
password_input = gr.Textbox(label="Contrasena", type="password")
|
| 37 |
+
test_btn = gr.Button("Ejecutar Test", variant="primary")
|
| 38 |
+
|
| 39 |
+
with gr.Column():
|
| 40 |
+
resultado_output = gr.Markdown()
|
| 41 |
+
|
| 42 |
+
test_btn.click(
|
| 43 |
+
fn=test_antena_remota,
|
| 44 |
+
inputs=[ip_input, usuario_input, password_input],
|
| 45 |
+
outputs=resultado_output
|
| 46 |
+
)
|
| 47 |
|
| 48 |
+
demo.launch()
|