def find_status():
"""This util is used to find the status of
sshd service. It will identify sshd status using
process id of sshd service.
input:
(No input required)
output:
{"name": "",
"port": "",
"status": ""}
"""
sshd = {"name": "",
"port": "",
"status": ""}
cmd = cmd_utils.Command("systemctl show sshd.service")
out, err, rc = cmd.run()
if not err:
pid = _find_pid(out)
if pid != 0:
p = psutil.Process(pid)
result = [con for con in p.connections() if con.status ==
psutil.CONN_LISTEN and con.laddr[0] == "0.0.0.0"]
if result:
sshd["name"] = p.name()
sshd["port"] = int(result[0].laddr[1])
sshd["status"] = result[0].status
else:
err = "Unable to find ssh port number"
Event(
Message(
priority="debug",
publisher="commons",
payload={"message": err}
)
)
else:
err = "sshd service is not running"
Event(
Message(
priority="debug",
publisher="commons",
payload={"message": err}
)
)
else:
Event(
Message(
priority="debug",
publisher="commons",
payload={"message": err}
)
)
return sshd, err
评论列表
文章目录