From 322088003195c6a0054a652f52a1a0683aebd75c Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 30 Mar 2010 21:55:13 +0200 Subject: [PATCH] utils_db_query: Added support for custom plugin intervals. The interval is specified when calling udb_query_prepare_result(). A value less than or equal to zero may be used to let udb use the default (interval_g). The dbi, oracle, and postgresql plugins have been updated accordingly. --- src/dbi.c | 2 +- src/oracle.c | 3 ++- src/postgresql.c | 2 +- src/utils_db_query.c | 14 +++++++++++++- src/utils_db_query.h | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/dbi.c b/src/dbi.c index 5dad197c..77f393f5 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -566,7 +566,7 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ udb_query_prepare_result (q, prep_area, hostname_g, /* plugin = */ "dbi", db->name, - column_names, column_num); + column_names, column_num, /* interval = */ -1); /* 0 = error; 1 = success; */ status = dbi_result_first_row (res); /* {{{ */ diff --git a/src/oracle.c b/src/oracle.c index 7ab5a0c1..3fe21254 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -585,7 +585,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ /* }}} End of the ``define'' stuff. */ status = udb_query_prepare_result (q, prep_area, hostname_g, - /* plugin = */ "oracle", db->name, column_names, column_num); + /* plugin = */ "oracle", db->name, column_names, column_num, + /* interval = */ -1); if (status != 0) { ERROR ("oracle plugin: o_read_database_query (%s, %s): " diff --git a/src/postgresql.c b/src/postgresql.c index 431f8e3b..99e40fec 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -424,7 +424,7 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q, host = db->host; status = udb_query_prepare_result (q, prep_area, host, "postgresql", - db->database, column_names, (size_t) column_num); + db->database, column_names, (size_t) column_num, db->interval); if (0 != status) { log_err ("udb_query_prepare_result failed with status %i.", status); diff --git a/src/utils_db_query.c b/src/utils_db_query.c index 13cdf9e5..7d594d81 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -84,6 +84,8 @@ struct udb_query_preparation_area_s /* {{{ */ char *plugin; char *db_name; + int interval; + udb_result_preparation_area_t *result_prep_areas; }; /* }}} */ @@ -228,6 +230,9 @@ static int udb_legacy_result_handle_result (udb_result_t *r, /* {{{ */ return (-1); } + if (q_area->interval > 0) + vl.interval = q_area->interval; + sstrncpy (vl.host, q_area->host, sizeof (vl.host)); sstrncpy (vl.plugin, q_area->plugin, sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, q_area->db_name, sizeof (vl.type_instance)); @@ -388,6 +393,9 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ } } + if (q_area->interval > 0) + vl.interval = q_area->interval; + sstrncpy (vl.host, q_area->host, sizeof (vl.host)); sstrncpy (vl.plugin, q_area->plugin, sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, q_area->db_name, sizeof (vl.type_instance)); @@ -1071,6 +1079,8 @@ void udb_query_finish_result (const udb_query_t const *q, /* {{{ */ sfree (prep_area->plugin); sfree (prep_area->db_name); + prep_area->interval = -1; + for (r = q->results, r_area = prep_area->result_prep_areas; r != NULL; r = r->next, r_area = r_area->next) { @@ -1137,7 +1147,7 @@ int udb_query_handle_result (const udb_query_t const *q, /* {{{ */ int udb_query_prepare_result (const udb_query_t const *q, /* {{{ */ udb_query_preparation_area_t *prep_area, const char *host, const char *plugin, const char *db_name, - char **column_names, size_t column_num) + char **column_names, size_t column_num, int interval) { udb_result_preparation_area_t *r_area; udb_result_t *r; @@ -1153,6 +1163,8 @@ int udb_query_prepare_result (const udb_query_t const *q, /* {{{ */ prep_area->plugin = strdup (plugin); prep_area->db_name = strdup (db_name); + prep_area->interval = interval; + if ((prep_area->host == NULL) || (prep_area->plugin == NULL) || (prep_area->db_name == NULL)) { diff --git a/src/utils_db_query.h b/src/utils_db_query.h index da235f79..fa2b2885 100644 --- a/src/utils_db_query.h +++ b/src/utils_db_query.h @@ -68,7 +68,7 @@ int udb_query_check_version (udb_query_t *q, unsigned int version); int udb_query_prepare_result (const udb_query_t const *q, udb_query_preparation_area_t *prep_area, const char *host, const char *plugin, const char *db_name, - char **column_names, size_t column_num); + char **column_names, size_t column_num, int interval); int udb_query_handle_result (const udb_query_t const *q, udb_query_preparation_area_t *prep_area, char **column_values); void udb_query_finish_result (const udb_query_t const *q, -- 2.30.2