Files
SnarfCode/scripts/test_live_ssh_alert.py

33 lines
1.2 KiB
Python

import paramiko
import sys
import time
sys.stdout.reconfigure(encoding='utf-8')
key_path = r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet'
print("--- Sending SSH probe from Spaceport to 14.4.4.99 ---")
sp = paramiko.SSHClient()
sp.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sp.connect("140.44.4.41", username="root", key_filename=key_path, timeout=10)
stdin, stdout, stderr = sp.exec_command("ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 -o BatchMode=yes admin@14.4.4.99 2>&1 || true")
print("SSH probe output:", stdout.read().decode())
sp.close()
time.sleep(2)
print("--- Checking Watcher Logs on 140.44.4.71 ---")
sw = paramiko.SSHClient()
sw.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sw.connect("140.44.4.71", username="root", key_filename=key_path, timeout=10)
stdin, stdout, stderr = sw.exec_command("journalctl -u opencanary-watcher.service -n 10 --no-pager")
print(stdout.read().decode())
print("\n--- Checking Gotify Messages ---")
stdin, stdout, stderr = sw.exec_command("sqlite3 /var/lib/docker/volumes/gotify_gotify_data/_data/gotify.db 'SELECT id, appid, title, message, date FROM messages WHERE appid = 6 ORDER BY id DESC LIMIT 5;'")
print(stdout.read().decode())
sw.close()