-
Notifications
You must be signed in to change notification settings - 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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation shows 'Environment: Physical/Virtual Machine' in the example output, but this line is not implemented in the actual code. The code only outputs kernel hash, distribution, version (hardcoded as 'Not available'), and kernel information.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||
===================================== | ||||
COMPATIBLE | ||||
``` | ||||
|
||||
This information can be easily shared with the support team for troubleshooting. | ||||
|
||||
If --silent flag is provided -- doesn't print anything | ||||
|
||||
Exit codes: | ||||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The flag parsing logic doesn't handle multiple arguments correctly. If both --silent and --report are provided, or if --report is provided as a second argument, the current logic will fail to detect it properly. Consider using argparse or at least checking all argv elements instead of just argv[1].
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
Comment on lines
119
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
|
||||||||||
if inside_vz_container() or inside_lxc_container(): | ||||||||||
myprint(silent, "UNSUPPORTED; INSIDE CONTAINER") | ||||||||||
return 2 | ||||||||||
|
||||||||||
try: | ||||||||||
with open('/proc/version', 'rb') as f: | ||||||||||
version_data = f.read() | ||||||||||
except (IOError, OSError): | ||||||||||
version_data = b'' | ||||||||||
|
||||||||||
kernel_hash = get_kernel_hash_from_data(version_data) | ||||||||||
distro_name, distro_version = get_distro_info() | ||||||||||
|
||||||||||
if report: | ||||||||||
print("=== KernelCare Compatibility Report ===") | ||||||||||
print(f"Kernel Hash: {kernel_hash}") | ||||||||||
print(f"Distribution: {distro_name or 'Unknown'}") | ||||||||||
print(f"Version: {distro_version or 'Unknown'}") | ||||||||||
print(f"Kernel: {version_data.decode('utf-8', errors='replace').strip()}") | ||||||||||
print("=====================================") | ||||||||||
|
||||||||||
try: | ||||||||||
if is_compat(): | ||||||||||
if is_compat(kernel_hash): | ||||||||||
myprint(silent, "COMPATIBLE") | ||||||||||
return 0 | ||||||||||
else: | ||||||||||
# Handle 404 case - check if distro is supported | ||||||||||
distro_name = get_distro_info() | ||||||||||
if distro_name and is_distro_supported(distro_name): | ||||||||||
myprint(silent, "NEEDS REVIEW") | ||||||||||
myprint(silent, "We support your distribution, but we're having trouble detecting your precise kernel configuration. Please, contact CloudLinux Inc. support by email at support@cloudlinux.com or by request form at https://www.cloudlinux.com/index.php/support") | ||||||||||
|
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.
Copilot uses AI. Check for mistakes.