Skip to content

Commit

Permalink
dimName: replace last char with * if it equals #
Browse files Browse the repository at this point in the history
  • Loading branch information
niemijoe committed Aug 11, 2022
1 parent 8b3ac91 commit f39b5f9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mqtt_data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,24 @@ def send_mqtt_msg_count_into_azure(topic_data_collection):

send_custom_metrics_request(custom_metric_json, attempts_remaining=3)

def replace_last_char_if_equals(topic_name, char_to_replace, char_to_use):
last_char = topic_name[-1]
if (last_char == char_to_replace):
topic_name = topic_name.rstrip(topic_name[-1])
topic_name = f"{topic_name}{char_to_use}"
return topic_name


def get_series_array(topic_data_collection):
series_array = []
for topic_name in topic_data_collection:
topic_msg_count = topic_data_collection[topic_name]

# Azure doesn't seem to like # in the end of a dimValue, replace it with *
parsed_topic_name = replace_last_char_if_equals(topic_name, "#", "*")
dimValue = {
"dimValues": [
topic_name
parsed_topic_name
],
"sum": topic_msg_count,
"count": 1
Expand Down

0 comments on commit f39b5f9

Please sign in to comment.