56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
import subprocess
|
|
import re
|
|
|
|
|
|
compute_nodes = [
|
|
"compute3", "compute4", "compute5", "compute6", "compute9", "compute10", "compute11", "compute12",
|
|
"compute13", "compute14", "compute15", "compute16", "compute17",
|
|
"compute18", "compute19", "compute20", "compute21", "compute22",
|
|
"compute23", "compute24", "compute25", "compute26", "compute27",
|
|
"compute28", "compute29", "compute30", "compute31", "compute32"
|
|
]
|
|
|
|
password = 'Ku643%^#@3&h6543agVfrTy98#4'
|
|
|
|
|
|
|
|
for node in compute_nodes:
|
|
running_service = []
|
|
inactive_service = []
|
|
error_service = []
|
|
cmd = ["sshpass","-p", password, "ssh", f"sysadmin@{node}", "-p", "58923","status"]
|
|
print(f"\n\nConnecting to {node}.....")
|
|
data_output=str(subprocess.run(cmd, capture_output=True, text=True).stdout)
|
|
service_blocks = re.split(r"-{10,}#+.*?status.*?#+-+", data_output)
|
|
|
|
|
|
|
|
|
|
for block in service_blocks:
|
|
match = re.search(r"●\s+(\S+)\s+-\s+(.+?)\n.*?Active:\s+(\S+)", block, re.DOTALL)
|
|
if match:
|
|
service_name = match.group(1)
|
|
description = match.group(2).strip()
|
|
status = match.group(3).strip()
|
|
|
|
if status == "active":
|
|
running_service.append(service_name)
|
|
elif status == "inactive":
|
|
inactive_service.append(service_name)
|
|
|
|
if "error" in block.lower() or "failed" in block.lower():
|
|
if service_name not in error_service:
|
|
error_service.append(service_name)
|
|
|
|
|
|
print (len(running_service), "services are running")
|
|
print (len(inactive_service), "services are inactive")
|
|
for inactive in inactive_service:
|
|
print("|")
|
|
print (" ---" ,inactive, "is inactive")
|
|
print (len(error_service), "services are in error state")
|
|
for error in error_service:
|
|
print("|")
|
|
print (" ---" ,error, "has error")
|
|
|