developer | 15a4331 | 2022-04-12 11:23:23 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ########################################################################## |
| 3 | # If not stated otherwise in this file or this component's Licenses.txt |
| 4 | # file the following copyright and licenses apply: |
| 5 | # |
| 6 | # Copyright 2016 RDK Management |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | ########################################################################## |
| 20 | |
| 21 | |
| 22 | #### |
| 23 | ## This script will be invoked upon receiving events from ATOM when processed telemetry dat is available for upload |
| 24 | ## This cript is expected to pull the |
| 25 | #### |
| 26 | |
| 27 | . /etc/include.properties |
| 28 | . /etc/device.properties |
| 29 | |
| 30 | if [ -f /lib/rdk/utils.sh ]; then |
| 31 | . /lib/rdk/utils.sh |
| 32 | fi |
| 33 | source /etc/log_timestamp.sh |
| 34 | TELEMETRY_PATH="$PERSISTENT_PATH/.telemetry" |
| 35 | TELEMETRY_RESEND_FILE="$PERSISTENT_PATH/.resend.txt" |
| 36 | TELEMETRY_TEMP_RESEND_FILE="$PERSISTENT_PATH/.temp_resend.txt" |
| 37 | |
| 38 | TELEMETRY_PROFILE_DEFAULT_PATH="/tmp/DCMSettings.conf" |
| 39 | TELEMETRY_PROFILE_RESEND_PATH="$PERSISTENT_PATH/.DCMSettings.conf" |
| 40 | TELEMETRY_TFTP_UPLOAD_JSON_FILE="$PERSISTENT_PATH/tftp_json.txt" |
| 41 | |
| 42 | RTL_LOG_FILE="$LOG_PATH/dcmscript.log" |
| 43 | |
| 44 | HTTP_FILENAME="$TELEMETRY_PATH/dca_httpresult.txt" |
| 45 | |
| 46 | DCMRESPONSE="$PERSISTENT_PATH/DCMresponse.txt" |
| 47 | |
| 48 | PEER_COMM_ID="/tmp/elxrretyt.swr" |
| 49 | |
| 50 | #pokuru if [ ! -f /usr/bin/GetConfigFile ];then |
| 51 | #pokuru echo "Error: GetConfigFile Not Found" |
| 52 | #pokuru exit 127 |
| 53 | #pokuru fi |
| 54 | |
| 55 | SIGN_FILE="/tmp/.signedRequest_$$_`date +'%s'`" |
| 56 | DIRECT_BLOCK_TIME=86400 |
| 57 | DIRECT_BLOCK_FILENAME="/tmp/.lastdirectfail_dca" |
| 58 | |
| 59 | SLEEP_TIME_FILE="/tmp/.rtl_sleep_time.txt" |
| 60 | #MAX_LIMIT_RESEND=2 |
| 61 | # Max backlog queue set to 5, after which the resend file will discard subsequent entries |
| 62 | MAX_CONN_QUEUE=5 |
| 63 | DIRECT_RETRY_COUNT=2 |
| 64 | |
| 65 | ignoreResendList="false" |
| 66 | |
| 67 | # exit if an instance is already running |
| 68 | if [ ! -f /tmp/.dca-splunk.upload ];then |
| 69 | # store the PID |
| 70 | echo $$ > /tmp/.dca-splunk.upload |
| 71 | else |
| 72 | pid=`cat /tmp/.dca-splunk.upload` |
| 73 | if [ -d /proc/$pid ];then |
| 74 | echo_t "dca : previous instance of dcaSplunkUpload.sh is running." |
| 75 | ignoreResendList="true" |
| 76 | # Cannot exit as triggers can be from immediate log upload |
| 77 | else |
| 78 | rm -f /tmp/.dca-splunk.upload |
| 79 | echo $$ > /tmp/.dca-splunk.upload |
| 80 | fi |
| 81 | fi |
| 82 | |
| 83 | conn_type_used="" # Use this to check the connection success, else set to fail |
| 84 | conn_type="Direct" # Use this to check the connection success, else set to fail |
| 85 | first_conn=useDirectRequest |
| 86 | sec_conn=useCodebigRequest |
| 87 | CodebigAvailable=0 |
| 88 | |
| 89 | CURL_TIMEOUT=30 |
| 90 | TLS="--tlsv1.2" |
| 91 | |
| 92 | mkdir -p $TELEMETRY_PATH |
| 93 | |
| 94 | # Processing Input Args |
| 95 | inputArgs=$1 |
| 96 | |
| 97 | # dca_utility.sh does not uses TELEMETRY_PROFILE_RESEND_PATH, to hardwired to TELEMETRY_PROFILE_DEFAULT_PATH |
| 98 | [ "x$sendInformation" != "x" ] || sendInformation=1 |
| 99 | if [ "$sendInformation" -ne 1 ] ; then |
| 100 | TELEMETRY_PROFILE_PATH=$TELEMETRY_PROFILE_RESEND_PATH |
| 101 | else |
| 102 | TELEMETRY_PROFILE_PATH=$TELEMETRY_PROFILE_DEFAULT_PATH |
| 103 | fi |
| 104 | |
| 105 | echo "Telemetry Profile File Being Used : $TELEMETRY_PROFILE_PATH" >> $RTL_LOG_FILE |
| 106 | |
| 107 | #Adding support for opt override for dcm.properties file |
| 108 | if [ "$BUILD_TYPE" != "prod" ] && [ -f $PERSISTENT_PATH/dcm.properties ]; then |
| 109 | . $PERSISTENT_PATH/dcm.properties |
| 110 | else |
| 111 | . /etc/dcm.properties |
| 112 | fi |
| 113 | TelemetryNewEndpointAvailable=0 |
| 114 | getTelemetryEndpoint() { |
| 115 | DEFAULT_DCA_UPLOAD_URL="$DCA_UPLOAD_URL" |
| 116 | TelemetryEndpoint=`dmcli eRT getv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.TelemetryEndpoint.Enable | grep value | awk '{print $5}'` |
| 117 | TelemetryEndpointURL="" |
| 118 | if [ "x$TelemetryEndpoint" = "xtrue" ]; then |
| 119 | TelemetryEndpointURL=`dmcli eRT getv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.TelemetryEndpoint.URL | grep value | awk '{print $5}'` |
| 120 | if [ ! -z "$TelemetryEndpointURL" ]; then |
| 121 | DCA_UPLOAD_URL="https://$TelemetryEndpointURL" |
| 122 | echo_t "dca upload url from RFC is $TelemetryEndpointURL" >> $RTL_LOG_FILE |
| 123 | TelemetryNewEndpointAvailable=1 |
| 124 | fi |
| 125 | else |
| 126 | if [ -f "$DCMRESPONSE" ]; then |
| 127 | TelemetryEndpointURL=`grep '"uploadRepository:URL":"' $DCMRESPONSE | awk -F 'uploadRepository:URL":' '{print $NF}' | awk -F '",' '{print $1}' | sed 's/"//g' | sed 's/}//g'` |
| 128 | |
| 129 | if [ ! -z "$TelemetryEndpointURL" ]; then |
| 130 | DCA_UPLOAD_URL="$TelemetryEndpointURL" |
| 131 | echo_t "dca upload url from dcmresponse is $TelemetryEndpointURL" >> $RTL_LOG_FILE |
| 132 | fi |
| 133 | fi |
| 134 | fi |
| 135 | |
| 136 | if [ -z "$TelemetryEndpointURL" ]; then |
| 137 | DCA_UPLOAD_URL="$DEFAULT_DCA_UPLOAD_URL" |
| 138 | fi |
| 139 | } |
| 140 | |
| 141 | getTelemetryEndpoint |
| 142 | |
| 143 | if [ -z $DCA_UPLOAD_URL ]; then |
| 144 | echo_t "dca upload url read from dcm.properties is NULL" |
| 145 | exit 1 |
| 146 | fi |
| 147 | |
| 148 | pidCleanup() |
| 149 | { |
| 150 | # PID file cleanup |
| 151 | if [ -f /tmp/.dca-splunk.upload ];then |
| 152 | rm -rf /tmp/.dca-splunk.upload |
| 153 | fi |
| 154 | } |
| 155 | |
| 156 | IsDirectBlocked() |
| 157 | { |
| 158 | ret=0 |
| 159 | # Temporarily disabling blocking of direct connection due to increased load on Codebig servers. |
| 160 | return $ret |
| 161 | } |
| 162 | |
| 163 | # Get the configuration of codebig settings |
| 164 | get_Codebigconfig() |
| 165 | { |
| 166 | # If GetServiceUrl not available, then only direct connection available and no fallback mechanism |
| 167 | if [ -f /usr/bin/GetServiceUrl ]; then |
| 168 | CodebigAvailable=1 |
| 169 | fi |
| 170 | if [ "$CodebigAvailable" -eq "1" ]; then |
| 171 | CodeBigEnable=`dmcli eRT getv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.CodeBigFirst.Enable | grep true 2>/dev/null` |
| 172 | fi |
| 173 | if [ "$CodebigAvailable" -eq "1" ] && [ "x$CodeBigEnable" != "x" ] ; then |
| 174 | conn_type="Codebig" |
| 175 | first_conn=useCodebigRequest |
| 176 | sec_conn=useDirectRequest |
| 177 | fi |
| 178 | |
| 179 | if [ "$CodebigAvailable" -eq 1 ]; then |
| 180 | echo_t "dca : Using $conn_type connection as the Primary" >> $RTL_LOG_FILE |
| 181 | else |
| 182 | echo_t "dca : Only $conn_type connection is available" >> $RTL_LOG_FILE |
| 183 | fi |
| 184 | } |
| 185 | |
| 186 | # Direct connection Download function |
| 187 | useDirectRequest() |
| 188 | { |
| 189 | # Direct connection will not be tried if .lastdirectfail exists |
| 190 | IsDirectBlocked |
| 191 | if [ "$?" -eq "1" ]; then |
| 192 | return 1 |
| 193 | fi |
| 194 | echo_t "dca$2: Using Direct commnication" |
| 195 | proUpdel=`cat /tmp/DCMSettings.conf | grep -i uploadRepository:uploadProtocol | tr -dc '"' |wc -c` |
| 196 | echo "number of proUPdel1:"$proUpdel |
| 197 | #proUpdel=$((proUpdel - 1)) |
| 198 | uploadProtocoltel=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | cut -d '"' -f$proUpdel` |
| 199 | echo "Upload protocol telemetry is:"$uploadProtocoltel |
| 200 | if [ "$uploadProtocoltel" != "TFTP" ]; then |
| 201 | echo "before HTTP upload" |
| 202 | delimhttp=`cat /tmp/DCMSettings.conf | grep -i uploadRepository:uploadProtocol | tr -dc '"' |wc -c` |
| 203 | echo "number of httpdeli:"$delimhttp |
| 204 | delimhttp=$((delimhttp - 4)) |
| 205 | HTTPURL=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | cut -d '"' -f$delimhttp` |
| 206 | if [ "$HTTPURL" == "" ]; then |
| 207 | echo "No HTTP URL configured in xconf,going with internal one !!" |
| 208 | HTTPURL=$DCM_HTTP_SERVER_URL |
| 209 | fi |
| 210 | echo "HTTPTELEMETRYURL:"$HTTPURL |
| 211 | CURL_CMD="curl --tlsv1.2 -w '%{http_code}\n' -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d @/nvram/rtl_json.txt '$HTTPURL' --connect-timeout 30 -m 30" |
| 212 | echo "------CURL_CMD:"$CURL_CMD |
| 213 | HTTP_CODE=`result= eval $CURL_CMD` |
| 214 | http_code=$(echo "$HTTP_CODE" | awk -F\" '{print $1}' ) |
| 215 | echo "http code in telemetry is :"$http_code |
| 216 | #curl --tlsv1.2 -w '%{http_code}\n' -H "Accept: application/json" -H "Content-type: application/json" -X POST -d @/nvram/hell.txt '$HTTPURL' -o "/nvram/dca_httpresult.txt" --connect-timeout 30 -m 30 |
| 217 | if [ $http_code -eq 200 ]; then |
| 218 | echo "HTTP telemetry curl upload succeded!!!!!!!!!!!!!!!!!" |
| 219 | ret=0 |
| 220 | else |
| 221 | uploadRetryCount=0 |
| 222 | while [ $uploadRetryCount -lt 2 ] |
| 223 | do |
| 224 | echo "Trying to upload telemetry file..." |
| 225 | CURL_CMD="curl --tlsv1.2 -w '%{http_code}\n' -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d @/nvram/rtl_json.txt '$HTTPURL' --connect-timeout 30 -m 30" |
| 226 | HTTP_CODE=`result= eval $CURL_CMD` |
| 227 | http_code_retry=$(echo "$HTTP_CODE" | awk -F\" '{print $1}' ) |
| 228 | echo "http code in telemetry is :"$http_code_retry |
| 229 | if [ "$http_code_retry" != "200" ]; then |
| 230 | echo "Error in uploading telemetry file" |
| 231 | else |
| 232 | echo "telemetry json upload succeded in retry" |
| 233 | ret=0 |
| 234 | break |
| 235 | fi |
| 236 | uploadRetryCount=`expr $uploadRetryCount + 1` |
| 237 | done |
| 238 | if [ $uploadRetryCount -eq 2]; then |
| 239 | ret=1 |
| 240 | echo "HTTP telemetry curl upload failed!!!!!!!!!!!!!!!!!" |
| 241 | fi |
| 242 | fi |
| 243 | if [ $ret -eq 0 ]; then |
| 244 | echo_t "dca$2: Direct connection success - ret:$ret " >> $RTL_LOG_FILE |
| 245 | # Use direct connection for rest of the connections |
| 246 | conn_type_used="Direct" |
| 247 | cd .. |
| 248 | return 0 |
| 249 | else |
| 250 | echo_t "dca$2: Direct Connection Failure - ret:$ret " >> $RTL_LOG_FILE |
| 251 | direct_retry=$(( direct_retry += 1 )) |
| 252 | if [ "$direct_retry" -ge "$DIRECT_RETRY_COUNT" ]; then |
| 253 | # .lastdirectfail will not be created for only direct connection |
| 254 | [ "$CodebigAvailable" -ne "1" ] || [ -f $DIRECT_BLOCK_FILENAME ] || touch $DIRECT_BLOCK_FILENAME |
| 255 | fi |
| 256 | sleep 10 |
| 257 | cd .. |
| 258 | return 1 |
| 259 | fi |
| 260 | else |
| 261 | echo "before TFTP load-----------" |
| 262 | delimnr=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | tr -dc ':' |wc -c` |
| 263 | echo "number of delim:"$delimnr |
| 264 | delimnr=$((delimnr - 1)) |
| 265 | IP=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | cut -d ":" -f$delimnr | cut -d '"' -f 2` |
| 266 | echo "tftp ip is :"$IP |
| 267 | cd /nvram/ |
| 268 | if [ -f "rtl_json.txt" ]; then |
| 269 | echo "rtl_json.txt available,going for tftp upload" |
| 270 | iptables -t raw -I OUTPUT -j CT -p udp -m udp --dport 69 --helper tftp |
developer | cc441a0 | 2022-05-09 19:04:26 +0800 | [diff] [blame^] | 271 | FilogicMacAddress=`ifconfig erouter0 | grep HWaddr | cut -c39-55` |
| 272 | extractVal=`echo $FilogicMacAddress | sed -e 's/://g'` |
developer | 15a4331 | 2022-04-12 11:23:23 +0800 | [diff] [blame] | 273 | dt=`date "+%m-%d-%y-%I-%M%p"` |
| 274 | cp /nvram/rtl_json.txt /nvram/$extractVal-TELE-$dt.json |
| 275 | tftp -p -r $extractVal-TELE-$dt.json $IP |
| 276 | else |
| 277 | echo "No rtl_json.txt available,returning 1" |
| 278 | return 1 |
| 279 | fi |
| 280 | ret=$? |
| 281 | echo $ret |
| 282 | if [ "$ret" -eq 1 ]; then |
| 283 | tftpuploadRetryCount=0 |
| 284 | while [ $tftpuploadRetryCount -lt 2 ] |
| 285 | do |
| 286 | echo "Trying to upload telemetry file using tftp again..." |
| 287 | tftp -p -r $extractVal-TELE-$dt.json $IP |
| 288 | ret=$? |
| 289 | if [ "$ret" -eq 1 ]; then |
| 290 | echo "error in uploading using tftp" |
| 291 | else |
| 292 | echo "tftp upload in retry succeded" |
| 293 | ret=0 |
| 294 | break |
| 295 | fi |
| 296 | tftpuploadRetryCount=`expr $tftpuploadRetryCount + 1` |
| 297 | done |
| 298 | if [ "$tftpuploadRetryCount" -eq 2]; then |
| 299 | ret=1 |
| 300 | echo "TFTP telemetry upload failed!!!!!!!!!!!!!!!!!" |
| 301 | fi |
| 302 | else |
| 303 | echo "TFTP Telemetry succeded !!!" |
| 304 | ret=0 |
| 305 | fi |
| 306 | sleep 10 |
| 307 | |
| 308 | echo_t "dca $2 : Direct Connection HTTP RESPONSE CODE : $http_code" >> $RTL_LOG_FILE |
| 309 | if [ $ret -eq 0 ]; then |
| 310 | echo_t "dca$2: Direct connection success - ret:$ret " >> $RTL_LOG_FILE |
| 311 | # Use direct connection for rest of the connections |
| 312 | conn_type_used="Direct" |
| 313 | cd .. |
| 314 | return 0 |
| 315 | else |
| 316 | echo_t "dca$2: Direct Connection Failure - ret:$ret " >> $RTL_LOG_FILE |
| 317 | direct_retry=$(( direct_retry += 1 )) |
| 318 | if [ "$direct_retry" -ge "$DIRECT_RETRY_COUNT" ]; then |
| 319 | # .lastdirectfail will not be created for only direct connection |
| 320 | [ "$CodebigAvailable" -ne "1" ] || [ -f $DIRECT_BLOCK_FILENAME ] || touch $DIRECT_BLOCK_FILENAME |
| 321 | fi |
| 322 | sleep 10 |
| 323 | cd .. |
| 324 | return 1 |
| 325 | fi |
| 326 | fi |
| 327 | } |
| 328 | |
| 329 | # Codebig connection Download function |
| 330 | useCodebigRequest() |
| 331 | { |
| 332 | # Do not try Codebig if CodebigAvailable != 1 (GetServiceUrl not there) |
| 333 | if [ "$CodebigAvailable" -eq "0" ] ; then |
| 334 | echo "dca$2 : Only direct connection Available" |
| 335 | return 1 |
| 336 | fi |
| 337 | |
| 338 | if [ "x$CodeBigEnable" = "x" ] ; then |
| 339 | echo_t "dca$2 : Codebig connection attempts are disabled through RFC. Exiting !!!" >> $RTL_LOG_FILE |
| 340 | return 1 |
| 341 | fi |
| 342 | |
| 343 | if [ "$TelemetryNewEndpointAvailable" -eq "1" ]; then |
| 344 | SIGN_CMD="GetServiceUrl 10 " |
| 345 | else |
| 346 | SIGN_CMD="GetServiceUrl 9 " |
| 347 | fi |
| 348 | eval $SIGN_CMD > $SIGN_FILE |
| 349 | CB_SIGNED_REQUEST=`cat $SIGN_FILE` |
| 350 | rm -f $SIGN_FILE |
| 351 | CURL_CMD="curl $TLS -w '%{http_code}\n' --interface $EROUTER_INTERFACE $addr_type -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d '$1' -o \"$HTTP_FILENAME\" \"$CB_SIGNED_REQUEST\" --connect-timeout $CURL_TIMEOUT -m $CURL_TIMEOUT" |
| 352 | echo_t "dca$2: Using Codebig connection at `echo "$CURL_CMD" | sed -ne 's#.*\(https:.*\)?.*#\1#p'`" >> $RTL_LOG_FILE |
| 353 | echo_t "CURL_CMD: `echo "$CURL_CMD" | sed -ne 's#oauth_consumer_key=.*oauth_signature=.* --#<hidden> --#p'`" >> $RTL_LOG_FILE |
| 354 | HTTP_CODE=`curl $TLS -w '%{http_code}\n' --interface $EROUTER_INTERFACE $addr_type -H "Accept: application/json" -H "Content-type: application/json" -X POST -d "$1" -o "$HTTP_FILENAME" "$CB_SIGNED_REQUEST" --connect-timeout $CURL_TIMEOUT -m $CURL_TIMEOUT` |
| 355 | curlret=$? |
| 356 | http_code=$(echo "$HTTP_CODE" | awk -F\" '{print $1}' ) |
| 357 | [ "x$http_code" != "x" ] || http_code=0 |
| 358 | # log security failure |
| 359 | echo_t "dca $2 : Codebig Connection HTTP RESPONSE CODE : $http_code" >> $RTL_LOG_FILE |
| 360 | case $curlret in |
| 361 | 35|51|53|54|58|59|60|64|66|77|80|82|83|90|91) |
| 362 | echo_t "dca$2: Codebig Connection Failure - ret:$curlret http_code:$http_code" >> $RTL_LOG_FILE |
| 363 | ;; |
| 364 | esac |
| 365 | if [ "$http_code" -eq 200 ]; then |
| 366 | echo_t "dca$2: Codebig connection success - ret:$curlret http_code:$http_code" >> $RTL_LOG_FILE |
| 367 | conn_type_used="Codebig" |
| 368 | return 0 |
| 369 | fi |
| 370 | if [ "$curlret" -eq 0 ]; then |
| 371 | echo_t "dca$2: Codebig Connection Failure - ret:$curlret http_code:$http_code" >> $RTL_LOG_FILE |
| 372 | fi |
| 373 | sleep 10 |
| 374 | return 1 |
| 375 | } |
| 376 | |
| 377 | # Function to get erouter0 ipv4 address |
| 378 | getErouterIpv4() |
| 379 | { |
| 380 | erouter_ipv4=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_IP | grep value | awk '{print $5}'` |
| 381 | if [ "$erouter_ipv4" != "" ];then |
| 382 | echo $erouter_ipv4 |
| 383 | else |
| 384 | echo "null" |
| 385 | fi |
| 386 | } |
| 387 | |
| 388 | # Function to get erouter0 ipv6 address |
| 389 | getErouterIpv6() |
| 390 | { |
| 391 | erouter_ipv6=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_IPv6 | grep value | awk '{print $5}'` |
| 392 | if [ "$erouter_ipv6" != "" ];then |
| 393 | echo $erouter_ipv6 |
| 394 | else |
| 395 | echo "null" |
| 396 | fi |
| 397 | } |
| 398 | |
| 399 | timestamp=`date +%Y-%b-%d_%H-%M-%S` |
| 400 | #main app |
| 401 | estbMac=`getErouterMacAddress` |
| 402 | cur_time=`date "+%Y-%m-%d %H:%M:%S"` |
| 403 | erouteripv4=`getErouterIpv4` |
| 404 | erouteripv6=`getErouterIpv6` |
| 405 | DEFAULT_IPV4="<#=#>EROUTER_IPV4<#=#>" |
| 406 | DEFAULT_IPV6="<#=#>EROUTER_IPV6<#=#>" |
| 407 | |
| 408 | # If interface doesnt have ipv6 address then we will force the curl to go with ipv4. |
| 409 | # Otherwise we will not specify the ip address family in curl options |
| 410 | addr_type="" |
| 411 | [ "x`ifconfig $EROUTER_INTERFACE | grep inet6 | grep -i 'Global'`" != "x" ] || addr_type="-4" |
| 412 | |
| 413 | if [ "x$DCA_MULTI_CORE_SUPPORTED" = "xyes" ]; then |
| 414 | ## 1] Pull processed data from ATOM |
| 415 | rm -f $TELEMETRY_JSON_RESPONSE |
| 416 | |
| 417 | |
| 418 | GetConfigFile $PEER_COMM_ID |
| 419 | scp -i $PEER_COMM_ID root@$ATOM_INTERFACE_IP:$TELEMETRY_JSON_RESPONSE $TELEMETRY_JSON_RESPONSE > /dev/null 2>&1 |
| 420 | if [ $? -ne 0 ]; then |
| 421 | scp -i $PEER_COMM_ID root@$ATOM_INTERFACE_IP:$TELEMETRY_JSON_RESPONSE $TELEMETRY_JSON_RESPONSE > /dev/null 2>&1 |
| 422 | fi |
| 423 | echo_t "Copied $TELEMETRY_JSON_RESPONSE " >> $RTL_LOG_FILE |
| 424 | rm -f $PEER_COMM_ID |
| 425 | sleep 2 |
| 426 | fi |
| 427 | |
| 428 | # Add the erouter MAC address from ARM as this is not available in ATOM |
| 429 | sed -i -e "s/ErouterMacAddress/$estbMac/g" $TELEMETRY_JSON_RESPONSE |
| 430 | |
| 431 | |
| 432 | if [ ! -f $SLEEP_TIME_FILE ]; then |
| 433 | if [ -f $DCMRESPONSE ]; then |
| 434 | cron=`grep -i TelemetryProfile $DCMRESPONSE | awk -F '"schedule":' '{print $NF}' | awk -F "," '{print $1}' | sed 's/://g' | sed 's/"//g' | sed -e 's/^[ ]//' | sed -e 's/^[ ]//'` |
| 435 | fi |
| 436 | |
| 437 | if [ -n "$cron" ]; then |
| 438 | sleep_time=`echo "$cron" | awk -F '/' '{print $2}' | cut -d ' ' -f1` |
| 439 | fi |
| 440 | |
| 441 | if [ -n "$sleep_time" ];then |
| 442 | sleep_time=`expr $sleep_time - 1` #Subtract 1 miute from it |
| 443 | sleep_time=`expr $sleep_time \* 60` #Make it to seconds |
| 444 | # Adding generic RANDOM number implementation as sh in RDK_B doesn't support RANDOM |
| 445 | RANDOM=`awk -v min=5 -v max=10 'BEGIN{srand(); print int(min+rand()*(max-min+1)*(max-min+1)*1000)}'` |
| 446 | sleep_time=$(($RANDOM%$sleep_time)) #Generate a random value out of it |
| 447 | echo "$sleep_time" > $SLEEP_TIME_FILE |
| 448 | else |
| 449 | sleep_time=10 |
| 450 | fi |
| 451 | else |
| 452 | sleep_time=`cat $SLEEP_TIME_FILE` |
| 453 | fi |
| 454 | |
| 455 | if [ -z "$sleep_time" ];then |
| 456 | sleep_time=10 |
| 457 | fi |
| 458 | |
| 459 | if [ "$inputArgs" = "logbackup_without_upload" ];then |
| 460 | echo_t "log backup during bootup, Will upload on later call..!" |
| 461 | if [ -f $TELEMETRY_JSON_RESPONSE ]; then |
| 462 | outputJson=`cat $TELEMETRY_JSON_RESPONSE` |
| 463 | fi |
| 464 | if [ ! -f $TELEMETRY_JSON_RESPONSE ] || [ "x$outputJson" = "x" ] ; then |
| 465 | echo_t "dca: Unable to find Json message or Json is empty." >> $RTL_LOG_FILE |
| 466 | if [ ! -f /etc/os-release ];then pidCleanup; fi |
| 467 | exit 0 |
| 468 | fi |
| 469 | if [ -f $TELEMETRY_RESEND_FILE ]; then |
| 470 | #If resend queue has already reached MAX_CONN_QUEUE entries then remove recent two |
| 471 | if [ "`cat $TELEMETRY_RESEND_FILE | wc -l`" -ge "$MAX_CONN_QUEUE" ]; then |
| 472 | echo_t "resend queue size at its max. removing recent two entries" >> $RTL_LOG_FILE |
| 473 | sed -i '1,2d' $TELEMETRY_RESEND_FILE |
| 474 | fi |
| 475 | mv $TELEMETRY_RESEND_FILE $TELEMETRY_TEMP_RESEND_FILE |
| 476 | fi |
| 477 | # ensure that Json is put at the top of the queue |
| 478 | echo "$outputJson" > $TELEMETRY_RESEND_FILE |
| 479 | if [ -f $TELEMETRY_TEMP_RESEND_FILE ] ; then |
| 480 | cat $TELEMETRY_TEMP_RESEND_FILE >> $TELEMETRY_RESEND_FILE |
| 481 | rm -f $TELEMETRY_TEMP_RESEND_FILE |
| 482 | fi |
| 483 | if [ ! -f /etc/os-release ];then pidCleanup; fi |
| 484 | exit 0 |
| 485 | fi |
| 486 | get_Codebigconfig |
| 487 | direct_retry=0 |
| 488 | ## 2] Check for unsuccessful posts from previous execution in resend que. |
| 489 | ## If present repost either with appending to existing or as independent post |
| 490 | echo "=============Telemetry has file only one upload=======================" |
| 491 | if [ -f $TELEMETRY_RESEND_FILE ] && [ "x$ignoreResendList" != "xtrue" ]; then |
| 492 | echo "=============Loop1=======================" |
| 493 | rm -f $TELEMETRY_TEMP_RESEND_FILE |
| 494 | while read resend |
| 495 | do |
| 496 | resend=`echo $resend | sed "s/$DEFAULT_IPV4/$erouteripv4/" | sed "s/$DEFAULT_IPV6/$erouteripv6/"` |
| 497 | echo_t "dca resend : $resend" >> $RTL_LOG_FILE |
| 498 | $first_conn "$resend" "resend" || $sec_conn "$resend" "resend" || conn_type_used="Fail" |
| 499 | |
| 500 | if [ "x$conn_type_used" = "xFail" ] ; then |
| 501 | echo "$resend" >> $TELEMETRY_TEMP_RESEND_FILE |
| 502 | echo_t "dca Connecion failed for this Json : requeuing back" >> $RTL_LOG_FILE |
| 503 | fi |
| 504 | echo_t "dca Attempting next Json in the queue " >> $RTL_LOG_FILE |
| 505 | sleep 10 |
| 506 | done < $TELEMETRY_RESEND_FILE |
| 507 | sleep 2 |
| 508 | rm -f $TELEMETRY_RESEND_FILE |
| 509 | fi |
| 510 | |
| 511 | ## 3] Attempt to post current message. Check for status if failed add it to resend queue |
| 512 | if [ -f $TELEMETRY_JSON_RESPONSE ]; then |
| 513 | outputJson=`cat $TELEMETRY_JSON_RESPONSE` |
| 514 | fi |
| 515 | if [ ! -f $TELEMETRY_JSON_RESPONSE ] || [ "x$outputJson" = "x" ] ; then |
| 516 | echo_t "dca: Unable to find Json message or Json is empty." >> $RTL_LOG_FILE |
| 517 | [ ! -f $TELEMETRY_TEMP_RESEND_FILE ] || mv $TELEMETRY_TEMP_RESEND_FILE $TELEMETRY_RESEND_FILE |
| 518 | if [ ! -f /etc/os-release ];then pidCleanup; fi |
| 519 | exit 0 |
| 520 | fi |
| 521 | |
| 522 | echo "$outputJson" > $TELEMETRY_RESEND_FILE |
| 523 | # sleep for random time before upload to avoid bulk requests on splunk server |
| 524 | echo_t "dca: Sleeping for $sleep_time before upload." >> $RTL_LOG_FILE |
| 525 | sleep $sleep_time |
| 526 | timestamp=`date +%Y-%b-%d_%H-%M-%S` |
| 527 | $first_conn "$outputJson" || $sec_conn "$outputJson" || conn_type_used="Fail" |
| 528 | if [ "x$conn_type_used" != "xFail" ]; then |
| 529 | echo_t "dca: Json message successfully submitted." >> $RTL_LOG_FILE |
| 530 | rm -f $TELEMETRY_RESEND_FILE |
| 531 | [ ! -f $TELEMETRY_TEMP_RESEND_FILE ] || mv $TELEMETRY_TEMP_RESEND_FILE $TELEMETRY_RESEND_FILE |
| 532 | else |
| 533 | if [ -f $TELEMETRY_TEMP_RESEND_FILE ] ; then |
| 534 | if [ "`cat $TELEMETRY_TEMP_RESEND_FILE | wc -l `" -ge "$MAX_CONN_QUEUE" ]; then |
| 535 | echo_t "dca: resend queue size has already reached MAX_CONN_QUEUE. Not adding anymore entries" >> $RTL_LOG_FILE |
| 536 | mv $TELEMETRY_TEMP_RESEND_FILE $TELEMETRY_RESEND_FILE |
| 537 | else |
| 538 | cat $TELEMETRY_TEMP_RESEND_FILE >> $TELEMETRY_RESEND_FILE |
| 539 | echo_t "dca: Json message submit failed. Adding message to resend queue" >> $RTL_LOG_FILE |
| 540 | fi |
| 541 | rm -f $TELEMETRY_TEMP_RESEND_FILE |
| 542 | fi |
| 543 | fi |
| 544 | #rm -f $TELEMETRY_JSON_RESPONSE |
| 545 | # PID file cleanup |
| 546 | if [ ! -f /etc/os-release ];then pidCleanup; fi |