housekeeping and cleanups...
This commit is contained in:
parent
dc0c54bc5b
commit
88b0c3dd7a
5 changed files with 23 additions and 33 deletions
|
|
@ -52,7 +52,7 @@ def parseHostGroupList(hostgroups, hosts, members, periods, services, log):
|
|||
if service is not None:
|
||||
services.append(service)
|
||||
else:
|
||||
log.w("could not find HostService(" +str(serviceName) + ") for host " + host.name)
|
||||
log.w("could not find HostService(" + str(serviceName) + ") for host " + host.name)
|
||||
hostGroupPeriods = [p for p in periods if p.name in servicePeriods]
|
||||
hostGroup.services.append(HostGroupService(services, hostGroupPeriods))
|
||||
parsedHostGroups.append(hostGroup)
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ class HostService:
|
|||
ret += "warning: " + str(self.warning)
|
||||
if self.critical:
|
||||
ret += "critical: " + str(self.critical)
|
||||
return ret;
|
||||
return ret
|
||||
|
||||
|
||||
def parseHostList(hosts, services, log):
|
||||
"""
|
||||
parse the HostList and replace any command as nessesary
|
||||
parse the HostList and replace any command as necessary
|
||||
"""
|
||||
#precompiled regexPattern which finds replacements in service strings
|
||||
pattern = re.compile("@(\w+)")
|
||||
|
|
@ -97,7 +97,7 @@ def parseHostList(hosts, services, log):
|
|||
#host will not be inside ServiceParameters, so check this also
|
||||
if 'host' in replacements:
|
||||
log.d("replacing host in " + hostService.getCommand())
|
||||
comm= re.sub('@host', host.host, hostService.getCommand())
|
||||
comm = re.sub('@host', host.host, hostService.getCommand())
|
||||
hostService.setCommand(comm)
|
||||
log.d("new Command: " +comm)
|
||||
log.d("set in hostService: " + str(hostService))
|
||||
|
|
|
|||
|
|
@ -10,19 +10,19 @@ class Command:
|
|||
self.output = None
|
||||
self.error = None
|
||||
self.retcode = 0
|
||||
self.commandStart=0
|
||||
self.commandStart = 0
|
||||
|
||||
def __str__(self):
|
||||
return self.command
|
||||
|
||||
def call(self):
|
||||
'''
|
||||
self.commandStart = dt.now()
|
||||
"called at: "
|
||||
process = sp.Popen(stdout=PIPE, *popenargs, **kwargs)
|
||||
self.output, self.error = process.communicate()
|
||||
self.retcode = process.poll()
|
||||
'''
|
||||
|
||||
# self.commandStart = dt.now()
|
||||
# "called at: "
|
||||
# process = sp.Popen(stdout=PIPE, *popenargs, **kwargs)
|
||||
# self.output, self.error = process.communicate()
|
||||
# self.retcode = process.poll()
|
||||
|
||||
try:
|
||||
self.commandStart = dt.now()
|
||||
self.log.i("calling command " + str(self.command) + " at " + str(self.commandStart))
|
||||
|
|
@ -33,10 +33,9 @@ class Command:
|
|||
self.log.d(str(self.error))
|
||||
self.retcode = process.poll()
|
||||
except CalledProcessError:
|
||||
self.error=CalledProcessError.output
|
||||
self.error = CalledProcessError.output
|
||||
self.retcode = CalledProcessError.returncode
|
||||
|
||||
|
||||
def getOutput(self):
|
||||
return self.output
|
||||
|
||||
|
|
@ -48,4 +47,3 @@ class Command:
|
|||
|
||||
def getReturnCode(self):
|
||||
return self.retcode
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ execute.
|
|||
|
||||
from command import Command
|
||||
|
||||
|
||||
def generateId():
|
||||
i=0
|
||||
i = 0
|
||||
while True:
|
||||
yield i
|
||||
i+=1
|
||||
yield i
|
||||
i += 1
|
||||
|
||||
|
||||
class JobInfo:
|
||||
def __init__(self, hostgroupname, members, hosts, hostServices, threshold, parent=None):
|
||||
|
|
@ -46,18 +48,8 @@ class JobInfo:
|
|||
|
||||
for hs in self.hostServices:
|
||||
self.log.d(str(hs))
|
||||
cmd=Command(hs.service.command, self.log)
|
||||
cmd = Command(hs.service.command, self.log)
|
||||
cmd.call()
|
||||
self.log.d(cmd.getAllOutput())
|
||||
except Exception:
|
||||
self.log.d(Exception)
|
||||
|
||||
|
||||
#must find real service command stored in hosts...
|
||||
#but because of error, mentioned in NOTES,ruff, there is no ping i.e.
|
||||
|
||||
#cmd = Command(service.command)
|
||||
#self.log.d("executing command: " + str(command))
|
||||
#cmd.call()
|
||||
#return cmd
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue