diff options
author | Alexander Couzens <lynxis@fe80.eu> | 2018-07-24 16:37:54 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2018-07-25 18:45:48 +0000 |
commit | 9af7076b01126ae07bb931b17ccb62cd9e48e6e6 (patch) | |
tree | 98c2fd85fc7596d1e7e28fe9ead5cff56584175b /src | |
parent | d910a3522782dace466a177a4bea35d6327b2b5f (diff) |
stats_statsd: sanitize statsd name
The statsd protocol use ':' as seperator between name and value.
It's not allowed to use the seperator in a name. Replace ':' with '.'
before sending the packet to the statsd server.
Change-Id: Ib46d08481e8ca04afd97cb9ae241e4e39c91ad66
Diffstat (limited to 'src')
-rw-r--r-- | src/stats_statsd.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/stats_statsd.c b/src/stats_statsd.c index c11c0132..5ae25702 100644 --- a/src/stats_statsd.c +++ b/src/stats_statsd.c @@ -68,6 +68,25 @@ struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name) return srep; } +/*! Replace all illegal ':' in the stats name, but not when used as value seperator. + * ':' is used as seperator between the name and the value in the statsd protocol. + * \param[inout] buf is a null terminated string containing name, value, unit. */ +static void osmo_stats_reporter_sanitize_name(char *buf) +{ + /* e.g. msc.loc_update_type:normal:1|c -> msc.loc_update_type.normal:1|c + * last is the seperator between name and value */ + char *last = strrchr(buf, ':'); + char *tmp = strchr(buf, ':'); + + if (!last) + return; + + while (tmp < last) { + *tmp = '.'; + tmp = strchr(buf, ':'); + } +} + static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep, const char *name1, unsigned int index1, const char *name2, int64_t value, const char *unit) @@ -134,8 +153,10 @@ static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep, return -EMSGSIZE; } - if (nchars > 0) + if (nchars > 0) { + osmo_stats_reporter_sanitize_name(buf); msgb_trim(srep->buffer, msgb_length(srep->buffer) + nchars); + } if (!srep->agg_enabled) rc = osmo_stats_reporter_send_buffer(srep); |