From: Pavel Rochnyack Date: Fri, 15 Jun 2018 05:05:58 +0000 (+0700) Subject: snmp plugin: Replace reserved chars in hostname value X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9b5561b57eafbbdb8560644250cfb09bee2e8ce7;p=collectd.git snmp plugin: Replace reserved chars in hostname value --- diff --git a/src/snmp.c b/src/snmp.c index f5916004..1bf6664c 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1193,6 +1193,15 @@ static bool csnmp_ignore_instance(csnmp_cell_char_t *cell, return 0; } /* bool csnmp_ignore_instance */ +static void csnmp_cell_replace_reserved_chars(csnmp_cell_char_t *cell) { + for (char *ptr = cell->value; *ptr != '\0'; ptr++) { + if ((*ptr > 0) && (*ptr < 32)) + *ptr = ' '; + else if (*ptr == '/') + *ptr = '_'; + } +} + static int csnmp_dispatch_table(host_definition_t *host, data_definition_t *data, csnmp_cell_char_t *instance_cells, @@ -1618,13 +1627,7 @@ static int csnmp_read_table(host_definition_t *host, data_definition_t *data) { if (csnmp_ignore_instance(cell, data)) { sfree(cell); } else { - /**/ - for (char *ptr = cell->value; *ptr != '\0'; ptr++) { - if ((*ptr > 0) && (*ptr < 32)) - *ptr = ' '; - else if (*ptr == '/') - *ptr = '_'; - } + csnmp_cell_replace_reserved_chars(cell); DEBUG("snmp plugin: il->instance = `%s';", cell->value); csnmp_cells_append(&instance_cells_head, &instance_cells_tail, cell); @@ -1651,6 +1654,8 @@ static int csnmp_read_table(host_definition_t *host, data_definition_t *data) { break; } + csnmp_cell_replace_reserved_chars(cell); + DEBUG("snmp plugin: il->hostname = `%s';", cell->value); csnmp_cells_append(&hostname_cells_head, &hostname_cells_tail, cell); } else /* The variable we are processing is a normal value */