Opened 8 years ago

Closed 6 years ago

Last modified 6 years ago

#766 closed enhancement (fixed)

JSON output mode for smartctl reports

Reported by: hi2u Owned by: Christian Franke
Priority: major Milestone: Release 7.0
Component: smartctl Version:
Keywords: json Cc:

Description

More and more command line programs now have an option to output information as a single big JSON string.

It makes it super easy for anybody to integrate another program or even simple scripts. Pretty much any programming/scripting language can read JSON very easily with only a few lines of code.

A good example of one program that does this (of many now) is "exiftool". Adding "-json" to the command arguments will have it output all information in a big JSON string (with pretty print so its not just one long line).

For example, the command...

exiftool -json /usr/sbin/smartctl

Will output:

[{
  "SourceFile": "/usr/sbin/smartctl",
  "ExifToolVersion": 9.74,
  "FileName": "smartctl",
  "Directory": "/usr/sbin",
  "FileSize": "620 kB",
  "FileModifyDate": "2014:12:21 05:29:41+10:00",
  "FileAccessDate": "2016:11:11 08:02:52+10:00",
  "FileInodeChangeDate": "2015:04:15 00:36:10+10:00",
  "FilePermissions": "rwxr-xr-x",
  "FileType": "ELF executable",
  "MIMEType": "application/octet-stream",
  "CPUArchitecture": "64 bit",
  "CPUByteOrder": "Little endian",
  "ObjectFileType": "Shared object file",
  "CPUType": "AMD x86-64"
}]

This is a much simpler method of effectively giving the same functionality requested in ticket "#501 make smartctl into a library". And would be usable to a much wider audience, much more easily.

I recommend this for any command line program that outputs any kind of information these days. In fact, considering that JSON is quite human readable anyway, I'd even suggest making it the first output format for any new program before bothering to create your own custom ASCII layout. In a lot of cases, the JSON would be all you really need. And anyone else can easily make their own scripts to generate a nicer looking ASCII output if they like. Much easier than doing it in reverse, i.e. writing custom code to parsing an ASCII table.

Change History (20)

comment:1 by Christian Franke, 8 years ago

Milestone: unscheduled

Makes plenty of sense - but is possibly too complex for next release.

comment:2 by Alex Samorukov, 7 years ago

+1, i think it would be much easier to implement compared to an API (mostly formatting changes) and is already implemented, for example, in nvmetools. Patches are welcome )

comment:3 by Christian Franke, 7 years ago

Milestone: unscheduledRelease 6.7

comment:4 by Christian Franke, 7 years ago

Ticket #916 has been marked as a duplicate of this ticket.

comment:5 by otakuto, 7 years ago

I wrote patch for now.
However, only drive info.
https://github.com/otakuto/smartmontools/commit/41068b6d8b05211f295f2f926398be693734cc86
Is this approach all right?
Thank you.

comment:6 by Christian Franke, 7 years ago

Sorry no. This 'direct output' approach would require that JSON structure follows program structure.

We already discuss a more general approach & patch on the smartmontools-devel mailing list.

comment:7 by Christian Franke, 7 years ago

Owner: set to Christian Franke
Status: newaccepted

comment:8 by Christian Franke, 7 years ago

r4640 added initial JSON support for ATA and some SCSI support:

smartctl -j -i -A -H /dev/sdX
smartctl --json=au -x /dev/sdX

comment:9 by Christian Franke, 7 years ago

r4641, r4642: compile fixes.
r4644: smartctl -j --scan ...
r4645: smartctl -j -l sataphy ...

comment:10 by Christian Franke, 7 years ago

r4646: smartctl --json=s ...
r4647: smartctl --json=g ...
r4648: compile fix.
r4650: smartctl -j -c ...
r4652: smartctl -j -l selftest -l xselftest ...
r4653: smartctl -j -l directory ...
r4654: show command line error messages.
r4655: smartctl --json=o ... (instead of --json=a)
r4656: smartctl -j -l error -l xerror ...
r4657: smartctl -j -A ... changes and enhancements.
r4659: smartctl -j -l scttemp ...
r4660: smartctl -j -l scterc ...
r4661: smartctl -j -g all ...

comment:11 by Andrius Štikonas, 7 years ago

Any idea when this might be released?

In KDE Partition Manager git branch we have ported away from libatasmart to calling "smartctl --all --json deviceNode"

in reply to:  11 comment:12 by Christian Franke, 7 years ago

Any idea when this might be released?

Not yet known, sorry.

In KDE Partition Manager git branch we have ported away from libatasmart to calling "smartctl --all --json deviceNode"

Which specific ATA/SCSI/NVMe info do you need for this use case?

BTW: Try --xall instead of --all.

comment:13 by Caio Jordão Carvalho, 7 years ago

Replying to chrfranke:

Any idea when this might be released?

Not yet known, sorry.

In KDE Partition Manager git branch we have ported away from libatasmart to calling "smartctl --all --json deviceNode"

Which specific ATA/SCSI/NVMe info do you need for this use case?

BTW: Try --xall instead of --all.

We don't need all data from --xall, because --all already provides the information that we need.

Actually, only these informations are needed by KDE Partition Manager:

  • Device attributes (model name, serial number, firmware)
  • Capacity
  • SMART status
  • Self Test status
  • Temperature
  • SMART attributes info as seen in ["ata_smart_attributes"]["table"] array.
Version 1, edited 7 years ago by Caio Jordão Carvalho (previous) (next) (diff)

comment:14 by Christian Franke, 7 years ago

r4721: smartctl -j -i -A -H (NVMe)

comment:15 by Christian Franke, 6 years ago

Keywords: json added

r4663: revision; scsi_version; (SCSI)
r4679: format_status.*; (SCSI)
r4683: pending_defects.*; (SCSI)
r4726: user_capacity.blocks.*; user_capacity.bytes.*;
r4745: 128-bit support
r4752: smartctl -j -l devstat
r4753: smartctl -j -l scttempsts enhancements
r4755: power_cycle_count; power_on_hours; (ATA, NVMe)

comment:16 by Christian Franke, 6 years ago

ticket #1079: SCSI enhancement error_counter_log;

comment:17 by Christian Franke, 6 years ago

r4762: power_on_time.*; (ATA, SCSI, NVMe)
r4775: temperature.op_limit*; (ATA)
r4779: smartctl -l selective
r4815: scsi_error_counter_log.*; temperature.drive_trip;
r4816: scsi_grown_defect_list;
r4817: scsi_percentage_used_endurance_indicator
r4827: smartctl -l defects
r4829: interface_speed.*; (ATA)

comment:18 by Christian Franke, 6 years ago

r4870: Minor SCSI fix for r4679.

comment:19 by Christian Franke, 6 years ago

Resolution: fixed
Status: acceptedclosed

Initial JSON support completed, see above comments for details. Format version set to 1.0 in r4871.

comment:20 by Christian Franke, 6 years ago

Milestone: Release 6.7Release 7.0

Milestone renamed

Note: See TracTickets for help on using tickets.