From: Sebastian Harl Date: Wed, 8 Jun 2016 22:36:18 +0000 (+0200) Subject: parse_identifier: Make hostname optional, if a default has been specified. X-Git-Tag: collectd-5.7.0~49^2~4 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5bed427b409db41140d5799c979ee556dd66393d;p=collectd.git parse_identifier: Make hostname optional, if a default has been specified. --- diff --git a/src/daemon/common.c b/src/daemon/common.c index 654a5a09..e05da5ce 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -1011,7 +1011,8 @@ int format_values (char *ret, size_t ret_len, /* {{{ */ int parse_identifier (char *str, char **ret_host, char **ret_plugin, char **ret_plugin_instance, - char **ret_type, char **ret_type_instance) + char **ret_type, char **ret_type_instance, + char *default_host) { char *hostname = NULL; char *plugin = NULL; @@ -1030,8 +1031,19 @@ int parse_identifier (char *str, char **ret_host, type = strchr (plugin, '/'); if (type == NULL) - return (-1); - *type = '\0'; type++; + { + if (default_host == NULL) + return (-1); + /* else: no host specified; use default */ + type = plugin; + plugin = hostname; + hostname = default_host; + } + else + { + *type = '\0'; + type++; + } plugin_instance = strchr (plugin, '-'); if (plugin_instance != NULL) @@ -1072,7 +1084,8 @@ int parse_identifier_vl (const char *str, value_list_t *vl) /* {{{ */ status = parse_identifier (str_copy, &host, &plugin, &plugin_instance, - &type, &type_instance); + &type, &type_instance, + /* default_host = */ NULL); if (status != 0) return (status); diff --git a/src/daemon/common.h b/src/daemon/common.h index 6d01ca4b..67ca1c14 100644 --- a/src/daemon/common.h +++ b/src/daemon/common.h @@ -320,7 +320,8 @@ int format_values (char *ret, size_t ret_len, int parse_identifier (char *str, char **ret_host, char **ret_plugin, char **ret_plugin_instance, - char **ret_type, char **ret_type_instance); + char **ret_type, char **ret_type_instance, + char *default_host); int parse_identifier_vl (const char *str, value_list_t *vl); int parse_value (const char *value, value_t *ret_value, int ds_type); int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds); diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c index cfd6a481..7e26be7b 100644 --- a/src/utils_cmd_flush.c +++ b/src/utils_cmd_flush.c @@ -82,7 +82,8 @@ cmd_status_t cmd_parse_flush (size_t argc, char **argv, ret_flush->identifiers_num++; if (parse_identifier (opt_value, &id->host, &id->plugin, &id->plugin_instance, - &id->type, &id->type_instance) != 0) + &id->type, &id->type_instance, + NULL) != 0) { cmd_error (CMD_PARSE_ERROR, err, "Invalid identifier `%s'.", opt_value); diff --git a/src/utils_cmd_getthreshold.c b/src/utils_cmd_getthreshold.c index b2a0a23b..e6086f27 100644 --- a/src/utils_cmd_getthreshold.c +++ b/src/utils_cmd_getthreshold.c @@ -101,7 +101,8 @@ int handle_getthreshold (FILE *fh, char *buffer) status = parse_identifier (identifier_copy, &host, &plugin, &plugin_instance, - &type, &type_instance); + &type, &type_instance, + /* default_host = */ NULL); if (status != 0) { DEBUG ("handle_getthreshold: Cannot parse identifier `%s'.", identifier); diff --git a/src/utils_cmd_getval.c b/src/utils_cmd_getval.c index 76af1894..3a8a2be8 100644 --- a/src/utils_cmd_getval.c +++ b/src/utils_cmd_getval.c @@ -55,7 +55,8 @@ cmd_status_t cmd_parse_getval (size_t argc, char **argv, status = parse_identifier (argv[0], &ret_getval->identifier.host, &ret_getval->identifier.plugin, &ret_getval->identifier.plugin_instance, - &ret_getval->identifier.type, &ret_getval->identifier.type_instance); + &ret_getval->identifier.type, &ret_getval->identifier.type_instance, + NULL); if (status != 0) { DEBUG ("cmd_parse_getval: Cannot parse identifier `%s'.", identifier_copy); diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c index af6b484d..0a0af8ae 100644 --- a/src/utils_cmd_putval.c +++ b/src/utils_cmd_putval.c @@ -102,7 +102,8 @@ cmd_status_t cmd_parse_putval (size_t argc, char **argv, status = parse_identifier (identifier, &hostname, &plugin, &plugin_instance, - &type, &type_instance); + &type, &type_instance, + NULL); if (status != 0) { DEBUG ("cmd_handle_putval: Cannot parse identifier `%s'.",