建立 /opt/kaspersky/ksmg-appliance-addon/bin/hastat 檔案,向其新增以下字串:#!/bin/env python3
匯入通訊端
columns = [ 'pxname', 'svname', 'status' ]
out_form = '{:<20} | {:<20} | {}'
out_line = '-' * 68
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect('/var/lib/haproxy/stats')
s.sendall('show stat\n'.encode())
response = s.recv(65000)
s.close()
rows = response.decode().split('\n')
headers = rows.pop(0)[2:].strip().split(',')
indexes = [ headers.index(c) for c in columns ]
print(out_line)
print(out_form.format(*columns))
print(out_line)
for row in rows:
vals = row.split(',')
if len(vals) >= len(headers):
data = [ vals[p] for p in indexes ]
print(out_form.format(*data))
print(out_line)