Создайте файл /opt/kaspersky/ksmg/bin/hastat и добавьте в него следующие строки:#!/bin/env python3
import socket
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)