feat: add various infrastructure check and automation scripts
This commit is contained in:
84
scripts/investigate_kuma_npm_db.py
Normal file
84
scripts/investigate_kuma_npm_db.py
Normal file
@@ -0,0 +1,84 @@
|
||||
import paramiko
|
||||
import json
|
||||
import urllib.request
|
||||
import ssl
|
||||
|
||||
SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
|
||||
|
||||
def run_ssh(host, user, password, cmd, sudo=False):
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
try:
|
||||
client.connect(host, username=user, key_filename=SSH_KEY, password=password, timeout=10)
|
||||
full_cmd = f"echo {password} | sudo -S sh -c '{cmd}'" if sudo else cmd
|
||||
stdin, stdout, stderr = client.exec_command(full_cmd)
|
||||
out = stdout.read().decode('utf-8', errors='ignore').strip()
|
||||
err = stderr.read().decode('utf-8', errors='ignore').strip()
|
||||
client.close()
|
||||
return out, err
|
||||
except Exception as e:
|
||||
return "", str(e)
|
||||
|
||||
print("=== 1. NPM PROXY HOSTS LIST ===")
|
||||
out, _ = run_ssh("140.44.4.71", "snarf", "Katzir476!", "docker exec $(docker ps -q -f name=nginx-proxy-manager) ls -la /data/nginx/proxy_host/", sudo=True)
|
||||
print("Proxy host files:")
|
||||
print(out)
|
||||
|
||||
# Search for heimdall in all files under /data/nginx
|
||||
out, _ = run_ssh("140.44.4.71", "snarf", "Katzir476!", "docker exec $(docker ps -q -f name=nginx-proxy-manager) grep -r 'heimdall' /data/nginx/", sudo=True)
|
||||
print("Heimdall occurrences in /data/nginx:")
|
||||
print(out)
|
||||
|
||||
print("\n=== 2. SWARM SERVICES & UPTIME KUMA LOCATION ===")
|
||||
out, _ = run_ssh("140.44.4.71", "snarf", "Katzir476!", "docker service ls", sudo=True)
|
||||
print(out)
|
||||
|
||||
print("\n=== 3. HEIMDALL DATABASE CONTENT ===")
|
||||
py_check = '''python3 - << 'PYEOF'
|
||||
import sqlite3
|
||||
|
||||
db = '/var/lib/docker/volumes/heimdall_heimdall_config/_data/www/app.sqlite'
|
||||
con = sqlite3.connect(db)
|
||||
cur = con.cursor()
|
||||
print("USERS:")
|
||||
for r in cur.execute("SELECT id, username, email, public_front FROM users").fetchall():
|
||||
print(r)
|
||||
|
||||
print("\nITEMS:")
|
||||
for r in cur.execute("SELECT id, title, url, pinned, user_id FROM items").fetchall():
|
||||
print(r)
|
||||
|
||||
print("\nSETTINGS:")
|
||||
for r in cur.execute("SELECT * FROM settings").fetchall():
|
||||
print(r)
|
||||
PYEOF
|
||||
'''
|
||||
out, err = run_ssh("140.44.4.71", "snarf", "Katzir476!", py_check, sudo=True)
|
||||
print(out if out else err)
|
||||
|
||||
print("\n=== 4. ZABBIX ALL HOSTS ===")
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
|
||||
def zabbix_api(method, params, auth=None):
|
||||
payload = {"jsonrpc": "2.0", "method": method, "params": params, "id": 1}
|
||||
if auth: payload["auth"] = auth
|
||||
req = urllib.request.Request("https://zabbix.snarfnet.net/api_jsonrpc.php",
|
||||
data=json.dumps(payload).encode('utf-8'),
|
||||
headers={"Content-Type": "application/json-rpc"})
|
||||
try:
|
||||
resp = urllib.request.urlopen(req, context=ctx, timeout=10)
|
||||
return json.loads(resp.read().decode('utf-8'))
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
|
||||
auth = zabbix_api("user.login", {"username": "Admin", "password": "zabbix"}).get("result")
|
||||
if auth:
|
||||
hosts = zabbix_api("host.get", {"output": ["hostid", "host", "name", "status"], "selectInterfaces": ["ip"]}, auth=auth).get("result", [])
|
||||
print(f"Total Zabbix Hosts: {len(hosts)}")
|
||||
print("Sample hosts:")
|
||||
for h in hosts[:20]:
|
||||
ips = [i['ip'] for i in h.get('interfaces', [])]
|
||||
print(f" {h['host']} ({h['name']}): IPs={ips}, status={h['status']}")
|
||||
|
||||
Reference in New Issue
Block a user