diff --git a/changelog.txt b/changelog.txt index 1411c121..6e76ded2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,7 +4,7 @@ jc changelog - Add ping and ping6 command parser tested on linux, macos, and freebsd - Add traceroute and traceroute6 command parser tested on linux, macos, and freebsd - Update ini parser to support files only containing key/value pairs - +- Update uname parser exception with a hint to use "uname -a" 20200711 v1.12.1 - Fix tests when using older version of pygments library diff --git a/jc/parsers/uname.py b/jc/parsers/uname.py index fe69ffd4..96014671 100644 --- a/jc/parsers/uname.py +++ b/jc/parsers/uname.py @@ -30,7 +30,7 @@ import jc.utils class info(): - version = '1.3' + version = '1.4' description = 'uname -a command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -43,6 +43,10 @@ class info(): __version__ = info.version +class ParseError(Exception): + pass + + def process(proc_data): """ Final processing to conform to the schema. @@ -94,6 +98,10 @@ def parse(data, raw=False, quiet=False): # check for OSX output if data.startswith('Darwin'): parsed_line = data.split() + + if len(parsed_line) < 5: + raise ParseError('Could not parse uname output. Make sure to use "uname -a".') + raw_output['machine'] = parsed_line.pop(-1) raw_output['kernel_name'] = parsed_line.pop(0) raw_output['node_name'] = parsed_line.pop(0) @@ -103,6 +111,10 @@ def parse(data, raw=False, quiet=False): # otherwise use linux parser else: parsed_line = data.split(maxsplit=3) + + if len(parsed_line) < 3: + raise ParseError('Could not parse uname output. Make sure to use "uname -a".') + raw_output['kernel_name'] = parsed_line.pop(0) raw_output['node_name'] = parsed_line.pop(0) raw_output['kernel_release'] = parsed_line.pop(0)