SPRKLstats/services.py

26 lines
864 B
Python

# Author: Stefan Weijers https://github.com/Stxfie
import os
from config import bcolors,env
def genLine(name, status, time):
if status == 'active': return '[' + name + '] [' + bcolors.EMPTY + '' + bcolors.RESET + '] [' + bcolors.EMPTY + time + bcolors.RESET + ']'
if status == 'inactive': return '[' + name + '] [' + bcolors.FULL + '' + bcolors.RESET + '] [' + bcolors.FULL + 'N/A' + bcolors.RESET + ']'
statuscmd = 'systemctl is-active {}'
timecmd = 'systemctl status {} | grep -Po \".*; \K(.*)(?= ago)\"'
statuslist = {}
timelist = {}
srv = env.services.keys()
for s in srv:
statuslist.update({s : os.popen(statuscmd.format(s)).read()})
timelist.update({s : os.popen(timecmd.format(s)).read()})
print("Services running:")
for s in srv:
print(genLine(env.services[s], statuslist[s].strip('\n'), timelist[s].strip('\n')))