Merge "Fix psutil inconsistencies"

This commit is contained in:
Zuul 2019-10-10 14:51:52 +00:00 committed by Gerrit Code Review
commit 34aed6f20c
2 changed files with 38 additions and 36 deletions

View File

@ -148,25 +148,26 @@ def tcp_socket_state_check(agentq):
rabbitmq_ports = get_rabbitmq_ports()
for pr in psutil.pids():
for p in psutil.process_iter():
try:
p = psutil.Process(pr)
if p.name() == proc:
if parentId == 0:
parentId = p.pid
else:
if p.ppid() == parentId:
continue
pcon = p.connections()
for con in pcon:
try:
port = con.raddr[1]
status = con.status
except IndexError:
continue
if port in rabbitmq_ports and status == tcp_established:
rabbit_sock_count = rabbit_sock_count + 1
except psutil.NoSuchProcess:
with p.oneshot():
if proc in " ".join(p.cmdline()):
if parentId == 0:
parentId = p.pid
else:
if p.ppid() == parentId:
continue
pcon = p.connections()
for con in pcon:
try:
port = con.raddr[1]
status = con.status
except IndexError:
continue
if port in rabbitmq_ports and\
status == tcp_established:
rabbit_sock_count = rabbit_sock_count + 1
except psutil.Error:
continue
if rabbit_sock_count == 0:

View File

@ -90,25 +90,26 @@ def tcp_socket_status(process, ports):
"""Check the tcp socket status on a process"""
sock_count = 0
parentId = 0
for pr in psutil.pids():
for p in psutil.process_iter():
try:
p = psutil.Process(pr)
if p.name() == process:
if parentId == 0:
parentId = p.pid
else:
if p.ppid() == parentId and not cfg.CONF.check_all_pids:
continue
pcon = p.connections()
for con in pcon:
try:
rport = con.raddr[1]
status = con.status
except IndexError:
continue
if rport in ports and status == tcp_established:
sock_count = sock_count + 1
except psutil.NoSuchProcess:
with p.oneshot():
if process in " ".join(p.cmdline()):
if parentId == 0:
parentId = p.pid
else:
if p.ppid() == parentId and \
not cfg.CONF.check_all_pids:
continue
pcon = p.connections()
for con in pcon:
try:
rport = con.raddr[1]
status = con.status
except IndexError:
continue
if rport in ports and status == tcp_established:
sock_count = sock_count + 1
except psutil.Error:
continue
if sock_count == 0: