int Ganglia_value_send( Ganglia_metric gmetric, Ganglia_udp_send_channels send_channels ) { int len, i; XDR x; char gmetricmsg[GANGLIA_MAX_MESSAGE_LEN]; Ganglia_value_msg msg; const apr_array_header_t *arr; const apr_table_entry_t *elts; const char *spoof = SPOOF; apr_pool_t *gm_pool=(apr_pool_t*)gmetric->pool; if (myhost[0] == '\0') apr_gethostname( (char*)myhost, APRMAXHOSTLEN+1, gm_pool); msg.id = gmetric_string; msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup (gm_pool, (char*)myhost); msg.Ganglia_value_msg_u.gstr.metric_id.name = apr_pstrdup (gm_pool, gmetric->msg->name); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = FALSE; msg.Ganglia_value_msg_u.gstr.fmt = apr_pstrdup (gm_pool, "%s"); msg.Ganglia_value_msg_u.gstr.str = apr_pstrdup (gm_pool, gmetric->value); arr = apr_table_elts(gmetric->extra); elts = (const apr_table_entry_t *)arr->elts; /* add all of the metadata to the packet */ for (i = 0; i < arr->nelts; ++i) { if (elts[i].key == NULL) continue; /* Replace the host name with the spoof host if it exists in the metadata */ if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HOST, elts[i].key) == 0) { msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup (gm_pool, elts[i].val); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE; } if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HEARTBEAT, elts[i].key) == 0) { msg.Ganglia_value_msg_u.gstr.metric_id.name = apr_pstrdup (gm_pool, "heartbeat"); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE; } } /* Send the message */ xdrmem_create(&x, gmetricmsg, GANGLIA_MAX_MESSAGE_LEN, XDR_ENCODE); if(!xdr_Ganglia_value_msg(&x, &msg)) { return 1; } len = xdr_getpos(&x); /* Send the encoded data along...*/ return Ganglia_udp_send_message( send_channels, gmetricmsg, len); }
int Ganglia_metadata_send_real( Ganglia_metric gmetric, Ganglia_udp_send_channels send_channels, char *override_string ) { int len, i; XDR x; char gmetricmsg[GANGLIA_MAX_MESSAGE_LEN]; Ganglia_metadata_msg msg; const apr_array_header_t *arr; const apr_table_entry_t *elts; const char *spoof = SPOOF; apr_pool_t *gm_pool=(apr_pool_t*)gmetric->pool; if (myhost[0] == '\0') apr_gethostname( (char*)myhost, APRMAXHOSTLEN+1, gm_pool); msg.id = gmetadata_full; memcpy( &(msg.Ganglia_metadata_msg_u.gfull.metric), gmetric->msg, sizeof(Ganglia_metadata_message)); msg.Ganglia_metadata_msg_u.gfull.metric_id.name = apr_pstrdup (gm_pool, gmetric->msg->name); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.name: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.name); if ( override_string != NULL ) { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, (char*)override_string); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.host: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.host); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } else { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, (char*)myhost); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.host: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.host); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = FALSE; } arr = apr_table_elts(gmetric->extra); elts = (const apr_table_entry_t *)arr->elts; msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_len = arr->nelts; msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val = (Ganglia_extra_data*)apr_pcalloc(gm_pool, sizeof(Ganglia_extra_data)*arr->nelts); /* add all of the metadata to the packet */ for (i = 0; i < arr->nelts; ++i) { if (elts[i].key == NULL) continue; /* Replace the host name with the spoof host if it exists in the metadata */ if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HOST, elts[i].key) == 0) { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, elts[i].val); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HEARTBEAT, elts[i].key) == 0) { msg.Ganglia_metadata_msg_u.gfull.metric_id.name = apr_pstrdup (gm_pool, "heartbeat"); msg.Ganglia_metadata_msg_u.gfull.metric.name = msg.Ganglia_metadata_msg_u.gfull.metric_id.name; msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val[i].name = apr_pstrdup(gm_pool, elts[i].key); msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val[i].data = apr_pstrdup(gm_pool, elts[i].val); } /* Send the message */ xdrmem_create(&x, gmetricmsg, GANGLIA_MAX_MESSAGE_LEN, XDR_ENCODE); if(!xdr_Ganglia_metadata_msg(&x, &msg)) { return 1; } len = xdr_getpos(&x); /* Send the encoded data along...*/ return Ganglia_udp_send_message( send_channels, gmetricmsg, len); }