mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
[monit_parser] replace 'commands' module with 'subprocess'
necessary for python3 support
This commit is contained in:
parent
0f24fe00eb
commit
9d62e55896
@ -8,9 +8,11 @@
|
|||||||
|
|
||||||
STATUS_CMD = "monit status"
|
STATUS_CMD = "monit status"
|
||||||
|
|
||||||
import sys
|
import os
|
||||||
import re
|
import re
|
||||||
from commands import getstatusoutput
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def sanitize(s):
|
def sanitize(s):
|
||||||
OK_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789"
|
OK_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
@ -22,12 +24,16 @@ def sanitize(s):
|
|||||||
|
|
||||||
procs = dict()
|
procs = dict()
|
||||||
|
|
||||||
status, output = getstatusoutput(STATUS_CMD)
|
try:
|
||||||
if status != 0:
|
output = subprocess.check_output(STATUS_CMD.split())
|
||||||
print "Errror running status command: %s" % (output)
|
except (OSError, subprocess.CalledProcessError) as exc:
|
||||||
sys.exit(status)
|
sys.stderr.write("Error running monit status command: %s%s" % (exc, os.linesep))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
output = output.split('\n')
|
# python3: the result of command execution is bytes and needs to be converted
|
||||||
|
if not isinstance(output, str):
|
||||||
|
output = output.decode("ascii", "ignore")
|
||||||
|
output = output.splitlines()
|
||||||
cur_proc = None
|
cur_proc = None
|
||||||
for line in output:
|
for line in output:
|
||||||
m = re.match("^Process '(.*)'.*$", line)
|
m = re.match("^Process '(.*)'.*$", line)
|
||||||
|
Loading…
Reference in New Issue
Block a user