RDKEMW-13061: Include utility indepenent of T2 for telemetry upload - #443
Conversation
Reason for change :
1] Adding utility that DS manager can use for critical deep sleep event notification to telemetry cloud
2] This provides a short circuited path only to be used for time critical eventing which is constrained
by scenarios like the CPU going to hibernate modes.
There was a problem hiding this comment.
Pull request overview
This PR adds a new utility script alertSystem.sh to provide direct telemetry uploads independent of T2, specifically designed for time-critical event notifications from the Deep Sleep Manager when the CPU is about to enter hibernate mode.
Changes:
- Adds a new alertSystem.sh script for immediate telemetry event notification
- Implements direct curl-based upload to telemetry cloud using mTLS
- Provides a short-circuited path for critical deep sleep events before system hibernation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fi | ||
|
|
||
| # Configuration Files | ||
| VERSION=1 |
There was a problem hiding this comment.
The VERSION variable is defined but never used in the script. Consider removing it if it's not needed, or include it in the telemetry payload if version tracking is required.
| VERSION=1 |
| # Message data is actual metadata header in case of trigger from deepSleep manager process | ||
| # This change is needed since there are data clouds in different deployment which are not flexible to accomodate any deviations in data format |
There was a problem hiding this comment.
The comment describes this as a "Message data is actual metadata header" but it's not clear what this means. The logic constructs different JSON structures for deepSleepMgrMain vs other processes, where MSG_DATA is used as a key name in one case and as a value in another. This dual interpretation could be confusing. Consider clarifying the comment to explain that for deepSleepMgrMain, MSG_DATA contains a marker name that becomes the JSON key, while for other processes it's a log entry message.
| strjson="{\"searchResult\":[{\"Time\":\"$currentTime\"},{\"process_name\":\"$PROCESS_NAME\"},{\"mac\":\"$estb_mac\"},{\"Version\":\"$software_version\"},{\"PartnerId\":\"$partnerId\"},{\"$MSG_DATA\":\"1\"}]}" | ||
| else | ||
| strjson="{\"searchResult\":[{\"process_name\":\"$PROCESS_NAME\"},{\"mac\":\"$estb_mac\"},{\"Version\":\"$software_version\"},{\"msgTime\":\"$currentTime\"},{\"PartnerId\":\"$partnerId\"},{\"logEntry\":\"$MSG_DATA\"}]}" |
There was a problem hiding this comment.
The MSG_DATA variable is directly embedded into JSON without any escaping or validation. If MSG_DATA contains special characters like quotes, backslashes, or newlines, it could break the JSON structure or potentially lead to injection issues. Consider sanitizing or escaping the input before including it in the JSON payload, especially since this data is being sent to an external telemetry endpoint.
| CURL_INPUT=" -w '%{http_code}\n' -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d '$strjson' -o \"$HTTP_FILENAME\" \"$UPLOAD_END_POINT\" --cert-status --connect-timeout 30 -m 30 " | ||
| else | ||
| CURL_INPUT=" -w '%{http_code}\n' -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d '$strjson' -o \"$HTTP_FILENAME\" \"$UPLOAD_END_POINT\" --connect-timeout 30 -m 30 " |
There was a problem hiding this comment.
The strjson variable containing user-provided data is embedded in single quotes within the CURL_INPUT string. If MSG_DATA or PROCESS_NAME contains single quotes, it could break out of the quoting and potentially cause command injection or curl execution failures. Consider using proper escaping or an alternative approach to pass the JSON data securely to curl.
| # Extract upload end point from DCM processed telemetry profile | ||
| if [ -f $TELEMETRY_PROFILE_DEFAULT_PATH ]; then | ||
| UPLOAD_END_POINT=`grep '"uploadRepository:URL":"' $TELEMETRY_PROFILE_DEFAULT_PATH | awk -F 'uploadRepository:URL":' '{print $NF}' | awk -F '",' '{print $1}' | sed 's/"//g' | sed 's/}//g'` | ||
| if [ ! -z "$UPLOAD_END_POINT" ]; then |
There was a problem hiding this comment.
Using '! -z' is a double negative that reduces readability. Use '-n' to test if a string is non-empty for better clarity. This is consistent with better shell scripting practices.
| exit 1 | ||
| fi | ||
|
|
||
| # Argument Assigment |
There was a problem hiding this comment.
Corrected spelling of 'Assigment' to 'Assignment'
| # Argument Assigment | |
| # Argument Assignment |
| . /lib/rdk/getPartnerId.sh | ||
| fi | ||
|
|
||
| if [ -f $RDK_PATH/exec_curl_mtls.sh ]; then |
There was a problem hiding this comment.
The variable RDK_PATH is used without checking if /etc/device.properties was successfully sourced or if RDK_PATH is defined. If device.properties doesn't exist or doesn't define RDK_PATH, the script will fail with unclear error messages. Add a check to ensure RDK_PATH is defined after sourcing device.properties, similar to how other scripts in the codebase handle this dependency (e.g., uploadSTBLogs.sh sources device.properties before using RDK_PATH).
| partnerId=$(getPartnerId) | ||
| echo "$SCRIPT_NAME: $currentTime" | ||
|
|
||
| # Loggging should be handled by the caller |
There was a problem hiding this comment.
Corrected spelling of 'Loggging' to 'Logging'
| # Loggging should be handled by the caller | |
| # Logging should be handled by the caller |
| software_version=`grep ^imagename: /version.txt | cut -d ':' -f2` | ||
|
|
||
|
|
||
| if [ "x$PROCESS_NAME" == "xdeepSleepMgrMain" ]; then |
There was a problem hiding this comment.
Using '==' for string comparison in shell test is Bash-specific. The shebang uses '#!/bin/sh' which may not be bash on all systems. For POSIX compliance, use single '=' for string comparison. This pattern is used throughout the codebase (see NM_Dispatcher.sh:56, cdlSupport.sh:225).
| else | ||
| CURL_INPUT=" -w '%{http_code}\n' -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d '$strjson' -o \"$HTTP_FILENAME\" \"$UPLOAD_END_POINT\" --connect-timeout 30 -m 30 " | ||
| fi | ||
| alertLog "$SCRIPT_NAME: CURL_INPUT : $CURL_INPUT" |
There was a problem hiding this comment.
The CURL_INPUT is logged including the complete JSON payload which may contain sensitive data. Consider whether the alert message content should be logged, or if it should be redacted for security/privacy reasons.
| alertLog "$SCRIPT_NAME: CURL_INPUT : $CURL_INPUT" | |
| alertLog "$SCRIPT_NAME: CURL request prepared for endpoint $UPLOAD_END_POINT (payload redacted)" |
Reason for change :
1] Adding utility that DS manager can use for critical deep sleep event notification to telemetry cloud 2] This provides a short circuited path only to be used for time critical eventing which is constrained
by scenarios like the CPU going to hibernate modes.