Skip to content

Commit a5a3ccb

Browse files
committed
plugins/solidigm: Added wildcard and filters to telemetry parsing.
Added support to jq filter directly in configuration file. Added wildcard support for Telemetry Object version. Signed-off-by: Leonardo da Cunha <[email protected]>
1 parent c16be1f commit a5a3ccb

File tree

3 files changed

+83
-17
lines changed

3 files changed

+83
-17
lines changed

plugins/solidigm/solidigm-nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "cmd.h"
1515

16-
#define SOLIDIGM_PLUGIN_VERSION "1.16"
16+
#define SOLIDIGM_PLUGIN_VERSION "1.17"
1717

1818
PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_VERSION),
1919
COMMAND_LIST(

plugins/solidigm/solidigm-telemetry.c

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct config {
5252
int data_area;
5353
char *cfg_file;
5454
char *binary_file;
55+
char *jq_filter;
5556
};
5657

5758
static void cleanup_json_object(struct json_object **jobj_ptr)
@@ -68,6 +69,7 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
6869
const char *dgen = "Pick which telemetry data area to report. Default is 3 to fetch areas 1-3. Valid options are 1, 2, 3, 4.";
6970
const char *cfile = "JSON configuration file";
7071
const char *sfile = "binary file containing log dump";
72+
const char *jqfilt = "JSON config entry name containing jq filter";
7173
bool has_binary_file = false;
7274
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
7375
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
@@ -93,6 +95,7 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
9395
OPT_UINT("data-area", 'd', &cfg.data_area, dgen),
9496
OPT_FILE("config-file", 'j', &cfg.cfg_file, cfile),
9597
OPT_FILE("source-file", 's', &cfg.binary_file, sfile),
98+
OPT_STR("jq-filter", 'q', &cfg.jq_filter, jqfilt),
9699
OPT_INCR("verbose", 'v', &nvme_cfg.verbose, verbose),
97100
OPT_END()
98101
};
@@ -144,19 +147,14 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
144147
nvme_show_status(err);
145148
return err;
146149
}
147-
struct json_tokener *jstok = json_tokener_new();
148-
149-
configuration = json_tokener_parse_ex(jstok, conf_str, length);
150-
if (jstok->err != json_tokener_success) {
151-
SOLIDIGM_LOG_WARNING("Parsing error on JSON configuration file %s: %s (at offset %d)",
152-
cfg.cfg_file,
153-
json_tokener_error_desc(jstok->err),
154-
jstok->char_offset);
155-
json_tokener_free(jstok);
150+
configuration = json_tokener_parse(conf_str);
151+
if (!configuration) {
152+
SOLIDIGM_LOG_WARNING(
153+
"Failed to parse JSON configuration file %s",
154+
cfg.cfg_file);
156155
err = EINVAL;
157156
return err;
158157
}
159-
json_tokener_free(jstok);
160158
tl.configuration = configuration;
161159
}
162160

@@ -196,7 +194,56 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru
196194
tl.log = tlog;
197195
solidigm_telemetry_log_data_areas_parse(&tl, cfg.data_area);
198196

199-
json_print_object(tl.root, NULL);
197+
/* Check if jq filter is requested and available */
198+
if (cfg.jq_filter && configuration) {
199+
struct json_object *jq_filter_obj = NULL;
200+
201+
if (json_object_object_get_ex(configuration, cfg.jq_filter,
202+
&jq_filter_obj)) {
203+
const char *jq_filter_str;
204+
205+
jq_filter_str = json_object_get_string(jq_filter_obj);
206+
if (jq_filter_str) {
207+
/* Get JSON string representation */
208+
const char *json_str;
209+
char cmd[1024];
210+
FILE *jq_pipe;
211+
212+
json_str = json_object_to_json_string(tl.root);
213+
214+
/* Create jq command and pipe JSON through it */
215+
snprintf(cmd, sizeof(cmd), "jq -r '%s'",
216+
jq_filter_str);
217+
jq_pipe = popen(cmd, "w");
218+
if (jq_pipe) {
219+
fprintf(jq_pipe, "%s", json_str);
220+
err = pclose(jq_pipe);
221+
if (err != 0)
222+
err = -EINVAL;
223+
} else {
224+
SOLIDIGM_LOG_WARNING(
225+
"Failed to execute jq command");
226+
err = -ENOENT;
227+
}
228+
} else {
229+
SOLIDIGM_LOG_WARNING(
230+
"jq filter entry '%s' is not a valid string",
231+
cfg.jq_filter);
232+
err = -EINVAL;
233+
}
234+
} else {
235+
SOLIDIGM_LOG_WARNING(
236+
"jq filter entry '%s' not found in configuration file",
237+
cfg.jq_filter);
238+
err = -ENOENT;
239+
}
240+
} else {
241+
/*
242+
* No jq filter requested or no config file,
243+
* use normal JSON output
244+
*/
245+
json_print_object(tl.root, NULL);
246+
}
200247
printf("\n");
201248

202249
return err;

plugins/solidigm/solidigm-telemetry/config.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string.h>
1010
#include <stdbool.h>
1111
#include <json.h>
12+
#include <stdint.h>
1213
#include "config.h"
1314

1415
// max 16 bit unsigned integer number 65535
@@ -27,11 +28,29 @@ static bool config_get_by_version(const struct json_object *obj, int version_maj
2728
snprintf(str_subkey, sizeof(str_subkey), "%d", version_minor);
2829
struct json_object *major_obj = NULL;
2930

30-
if (!json_object_object_get_ex(obj, str_key, &major_obj))
31-
return false;
32-
if (!json_object_object_get_ex(major_obj, str_subkey, value))
33-
return false;
34-
return value != NULL;
31+
/* Try exact major version match first */
32+
if (json_object_object_get_ex(obj, str_key, &major_obj)) {
33+
/* Try exact minor version match first */
34+
if (json_object_object_get_ex(major_obj, str_subkey, value))
35+
return value != NULL;
36+
37+
/* Try wildcard minor version if exact match failed */
38+
if (json_object_object_get_ex(major_obj, "*", value))
39+
return value != NULL;
40+
}
41+
42+
/* Try wildcard major version if exact major version not found */
43+
if (json_object_object_get_ex(obj, "*", &major_obj)) {
44+
/* Try exact minor version match */
45+
if (json_object_object_get_ex(major_obj, str_subkey, value))
46+
return value != NULL;
47+
48+
/* Try wildcard minor version */
49+
if (json_object_object_get_ex(major_obj, "*", value))
50+
return value != NULL;
51+
}
52+
53+
return false;
3554
}
3655

3756
bool sldm_config_get_struct_by_key_version(const struct json_object *config, char *key,

0 commit comments

Comments
 (0)