From 0b8459b2769d1be2db54f8c817f21b9944b278c0 Mon Sep 17 00:00:00 2001 From: Paco Hope Date: Wed, 4 Oct 2023 13:18:50 -0400 Subject: [PATCH] added base64 and json --- src/hetrixtools_freebsd/cli.py | 66 ++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/src/hetrixtools_freebsd/cli.py b/src/hetrixtools_freebsd/cli.py index 2fda482..ff3acdc 100644 --- a/src/hetrixtools_freebsd/cli.py +++ b/src/hetrixtools_freebsd/cli.py @@ -9,6 +9,8 @@ import argparse import logging import sys import subprocess +import base64 +import json from hetrixtools_freebsd import __version__ @@ -75,9 +77,65 @@ class Update: """ Calls commands and sets self.cpumodel self.cpusockets self.cpucores self.cputhreads self.cpuspeed """ - ncpu = self.callCommand(['sysctl', 'hw.ncpu']).split("\n")[0].split(" ")[1] - cpuspeed = self.callCommand(['sysctl', 'hw.clockrate']).split("\n")[0].split(" ")[1] - print(f"ncpu = {ncpu}, cpuspeed = {cpuspeed}") + self.cpusockets = self.callCommand(['sysctl', 'hw.ncpu']).split("\n")[0].split(" ")[1] + self.cpuspeed = self.callCommand(['sysctl', 'hw.clockrate']).split("\n")[0].split(" ")[1] + self.cputhreads = self.callCommand(['sysctl', 'kern.smp.threads_per_core']).split("\n")[0].split(" ")[1] + self.cpucores = self.callCommand(['sysctl', 'kern.smp.cores']).split("\n")[0].split(" ")[1] + self.cpumodel = self.callCommand(['sysctl', 'hw.model']).split("\n")[0].split(" ")[1] + self.cpumodel = base64.b64encode(self.cpumodel.encode()).decode('utf-8') + + print(f"cpusockets = {self.cpusockets}, cpuspeed = {self.cpuspeed}") + print(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}") + print(f"cpumodel = {self.cpumodel}") + + def toJsonString(self): + """Return the object as a JSON string.""" + retval = { + version : self.version , + SID : self.SID , + agent : self.agent , + user : self.user , + os : self.os , + kernel : self.kernel , + hostname : self.hostname , + time : self.time , + reqreboot : self.reqreboot , + uptime : self.uptime , + cpumodel : self.cpumodel , + cpusockets : self.cpusockets , + cpucores : self.cpucores , + cputhreads : self.cputhreads , + cpuspeed : self.cpuspeed , + cpu : self.cpu , + wa : self.wa , + st : self.st , + us : self.us , + sy : self.sy , + load1 : self.load1 , + load5 : self.load5 , + load15 : self.load15 , + ramsize : self.ramsize , + ram : self.ram , + ramswapsize : self.ramswapsize, + ramswap : self.ramswap , + rambuff : self.rambuff , + ramcache : self.ramcache , + disks : self.disks , + inodes : self.inodes , + iops : self.iops , + raid : self.raid , + dh : self.dh , + nics : self.nics , + ipv4 : self.ipv4 , + ipv6 : self.ipv6 , + conn : self.conn , + temp : self.temp , + serv : self.serv , + cust : self.cust , + rps1 : self.rps1 , + rps2 : self.rps2 , + } + return json.dumps(retval) # ---- Python API ---- @@ -85,6 +143,8 @@ def go(): """Run the command.""" update = Update() update.getCPUInfo() + output = update.toJsonString() + print(f"{output}") def parse_args(args): """Parse command line parameters