summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cb23b65)
raw | patch | inline | side by side (parent: cb23b65)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 26 Aug 2008 14:09:27 +0000 (16:09 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Tue, 26 Aug 2008 17:09:09 +0000 (19:09 +0200) |
Those options may be used to specify the minimum and maximum version of
PostgreSQL which is required for some query. This may be used to automatically
configure the plugin for a heterogeneous environment while using the same
configuration file on all hosts.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
PostgreSQL which is required for some query. This may be used to automatically
configure the plugin for a heterogeneous environment while using the same
configuration file on all hosts.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/postgresql.c | patch | blob | history |
diff --git a/src/postgresql.c b/src/postgresql.c
index ed55ee7e51316a59e9d797632aee4e98d8bcd200..046cf5a68354fda7c29b978f0502d483ba007e9b 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
c_psql_col_t *cols;
int cols_num;
+
+ int min_pg_version;
+ int max_pg_version;
} c_psql_query_t;
typedef struct {
query->cols = NULL;
query->cols_num = 0;
+
+ query->min_pg_version = 0;
+ query->max_pg_version = INT_MAX;
return query;
} /* c_psql_query_new */
return;
} /* c_psql_query_delete */
-static c_psql_query_t *c_psql_query_get (const char *name)
+static c_psql_query_t *c_psql_query_get (const char *name, int server_version)
{
int i;
for (i = 0; i < queries_num; ++i)
- if (0 == strcasecmp (name, queries[i].name))
+ if (0 == strcasecmp (name, queries[i].name)
+ && ((-1 == server_version)
+ || ((queries[i].min_pg_version <= server_version)
+ && (server_version <= queries[i].max_pg_version))))
return queries + i;
return NULL;
} /* c_psql_query_get */
char *server_host;
int server_version;
+ int j;
+
status = ssnprintf (buf, buf_len, "dbname = '%s'", db->database);
if (0 < status) {
buf += status;
if (3 > db->proto_version)
log_warn ("Protocol version %d does not support parameters.",
db->proto_version);
+
+ /* Now that we know the PostgreSQL server version, we can get the
+ * right version of each query definition. */
+ for (j = 0; j < db->queries_num; ++j) {
+ c_psql_query_t *tmp;
+
+ tmp = c_psql_query_get (db->queries[j]->name, server_version);
+
+ if (tmp == db->queries[j])
+ continue;
+
+ if (NULL == tmp) {
+ log_err ("Query \"%s\" not found for server version %i - "
+ "please check your configuration.",
+ db->queries[j]->name, server_version);
+
+ if (db->queries_num - j - 1 > 0)
+ memmove (db->queries + j, db->queries + j + 1,
+ (db->queries_num - j - 1) * sizeof (*db->queries));
+
+ --db->queries_num;
+ --j;
+ continue;
+ }
+
+ db->queries[j] = tmp;
+ }
}
plugin_register_read ("postgresql", c_psql_read);
return 0;
} /* config_set_s */
+static int config_set_i (char *name, int *var, const oconfig_item_t *ci)
+{
+ if ((0 != ci->children_num) || (1 != ci->values_num)
+ || (OCONFIG_TYPE_NUMBER != ci->values[0].type)) {
+ log_err ("%s expects a single number argument.", name);
+ return 1;
+ }
+
+ *var = (int)ci->values[0].value.number;
+ return 0;
+} /* config_set_i */
+
static int config_set_param (c_psql_query_t *query, const oconfig_item_t *ci)
{
c_psql_param_t param;
{
c_psql_query_t *query;
- query = c_psql_query_get (name);
+ query = c_psql_query_get (name, -1);
if (NULL == query) {
log_err ("Query \"%s\" not found - please check your configuration.",
name);
config_set_param (query, c);
else if (0 == strcasecmp (c->key, "Column"))
config_set_column (query, c);
+ else if (0 == strcasecmp (c->key, "MinPGVersion"))
+ config_set_i ("MinPGVersion", &query->min_pg_version, c);
+ else if (0 == strcasecmp (c->key, "MaxPGVersion"))
+ config_set_i ("MaxPGVersion", &query->max_pg_version, c);
else
log_warn ("Ignoring unknown config key \"%s\".", c->key);
}