yonatan8070 / homelab-fetch

GNU General Public License v3.0
12 stars 4 forks source link

Trouble parsing CPU info from FreeBSD (TrueNAS) #4

Open vom513 opened 2 years ago

vom513 commented 2 years ago

Tried this against my FreeNAS/TrueNAS box. I'm happy to troubleshoot to figure out what FreeBSD is doing...

vom@onosendai 💀 bin % ./hlfetch -t vom@freenas.internal.burn.net
Traceback (most recent call last):
  File "/Users/vom/bin/./hlfetch", line 208, in <module>
    main()
  File "/Users/vom/bin/./hlfetch", line 200, in main
    machine_info = process_ssh_output(ssh_output_str)
  File "/Users/vom/bin/./hlfetch", line 39, in process_ssh_output
    cpu = filter_cpu(command_outputs[3])
  File "/Users/vom/bin/./hlfetch", line 81, in filter_cpu
    _, cpu = cpu_info.split(": ")
ValueError: not enough values to unpack (expected 2, got 1)
hillmanation commented 2 years ago

In my case, I got it working by modifying the proces_ssh_output function to the following:

def process_ssh_output(ssh_output: str): command_outputs = ssh_output.split("::")

distro, ansi_color = filter_os_release(command_outputs[0])
kernel = command_outputs[2].strip()
hostname = command_outputs[3].strip()
cpu = filter_cpu(command_outputs[4])
mem_total, mem_avail, mem_used = filter_memory(command_outputs[5])
system_platform = command_outputs[6].strip().replace("\n", " ")
uptime = process_uptime(command_outputs[7])
shell = filter_shell(command_outputs[8])

It seems there is an extra value present in the 'command_outputs' variable. 'command_outputs[3]' was passing the hostname info to the filter_cpu function resulting in the ValueError.

EDIT: Corrected array value numbers.

Looking into it further it looks like some native OS support information is included in command_outputs[1] which may be unexpected behavior but I'm unsure.

yonatan8070 commented 2 years ago

I just pushed a commit with a new --debug flag that will print the raw data from the target, could you pull that version and post the output of your server?

vom513 commented 2 years ago

I will post a debug from FreeBSD in a bit. However looking at your code - looks like you are grabbing the model from /proc/cpuinfo. You'll probably need an if condition to maybe check uname for BSD and if so, do this:

[vom@freenas ~]$ sysctl hw.model
hw.model: Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
vom513 commented 2 years ago

FreeBSD debug:

vom@ice:~/bin$ ./hlfetch -d -t vom@freenas
NAME=FreeBSD
VERSION="13.1-RELEASE"
VERSION_ID="13.1"
ID=freebsd
ANSI_COLOR="0;31"
PRETTY_NAME="FreeBSD 13.1-RELEASE"
CPE_NAME="cpe:/o:freebsd:freebsd:13.1"
HOME_URL="https://FreeBSD.org/"
BUG_REPORT_URL="https://bugs.FreeBSD.org/"
::FreeBSD 13.1-RELEASE
::::::::::::/usr/local/bin/bash
yonatan8070 commented 2 years ago

Strange, it seems most of the files I'm reading either don't exist or aren't in the same place on FreeBSD.

I'm downloading a FreeBSD ISO to test out how it works in a VM.