kellyjonbrazil / jc

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
MIT License
7.92k stars 210 forks source link

uptime error parsing, in newer version #611

Open gbit-is opened 2 weeks ago

gbit-is commented 2 weeks ago

I just noticed something and thought I'd let you know.

Using an older version of jc (jc version 1.17.3, installed from apt or dpkg)

I can do:

echo "08:03:49 up 80 days, 18:01, 1 user, load average: 2.08, 1.84, 2.13" | jc --uptime {"time":"08:03:49","uptime":"80 days, 18:01","users":1,"load_1m":2.08,"load_5m":1.84,"load_15m":2.13,"time_hour":8,"time_minute":3,"time_second":49,"uptime_days":80,"uptime_hours":18,"uptime_minutes":1,"uptime_total_seconds":6976860}

but with a newer version, installed with pip (in venv): jc version: 1.25.3 python interpreter version: 3.10.12

if I perform the same command, it throws an error, with -d enabled it throws

Traceback (most recent call last): File "/path/to/venv/bin/jc", line 8, in <module> sys.exit(main()) File "/path/to/venv/lib/python3.10/site-packages/jc/cli.py", line 965, in main JcCli().run() File "/path/to/venv/lib/python3.10/site-packages/jc/cli.py", line 947, in run self._run() File "/path/to/venv/lib/python3.10/site-packages/jc/cli.py", line 911, in _run self.standard_parse_and_print() File "/path/to/venv/lib/python3.10/site-packages/jc/cli.py", line 803, in standard_parse_and_print self.create_normal_output() File "/path/to/venv/lib/python3.10/site-packages/jc/cli.py", line 755, in create_normal_output self.data_out = self.parser_module.parse( File "/path/to/venv/lib/python3.10/site-packages/jc/parsers/uptime.py", line 186, in parse return raw_output if raw else _process(raw_output) File "/path/to/venv/lib/python3.10/site-packages/jc/parsers/uptime.py", line 121, in _process uptime_hours = jc.utils.convert_to_int(proc_data['uptime'].split()[-1].split(':')[-2]) IndexError: list index out of range

gbit-is commented 2 weeks ago

It seems to work in 1.25.0, but not 1.25.1

kellyjonbrazil commented 2 weeks ago

I think this may have to do with there being a "user" label instead of "users". This sample doesn't seem to break on my pre-release dev version of 1.25.4, so I think it may be fixed by https://github.com/kellyjonbrazil/jc/commit/40eb2b7ef60184a049c34c4f423585f31e42fd99.