Skip to content

Instantly share code, notes, and snippets.

@sikmir
Created March 10, 2023 14:07
Show Gist options
  • Save sikmir/a2b5c76c5dc414a0a8b8655c1e204a21 to your computer and use it in GitHub Desktop.
Save sikmir/a2b5c76c5dc414a0a8b8655c1e204a21 to your computer and use it in GitHub Desktop.
mosquitto2puml.sh
#!/bin/bash
#
# How to use:
# ./mosquitto2puml.sh > mosquitto.puml
# PLANTUML_LIMIT_SIZE=8192 plantuml mosquitto.puml
#
LOG=${1:-/var/log/mosquitto/mosquitto.log}
echo "@startuml"
echo "queue Mosquitto as mqtt #lightblue"
while IFS= read -r line; do
if [[ $line =~ "Received " ]]; then
echo $line | awk '{from=$5; msg=$3; $1=$2=$3=$4=$5=""; printf("\"%s\" -> mqtt: %s %s\n",from,msg,$0)}'
elif [[ $line =~ "Sending " ]]; then
echo $line | awk '{to=$5; msg=$3; $1=$2=$3=$4=$5=""; printf("mqtt -> \"%s\": %s %s\n",to,msg,$0)}'
fi
done < $LOG
echo "@enduml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment