-
Couldn't load subscription status.
- Fork 1
feat(kc-compat): add --report flag to output system info before status #4
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -71,7 +71,7 @@ else if needs_update == False { | |||
| Checks if server is running kernel compatible with KernelCare. | ||||
| Usage: | ||||
| ```bash | ||||
| python kc-compat.py [--silent|-q] | ||||
| python kc-compat.py [--silent|-q|--report] | ||||
| ``` | ||||
|
|
||||
| Outputs: | ||||
|
|
@@ -82,6 +82,26 @@ Outputs: | |||
| - `SYSTEM ERROR; <error>` for file system issues | ||||
| - `UNEXPECTED ERROR; <error>` for other errors | ||||
|
|
||||
| ### Flags: | ||||
| - `--silent` or `-q`: Silent mode - no output, only exit codes | ||||
| - `--report`: Generate system information report for support team | ||||
|
|
||||
| ### Report Mode: | ||||
| When using `--report`, the script outputs detailed system information followed by the compatibility status: | ||||
|
|
||||
| ``` | ||||
| === KernelCare Compatibility Report === | ||||
| Kernel Hash: abcdef1234567890abcdef1234567890abcdef12 | ||||
| Distribution: centos | ||||
| Version: 7 | ||||
| Kernel: Linux version 5.4.0-74-generic (buildd@lcy01-amd64-023) (gcc version 9.3.0) | ||||
| Environment: Physical/Virtual Machine | ||||
|
||||
| Environment: Physical/Virtual Machine |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,17 +34,13 @@ | |||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def get_kernel_hash(): | ||||||||||
| def get_kernel_hash_from_data(version_data): | ||||||||||
| try: | ||||||||||
| # noinspection PyCompatibility | ||||||||||
| from hashlib import sha1 | ||||||||||
| except ImportError: | ||||||||||
| from sha import sha as sha1 | ||||||||||
| f = open('/proc/version', 'rb') | ||||||||||
| try: | ||||||||||
| return sha1(f.read()).hexdigest() | ||||||||||
| finally: | ||||||||||
| f.close() | ||||||||||
| return sha1(version_data).hexdigest() | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def inside_vz_container(): | ||||||||||
|
|
@@ -62,24 +58,29 @@ def inside_lxc_container(): | |||||||||
| def get_distro_info(): | ||||||||||
| """ | ||||||||||
| Get current distribution name and version | ||||||||||
| :return: distro name or None if detection fails | ||||||||||
| :return: tuple of (distro_name, distro_version) or (None, None) if detection fails | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| def parse_value(line): | ||||||||||
| return line.split('=', 1)[1].strip().strip('"\'') | ||||||||||
|
|
||||||||||
| os_release_path = '/etc/os-release' | ||||||||||
| if not os.path.exists(os_release_path): | ||||||||||
| return None | ||||||||||
| return None, None | ||||||||||
|
|
||||||||||
| try: | ||||||||||
| distro_name = None | ||||||||||
| distro_version = None | ||||||||||
| with open(os_release_path, 'r') as f: | ||||||||||
| for line in f: | ||||||||||
| line = line.strip() | ||||||||||
| if line.startswith('ID='): | ||||||||||
| return parse_value(line) | ||||||||||
| distro_name = parse_value(line) | ||||||||||
| elif line.startswith('VERSION_ID='): | ||||||||||
| distro_version = parse_value(line) | ||||||||||
| return distro_name, distro_version | ||||||||||
| except (IOError, OSError): | ||||||||||
| return None | ||||||||||
| return None, None | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def is_distro_supported(distro_name): | ||||||||||
|
|
@@ -89,8 +90,8 @@ def is_distro_supported(distro_name): | |||||||||
| return distro_name in SUPPORTED_DISTROS | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def is_compat(): | ||||||||||
| url = 'http://patches.kernelcare.com/' + get_kernel_hash() + '/version' | ||||||||||
| def is_compat(kernel_hash): | ||||||||||
| url = 'http://patches.kernelcare.com/' + kernel_hash + '/version' | ||||||||||
| try: | ||||||||||
| urlopen(url) | ||||||||||
| return True | ||||||||||
|
|
@@ -111,21 +112,40 @@ def myprint(silent, message): | |||||||||
| def main(): | ||||||||||
| """ | ||||||||||
| if --silent or -q argument provided, don't print anything, just use exit code | ||||||||||
| if --report provided, show system information for support | ||||||||||
| otherwise print results (COMPATIBLE or support contact messages) | ||||||||||
| else exit with 0 if COMPATIBLE, 1 or more otherwise | ||||||||||
| """ | ||||||||||
| silent = len(sys.argv) > 1 and (sys.argv[1] == '--silent' or sys.argv[1] == '-q') | ||||||||||
| report = len(sys.argv) > 1 and sys.argv[1] == '--report' | ||||||||||
|
Comment on lines
117
to
+120
|
||||||||||
| silent = len(sys.argv) > 1 and (sys.argv[1] == '--silent' or sys.argv[1] == '-q') | |
| report = len(sys.argv) > 1 and sys.argv[1] == '--report' | |
| silent = ('--silent' in sys.argv[1:]) or ('-q' in sys.argv[1:]) | |
| report = '--report' in sys.argv[1:] |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current argument parsing logic only checks the first argument, making it impossible to use both --silent and --report flags together or handle multiple arguments properly. Consider using argparse for proper command-line argument handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation shows 'Version: 7' in the example output, but the actual code on line 136 in kc-compat.py always prints 'Version: Not available'. This inconsistency could confuse users about what to expect from the --report output.