rsstats 0.0.1
Redis Enterprise Statistic collector
rptsample.c
Go to the documentation of this file.
1
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include "rptsample.h"
24#include "clustercon.h"
25#include "json.h"
26#include "csv.h"
27#include <string.h>
28
29/* To refactor in a report common file */
30static void csv_addjsonfield(FILE* reportfile, const cJSON* json, char* fieldname) {
31 char* text = json2text(cJSON_GetObjectItemCaseSensitive(json, fieldname));
32 csv_addfield(reportfile,text);
33 free(text);
34}
35
36void report_sample_header(FILE* reportfile) {
37 fprintf(reportfile,
38 "field1,field2,field3\r\n"
39 );
40}
41
42void report_sample(FILE* reportfile, const cluster_t* cluster) {
43 cJSON* samples_json;
44 (void)cluster;
45
46 samples_json = cJSON_Parse("["
47 "{\"field1\":\"value1\",\"field2\":\"value 2\",\"field3\":\" value3\"},"
48 "{\"field1\":\"value4 \",\"field2\":\"value,5\",\"field3\":\"value\\\"6\\\"\"}"
49 "]");
50 const cJSON* sample_json;
51 cJSON_ArrayForEach(sample_json, samples_json) {
52 csv_addfield(reportfile,cluster->host);
53 csv_addjsonfield(reportfile, sample_json, "field1");
54 csv_addjsonfield(reportfile, sample_json, "field2");
55 csv_addjsonfield(reportfile, sample_json, "field3");
56
57 csv_addline(reportfile);
58 }
59 cJSON_Delete(samples_json);
60}
61/* vim: set tw=80: */
#define cJSON_ArrayForEach(element, array)
Definition: cJSON.h:294
<+DETAILED+>
void csv_addfield(FILE *reportfile, const char *value)
Definition: csv.c:37
void csv_addline(FILE *reportfile)
Definition: csv.c:32
<+DETAILED+>
char * json2text(cJSON *value_json)
Convert a cJSON object in a C String.
Definition: json.c:31
Wrapper around cJSON library with helpers.
void report_sample(FILE *reportfile, const cluster_t *cluster)
Definition: rptsample.c:42
void report_sample_header(FILE *reportfile)
Definition: rptsample.c:36
Basic report without connection to test output format.
Definition: cJSON.h:103
char * host
Definition: cluster.h:26