/usr/lib/imh-ultrastack-common/venv/lib/python3.13/site-packages/ngxutil
NameSizeModeActions
__pycache__/-0755rm
api.py47230644editdlrm
cache.py69380644editdlrm
cli.py107020644editdlrm
info.py149160644editdlrm
logparse.py105370644editdlrm
profile.py17580644editdlrm
report.py146180644editdlrm
sendmail.py13740644editdlrm
util.py28880644editdlrm
vts.py17100644editdlrm
__init__.py4050644editdlrm
Edit: /usr/lib/imh-ultrastack-common/venv/lib/python3.13/site-packages/ngxutil/vts.py (1710B)
#!/opt/imh-python/bin/python3.9 # vim: set ts=4 sw=4 expandtab syntax=python: """ ngxutil.vts VTS Parser & Formatter @author J. Hipps """ import logging import socket import json import re from ngxutil import default_vts_socket_path logger = logging.getLogger('ngxutil') def parse_vts(sockpath=default_vts_socket_path, uri='/vstatus'): """ Parse VTS data from socket @sock """ # Connect to UNIX socket try: sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(sockpath) except Exception as e: logger.error("Failed to connect to socket [%s]: %s", sockpath, str(e)) return None sock.settimeout(0.5) # Send HTTP request over UNIX socket m_req = "GET {} HTTP/1.0\nHost: localhost\n\n\n".format(uri).encode('utf8', errors='ignore') try: rawdata = bytes() while True: sock.sendall(m_req) lastdata = sock.recv(524288) if not len(lastdata): break rawdata += lastdata sock.close() except Exception as e: logger.error("Failed to retrieve data from socket: %s", str(e)) return None # Parse response try: r_head, r_body = re.match('^(.+)\r\n\r\n(.+)$', rawdata.decode('utf8', errors='ignore'), re.S).groups() except: logger.error("Failed to parse response body") return None # Parse JSON body try: logger.debug("Got data from VTS:\n%s", r_body.strip()) vdata = json.loads(r_body.strip()) except Exception as e: logger.error("Failed to parse JSON response body: %s", str(e)) return None return vdata