-
Notifications
You must be signed in to change notification settings - Fork 19
Add snap debug info script #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script collects information about the status of a device to aid in debugging. | ||
| # There is a slight limitation when trying to extract logs using the journalctl | ||
| # command. | ||
| # | ||
| # If your Landscape snap is based on Core 22 and your device is Core 24, you will not | ||
| # be able to extract logs using the journalctl command. This is because the journalctl | ||
| # command does not support the log format used by Core 24. | ||
| # | ||
| # If you are using Core 24, you can resovle this by using a Landscape client track | ||
|
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. typo: |
||
| # that is based on Core 24. | ||
|
|
||
|
|
||
| # Collect snapd information | ||
| # PRINT DEBUG INFO | ||
| echo "SNAP DEBUG INFO REPORT" | ||
| echo "=================================" | ||
| echo "" | ||
| echo "UTC DATE:" | ||
| echo "=================================" | ||
| date --utc | ||
|
|
||
| echo "UPTIME:" | ||
| echo "=================================" | ||
| uptime -p | ||
|
|
||
| echo "DISK SPACE:" | ||
| echo "=================================" | ||
| df -h | ||
|
|
||
| # System Logs | ||
| echo "SNAPD JOURNAL OUTPUT:" | ||
| echo "=================================" | ||
| journalctl -u snapd --no-pager | ||
|
|
||
| echo "" | ||
| echo "SNAPD JOURNAL DENIED OUTPUT:" | ||
| echo "=================================" | ||
| # Filter journal output for lines containing "DENIED" | ||
| journalctl -u snapd --no-pager | grep "DENIED" | ||
|
|
||
| echo "" | ||
| echo "\nSNAPD PROCESS INFORMATION:" | ||
| echo "=================================" | ||
| ps -ax | grep snapd | ||
|
|
||
|
|
||
| # Run Python script to collect snapd information | ||
|
|
||
| python3 << END | ||
| import socket | ||
| import pprint | ||
| import subprocess | ||
| import json | ||
| from http.client import HTTPResponse | ||
| from io import BytesIO | ||
|
|
||
| BASE_URL = "http://localhost/v2" | ||
| SNAPD_SOCKET = "/run/snapd.socket" | ||
|
|
||
|
|
||
| def print_services(apps, indent=0): | ||
| for app in apps: | ||
| line = ( | ||
| " " * indent + | ||
| f"- {app['name']} " | ||
| f"(snap: {app['snap']}, " | ||
| f"active: {app['active']}, " | ||
| f"enabled: {app['enabled']})" | ||
| ) | ||
| print(line) | ||
|
|
||
|
|
||
| def make_API_call(method, path): | ||
| sock = socket.socket(family=socket.AF_UNIX) | ||
| sock.connect(SNAPD_SOCKET) | ||
|
|
||
| url = BASE_URL + path | ||
| response = HTTPResponse(sock, method=method, url=url) | ||
|
|
||
| request = BytesIO() | ||
| request.write( | ||
| f"{method} {url} HTTP/1.1\r\nHost: localhost\r\n\r\n".encode()) | ||
|
|
||
| sock.sendall(request.getvalue()) | ||
| response.begin() | ||
| response_body = response.read() | ||
| response.close() | ||
| sock.close() | ||
|
|
||
| response_type = response.getheader("Content-Type") | ||
| if response_type == "application/json": | ||
| return json.loads(response_body)["result"] | ||
| else: | ||
| response_code = response.getcode() | ||
| is_async = response_code == 202 | ||
| return { | ||
| "type": "async" if is_async else "sync", | ||
| "status_code": response_code, | ||
| "result": response_body, | ||
| } | ||
|
|
||
| print("\nSystem Information:") | ||
| print("=================================") | ||
| pprint.pprint(make_API_call("GET", "/system-info")) | ||
|
|
||
| # Get SnapD Info | ||
| print("\nModel and Serial Information:") | ||
| print("=================================") | ||
| pprint.pprint(make_API_call("GET", "/model/serial")) | ||
|
|
||
| print("\nInstalled Snap Information:") | ||
| print("=================================") | ||
| pprint.pprint(make_API_call("GET", "/apps")) | ||
|
|
||
| print("\nSnap Services Information:") | ||
| print("=================================") | ||
| response_json = make_API_call("GET", "/apps") | ||
|
|
||
| # Extract the JSON part from the HTTP response | ||
|
|
||
| filtered = [ | ||
| { | ||
| "name": app.get("name"), | ||
| "snap": app.get("snap"), | ||
| "active": app.get("active"), | ||
| "enabled": app.get("enabled"), | ||
| } | ||
| for app in response_json | ||
| if "daemon" in app | ||
| ] | ||
|
|
||
| print_services(filtered) | ||
|
|
||
| print("\nInterface Connection Information:") | ||
| print("=================================") | ||
| pprint.pprint(make_API_call("GET", "/connections")) | ||
|
|
||
| print("\nSnapD Changes Information:") | ||
| print("=================================") | ||
| pprint.pprint(make_API_call("GET", "/changes?select=all")) | ||
|
|
||
| print("\nValidation Sets Information:") | ||
| print("=================================") | ||
| pprint.pprint(make_API_call("GET", "/validation-sets")) | ||
|
|
||
| END | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should probably rename the
remove-user.pytosnap-debug-info.sh.