Fixed fortune plugin failures

On alpine containers the fortune options aren't all available
and we were silently failing.  Updated the fortune plugin to capture
shell failures.
This commit is contained in:
Hemna 2021-01-11 14:13:20 -05:00
parent 76bbdfc728
commit 7ab26135c2
1 changed files with 11 additions and 8 deletions

View File

@ -24,14 +24,17 @@ class FortunePlugin(plugin.APRSDPluginBase):
return reply
try:
process = subprocess.Popen(
[fortune_path, "-s", "-n 60"],
stdout=subprocess.PIPE,
cmnd = [fortune_path, "-s", "-n 60"]
command = " ".join(cmnd)
output = subprocess.check_output(
command,
shell=True,
timeout=3,
universal_newlines=True,
)
reply = process.communicate()[0]
reply = reply.decode(errors="ignore").rstrip()
except Exception as ex:
reply = "Fortune command failed '{}'".format(ex)
LOG.error(reply)
except subprocess.CalledProcessError as ex:
reply = "Fortune command failed '{}'".format(ex.output)
else:
reply = output
return reply