32static void csv_addjsonfield(FILE* reportfile,
const cJSON* json,
char* fieldname) {
33 char* text =
json2text(cJSON_GetObjectItemCaseSensitive(json, fieldname));
40 "cluster_host,uid,name,shards_count,replication,data_persistence,memory_size,used_memory,module_list\r\n"
44static cJSON* report_querygetjson(
const cluster_t* cluster,
const char* endpoint) {
48 fprintf(stderr,
"report_querygetjson cluster_new failed\n");
52 fprintf(stderr,
"report_querygetjson cluster_open failed\n");
59 const char *error_ptr = cJSON_GetErrorPtr();
60 if (error_ptr !=
NULL)
61 fprintf(stderr,
"Error before: %s\n", error_ptr);
62 retval = cJSON_CreateObject();
73 cJSON* bdbsstats_json;
75 bdbs_json = report_querygetjson(cluster,
"/v1/bdbs");
76 bdbsstats_json = report_querygetjson(cluster,
"/v1/bdbs/stats/last");
78 const cJSON* bdb_json;
80 char* uid=
json2text(cJSON_GetObjectItemCaseSensitive(bdb_json,
"uid"));
81 cJSON* stats_json = cJSON_GetObjectItemCaseSensitive(bdbsstats_json, uid);
84 csv_addjsonfield(reportfile, bdb_json,
"uid");
85 csv_addjsonfield(reportfile, bdb_json,
"name");
86 csv_addjsonfield(reportfile, bdb_json,
"shards_count");
87 csv_addjsonfield(reportfile, bdb_json,
"replication");
88 csv_addjsonfield(reportfile, bdb_json,
"data_persistence");
89 csv_addjsonfield(reportfile, bdb_json,
"memory_size");
90 csv_addjsonfield(reportfile, stats_json,
"used_memory");
94 if (
NULL==(modlst=strdup(
""))) {
95 perror(
"rptbdbs repport_bdbs module_list");
99 const cJSON* module_json;
100 cJSON_ArrayForEach(module_json, cJSON_GetObjectItemCaseSensitive(bdb_json,
"module_list")) {
101 char* modulename = cJSON_GetObjectItemCaseSensitive(module_json,
"module_name")->valuestring;
103 if (
NULL==(newmodlst = (
char*)realloc(modlst,strlen(modlst)+strlen(modulename?modulename:
"")+2+1))) {
104 perror(
"rptbdbs repport_bdbs module_list");
109 strcat(modlst,(modulename?modulename:
""));
114 if (strlen(modlst)>2)
115 modlst[strlen(modlst)-2]=0;
121 cJSON_Delete(bdbs_json);
122 cJSON_Delete(bdbsstats_json);
#define cJSON_ArrayForEach(element, array)
void cluster_close(rsclustercon_t *rsclustercon)
void cluster_del(rsclustercon_t *rsclustercon)
rsclustercon_t * cluster_new(const cluster_t *cluster)
int cluster_open(rsclustercon_t *rsclustercon)
cJSON * cluster_queryget(const rsclustercon_t *rsclustercon, const char *endpoint)
void csv_addfield(FILE *reportfile, const char *value)
void csv_addline(FILE *reportfile)
char * json2text(cJSON *value_json)
Convert a cJSON object in a C String.
Wrapper around cJSON library with helpers.
void report_bdbs_header(FILE *reportfile)
void report_bdbs(FILE *reportfile, const cluster_t *cluster)