Skip to content

Commit

Permalink
Fix OS detection for non-systemd hosts (deprecated with Python 3.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
widhalmt committed Nov 7, 2019
1 parent eb25ffe commit 5aba523
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions icinga-diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ def __init__(self):
if self.os != "Linux":
self.distro = "n/a"
else:
hostnamectl_output = str(subprocess.check_output(["hostnamectl"])).splitlines()
for line in hostnamectl_output:
if "Operating System" in line:
self.distro = line.split(':')[1]
try:
hostnamectl_output = str(subprocess.check_output(["hostnamectl"])).splitlines()
for line in hostnamectl_output:
if "Operating System" in line:
self.distro = str(line.split(':')[1])
except AttributeError:
self.distro = platform.linux_distribution()[0] + " " + platform.linux_distribution()[1]
self.pythonversion = sys.version.split('\n')[0]
self.cpucores = multiprocessing.cpu_count()
self.memory = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES'))//(1024.**3)
Expand Down

0 comments on commit 5aba523

Please sign in to comment.