Added jc parsing of sysctl -a

main
Paco Hope 2023-10-04 17:31:33 -04:00
parent 4b559fb57b
commit 338eea67aa
1 changed files with 12 additions and 10 deletions

View File

@ -73,8 +73,8 @@ class Update:
it 20 times and parsing each one, we just call it once, and then parse the
various keys that it produces
"""
rawtext = subprocess.run(['sysctl', '-a'], subprocess.PIPE)
self.sysctl = jc.parse('sysctl', cmd_output)
rawtext = subprocess.check_output(['sysctl', '-a'], subprocess.PIPE, text=True )
self.sysctl = jc.parse(parser_mod_name="sysctl", data=rawtext)
def callCommand(self, command=[]):
"""Given a command and args in a list, run the command and return its
@ -87,12 +87,12 @@ class Update:
""" Calls commands and sets
self.cpumodel self.cpusockets self.cpucores self.cputhreads self.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')
self.cpusockets = self.sysctl.get('hw.ncpu', "garbage")
self.cpuspeed = self.sysctl.get('hw.clockrate', "")
self.cputhreads = self.sysctl.get('kern.smp.threads_per_core', "")
self.cpucores = self.sysctl.get('kern.smp.cores', "")
self.cpumodel = base64.b64encode(self.sysctl.get('hw.model', "").encode()).decode('utf-8')
self.logger.debug(f"cpusockets = {self.cpusockets}, cpuspeed = {self.cpuspeed}")
self.logger.debug(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}")
@ -155,8 +155,10 @@ def go():
_logger.info(f"Starting to fetch results")
update.getSysCtlAll()
if( update.sysctl is not None ):
_logger.info(f"{update.sysctl}")
update.getCPUInfo()
# _logger.debug(f"{update.sysctl}")
update.getCPUInfo()
else:
_logger.fatal("Failed to get output from sysctl")
_logger.info(f"Done fetching results")
output = update.toJsonString()
_logger.debug(f"{output}")