projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tree wide: Replace sstrerror() with STRERROR().
[collectd.git]
/
src
/
dbi.c
diff --git
a/src/dbi.c
b/src/dbi.c
index
0e5c5de
..
62ef1dc
100644
(file)
--- a/
src/dbi.c
+++ b/
src/dbi.c
@@
-62,6
+62,7
@@
struct cdbi_database_s /* {{{ */
{
char *name;
char *select_db;
{
char *name;
char *select_db;
+ char *plugin_name;
cdtime_t interval;
cdtime_t interval;
@@
-101,18
+102,18
@@
static const char *cdbi_strerror(dbi_conn conn, /* {{{ */
if (conn == NULL) {
sstrncpy(buffer, "connection is NULL", buffer_size);
if (conn == NULL) {
sstrncpy(buffer, "connection is NULL", buffer_size);
- return
(buffer)
;
+ return
buffer
;
}
msg = NULL;
status = dbi_conn_error(conn, &msg);
if ((status >= 0) && (msg != NULL))
}
msg = NULL;
status = dbi_conn_error(conn, &msg);
if ((status >= 0) && (msg != NULL))
- s
s
nprintf(buffer, buffer_size, "%s (status %i)", msg, status);
+ snprintf(buffer, buffer_size, "%s (status %i)", msg, status);
else
else
- s
s
nprintf(buffer, buffer_size, "dbi_conn_error failed with status %i",
-
status);
+ snprintf(buffer, buffer_size, "dbi_conn_error failed with status %i",
+ status);
- return
(buffer)
;
+ return
buffer
;
} /* }}} const char *cdbi_conn_error */
static int cdbi_result_get_field(dbi_result res, /* {{{ */
} /* }}} const char *cdbi_conn_error */
static int cdbi_result_get_field(dbi_result res, /* {{{ */
@@
-124,19
+125,19
@@
static int cdbi_result_get_field(dbi_result res, /* {{{ */
if (src_type == DBI_TYPE_ERROR) {
ERROR("dbi plugin: cdbi_result_get: "
"dbi_result_get_field_type_idx failed.");
if (src_type == DBI_TYPE_ERROR) {
ERROR("dbi plugin: cdbi_result_get: "
"dbi_result_get_field_type_idx failed.");
- return
(-1)
;
+ return
-1
;
}
if (src_type == DBI_TYPE_INTEGER) {
long long value;
value = dbi_result_get_longlong_idx(res, index);
}
if (src_type == DBI_TYPE_INTEGER) {
long long value;
value = dbi_result_get_longlong_idx(res, index);
- s
s
nprintf(buffer, buffer_size, "%lli", value);
+ snprintf(buffer, buffer_size, "%lli", value);
} else if (src_type == DBI_TYPE_DECIMAL) {
double value;
value = dbi_result_get_double_idx(res, index);
} else if (src_type == DBI_TYPE_DECIMAL) {
double value;
value = dbi_result_get_double_idx(res, index);
- s
s
nprintf(buffer, buffer_size, "%63.15g", value);
+ snprintf(buffer, buffer_size, "%63.15g", value);
} else if (src_type == DBI_TYPE_STRING) {
const char *value;
} else if (src_type == DBI_TYPE_STRING) {
const char *value;
@@
-144,7
+145,7
@@
static int cdbi_result_get_field(dbi_result res, /* {{{ */
if (value == NULL)
sstrncpy(buffer, "", buffer_size);
else if (strcmp("ERROR", value) == 0)
if (value == NULL)
sstrncpy(buffer, "", buffer_size);
else if (strcmp("ERROR", value) == 0)
- return
(-1)
;
+ return
-1
;
else
sstrncpy(buffer, value, buffer_size);
}
else
sstrncpy(buffer, value, buffer_size);
}
@@
-160,10
+161,10
@@
static int cdbi_result_get_field(dbi_result res, /* {{{ */
ERROR("dbi plugin: Column `%s': Don't know how to handle "
"source type %hu.",
field_name, src_type);
ERROR("dbi plugin: Column `%s': Don't know how to handle "
"source type %hu.",
field_name, src_type);
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_result_get_field */
static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
} /* }}} int cdbi_result_get_field */
static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
@@
-173,6
+174,7
@@
static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
sfree(db->name);
sfree(db->select_db);
sfree(db->name);
sfree(db->select_db);
+ sfree(db->plugin_name);
sfree(db->driver);
sfree(db->host);
sfree(db->driver);
sfree(db->host);
@@
-226,14
+228,14
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
(ci->values[1].type != OCONFIG_TYPE_NUMBER))) {
WARNING("dbi plugin: The `DriverOption' config option "
"needs exactly two arguments.");
(ci->values[1].type != OCONFIG_TYPE_NUMBER))) {
WARNING("dbi plugin: The `DriverOption' config option "
"needs exactly two arguments.");
- return
(-1)
;
+ return
-1
;
}
option = realloc(db->driver_options,
sizeof(*option) * (db->driver_options_num + 1));
if (option == NULL) {
ERROR("dbi plugin: realloc failed");
}
option = realloc(db->driver_options,
sizeof(*option) * (db->driver_options_num + 1));
if (option == NULL) {
ERROR("dbi plugin: realloc failed");
- return
(-1)
;
+ return
-1
;
}
db->driver_options = option;
}
db->driver_options = option;
@@
-243,7
+245,7
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
option->key = strdup(ci->values[0].value.string);
if (option->key == NULL) {
ERROR("dbi plugin: strdup failed.");
option->key = strdup(ci->values[0].value.string);
if (option->key == NULL) {
ERROR("dbi plugin: strdup failed.");
- return
(-1)
;
+ return
-1
;
}
if (ci->values[1].type == OCONFIG_TYPE_STRING) {
}
if (ci->values[1].type == OCONFIG_TYPE_STRING) {
@@
-251,7
+253,7
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
if (option->value.string == NULL) {
ERROR("dbi plugin: strdup failed.");
sfree(option->key);
if (option->value.string == NULL) {
ERROR("dbi plugin: strdup failed.");
sfree(option->key);
- return
(-1)
;
+ return
-1
;
}
} else {
assert(ci->values[1].type == OCONFIG_TYPE_NUMBER);
}
} else {
assert(ci->values[1].type == OCONFIG_TYPE_NUMBER);
@@
-260,7
+262,7
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
}
db->driver_options_num++;
}
db->driver_options_num++;
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_config_add_database_driver_option */
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
} /* }}} int cdbi_config_add_database_driver_option */
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
@@
-271,19
+273,19
@@
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("dbi plugin: The `Database' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("dbi plugin: The `Database' block "
"needs exactly one string argument.");
- return
(-1)
;
+ return
-1
;
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("dbi plugin: calloc failed.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("dbi plugin: calloc failed.");
- return
(-1)
;
+ return
-1
;
}
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
}
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
- return
(status)
;
+ return
status
;
}
/* Fill the `cdbi_database_t' structure.. */
}
/* Fill the `cdbi_database_t' structure.. */
@@
-303,6
+305,8
@@
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
status = cf_util_get_string(child, &db->host);
else if (strcasecmp("Interval", child->key) == 0)
status = cf_util_get_cdtime(child, &db->interval);
status = cf_util_get_string(child, &db->host);
else if (strcasecmp("Interval", child->key) == 0)
status = cf_util_get_cdtime(child, &db->interval);
+ else if (strcasecmp("Plugin", child->key) == 0)
+ status = cf_util_get_string(child, &db->plugin_name);
else {
WARNING("dbi plugin: Option `%s' not allowed here.", child->key);
status = -1;
else {
WARNING("dbi plugin: Option `%s' not allowed here.", child->key);
status = -1;
@@
-376,10
+380,10
@@
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
if (status != 0) {
cdbi_database_free(db);
if (status != 0) {
cdbi_database_free(db);
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_config_add_database */
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int cdbi_config_add_database */
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
@@
-396,7
+400,7
@@
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
}
} /* for (ci->children) */
}
} /* for (ci->children) */
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_config */
/* }}} End of configuration handling functions */
} /* }}} int cdbi_config */
/* }}} End of configuration handling functions */
@@
-407,34
+411,34
@@
static int cdbi_init(void) /* {{{ */
int status;
if (did_init != 0)
int status;
if (did_init != 0)
- return
(0)
;
+ return
0
;
if (queries_num == 0) {
ERROR("dbi plugin: No <Query> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
if (queries_num == 0) {
ERROR("dbi plugin: No <Query> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
- return
(-1)
;
+ return
-1
;
}
if (databases_num == 0) {
ERROR("dbi plugin: No <Database> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
}
if (databases_num == 0) {
ERROR("dbi plugin: No <Database> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
- return
(-1)
;
+ return
-1
;
}
status = dbi_initialize_r(/* driverdir = */ NULL, &dbi_instance);
if (status < 0) {
ERROR("dbi plugin: cdbi_init: dbi_initialize_r failed with status %i.",
status);
}
status = dbi_initialize_r(/* driverdir = */ NULL, &dbi_instance);
if (status < 0) {
ERROR("dbi plugin: cdbi_init: dbi_initialize_r failed with status %i.",
status);
- return
(-1)
;
+ return
-1
;
} else if (status == 0) {
ERROR("dbi plugin: `dbi_initialize_r' could not load any drivers. Please "
"install at least one `DBD' or check your installation.");
} else if (status == 0) {
ERROR("dbi plugin: `dbi_initialize_r' could not load any drivers. Please "
"install at least one `DBD' or check your installation.");
- return
(-1)
;
+ return
-1
;
}
DEBUG("dbi plugin: cdbi_init: dbi_initialize_r reports %i driver%s.", status,
(status == 1) ? "" : "s");
}
DEBUG("dbi plugin: cdbi_init: dbi_initialize_r reports %i driver%s.", status,
(status == 1) ? "" : "s");
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_init */
static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
} /* }}} int cdbi_init */
static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
@@
-545,7
+549,8
@@
static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
udb_query_prepare_result(
q, prep_area, (db->host ? db->host : hostname_g),
udb_query_prepare_result(
q, prep_area, (db->host ? db->host : hostname_g),
- /* plugin = */ "dbi", db->name, column_names, column_num,
+ /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "dbi",
+ db->name, column_names, column_num,
/* interval = */ (db->interval > 0) ? db->interval : 0);
/* 0 = error; 1 = success; */
/* interval = */ (db->interval > 0) ? db->interval : 0);
/* 0 = error; 1 = success; */
@@
-624,7
+629,7
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
if (db->connection != NULL) {
status = dbi_conn_ping(db->connection);
if (status != 0) /* connection is alive */
if (db->connection != NULL) {
status = dbi_conn_ping(db->connection);
if (status != 0) /* connection is alive */
- return
(0)
;
+ return
0
;
dbi_conn_close(db->connection);
db->connection = NULL;
dbi_conn_close(db->connection);
db->connection = NULL;
@@
-640,14
+645,14
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
driver = dbi_driver_list_r(driver, dbi_instance)) {
INFO("dbi plugin: * %s", dbi_driver_get_name(driver));
}
driver = dbi_driver_list_r(driver, dbi_instance)) {
INFO("dbi plugin: * %s", dbi_driver_get_name(driver));
}
- return
(-1)
;
+ return
-1
;
}
connection = dbi_conn_open(driver);
if (connection == NULL) {
ERROR("dbi plugin: cdbi_connect_database: dbi_conn_open (%s) failed.",
db->driver);
}
connection = dbi_conn_open(driver);
if (connection == NULL) {
ERROR("dbi plugin: cdbi_connect_database: dbi_conn_open (%s) failed.",
db->driver);
- return
(-1)
;
+ return
-1
;
}
/* Set all the driver options. Because this is a very very very generic
}
/* Set all the driver options. Because this is a very very very generic
@@
-691,7
+696,7
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
}
dbi_conn_close(connection);
}
dbi_conn_close(connection);
- return
(-1)
;
+ return
-1
;
}
} /* for (i = 0; i < db->driver_options_num; i++) */
}
} /* for (i = 0; i < db->driver_options_num; i++) */
@@
-702,7
+707,7
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
"dbi_conn_connect failed: %s",
db->name, cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
"dbi_conn_connect failed: %s",
db->name, cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
- return
(-1)
;
+ return
-1
;
}
if (db->select_db != NULL) {
}
if (db->select_db != NULL) {
@@
-715,12
+720,12
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
db->name, db->select_db,
cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
db->name, db->select_db,
cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
- return
(-1)
;
+ return
-1
;
}
}
db->connection = connection;
}
}
db->connection = connection;
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_connect_database */
static int cdbi_read_database(user_data_t *ud) /* {{{ */
} /* }}} int cdbi_connect_database */
static int cdbi_read_database(user_data_t *ud) /* {{{ */
@@
-733,7
+738,7
@@
static int cdbi_read_database(user_data_t *ud) /* {{{ */
status = cdbi_connect_database(db);
if (status != 0)
status = cdbi_connect_database(db);
if (status != 0)
- return
(status)
;
+ return
status
;
assert(db->connection != NULL);
db_version = dbi_conn_get_engine_version(db->connection);
assert(db->connection != NULL);
db_version = dbi_conn_get_engine_version(db->connection);
@@
-754,10
+759,10
@@
static int cdbi_read_database(user_data_t *ud) /* {{{ */
if (success == 0) {
ERROR("dbi plugin: All queries failed for database `%s'.", db->name);
if (success == 0) {
ERROR("dbi plugin: All queries failed for database `%s'.", db->name);
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_read_database */
static int cdbi_shutdown(void) /* {{{ */
} /* }}} int cdbi_read_database */
static int cdbi_shutdown(void) /* {{{ */
@@
-776,7
+781,7
@@
static int cdbi_shutdown(void) /* {{{ */
queries = NULL;
queries_num = 0;
queries = NULL;
queries_num = 0;
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_shutdown */
void module_register(void) /* {{{ */
} /* }}} int cdbi_shutdown */
void module_register(void) /* {{{ */
@@
-785,7
+790,3
@@
void module_register(void) /* {{{ */
plugin_register_init("dbi", cdbi_init);
plugin_register_shutdown("dbi", cdbi_shutdown);
} /* }}} void module_register */
plugin_register_init("dbi", cdbi_init);
plugin_register_shutdown("dbi", cdbi_shutdown);
} /* }}} void module_register */
-
-/*
- * vim: shiftwidth=2 softtabstop=2 et fdm=marker
- */