Skip to content

Commit

Permalink
Attempt to sanitize metric names.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbuchbinder committed Oct 31, 2011
1 parent a2e46b3 commit 1879103
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gmond/gmond.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,27 @@ setup_listen_channels_pollset( int reset )
}
}

void sanitize_metric_name(char *metric_name)
{
if (metric_name == NULL) return;
if (strlen(metric_name) < 1) return;
char *p = metric_name;
while (p < (metric_name + strlen(metric_name))) {
if (
!(*p >= 'A' && *p <= 'Z')
&& !(*p >= 'a' && *p <= 'z')
&& (*p != '_')
&& (*p != '-')
&& (*p != '.')
&& (*p != '\0')
) {
*p = '_';
}
p++;
}
}


static void
get_metric_names (Ganglia_metric_id *metric_id, char **metricName, char **realName)
{
Expand Down Expand Up @@ -1034,6 +1055,7 @@ void
Ganglia_metadata_save( Ganglia_host *host, Ganglia_metadata_msg *message )
{
/* Search for the Ganglia_metadata in the Ganglia_host */
sanitize_metric_name(message->Ganglia_metadata_msg_u.gfull.metric_id.name);
Ganglia_metadata *metric =
(Ganglia_metadata *)apr_hash_get(host->metrics,
message->Ganglia_metadata_msg_u.gfull.metric_id.name,
Expand Down Expand Up @@ -1336,6 +1358,7 @@ process_udp_recv_channel(const apr_pollfd_t *desc, apr_time_t now)
ret = xdr_Ganglia_metadata_msg(&x, &fmsg);
if (ret)
hostdata = Ganglia_host_get(remoteip, remotesa, &(fmsg.Ganglia_metadata_msg_u.grequest.metric_id));
sanitize_metric_name(fmsg.Ganglia_metadata_msg_u.grequest.metric_id.name);
if(!ret || !hostdata)
{
ganglia_scoreboard_inc(PKTS_RECVD_FAILED);
Expand All @@ -1352,6 +1375,7 @@ process_udp_recv_channel(const apr_pollfd_t *desc, apr_time_t now)
ret = xdr_Ganglia_metadata_msg(&x, &fmsg);
if (ret)
hostdata = Ganglia_host_get(remoteip, remotesa, &(fmsg.Ganglia_metadata_msg_u.gfull.metric_id));
sanitize_metric_name(fmsg.Ganglia_metadata_msg_u.gfull.metric_id.name);
if(!ret || !hostdata)
{
ganglia_scoreboard_inc(PKTS_RECVD_FAILED);
Expand All @@ -1374,6 +1398,7 @@ process_udp_recv_channel(const apr_pollfd_t *desc, apr_time_t now)
ret = xdr_Ganglia_value_msg(&x, &vmsg);
if (ret)
hostdata = Ganglia_host_get(remoteip, remotesa, &(vmsg.Ganglia_value_msg_u.gstr.metric_id));
sanitize_metric_name(vmsg.Ganglia_value_msg_u.gstr.metric_id.name);
if(!ret || !hostdata)
{
ganglia_scoreboard_inc(PKTS_RECVD_FAILED);
Expand Down

3 comments on commit 1879103

@cburroughs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This excludes numbers too :-( So names like 95thpercentil and 90thpercentile both become __percentile cc @abramsm

@jbuchbinder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How right you are. Adjusting patch now. (hiding head in paper bag)

@jbuchbinder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 03fa55f

Please sign in to comment.