Skip to content

Commit

Permalink
Replace + with ^ in dimValue
Browse files Browse the repository at this point in the history
  • Loading branch information
niemijoe committed Aug 11, 2022
1 parent 1f1edf9 commit 4698a4c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions mqtt_data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,16 @@ 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, "#", "*")
# Azure doesn't seem to like # in a dimValue, replace it with *
parsed_topic_name = topic_name.replace("#", "*")
# Azure doesn't seem to like + in a dimValue, replace it with ^
parsed_topic_name = parsed_topic_name.replace("+", "^")

dimValue = {
"dimValues": [
parsed_topic_name
Expand Down

0 comments on commit 4698a4c

Please sign in to comment.