zioinfo-mail/scripts/check/verify_guardia_itsm.py
2026-06-01 21:55:48 +09:00

51 lines
2.4 KiB
Python

"""GUARDiA ITSM 서버 배포 상태 전체 검증"""
import paramiko, sys, json, base64
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15)
def run(label, cmd, timeout=20):
_, o, _ = c.exec_command(cmd, timeout=timeout)
print(f'\n[{label}]\n' + o.read().decode('utf-8','replace').strip()[:800])
# 1. 서버 git 최신 커밋
run('서버 /opt/guardia/app git 커밋',
'git -C /opt/guardia/app log -3 --oneline 2>/dev/null || echo "git 없음"')
run('서버 /opt/guardia/src git 커밋',
'git -C /opt/guardia/src log -3 --oneline 2>/dev/null || echo "git 없음"')
# 2. Gitea 최신 커밋
GITEA_B64 = base64.b64encode(b'zio:Zio@Admin2026!').decode()
run('Gitea guardia-itsm 최신 커밋',
f"curl -sf 'http://127.0.0.1:9003/api/v1/repos/zio/guardia-itsm/commits?limit=3' "
f"-H 'Authorization: Basic {GITEA_B64}' 2>/dev/null | "
"python3 -c \"import sys,json; "
"[print(c['sha'][:8], c['commit']['message'][:60]) for c in json.load(sys.stdin)]\" 2>/dev/null")
# 3. workspace vs 서버 핵심 파일 비교
run('서버 routers 목록',
'ls /opt/guardia/app/routers/*.py 2>/dev/null | xargs -I{} basename {} | sort')
run('서버 routers 개수', 'ls /opt/guardia/app/routers/*.py 2>/dev/null | wc -l')
# 4. 핵심 최신 기능 파일 존재 확인 (DR, CSAP, network, RPA, scraping)
run('최신 기능 파일 존재 여부',
'''for f in dr.py network_devices.py compliance.py rpa.py scraping.py ai_cmd.py; do
[ -f "/opt/guardia/app/routers/$f" ] && echo "✅ $f" || echo "❌ $f 없음"
done''')
# 5. 서버 서비스 상태 및 API 응답
run('guardia 서비스 상태',
'systemctl is-active guardia && systemctl status guardia --no-pager | grep -E "Active|Main PID" | head -3')
run('ITSM API 응답 확인',
'curl -sf http://localhost:8001/health 2>/dev/null || '
'curl -sf http://localhost:8001/docs 2>/dev/null | head -3 || '
'curl -sf http://localhost:9001/health 2>/dev/null || echo "API 확인 필요"')
# 6. 서버 stash 여부 (혹시 못 올린 작업 있는지)
run('서버 /opt/guardia/src stash',
'git -C /opt/guardia/src stash list 2>/dev/null || echo "stash 없음"')
run('서버 uncommitted 변경',
'git -C /opt/guardia/src status --short 2>/dev/null | head -10 || echo "없음"')
c.close()