Files
SnarfCode/scripts/deploy_zabbix_21.py

47 lines
1.4 KiB
Python

import sys, paramiko, time
sys.stdout.reconfigure(encoding='utf-8')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('140.44.4.21', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
script = """#!/bin/bash
set -e
mkdir -p /etc/zabbix
echo "a1142332ccfa9c53040e36171bb551ceb2865fb4051d203404df39e88ebe94f0" > /etc/zabbix/zabbix_agent2.psk
chmod 600 /etc/zabbix/zabbix_agent2.psk
chown zabbix:zabbix /etc/zabbix/zabbix_agent2.psk 2>/dev/null || true
cat << 'EOF' > /etc/zabbix/zabbix_agent2.conf
Server=zabbix.snarfnet.net
ServerActive=zabbix.snarfnet.net
HostnameItem=system.hostname
HostMetadata=Linux
TLSConnect=psk
TLSAccept=psk
TLSPSKIdentity=PSK_autoregister
TLSPSKFile=/etc/zabbix/zabbix_agent2.psk
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=10
BufferSend=5
BufferSize=100
EOF
systemctl enable --now zabbix-agent2.service
systemctl restart zabbix-agent2.service
sleep 2
systemctl is-active zabbix-agent2.service
"""
stdin, stdout, stderr = ssh.exec_command(script)
print("OUT:", stdout.read().decode('utf-8', errors='replace').strip())
print("ERR:", stderr.read().decode('utf-8', errors='replace').strip())
time.sleep(3)
stdin, stdout, stderr = ssh.exec_command("tail -n 15 /var/log/zabbix/zabbix_agent2.log")
print("\nLOG:\n", stdout.read().decode('utf-8', errors='replace'))
ssh.close()