Skip to content

Commit

Permalink
collect: update sys, add commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Powers committed Jul 7, 2020
1 parent 65c33e7 commit 92b7ad3
Showing 1 changed file with 74 additions and 5 deletions.
79 changes: 74 additions & 5 deletions whatsthis/collect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,53 @@
import shutil
import tempfile

from whatsthis.collect import proc, sys
from whatsthis.file import copy, dd, exists, tar
from whatsthis.subp import execute

COMMANDS = {
"lsblk": "lsblk",
"ip a": "ip_a",
"lscpu": "lscpu",
"lshw -short": "lshw",
"lshw -json": "lshw.json",
"lsipc": "lsipc",
"lsmem": "lsmem",
"lspci": "lspci",
"lspci -vv": "lspci_vv",
"blkid -o export": "blkid"
}

PROC_FILES = [
"/proc/buddyinfo",
"/proc/cmdline",
"/proc/cpuinfo",
"/proc/crypto",
"/proc/devices",
"/proc/diskstats",
"/proc/interrupts",
"/proc/iomem",
"/proc/mdstat",
"/proc/meminfo",
"/proc/misc",
"/proc/modules",
"/proc/mounts",
"/proc/net/vlan",
"/proc/net/bonding",
"/proc/partitions",
"/proc/sched_debug",
"/proc/schedstat",
"/proc/scsi/scsi",
"/proc/scsi/sg/device_strs",
"/proc/stat",
"/proc/swaps",
"/proc/version",
"/proc/zoneinfo",
]

SYS_FILES = [
"/sys",
]


class Collect:
"""Collect /proc and /sys from a system."""
Expand All @@ -42,9 +85,19 @@ def __init__(self, output_dir=""):

logging.info("starting collection")
logging.debug("tempdir: %s", self.tmp_dir)

self.proc()
self.sys()

os.makedirs(os.path.join(self.tmp_dir, 'cmd'))
for command, filename in COMMANDS.items():
print("running: %s" % command)
result = execute(command)

output_file = os.path.join(self.tmp_dir, 'cmd', filename)
with open(output_file, "w") as file_out:
file_out.write(result.stdout)

tar_filename = "%s-%s.tar.gz" % (
platform.node(),
datetime.datetime.now().strftime("%Y%m%d-%H%M%S"),
Expand All @@ -59,7 +112,7 @@ def proc(self):
"""Collect specific files from /proc."""
logging.info("/proc")

for file_path in proc.FILES:
for file_path in PROC_FILES:
if not exists(file_path):
continue
copy(file_path, os.path.join(self.tmp_dir, file_path[1:]))
Expand All @@ -72,15 +125,31 @@ def sys(self):
"""
logging.info("/sys")

for sys_path in sys.FILES:
for sys_path in SYS_FILES:
result = execute(
["find", sys_path, "-noleaf", "-type", "f", "-perm", "/444"]
)

for file_path in sorted(result.split("\n")):
if "autosuspend_delay_ms" in file_path:
if 'autosuspend_delay_ms' in file_path:
continue
if 'kernel/slab' in file_path:
continue
if 'firmware/efi' in file_path:
continue
if "thermal_zone" in file_path:
if 'sys/module' in file_path:
continue
if 'thermal/thermal_zone' in file_path:
continue
if 'firmware/acpi' in file_path:
continue
if 'devices/virtual/thermal' in file_path:
continue
if 'sys/devices/platform' in file_path:
continue

file_stat = os.stat(file_path)
if oct(file_stat.st_mode)[-1:] == 0:
continue

dd(file_path, os.path.join(self.tmp_dir, file_path[1:]))

0 comments on commit 92b7ad3

Please sign in to comment.