Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue in integration about smartctl and return error code 4 #43

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SOURCES/etc/xapi.d/plugins/smartctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_information(session, args):
with OperationLocker():
disks = _list_disks()
for disk in disks:
cmd = run_command(["smartctl", "-j", "-a", disk])
cmd = run_command(["smartctl", "-j", "-a", disk], check=False)
results[disk] = json.loads(cmd['stdout'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does smartctl always output JSON, even when there's an error? And what about stderr in case the command failed?

Copy link
Member

@stormi stormi Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still would have checked the return code, and whenever the return code differs from 0 and 4, replace result[disk] with something which contains the return code, raw stdout and stderr (but just for the affected disks). That's why I'd also check with XO so that we know how they would handle this case. Do they display the JSON, uninterpreted? Do they look for specific pieces of information?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we are already returning stdout that contains the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they just display the raw json (and we see the error code in it)

Copy link
Member

@stormi stormi Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this, the man page and a test I made gives me all I wanted to know: it wraps the call to "regular" smartctl and apparently always puts the result inside JSON, even when there are non-recoverable errors (unless there's an error generating the JSON itself, I guess).

See this example where I gave it a non recognised argument:

smartctl -j -a --wrongarg /dev/sdb
{
  "json_format_version": [
    1,
    0
  ],
  "smartctl": {
    "version": [
      7,
      0
    ],
    "svn_revision": "4883",
    "platform_info": "x86_64-linux-4.19.0+1",
    "build_info": "(local build)",
    "argv": [
      "smartctl",
      "-j",
      "-a",
      "--wrongarg",
      "/dev/sdb"
    ],
    "messages": [
      {
        "string": "=======> UNRECOGNIZED OPTION: wrongarg",
        "severity": "error"
      }
    ],
    "exit_status": 1
  }
}

So LGTM.

return json.dumps(results)

Expand Down
Loading