Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions openwisp-monitoring/files/monitoring.agent
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ send_data() {
fi
filename="$TMP_DIR/$filename"
# check if the data file exist
if [ -f "$filename" ]; then
data=$(cat "$filename")
else
if ! [ -f "$filename" ]; then
[ "$VERBOSE_MODE" -eq "1" ] && logger -s "data file $filename not found." \
-p daemon.info
continue
Expand All @@ -176,7 +174,13 @@ send_data() {
break
fi
# send data
response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "$data" "$url")
if [ "$VERBOSE_MODE" -eq "1" ]; then
printf "data="
cat "$filename"
set -x
fi
response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "@$filename" "$url")
set +x
Comment on lines 176 to +183
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Guard xtrace toggling to avoid disabling external debugging.

set +x runs even when VERBOSE_MODE=0, which can unexpectedly disable xtrace enabled by the caller. Gate the disable to verbose mode only.

🔧 Proposed fix
-				if [ "$VERBOSE_MODE" -eq "1" ]; then
-					printf "data="
-					cat "$filename"
-					set -x
-				fi
-				response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "@$filename" "$url")
-				set +x
+				if [ "$VERBOSE_MODE" -eq "1" ]; then
+					printf "data="
+					cat "$filename"
+					set -x
+				fi
+				response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "@$filename" "$url")
+				if [ "$VERBOSE_MODE" -eq "1" ]; then
+					set +x
+				fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# send data
response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "$data" "$url")
if [ "$VERBOSE_MODE" -eq "1" ]; then
printf "data="
cat "$filename"
set -x
fi
response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "@$filename" "$url")
set +x
# send data
if [ "$VERBOSE_MODE" -eq "1" ]; then
printf "data="
cat "$filename"
set -x
fi
response_code=$($CURL_COMMAND -H "Content-Type: application/json" -d "@$filename" "$url")
if [ "$VERBOSE_MODE" -eq "1" ]; then
set +x
fi
🤖 Prompt for AI Agents
In `@openwisp-monitoring/files/monitoring.agent` around lines 176 - 183, The
script unconditionally runs "set +x" which can turn off caller-enabled xtrace;
modify the verbose block that currently does "if [ "$VERBOSE_MODE" -eq "1" ];
then ... set -x fi" so that the corresponding "set +x" is executed only when
VERBOSE_MODE is 1 — i.e., wrap or move the "set +x" into the same conditional
that prints the data and runs "set -x" (refer to the VERBOSE_MODE check, the
printf/cat section, and the set -x/set +x invocations) so external xtrace is not
disabled when VERBOSE_MODE is 0.

if [ "$response_code" = "200" ]; then
success=$((success + 1))
if [ "$VERBOSE_MODE" -eq "1" ]; then
Expand Down