fixed compatibility with newer systemd versions
This commit is contained in:
parent
4e45885de3
commit
a94e45a7c7
|
@ -12,9 +12,15 @@
|
||||||
#
|
#
|
||||||
###################################################
|
###################################################
|
||||||
|
|
||||||
from sys import argv, path, stderr, exit
|
from sys import argv
|
||||||
|
from sys import path
|
||||||
|
from sys import stderr
|
||||||
|
from sys import exit
|
||||||
|
from subprocess import Popen
|
||||||
|
from subprocess import PIPE
|
||||||
|
from subprocess import DEVNULL
|
||||||
|
from subprocess import getstatusoutput
|
||||||
import psutil
|
import psutil
|
||||||
from subprocess import *
|
|
||||||
|
|
||||||
global module_list
|
global module_list
|
||||||
module_list = []
|
module_list = []
|
||||||
|
@ -116,7 +122,7 @@ def service_module(name, value, parent=None):
|
||||||
"value" : value,
|
"value" : value,
|
||||||
"module_parent" : parent,
|
"module_parent" : parent,
|
||||||
}]
|
}]
|
||||||
#print ("service_module END "+str(now(0,1)))
|
#print ("service_module END "+str(now(0,1)))
|
||||||
return (module)
|
return (module)
|
||||||
|
|
||||||
def get_memcpu (process, servicename):
|
def get_memcpu (process, servicename):
|
||||||
|
@ -169,7 +175,7 @@ def win_service(servicelist, option=False, memcpu=False):
|
||||||
if output != None and output["modules"]:
|
if output != None and output["modules"]:
|
||||||
modules += PSCheck.check_service(srvc.strip(), option, memcpu)["modules"]
|
modules += PSCheck.check_service(srvc.strip(), option, memcpu)["modules"]
|
||||||
module_list.append(srvc)
|
module_list.append(srvc)
|
||||||
winprocess = output["name"]
|
#winprocess = output["name"]
|
||||||
#if memcpu == True:
|
#if memcpu == True:
|
||||||
# modules += get_memcpu(winprocess) ## Only available for parent service ATM.
|
# modules += get_memcpu(winprocess) ## Only available for parent service ATM.
|
||||||
else:
|
else:
|
||||||
|
@ -189,18 +195,19 @@ def lnx_service(services_list, memcpu=False):
|
||||||
status = None
|
status = None
|
||||||
if sysctl == 0:
|
if sysctl == 0:
|
||||||
### Systemd available
|
### Systemd available
|
||||||
syscall = Popen(["systemctl", "is-active", srvc], stdout=PIPE,
|
syscall = Popen(["systemctl", "show", "-pLoadState", "-pActiveState", srvc], stdout=PIPE,
|
||||||
stdin=DEVNULL, universal_newlines=True)
|
stdin=DEVNULL, universal_newlines=True)
|
||||||
result = syscall.communicate()
|
result = syscall.communicate()
|
||||||
result = result[0].strip().lower()
|
srvstatus= result[0].strip().lower().split("\n")
|
||||||
if result == "active":
|
if srvstatus[0] == "loadstate=not-found":
|
||||||
modules += service_module(srvc, 1)
|
|
||||||
status = 1
|
|
||||||
elif result == "inactive":
|
|
||||||
modules += service_module(srvc, 0)
|
|
||||||
status = 0
|
|
||||||
elif result == "unknown":
|
|
||||||
next
|
next
|
||||||
|
else:
|
||||||
|
if srvstatus[1] == "activestate=active":
|
||||||
|
modules += service_module(srvc, 1)
|
||||||
|
status = 1
|
||||||
|
elif srvstatus[1] == "activestate=inactive":
|
||||||
|
modules += service_module(srvc, 0)
|
||||||
|
status = 0
|
||||||
elif sysctl != 0 and servic == 0:
|
elif sysctl != 0 and servic == 0:
|
||||||
### Systemd not available, switch to service command
|
### Systemd not available, switch to service command
|
||||||
syscall = Popen(["service", srvc, "status"], stdout=PIPE,
|
syscall = Popen(["service", srvc, "status"], stdout=PIPE,
|
||||||
|
@ -382,7 +389,7 @@ def discover(osyst, servicelist):
|
||||||
print ("--help")
|
print ("--help")
|
||||||
print ("\tPrints this help screen")
|
print ("\tPrints this help screen")
|
||||||
print ("--default")
|
print ("--default")
|
||||||
print ("\tRuns this tool with default monitoring.".format(argv[0]))
|
print ("\tRuns this tool with default monitoring.")
|
||||||
print ("\tServices monitored by default for {}:".format(osyst))
|
print ("\tServices monitored by default for {}:".format(osyst))
|
||||||
print ("\t",", ".join(servicelist))
|
print ("\t",", ".join(servicelist))
|
||||||
print ("--list \"<srvc1,srvc2,srvc3>\"")
|
print ("--list \"<srvc1,srvc2,srvc3>\"")
|
||||||
|
|
Loading…
Reference in New Issue