-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsnap-debug-info.sh
More file actions
154 lines (123 loc) · 4.04 KB
/
snap-debug-info.sh
File metadata and controls
154 lines (123 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/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 resolve this by using a Landscape client track
# 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 "SNAPD PROCESS INFORMATION:"
echo "================================="
ps -ax | grep snapd
# Run Python script to collect snapd information
python3 << END
import socket
import pprint
import json
from http.client import HTTPResponse
from io import BytesIO
import errno
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)
try:
sock.connect(SNAPD_SOCKET)
except OSError as e:
if e.errno in (errno.ECONNREFUSED, errno.ENOENT, errno.ETIMEDOUT):
raise Exception(f"Could not connect to snapd socket: {e}")
else:
raise
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