index f03380871a1de9dc38c733cea763f592f7624c2f..4c92c151770c53a34b44b147df793658c3343752 100644 (file)
#include "sysdb.h"
#include "core/plugin.h"
#include "core/store.h"
+#include "utils/error.h"
#include "utils/dbi.h"
#include "utils/string.h"
status = sdb_store_host(&host);
if (status < 0) {
- fprintf(stderr, "puppet storeconfigs backend: Failed to store/update "
- "host '%s'.\n", host.host_name);
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+ "store/update host '%s'.\n", host.host_name);
free(host.host_name);
return -1;
}
else if (! status)
- fprintf(stderr, "puppet storeconfigs backend: Added/updated host '%s' "
- "(last update timestamp = %"PRIscTIME").\n",
- host.host_name, host.host_last_update);
+ sdb_error_set(SDB_LOG_DEBUG, "puppet storeconfigs backend: "
+ "Added/updated host '%s' (last update timestamp = "
+ "%"PRIscTIME").\n", host.host_name, host.host_last_update);
free(host.host_name);
return 0;
} /* sdb_puppet_stcfg_get_hosts */
status = sdb_store_attribute(&attr);
if (status < 0) {
- fprintf(stderr, "puppet storeconfigs backend: Failed to store/update "
- "host attribute '%s' for host '%s'.\n", attr.attr_name,
- attr.hostname);
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+ "store/update host attribute '%s' for host '%s'.\n",
+ attr.attr_name, attr.hostname);
free(attr.hostname);
free(attr.attr_name);
free(attr.attr_value);
client = SDB_OBJ_WRAPPER(user_data)->data;
if (sdb_dbi_client_connect(client)) {
- fprintf(stderr, "puppet storeconfigs backend: "
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
"Failed to connect to the storeconfigs DB.\n");
return -1;
}
- fprintf(stderr, "puppet storeconfigs backend: Successfully "
+ sdb_error_set(SDB_LOG_INFO, "puppet storeconfigs backend: Successfully "
"connected to the storeconfigs DB.\n");
return 0;
} /* sdb_puppet_stcfg_init */
client = SDB_OBJ_WRAPPER(user_data)->data;
if (sdb_dbi_client_check_conn(client)) {
- fprintf(stderr, "puppet storeconfigs backend: "
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
"Connection to storeconfigs DB failed.\n");
return -1;
}
if (sdb_dbi_exec_query(client, "SELECT name, updated_at FROM hosts;",
sdb_puppet_stcfg_get_hosts, NULL, /* #columns = */ 2,
/* col types = */ SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
- fprintf(stderr, "puppet storeconfigs backend: Failed to retrieve "
- "hosts from the storeconfigs DB.\n");
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+ "retrieve hosts from the storeconfigs DB.\n");
return -1;
}
sdb_puppet_stcfg_get_attrs, NULL, /* #columns = */ 4,
/* col types = */ SDB_TYPE_STRING, SDB_TYPE_STRING,
SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
- fprintf(stderr, "puppet storeconfigs backend: Failed to retrieve "
- "host attributes from the storeconfigs DB.\n");
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+ "retrieve host attributes from the storeconfigs DB.\n");
return -1;
}
return 0;
int i;
if (oconfig_get_string(ci, &name)) {
- fprintf(stderr, "puppet storeconfigs backend: Connection requires a "
- "single string argument\n\tUsage: <Connection NAME>\n");
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Connection "
+ "requires a single string argument\n"
+ "\tUsage: <Connection NAME>\n");
return -1;
}
if (! strcasecmp(child->key, "DBAdapter")) {
if (oconfig_get_string(child, &driver)) {
- fprintf(stderr, "puppet storeconfigs backend: DBAdapter "
- "requires a single string argument inside "
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+ "DBAdapter requires a single string argument inside "
"<Connection %s>\n\tUsage: DBAdapter NAME\n",
name);
}
}
else if (! strcasecmp(child->key, "DBName")) {
if (oconfig_get_string(child, &database)) {
- fprintf(stderr, "puppet storeconfigs backend: DBName"
- "requires a single string argument inside "
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+ "DBName requires a single string argument inside "
"<Connection %s>\n\tUsage: DBName NAME\n",
name);
}
if ((child->values_num != 2)
|| (child->values[0].type != OCONFIG_TYPE_STRING)
|| (child->values[1].type != OCONFIG_TYPE_STRING)) {
- fprintf(stderr, "puppet storeconfigs backend: DBIOption "
- "requires exactly two string arguments inside "
- "<Connection %s>\n\tUsage: DBIOption KEY VALUE\n",
- name);
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+ "DBIOption requires exactly two string arguments "
+ "inside <Connection %s>\n"
+ "\tUsage: DBIOption KEY VALUE\n", name);
continue;
}
value = child->values[1].value.string;
}
else {
- fprintf(stderr, "puppet storeconfigs backend: Ignoring unknown "
- "config option '%s' inside <Connection %s>.\n",
- child->key, name);
+ sdb_error_set(SDB_LOG_WARNING, "puppet storeconfigs backend: "
+ "Ignoring unknown config option '%s' inside "
+ "<Connection %s>.\n", child->key, name);
continue;
}
if (status) {
- fprintf(stderr, "puppet storeconfigs backend: Option '%s' "
- "requires a single string argument inside "
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Option "
+ "'%s' requires a single string argument inside "
"<Connection %s>\n\tUsage: DBAdapter NAME\n",
child->key, name);
continue;
if (! options) {
if (! (options = sdb_dbi_options_create())) {
char errmsg[1024];
- fprintf(stderr, "puppet storeconfigs backend: Failed to "
- "create DBI options object: %s\n",
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+ "Failed to create DBI options object: %s\n",
sdb_strerror(errno, errmsg, sizeof(errmsg)));
continue;
}
if (sdb_dbi_options_add(options, key, value)) {
char errmsg[1024];
- fprintf(stderr, "puppet storeconfigs backend: Failed to add "
- "option '%s': %s\n", key,
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+ "Failed to add option '%s': %s\n", key,
sdb_strerror(errno, errmsg, sizeof(errmsg)));
continue;
}
}
if (! driver) {
- fprintf(stderr, "puppet storeconfigs backend: Connection '%s' "
- "missing the 'DBAdapter' option.\n", name);
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+ "Connection '%s' " "missing the 'DBAdapter' option.\n",
+ name);
return -1;
}
if (! database) {
- fprintf(stderr, "puppet storeconfigs backend: Connection '%s' "
- "missing the 'DBName' option.\n", name);
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+ "Connection '%s' missing the 'DBName' option.\n", name);
return -1;
}
client = sdb_dbi_client_create(driver, database);
if (! client) {
char errbuf[1024];
- fprintf(stderr, "puppet storeconfigs backend: "
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
"Failed to create DBI client: %s\n",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
(void (*)(void *))sdb_dbi_client_destroy);
if (! user_data) {
sdb_dbi_client_destroy(client);
- fprintf(stderr, "puppet storeconfigs backend: "
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
"Failed to allocate sdb_object_t\n");
return -1;
}
if (! strcasecmp(child->key, "Connection"))
sdb_puppet_stcfg_config_conn(child);
else
- fprintf(stderr, "puppet storeconfigs backend: Ignoring unknown "
- "config option '%s'.\n", child->key);
+ sdb_error_set(SDB_LOG_WARNING, "puppet storeconfigs backend: "
+ "Ignoring unknown config option '%s'.\n", child->key);
}
return 0;
} /* sdb_puppet_stcfg_config */
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
if (dbi_initialize(/* driver dir = */ NULL) < 0) {
- fprintf(stderr, "puppet storeconfigs backend: failed to initialize "
- "DBI; possibly you don't have any drivers installed.\n");
+ sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: failed to "
+ "initialize DBI; possibly you don't have any drivers "
+ "installed.\n");
return -1;
}