Example #1
0
s_influxdb_series
*influxdb_serie_from_json(json_object *jo)
{
    s_influxdb_series *series = malloc(sizeof (s_influxdb_series));

    series->free_cb = NULL;

    /* Name */
    series->name = influxdb_strdup(
        json_object_get_string(
            json_object_object_get(jo, "name")
            )
        );

    /* Columns */
    {
        json_object *cols = json_object_object_get(jo, "columns");

        series->columns_length = json_object_array_length(cols);
        series->columns = malloc(sizeof (char *) * series->columns_length);

        {
            size_t i;
            for (i = 0; i < series->columns_length; i++)
                series->columns[i] = influxdb_strdup(
                    json_object_get_string(
                        json_object_array_get_idx(cols, i)
                        )
                    );
        }
    }

    /* Points */
    {
        json_object *points = json_object_object_get(jo, "points");

        series->points_length = json_object_array_length(points);
        series->points = malloc(sizeof (char **) * series->points_length);

        {
            size_t i, j;
            for (i = 0; i < series->points_length; i++)
            {
                json_object *cols = json_object_array_get_idx(points, i);

                series->points[i] = malloc(
                    sizeof (char *) * series->columns_length);

                for (j = 0; j < series->columns_length; j++)
                    series->points[i][j] = influxdb_strdup(
                        json_object_get_string(
                            json_object_array_get_idx(cols, j)
                            )
                        );
            }
        }
    }

    return series;
}
Example #2
0
char
influxdb_series_set_name(s_influxdb_series *series, char *name)
{
    free(series->name);
    series->name = influxdb_strdup(name);
    return 1;
}
Example #3
0
s_influxdb_client
*influxdb_client_new(char *host,
                     char *username,
                     char *password,
                     char *database,
                     char ssl)
{
    s_influxdb_client *client = malloc(sizeof (s_influxdb_client));

    client->schema = ssl ? "https" : "http";
    client->host = influxdb_strdup(host);
    client->username = influxdb_strdup(username);
    client->password = influxdb_strdup(password);
    client->database = curl_easy_escape(NULL, database, 0);
    client->ssl = ssl;

    return client;
}
Example #4
0
void
*influxdb_continuous_queries_extractor(json_object *obj)
{
    s_influxdb_continuous_query *cq =
        malloc(sizeof (s_influxdb_continuous_query));

    cq->id = json_object_get_int(
        json_object_object_get(obj, "id"));
    cq->query = influxdb_strdup(json_object_get_string(
        json_object_object_get(obj, "query")));

    return cq;
}
Example #5
0
s_influxdb_series
*influxdb_series_create(char *name, influxdb_series_free_callback free_cb)
{
    s_influxdb_series *series = malloc(sizeof (s_influxdb_series));

    if (series != NULL)
    {
        series->name = influxdb_strdup(name);
        series->columns = NULL;
        series->points = NULL;
        series->columns_length = 0;
        series->points_length = 0;
        series->free_cb = free_cb;
    }

    return series;
}
Example #6
0
char
influxdb_series_add_colums(s_influxdb_series *series, char *name)
{
    if (series->columns_length == 0) {
        series->columns = malloc(sizeof (char *) * INFLUXDB_SERIES_STEP);
    } else if (series->columns_length % INFLUXDB_SERIES_STEP == 0) {
        series->columns = realloc(series->columns,
                                  sizeof (char *) * (series->columns_length + INFLUXDB_SERIES_STEP));
    }

    if (series->columns == NULL)
        return 0;

    series->columns[series->columns_length++] = influxdb_strdup(name);

    return 1;
}
Example #7
0
char
influxdb_series_add_colums(s_influxdb_series *series, char *name, unsigned int type)
{
    if (series->columns_length == 0) {
        series->columns = malloc(sizeof (char *) * sizeof(name));
        series->column_types = malloc(sizeof (unsigned int));
    } else
//    	if (series->columns_length % INFLUXDB_SERIES_STEP == 0)
    	{
        series->columns = realloc(series->columns,
            sizeof (char *) * (series->columns_length + sizeof(name)));
        series->column_types = realloc(series->column_types,
        		sizeof (unsigned int) * (series->columns_length + 1));
    }

    if (series->columns == NULL)
        return 0;

    series->column_types[series->columns_length] = type;
    series->columns[series->columns_length++] = influxdb_strdup(name);

    return 1;
}