6b89f82448bf84fe1ce5e92d7617a4263060cad7
1#
2# sysinfo.py
3#
4# Get standard system information from basic Unix commands
5#
6
7import platform
8import subprocess
9import os
10import re
11
12from logparse.formatting import *
13from logparse.config import prefs
14from logparse.load_parsers import Parser
15
16class Sysinfo(Parser):
17
18 def __init__(self):
19 super().__init__()
20 self.name = "sysinfo"
21 self.info = "Get standard system information from basic Unix commands"
22
23 def parse_log(self):
24
25 logger.debug("Starting sysinfo section")
26 section = Section("system")
27 table = Table()
28
29 table.add_row(Row([Column("Hostname"), Column(util.hostname(prefs.get("logparse", "hostname-path")))]))
30 table.add_row(Row([Column("OS"), Column(platform.platform())]))
31 table.add_row(Row([Column("OS version"), Column(platform.version())]))
32 table.add_row(Row([Column("Platform"), Column(platform.system() + " " + platform.machine())]))
33
34 processors = []
35 raw_proc = util.readlog(prefs.get("logs", "cpuinfo"))
36 line_regex = re.compile(".*model name.*:\s*")
37 proc_regex = re.compile("\s*(\(R\)|\(TM\)|CPU)")
38 for line in raw_proc.splitlines():
39 if "model name" in line:
40 processor = line_regex.sub("", line, 1)
41 processor = " ".join(proc_regex.sub("", processor).split()) # remove extraneous text and whitespace
42 if not processor in processors:
43 processors.append(processor)
44 else:
45 logger.debug("Found duplicate entry (perhaps multiple cores?) for {0}".format(processor))
46 table.align_column(0, "right")
47 if len(processors) == 1:
48 table.add_row(Row([Column("Processor"), Column("; ".join(processors))]))
49 section.append_table(table)
50 elif len(processors) > 1:
51 section.append_table(table)
52 proc_data = Data("Processors")
53 proc_data.items = processors
54 section.append_data(proc_data)
55 else:
56 logger.warning("Failed to find processor data")
57
58 logger.info("Finished sysinfo section")
59 return section