From: Sage Weil Date: Fri, 28 Jun 2019 14:34:23 +0000 (-0500) Subject: common/blkdev: include bad json from smartctl when unparseable X-Git-Tag: v15.1.0~2266^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7ac955e5ddc106a7e04fd4f580377bd104706d30;p=ceph.git common/blkdev: include bad json from smartctl when unparseable Signed-off-by: Sage Weil --- diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index 074eb2c80c6d..4ecd1d8d3f48 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -708,6 +708,17 @@ static int block_device_run_smartctl(const string& devname, int timeout, return ret; } +static std::string escape_quotes(const std::string& s) +{ + std::string r = s; + auto pos = r.find("\""); + while (pos != std::string::npos) { + r.replace(pos, 1, "\""); + pos = r.find("\"", pos + 1); + } + return r; +} + int block_device_get_metrics(const string& devname, int timeout, json_spirit::mValue *result) { @@ -721,10 +732,12 @@ int block_device_get_metrics(const string& devname, int timeout, s += "\", \"smartctl_error_code\": " + stringify(r); s += "\", \"smartctl_output\": \"" + s; s += + "\"}"; - } - if (!json_spirit::read(s, *result)) { + } else if (!json_spirit::read(s, *result)) { + string orig = s; s = "{\"error\": \"smartctl returned invalid JSON\", \"dev\": \"/dev/"; s += devname; + s += "\",\"output\":\""; + s += escape_quotes(orig); s += "\"}"; } if (!json_spirit::read(s, *result)) {