Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.8 #2

Open
martindemharter opened this issue Oct 15, 2020 · 5 comments
Open

Python3.8 #2

martindemharter opened this issue Oct 15, 2020 · 5 comments

Comments

@martindemharter
Copy link

Hello everybody,

this script won't work on python3.8 onward anymore. The function platform.linux_distribution() was deprecated with python 3.5 and removed with 3.8. The function platform.uname() is not really helpful for CentOS/RedHat Distributions, so i went the route of /etc/os-release and parsing the relevant part.

It is tested and works for Python 3.6.9 (on Ubuntu 18.04.5) and Python 3.8.5 (on Ubuntu 20.04.1) as well as CentOS 8.2.2004 with Python 3.8.0.

@winem
Copy link
Owner

winem commented Oct 15, 2020

Hi,

thanks for the heads up. I'll fix this soon.

@martindemharter
Copy link
Author

i already did a fix. just cannot open pull request.

@martindemharter
Copy link
Author

martindemharter commented Oct 15, 2020

This is basically what i did + removing import plaform:

def get_os():
    if os.name == 'posix':
        os_family = linux_distrib()
    else:
        print("Unsupported operating system.")
        sys.exit(3)
    return os_family

# checks for os-release file to extract os type. Fix for Python3.8 platform.linux_distribution() removal.
def linux_distrib():
    f = open("/etc/os-release")
    os_family = str(f.readline()) # read first line of file. there usually you find >NAME="Ubuntu"< or >NAME="CentOS Linux"<
    return os_family.split('\"')[1] # removing the >NAME=""< part

def main(args):
    os_family = get_os()
    if args.chk_resource.lower() == 'leapstatus':
        if 'Ubuntu' in os_family:
            timesyncd_monitoring = timedatectlStatus()
            resultToIcinga(timesyncd_monitoring)
        elif os_family == "Red Hat Enterprise Linux" or os_family == "CentOS Linux":
            chronyc_monitoring = chronycTracking()
            resultToIcinga(chronyc_monitoring)
        else:
            print('Unsupported operating system.')
            sys.exit(3)

@as149
Copy link

as149 commented Aug 13, 2021

Hi,

an other simple Solution is to change the code as followed:

@@ -4,13 +4,13 @@
 import csv
 import io
 import os
-import platform
+import distro
 import socket
 import subprocess
 import sys

 def main(args):
-    os_family           = platform.linux_distribution()[0]
+    os_family           = distro.like()

     if args.daemon == 'chronyc':
         if args.resource == 'leap_status':

@vmpr
Copy link

vmpr commented Oct 12, 2022

I just also ran into that problem, can you fix that @winem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants