X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdbi.c;h=8466bd11b1271f49c38f885f6b72d4c13e8a6d99;hp=4ef9f8c59f3fe5f08fb39b714366ae4ab37cf630;hb=54619dc85fd308b21ed09a0271e5c7383c7921b9;hpb=38e94dcc796e5d00088826ffd5d43ca5a2e590a2 diff --git a/src/dbi.c b/src/dbi.c index 4ef9f8c5..8466bd11 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -26,9 +26,9 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" -#include "utils_db_query.h" +#include "utils/common/common.h" +#include "utils/db_query/db_query.h" #include @@ -64,8 +64,6 @@ struct cdbi_database_s /* {{{ */ char *select_db; char *plugin_name; - cdtime_t interval; - char *driver; char *host; cdbi_driver_option_t *driver_options; @@ -267,6 +265,7 @@ static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ { + cdtime_t interval = 0; cdbi_database_t *db; int status; @@ -304,7 +303,7 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("Host", child->key) == 0) 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_cdtime(child, &interval); else if (strcasecmp("Plugin", child->key) == 0) status = cf_util_get_string(child, &db->plugin_name); else { @@ -370,7 +369,7 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ /* group = */ NULL, /* name = */ name ? name : db->name, /* callback = */ cdbi_read_database, - /* interval = */ (db->interval > 0) ? db->interval : 0, + /* interval = */ interval, &(user_data_t){ .data = db, }); @@ -547,11 +546,16 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ sstrncpy(column_names[i], column_name, DATA_MAX_NAME_LEN); } /* }}} for (i = 0; i < column_num; i++) */ - udb_query_prepare_result( + status = udb_query_prepare_result( q, prep_area, (db->host ? db->host : hostname_g), /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "dbi", - db->name, column_names, column_num, - /* interval = */ (db->interval > 0) ? db->interval : 0); + db->name, column_names, column_num); + + if (status != 0) { + ERROR("dbi plugin: udb_query_prepare_result failed with status %i.", + status); + BAIL_OUT(-1); + } /* 0 = error; 1 = success; */ status = dbi_result_first_row(res); /* {{{ */ @@ -599,15 +603,16 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ } /* }}} */ /* Get the next row from the database. */ + if (!dbi_result_has_next_row(res)) + break; + status = dbi_result_next_row(res); /* {{{ */ if (status != 1) { - if (dbi_conn_error(db->connection, NULL) != 0) { - char errbuf[1024]; - WARNING("dbi plugin: cdbi_read_database_query (%s, %s): " - "dbi_result_next_row failed: %s.", - db->name, udb_query_get_name(q), - cdbi_strerror(db->connection, errbuf, sizeof(errbuf))); - } + char errbuf[1024]; + WARNING("dbi plugin: cdbi_read_database_query (%s, %s): " + "dbi_result_next_row failed: %s.", + db->name, udb_query_get_name(q), + cdbi_strerror(db->connection, errbuf, sizeof(errbuf))); break; } /* }}} */ } /* }}} while (42) */