diff --git a/scripts/DCMscript.sh b/scripts/DCMscript.sh new file mode 100644 index 0000000..b782ca3 --- /dev/null +++ b/scripts/DCMscript.sh @@ -0,0 +1,738 @@ +#!/bin/sh +########################################################################## +# If not stated otherwise in this file or this component's Licenses.txt +# file the following copyright and licenses apply: +# +# Copyright 2018 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################## +# + +. /etc/include.properties +. /etc/device.properties +if [ -f /etc/telemetry2_0.properties ]; then + . /etc/telemetry2_0.properties +fi + +source /etc/log_timestamp.sh +source /lib/rdk/getpartnerid.sh +source /lib/rdk/getaccountid.sh +# Enable override only for non prod builds +if [ "$BUILD_TYPE" != "prod" ] && [ -f $PERSISTENT_PATH/dcm.properties ]; then + . $PERSISTENT_PATH/dcm.properties +else + . /etc/dcm.properties +fi + +if [ -f /lib/rdk/utils.sh ]; then + . /lib/rdk/utils.sh +fi + +if [ -f /etc/mount-utils/getConfigFile.sh ];then + . /etc/mount-utils/getConfigFile.sh +fi +SIGN_FILE="/tmp/.signedRequest_$$_`date +'%s'`" +DIRECT_BLOCK_TIME=86400 +DIRECT_BLOCK_FILENAME="/tmp/.lastdirectfail_dcm" +TFTP_SERVER_IP=/tmp/tftpip.txt +export PATH=$PATH:/usr/bin:/bin:/usr/local/bin:/sbin:/usr/local/lighttpd/sbin:/usr/local/sbin +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/lib + +if [ -z $LOG_PATH ]; then + LOG_PATH="/rdklogs/logs" +fi + +if [ -z $PERSISTENT_PATH ]; then + PERSISTENT_PATH="/nvram" +fi + +T2_XCONF_PERSISTENT_PATH="$PERSISTENT_PATH/.t2persistentfolder" +T2_BULK_PERSISTENT_PATH="$PERSISTENT_PATH/.t2reportprofiles" +TELEMETRY_PATH="$PERSISTENT_PATH/.telemetry" +DCMFLAG="/tmp/.DCMSettingsFlag" +DCM_LOG_FILE="$LOG_PATH/dcmscript.log" +TELEMETRY_INOTIFY_FOLDER="/rdklogs/logs/" +TELEMETRY_INOTIFY_EVENT="$TELEMETRY_INOTIFY_FOLDER/eventType.cmd" +DCMRESPONSE="$PERSISTENT_PATH/DCMresponse.txt" +T2_RESPONSE="$T2_XCONF_PERSISTENT_PATH/DCMresponse.txt" +TELEMETRY_TEMP_RESEND_FILE="/rdklogs/logs/.temp_resend.txt" + +PEER_COMM_ID="/tmp/elxrretyt.swr" +FORMATTED_TMP_DCM_RESPONSE='/tmp/DCMSettings.conf' +TELEMETRY_PREVIOUS_LOG_COMPLETE="/tmp/.telemetry_previous_log_done" +TELEMETRY_PREVIOUS_LOG="/tmp/.telemetry_previous_log" +MAX_PREV_LOG_COMPLETE_WAIT=12 + +IDLE_TIMEOUT=30 + +# http header +HTTP_HEADERS='Content-Type: application/json' +## RETRY DELAY in secs +RETRY_DELAY=60 +## RETRY COUNT +RETRY_COUNT=3 + +echo_t "Starting execution of DCMscript.sh" + +if [ $# -ne 5 ]; then + echo_t "Argument does not match" + echo 0 > $DCMFLAG + exit 1 +fi + +. $RDK_PATH/utils.sh + +echo "`/bin/timestamp` Starting execution of DCMscript.sh" >> $LOG_PATH/dcmscript.log +#--------------------------------- +# Initialize Variables +#--------------------------------- +# URL +URL=$2 +tftp_server=$3 +reboot_flag=$4 +checkon_reboot=$5 +touch $TFTP_SERVER_IP +echo_t "URL: "$URL +echo_t "DCM_TFTP_SERVER: "$tftp_server >> $TFTP_SERVER_IP +echo_t "BOOT_FLAG: "$reboot_flag +echo_t "CHECK_ON_REBOOT: "$checkon_reboot +rm -f $TELEMETRY_TEMP_RESEND_FILE + +conn_str="Direct" +first_conn=useDirectRequest +sec_conn=useCodebigRequest +CodebigAvailable=0 + + +if [ -f "/tmp/DCMSettings.conf" ] +then + Check_URL=`grep 'urn:settings:ConfigurationServiceURL' /tmp/DCMSettings.conf | cut -d '=' -f2 | head -n 1` + if [ -n "$Check_URL" ] + then + URL=`grep 'urn:settings:ConfigurationServiceURL' /tmp/DCMSettings.conf | cut -d '=' -f2 | head -n 1` + #last_char=`echo $URL | sed -e 's/\(^.*\)\(.$\)/\2/'` + last_char=`echo $URL | awk '$0=$NF' FS=` + if [ "$last_char" != "?" ] + then + URL="$URL?" + fi + fi +fi +# File to save curl response +#FILENAME="$PERSISTENT_PATH/DCMresponse.txt" +TELE_HTTP_CODE="$PERSISTENT_PATH/telemetry_http_code" +# File to save http code +HTTP_CODE="$PERSISTENT_PATH/http_code" +rm -rf $HTTP_CODE +# Cron job file name +current_cron_file="$PERSISTENT_PATH/cron_file.txt" +# Tftpboot Server Ip +echo TFTP_SERVER: $tftp_server >> $LOG_PATH/dcmscript.log +# Timeout value +timeout=30 +default_IP=$DEFAULT_IP +upload_protocol='TFTP' +upload_httplink=$HTTP_UPLOAD_LINK + +#--------------------------------- +# Function declarations +#--------------------------------- + +## FW version from version.txt +getFWVersion() +{ + #cat /version.txt | grep ^imagename:PaceX1 | grep -v image + verStr=`cat /version.txt | grep ^imagename: | cut -d ":" -f 2` + echo $verStr +} + +## Identifies whether it is a VBN or PROD build +getBuildType() +{ + echo $BUILD_TYPE +} + +## Get ECM mac address +getECMMacAddress() +{ + address=`getECMMac` + mac=`echo $address | tr -d ' ' | tr -d '"'` + echo $mac +} + +## Get Receiver Id +getReceiverId() +{ + if [ -f "$PERSISTENT_PATH/www/whitebox/wbdevice.dat" ] + then + ReceiverId=`cat $PERSISTENT_PATH/www/whitebox/wbdevice.dat` + echo "$ReceiverId" + else + echo " " + fi +} + +## Get Controller Id +getControllerId() +{ + echo "2504" +} + +## Get ChannelMap Id +getChannelMapId() +{ + echo "2345" +} + +## Get VOD Id +getVODId() +{ + echo "15660" +} + +IsDirectBlocked() +{ + ret=0 + if [ -f $DIRECT_BLOCK_FILENAME ]; then + modtime=$(($(date +%s) - $(date +%s -r $DIRECT_BLOCK_FILENAME))) + if [ "$modtime" -le "$DIRECT_BLOCK_TIME" ]; then + echo "DCM: Last direct failed blocking is still valid, preventing direct" >> $DCM_LOG_FILE + ret=1 + else + echo "DCM: Last direct failed blocking has expired, removing $DIRECT_BLOCK_FILENAME, allowing direct" >> $DCM_LOG_FILE + rm -f $DIRECT_BLOCK_FILENAME + ret=0 + fi + fi + return $ret +} + +# Get the configuration of codebig settings +get_Codebigconfig() +{ + # If GetServiceUrl not available, then only direct connection available and no fallback mechanism + if [ -f /usr/bin/GetServiceUrl ]; then + CodebigAvailable=1 + fi + + if [ "$CodebigAvailable" -eq "1" ]; then + CodeBigEnable=`dmcli eRT getv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.CodeBigFirst.Enable | grep true 2>/dev/null` + fi + if [ "$CodebigAvailable" -eq "1" ] && [ "x$CodeBigEnable" != "x" ] ; then + conn_str="Codebig" + first_conn=useCodebigRequest + sec_conn=useDirectRequest + fi + + if [ "$CodebigAvailable" -eq 1 ]; then + echo_t "Xconf dcm : Using $conn_str connection as the Primary" >> $DCM_LOG_FILE + else + echo_t "Xconf dcm : Only $conn_str connection is available" >> $DCM_LOG_FILE + fi +} + +# Direct connection Download function +useDirectRequest() +{ + # Direct connection will not be tried if .lastdirectfail exists + IsDirectBlocked + if [ "$?" -eq "1" ]; then + return 1 + fi + count=0 + while [ "$count" -lt "$RETRY_COUNT" ] ; do + echo_t " DCM connection type DIRECT" + CURL_CMD="curl -w '%{http_code}\n' --tlsv1.2 --interface $EROUTER_INTERFACE $addr_type --connect-timeout $timeout -m $timeout -o \"$FILENAME\" '$HTTPS_URL$JSONSTR'" + echo_t "CURL_CMD: $CURL_CMD" >> $DCM_LOG_FILE + HTTP_CODE=`result= eval $CURL_CMD` + ret=$? + + sleep 2 + http_code=$(echo "$HTTP_CODE" | awk -F\" '{print $1}' ) + [ "x$http_code" != "x" ] || http_code=0 + echo_t "ret = $ret http_code: $http_code" >> $DCM_LOG_FILE + + # log security failure + case $ret in + 35|51|53|54|58|59|60|64|66|77|80|82|83|90|91) + echo_t "DCM Direct Connection Failure Attempt:$count - ret:$ret http_code:$http_code" >> $DCM_LOG_FILE + ;; + esac + if [ $http_code -eq 200 ]; then + echo_t "Direct connection success - ret:$ret http_code:$http_code" >> $DCM_LOG_FILE + return 0 + elif [ $http_code -eq 404 ]; then + echo "`Timestamp` Direct connection Received HTTP $http_code Response from Xconf Server. Retry logic not needed" >> $DCM_LOG_FILE + bypass_conn=1 + return 0 # Do not return 1, if retry for next conn type is not to be done + else + if [ "$ret" -eq 0 ]; then + echo_t "DCM Direct Connection Failure Attempt:$count - ret:$ret http_code:$http_code" >> $DCM_LOG_FILE + fi + rm -rf $DCMRESPONSE + fi + count=$((count + 1)) + sleep $RETRY_DELAY + done + echo_t "DCM :Retries for Direct connection exceeded " >> $DCM_LOG_FILE + [ "$CodebigAvailable" -ne "1" ] || [ -f $DIRECT_BLOCK_FILENAME ] || touch $DIRECT_BLOCK_FILENAME + return 1 +} + +# Codebig connection Download function +useCodebigRequest() +{ + # Do not try Codebig if CodebigAvailable != 1 (GetServiceUrl not there) + if [ "$CodebigAvailable" -eq "0" ] ; then + echo "DCM : Only direct connection Available" >> $DCM_LOG_FILE + return 1 + fi + count=0 + while [ "$count" -lt "$RETRY_COUNT" ] ; do + SIGN_CMD="GetServiceUrl 3 \"$JSONSTR\"" + eval $SIGN_CMD > $SIGN_FILE + CB_SIGNED_REQUEST=`cat $SIGN_FILE` + rm -f $SIGN_FILE + CURL_CMD="curl -w '%{http_code}\n' --tlsv1.2 --interface $EROUTER_INTERFACE $addr_type --connect-timeout $timeout -m $timeout -o \"$FILENAME\" \"$CB_SIGNED_REQUEST\"" + echo_t " DCM connection type CODEBIG at `echo "$CURL_CMD" | sed -ne 's#.*\(https:.*\)?.*#\1#p'`" >> $DCM_LOG_FILE + echo_t "CURL_CMD: `echo "$CURL_CMD" | sed -ne 's#oauth_consumer_key=.*##p'`" >> $DCM_LOG_FILE + HTTP_CODE=`result= eval $CURL_CMD` + curlret=$? + http_code=$(echo "$HTTP_CODE" | awk -F\" '{print $1}' ) + [ "x$http_code" != "x" ] || http_code=0 + echo_t "ret = $curlret http_code: $http_code" >> $DCM_LOG_FILE + + # log security failure + case $curlret in + 35|51|53|54|58|59|60|64|66|77|80|82|83|90|91) + echo_t "DCM Codebig Connection Failure Attempt: $count - ret:$curlret http_code:$http_code" >> $DCM_LOG_FILE + ;; + esac + if [ "$http_code" -eq 200 ]; then + echo_t "Codebig connection success - ret:$curlret http_code:$http_code" >> $DCM_LOG_FILE + return 0 + elif [ "$http_code" -eq 404 ]; then + echo_t "DCM Codebig connection Received HTTP $http_code Response from Xconf Server. Retry logic not needed" >> $DCM_LOG_FILE + bypass_conn=1 + return 0 # Do not return 1, if retry for next conn type is not to be done + else + if [ "$curlret" -eq 0 ]; then + echo_t "DCM Codebig Connection Failure Attempt:$count - ret:$curlret http_code:$http_code" >> $DCM_LOG_FILE + fi + rm -rf $DCMRESPONSE + fi + count=$((count + 1)) + sleep $RETRY_DELAY + done + echo_t "Retries for Codebig connection exceeded " >> $DCM_LOG_FILE + return 1 +} + +# Output file from this processing is used by : +# 1] RFC module - RFCBase.sh +# 2] Firmware upgrade module - firmwareSched.sh +processJsonResponse() +{ + if [ -f "$DCMRESPONSE" ] + then + # Do not use persistent locations with inline stream edit operators + tmpConfigFile="/tmp/dcm$$.txt" + cp $DCMRESPONSE $tmpConfigFile + sed -i 's/,"urn:/\n"urn:/g' $tmpConfigFile # Updating the file by replacing all ',"urn:' with '\n"urn:' + sed -i 's/^{//g' $tmpConfigFile # Delete first character from file '{' + sed -i 's/}$//g' $tmpConfigFile # Delete first character from file '}' + echo "" >> $tmpConfigFile # Adding a new line to the file + cat /dev/null > $FORMATTED_TMP_DCM_RESPONSE # empty old file + while read line + do + + # Parse the settings by + # 1) Replace the '":' with '=' + # 2) Updating the result in a output file + profile_Check=`echo "$line" | grep -ci 'TelemetryProfile'` + if [ $profile_Check -ne 0 ];then + echo "$line" | sed 's/"header":"/"header" : "/g' | sed 's/"content":"/"content" : "/g' | sed 's/"type":"/"type" : "/g' >> $FORMATTED_TMP_DCM_RESPONSE + else + echo "$line" | sed 's/":/=/g' | sed 's/"//g' >> $FORMATTED_TMP_DCM_RESPONSE + fi + done < $tmpConfigFile + rm -f $tmpConfigFile + + else + echo "$DCMRESPONSE not found." >> $LOG_PATH/dcmscript.log + fi +} + +sendHttpRequestToServer() +{ + resp=0 + FILENAME=$1 + URL=$2 + echo "filename--args in sendHttpRequestToServer-------"$FILENAME + echo "url---args in sendHttpRequestToServer------"$URL + + estbMacAddress=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_MAC | grep type: | awk '{print $5}' | tr '[:upper:]' '[:lower:]'` + JSONSTR=$estbMacAddress + CURL_CMD="curl -w "%{http_code}" '$URL?estbMacAddress=$JSONSTR&model=$MODEL_NAME' -o $DCMRESPONSE >> /tmp/telehttpcode.txt " + echo "------CURL_CMD:"$CURL_CMD + + # Execute curl command + result= eval $CURL_CMD > $TELE_HTTP_CODE + #echo "Processing $FILENAME" + sleep $timeout + echo "sleep for :------------------"$timeout + # Get the http_code + http_code=$(awk -F\" '{print $1}' /tmp/telehttpcode.txt) + #start of pokuru + +if [ "$http_code" != "200" ]; then + #Added for retry - START + rm -rf /tmp/telehttpcode.txt + rm -rf $DCMRESPONSE + + xconfRetryCount=0 + while [ $xconfRetryCount -lt 2 ] + do + echo "Trying to Retry connection with XCONF server..." + + CURL_CMD="curl -w "%{http_code}" '$URL?estbMacAddress=$JSONSTR&model=$MODEL_NAME' -o $DCMRESPONSE >> /tmp/telehttpcode.txt " + + result= eval $CURL_CMD + + http_code_retry=$(awk -F\" '{print $1}' /tmp/telehttpcode.txt) + + if [ "$http_code_retry" != "200" ]; then + echo "Error in establishing communication with xconf server." + if [ $xconfRetryCount -ne 0 ]; then sleep 30; fi + rm -f /tmp/telehttpcode.txt + rm -rf $DCMRESPONSE + + else + echo "After retries...No error in curl command and curl http code is:"$http_code_retry + resp=0 + break + fi + + xconfRetryCount=`expr $xconfRetryCount + 1` + done + echo "xconf retry count is:"$xconfRetryCount + if [ $xconfRetryCount -eq 2 ]; then + echo "No xconf comm ,exiting script" + startdcmEnd=`ps -ef | grep -i "StartDCM.sh" | head -n 1` + kill -9 $startdcmEnd + exit 0 + fi + #Added for retry - END + #echo "Error from cloud exiting,check in upcoming reboot-------------" + #exit 0 +else + echo "No error in curl command and curl http code is:"$http_code +fi + #end of pokuru + echo "----------ret http_code:"$http_code + echo "----------ret http_code_retry:"$http_code_retry + + if [ $http_code -ne 200 ] ; then + if [ $http_code_retry -ne 200 ]; then + echo "curl HTTP request failed http_code :"$http_code + echo "curl HTTP request failed http_code_retry :"$http_code_retry + #pokuru rm -rf /tmp/DCMSettings.conf + resp=1 + fi + else + echo "curl HTTP request success. Processing response.." + resp=0 + fi + echo "----------res:"$resp + return $resp +} + +dropbearRecovery() +{ + dropbearPid=`ps | grep -i dropbear | grep "$ARM_INTERFACE_IP" | grep -v grep` + if [ -z "$dropbearPid" ]; then + echo "Dropbear instance is missing ... Recovering dropbear !!! " >> $DCM_LOG_FILE + DROPBEAR_PARAMS_1="/tmp/.dropbear/dropcfg1$$" + DROPBEAR_PARAMS_2="/tmp/.dropbear/dropcfg2$$" + if [ ! -d '/tmp/.dropbear' ]; then + echo "wan_ssh.sh: need to create dropbear dir !!! " >> $DCM_LOG_FILE + mkdir -p /tmp/.dropbear + fi + echo "wan_ssh.sh: need to create dropbear files !!! " >> $DCM_LOG_FILE + getConfigFile $DROPBEAR_PARAMS_1 + getConfigFile $DROPBEAR_PARAMS_2 + dropbear -r $DROPBEAR_PARAMS_1 -r $DROPBEAR_PARAMS_2 -E -s -p $ARM_INTERFACE_IP:22 & + sleep 2 + fi + rm -rf /tmp/.dropbear/* +} + +T2_ENABLE=`syscfg get T2Enable` +# Safe wait for IP acquisition +if [ “x$T2_enable” == “xfalse” ]; then + loop=1 + counter=0 + while [ $loop -eq 1 ] + do + estbIp=`getErouterIPAddress` # This needs to be changed to wait for erouter IP address + if [ "X$estbIp" == "X" ]; then + echo_t "waiting for IP" >> $DCM_LOG_FILE + sleep 2 + let counter++ + else + loop=0 + fi + done +fi + +TELEMETRY_PATH_TEMP="$TELEMETRY_PATH/tmp" + +t2Log() { + timestamp=`date +%Y-%b-%d_%H-%M-%S` + echo "$0 : $timestamp $*" >> $T2_0_LOGFILE +} + +# Check for RFC Telemetry.Enable settings +# Internal syscfg database used by RFC parameter - Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Telemetry.Enable + +t2Log "RFC value for Telemetry 2.0 Enable is $T2_ENABLE ." + +if [ ! -f $T2_0_BIN ]; then + t2Log "Unable to find $T2_0_BIN ... Switching T2 Enable to false !!!" + T2_ENABLE="false" +fi + +WAIT_COUNT=0 +MAX_PAMINIT_CHECK_TIMEOUT=30 +t2Log "Checking For PAM processes" +while [ $WAIT_COUNT -lt $MAX_PAMINIT_CHECK_TIMEOUT ] +do + if [ ! -f "/tmp/pam_initialized" ]; then + sleep 10 + let WAIT_COUNT++ + else + t2Log "PAM is Initilized" + break + fi +done + +if [ "x$T2_ENABLE" == "xtrue" ]; then + t2Pid=`pidof $T2_0_APP` + if [ -z "$t2Pid" ]; then + echo "${T2_BIN} is present, XCONF config fetch and parse will be handled by T2 implementation" >> $DCM_LOG_FILE + t2Log "Clearing markers from $TELEMETRY_PATH" + rm -rf $TELEMETRY_PATH + mkdir -p $TELEMETRY_PATH + mkdir -p $TELEMETRY_PATH_TEMP + mkdir -p $T2_XCONF_PERSISTENT_PATH + t2Log "Starting $T2_0_BIN daemon." + ${T2_0_BIN} + else + mkdir -p $TELEMETRY_PATH_TEMP + t2Log "telemetry daemon is already running .. Trigger from maintenance window." + t2Log "Send signal 15 $T2_0_APP to restart for config fetch " + kill -15 $t2Pid + fi + ## Clear any dca_utility.sh cron entries if present from T1.1 previous execution + tempfile="/tmp/tempfile$$.txt" + rm -rf $tempfile # Delete temp file if existing + crontab -l -c $CRON_SPOOL > $tempfile + # Check whether any cron jobs are existing or not + existing_cron_check=`cat $tempfile | tail -n 1` + if [ -n "$existing_cron_check" ]; then + rtl_cron_check=`grep -c 'dca_utility.sh' $tempfile` + if [ $rtl_cron_check -ne 0 ]; then + # delete entry + sed -i '/dca_utility/d' $tempfile + # Set new cron job from the file + crontab $tempfile -c $CRON_SPOOL + fi + fi + rm -rf $tempfile + # Refer to config downloaded from telemetry version 2.0 to avoid additional persistent storage usage + if [ ! -L $DCMRESPONSE ]; then + echo_t "Remove config from DCA $DCMRESPONSE and create symlink to $T2_RESPONSE" >> $DCM_LOG_FILE + # Clear persistent file from DCA execution + rm -f $DCMRESPONSE + touch $T2_RESPONSE + ln -s $T2_RESPONSE $DCMRESPONSE + fi + # Dependent modules should still get the parsed /tmp/DCMSettings.conf file + processJsonResponse + + isPeriodicFWCheckEnabled=`syscfg get PeriodicFWCheck_Enable` + if [ "$isPeriodicFWCheckEnabled" == "true" ]; then + # bypassing firmwareSched.sh once on boot up because it is called from xconf + if [ ! -f $FWDL_FLAG ]; then + touch $FWDL_FLAG + echo_t "XCONF SCRIPT : Ignoring running firmwareSched.sh on bootup from dcm script" >> $DCM_LOG_FILE + else + echo_t "XCONF SCRIPT : Calling XCONF Client firmwareSched for the updated time" >> $DCM_LOG_FILE + sh /etc/firmwareSched.sh & + fi + fi + exit 0 +fi + +# Safe wait for IP acquisition +loop=1 +counter=0 +while [ $loop -eq 1 ] +do + estbIp=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_IP | grep value | awk '{print $5}'` + if [ "X$estbIp" == "X" ]; then + echo_t "waiting for IP" + sleep 2 + let counter++ + else + echo "got IP in erouter0-------------------" + loop=0 + fi +done + + ret=1 + if [ "$estbIp" == "$default_IP" ] ; then + ret=0 + fi + if [ $checkon_reboot -eq 1 ]; then + # Clear response from telemetry 2.0 configs from persistent location with previous execution to avoid high persistent location usage + if [ -d "$T2_XCONF_PERSISTENT_PATH" ]; then + rm -rf $T2_XCONF_PERSISTENT_PATH + fi + if [ -d "$T2_BULK_PERSISTENT_PATH" ]; then + rm -rf $T2_BULK_PERSISTENT_PATH + fi + if [ -L "$DCMRESPONSE" ]; then + echo_t "Remove symbolic link from telemetry 2.0 execution " >> $DCM_LOG_FILE + rm -f $DCMRESPONSE + fi + + echo "call sendHttpRequestToServer-------------------" + sendHttpRequestToServer $DCMRESPONSE $URL + ret=$? + echo_t "sendHttpRequestToServer returned "$ret + else + ret=0 + echo_t "sendHttpRequestToServer has not executed since the value of 'checkon_reboot' is $checkon_reboot" >> $DCM_LOG_FILE + fi + + echo "after sendHttpRequestToServer-----sleep for 5 sec-------------" + sleep 5 + + + if [ $ret -ne 0 ]; then + echo_t "Processing response failed." >> $DCM_LOG_FILE + rm -rf $FILENAME + echo_t "count = $count. Sleeping $RETRY_DELAY seconds ..." >> $DCM_LOG_FILE + exit 1 + fi + + if [ "x$DCA_MULTI_CORE_SUPPORTED" == "xyes" ]; then + dropbearRecovery + + isPeriodicFWCheckEnabled=`syscfg get PeriodicFWCheck_Enable` + if [ "$isPeriodicFirmwareEnabled" == "true" ]; then + echo "XCONF SCRIPT : Calling XCONF Client firmwareSched for the updated time" + sh /etc/firmwareSched.sh & + fi + + isAxb6Device="no" + if [ "$MODEL_NUM" == "TG3482G" ]; then + isNvram2Mounted=`grep nvram2 /proc/mounts` + if [ "$isNvram2Mounted" == "" -a -d "/nvram/logs" ]; then + isAxb6Device="yes" + fi + fi + + if [ "x$isAxb6Device" == "xno" ]; then + # wait for telemetry previous log to be copied to atom + loop=1 + while [ $loop -eq 1 ] + do + if [ ! -f $TELEMETRY_PREVIOUS_LOG ]; then + echo_t "waiting for previous log file" >> $DCM_LOG_FILE + sleep 10 + else + echo_t "scp previous logs from arm to atom done, so breaking loop" >> $DCM_LOG_FILE + loop=0 + fi + done + + ### Trigger an inotify event on ATOM + echo "Telemetry run for previous log trigger to atom" >> $DCM_LOG_FILE + GetConfigFile $PEER_COMM_ID + ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ATOM_INTERFACE_IP "/bin/echo 'xconf_update' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1 + rm -f $PEER_COMM_ID + + fi + + # wait for telemetry previous log to be completed upto 2 mins . Avoid indefenite loops + loop=1 + count=0 + while [ "$loop" = "1" ] + do + if [ ! -f $TELEMETRY_PREVIOUS_LOG_COMPLETE ]; then + echo_t "waiting for previous log done file" >> $DCM_LOG_FILE + sleep 10 + if [ $count -ge $MAX_PREV_LOG_COMPLETE_WAIT ]; then + echo_t "Max wait for previous log done file reached. Proceeding with new config from xconf " >> $DCM_LOG_FILE + loop=0 + fi + else + echo_t "Telemetry run for previous log done, so breaking loop" >> $DCM_LOG_FILE + loop=0 + fi + count=`expr $count + 1` + done + + GetConfigFile $PEER_COMM_ID + scp -i $PEER_COMM_ID $DCMRESPONSE root@$ATOM_INTERFACE_IP:$PERSISTENT_PATH > /dev/null 2>&1 + if [ $? -ne 0 ]; then + scp -i $PEER_COMM_ID $DCMRESPONSE root@$ATOM_INTERFACE_IP:$PERSISTENT_PATH > /dev/null 2>&1 + fi + echo "Signal atom to pick the XCONF config data $DCMRESPONSE and schedule telemetry !!! " >> $DCM_LOG_FILE + ## Trigger an inotify event on ATOM + ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ATOM_INTERFACE_IP "/bin/echo 'xconf_update' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1 + rm -f $PEER_COMM_ID + else + echo "opensource platforms----------------------------" + + isPeriodicFWCheckEnabled=`syscfg get PeriodicFWCheck_Enable` + if [ "$isPeriodicFirmwareEnabled" == "true" ]; then + echo "XCONF SCRIPT : Calling XCONF Client firmwareSched for the updated time" + sh /etc/firmwareSched.sh & + fi + + # wait for telemetry previous log to be completed + loop=1 + count=0 + while [ "$loop" = "1" ] + do + echo "TELEMETRY_PREVIOUS_LOG_COMPLETE--------------"$TELEMETRY_PREVIOUS_LOG_COMPLETE + if [ ! -f $TELEMETRY_PREVIOUS_LOG_COMPLETE ]; then + echo_t "waiting for previous log done file" + sleep 10 + if [ $count -ge $MAX_PREV_LOG_COMPLETE_WAIT ]; then + echo_t "Max wait for previous log done file reached. Proceeding with new config from xconf " + loop=0 + fi + else + echo_t "Telemetry run for previous log done, so breaking loop" + loop=0 + fi + count=`expr $count + 1` + done + echo "before calling dca_utility start of TELEMETRY LOGIC-----------------" + sh /lib/rdk/dca_utility.sh 1 & + fi diff --git a/scripts/corrective_action.sh b/scripts/corrective_action.sh index 21f930b..c35663c 100755 --- a/scripts/corrective_action.sh +++ b/scripts/corrective_action.sh @@ -38,7 +38,7 @@ case $SELFHEAL_TYPE in CM_INTERFACE=`sysevent get current_wan_ifname` if [ "$CM_INTERFACE" = "" ] then - CM_INTERFACE=erouter0 + CM_INTERFACE=`syscfg get wan_physical_ifname` fi if [ -f $ADVSEC_PATH ] then @@ -117,7 +117,8 @@ getCMMac() "BASE") if [ "$CMMac" = "" ] then - CMMac=`ifconfig erouter0 | grep HWaddr | cut -d" " -f7` + wan_name=`syscfg get wan_physical_ifname` + CMMac=`ifconfig $wan_name | grep HWaddr | cut -d" " -f7` fi ;; "SYSTEMD") diff --git a/scripts/dca_utility.sh b/scripts/dca_utility.sh new file mode 100644 index 0000000..1b342f3 --- /dev/null +++ b/scripts/dca_utility.sh @@ -0,0 +1,780 @@ +#!/bin/sh +########################################################################## +# If not stated otherwise in this file or this component's Licenses.txt +# file the following copyright and licenses apply: +# +# Copyright 2016 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################## + +. /etc/include.properties +. /etc/device.properties + +echo "inside dca_utility script with 1 as value for arguments" + +if [ -f /lib/rdk/utils.sh ]; then + . /lib/rdk/utils.sh +fi +if [ -f /etc/mount-utils/getConfigFile.sh ];then + . /etc/mount-utils/getConfigFile.sh +fi +source /etc/log_timestamp.sh +source /lib/rdk/getpartnerid.sh +source /lib/rdk/getaccountid.sh +EROUTER_IF=erouter0 +DCMRESPONSE="$PERSISTENT_PATH/DCMresponse.txt" +DCM_SETTINGS_CONF="/tmp/DCMSettings.conf" + +TELEMETRY_PATH="$PERSISTENT_PATH/.telemetry" +TELEMETRY_PATH_TEMP="$TELEMETRY_PATH/tmp" +TELEMETRY_PROFILE_PATH="$PERSISTENT_PATH/.DCMSettings.conf" +LOG_SYNC_PATH="/rdklogs/logs/" + +RTL_LOG_FILE="$LOG_PATH/dcmProcessing.log" +RTL_DELTA_LOG_FILE="$RAMDISK_PATH/.rtl_temp.log" +MAP_PATTERN_CONF_FILE="$TELEMETRY_PATH/dcafile.conf" +TEMP_PATTERN_CONF_FILE="$TELEMETRY_PATH/temp_dcafile.conf" +EXEC_COUNTER_FILE="/tmp/.dcaCounter.txt" + +# Persist this files for telemetry operation +# Regenerate this only when there is a change identified from XCONF update +SORTED_PATTERN_CONF_FILE="$TELEMETRY_PATH/dca_sorted_file.conf" + +current_cron_file="$PERSISTENT_PATH/cron_file.txt" + +#Performance oriented binaries +DCA_BINARY="/usr/bin/dca" + +TELEMETRY_INOTIFY_FOLDER=/rdklogs/logs/ +TELEMETRY_INOTIFY_EVENT="$TELEMETRY_INOTIFY_FOLDER/eventType.cmd" +TELEMETRY_EXEC_COMPLETE="/tmp/.dca_done" +SCP_COMPLETE="/tmp/.scp_done" + +PEER_COMM_ID="/tmp/elxrretyt.swr" +IDLE_TIMEOUT=30 + +DEFAULT_IPV4="<#=#>EROUTER_IPV4<#=#>" +DEFAULT_IPV6="<#=#>EROUTER_IPV6<#=#>" +TELEMETRY_PREVIOUS_LOG="/tmp/.telemetry_previous_log" +TELEMETRY_PREVIOUS_LOG_COMPLETE="/tmp/.telemetry_previous_log_done" +TEMP_NVRAM_LOG_PATH="/tmp/nvram2_logs/" +NVRAM_LOG_PATH="/nvram/logs/" + + +# Retain source for future enabling. Defaulting to disable for now +snmpCheck=false + +dcaCleanup() +{ + if [ "x$DCA_MULTI_CORE_SUPPORTED" = "xyes" ]; then + $CONFIGPARAMGEN jx $PEER_COMM_DAT $PEER_COMM_ID + ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ARM_INTERFACE_IP "/bin/echo 'notifyTelemetryCleanup' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1 + echo_t "notify ARM for dca execution completion" >> $RTL_LOG_FILE + rm -f $PEER_COMM_ID + else + touch $TELEMETRY_EXEC_COMPLETE + fi + + echo_t "forced DCA execution before log upload/reboot. Clearing all markers !!!" >> $RTL_LOG_FILE + # Forced execution before flusing of logs, so clear the markers + if [ -d $TELEMETRY_PATH_TEMP ]; then + rm -rf $TELEMETRY_PATH_TEMP + fi + rm -rf $TELEMETRY_PATH + +} + +# exit if an instance is already running +if [ ! -f /tmp/.dca-utility.pid ];then + # store the PID + echo $$ > /tmp/.dca-utility.pid + echo "No dca-utility pid -------" +else + echo "dca-utility pis existing----------" + pid=`cat /tmp/.dca-utility.pid` + if [ -d /proc/$pid ];then + if [ "$1" == "2" ]; then + loop=0 + while [ $loop -le 6 ] + do + sleep 10 + loop=$((loop+1)) + if [ ! -f /tmp/.dca-utility.pid ] || [ ! -d /proc/`cat /tmp/.dca-utility.pid` ]; then + dcaCleanup + break + fi + done + fi + exit 0 + else + echo $$ > /tmp/.dca-utility.pid + fi +fi + +mkdir -p $LOG_PATH +touch $RTL_LOG_FILE + +previousLogPath="" +if [ -f $TELEMETRY_PREVIOUS_LOG ]; then + + isAxb6Device="no" + if [ "$MODEL_NUM" == "TG3482G" ];then + isNvram2Mounted=`grep nvram2 /proc/mounts` + if [ "$isNvram2Mounted" == "" -a -d "/nvram/logs" ];then + isAxb6Device="yes" + fi + fi + + if [ "x$DCA_MULTI_CORE_SUPPORTED" = "xyes" -a "x$isAxb6Device" == "xno" ]; then + previousLogPath="$TEMP_NVRAM_LOG_PATH" + elif [ "x$isAxb6Device" = "xyes" ]; then + previousLogPath="$NVRAM_LOG_PATH" + else + previousLogPath="$LOG_SYNC_PATH" + fi + + echo_t "Telemetry run for previous log path : "$previousLogPath +fi + +if [ ! -f /tmp/.dca_bootup -a ! -f $TELEMETRY_PREVIOUS_LOG ]; then + echo_t "First dca execution after bootup. Clearing all markers." + touch /tmp/.dca_bootup + rm -rf $TELEMETRY_PATH + rm -f $RTL_LOG_FILE +fi + + +PrevFileName='' + +#Adding support for opt override for dcm.properties file +if [ "$BUILD_TYPE" != "prod" ] && [ -f $PERSISTENT_PATH/dcm.properties ]; then + . $PERSISTENT_PATH/dcm.properties +else + . /etc/dcm.properties +fi + + +if [ ! -d "$TELEMETRY_PATH_TEMP" ] +then + echo_t "Telemetry Folder does not exist . Creating now" + mkdir -p "$TELEMETRY_PATH_TEMP" +else + cp $TELEMETRY_PATH/rtl_* $TELEMETRY_PATH_TEMP/ +fi + +mkdir -p $TELEMETRY_PATH + +pidCleanup() +{ + # PID file cleanup + if [ -f /tmp/.dca-utility.pid ];then + rm -rf /tmp/.dca-utility.pid + fi +} + +if [ $# -ne 1 ]; then + echo "Usage : `basename $0` <0/1/2> 0 - Telemtry From Cron 1 - Reinitialize Map 2 - Forced Telemetry search " >> $RTL_LOG_FILE + pidCleanup + exit 0 +fi + +# 0 if as part of normal execution +# 1 if initiated due to an XCONF update +# 2 if forced execution before log upload +# 3 if modify the cron schedule + +triggerType=$1 +echo_t "dca: Trigger type is :"$triggerType + +cd $LOG_PATH + + +isNum() +{ + Number=$1 + if [ $Number -ne 0 -o $Number -eq 0 2>/dev/null ];then + echo 0 + else + echo 1 + fi +} + +# Function to get erouerMAC +getEstbMac() +{ + + estbMac=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_MAC | grep type: | awk '{print $5}'|tr '[:lower:]' '[:upper:]'` + + if [ "$estbMac" ]; then + echo "$estbMac" + else + if [ "$BOX_TYPE" == "XB3" ]; then + estbMac=`/usr/bin/rpcclient $ARM_ARPING_IP "ifconfig erouter0" | grep 'Link encap:' | cut -d ' ' -f7` + echo "$estbMac" + else + wan_name=`syscfg get wan_physical_ifname` + estbMac=`ifconfig $wan_name | grep 'Link encap:' | cut -d ' ' -f7` + echo "$estbMac" + fi + fi + +} + +# Function to get erouter0 ipv4 address +getErouterIpv4() +{ + erouter_ipv4=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_IP | grep value | awk '{print $5}'` + if [ "$erouter_ipv4" != "" ];then + echo $erouter_ipv4 + else + echo "null" + fi +} + +# Function to get erouter0 ipv6 address +getErouterIpv6() +{ + erouter_ipv6=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_IPv6 | grep value | awk '{print $5}'` + if [ "$erouter_ipv6" != "" ];then + echo $erouter_ipv6 + else + echo "null" + fi +} + +getSNMPUpdates() { + snmpMIB=$1 + TotalCount=0 + export MIBS=ALL + export MIBDIRS=/mnt/nfs/bin/target-snmp/share/snmp/mibs:/usr/share/snmp/mibs + export PATH=$PATH:/mnt/nfs/bin/target-snmp/bin + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/nfs/bin/target-snmp/lib:/mnt/nfs/usr/lib + snmpCommunityVal=`head -n 1 /tmp/snmpd.conf | awk '{print $4}'` + tuneString=`snmpwalk -OQv -v 2c -c $snmpCommunityVal 127.0.0.1 $snmpMIB` + for count in $tuneString + do + count=`echo $count | tr -d ' '` + if [ $(isNum $count) -eq 0 ]; then + TotalCount=`expr $TotalCount + $count` + else + TotalCount=$count + fi + done + + echo $TotalCount +} + +## Reatining for future support when net-snmp tools will be enabled in XB3s +getControllerId(){ + ChannelMapId='' + ControllerId='' + VctId='' + vodServerId='' + export MIBS=ALL + export MIBDIRS=/mnt/nfs/bin/target-snmp/share/snmp/mibs:/usr/share/snmp/mibs + export PATH=$PATH:/mnt/nfs/bin/target-snmp/bin + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/nfs/bin/target-snmp/lib:/mnt/nfs/usr/lib + + snmpCommunityVal=`head -n 1 /tmp/snmpd.conf | awk '{print $4}'` + ChannelMapId=`snmpwalk -OQ -v 2c -c $snmpCommunityVal 127.0.0.1 1.3.6.1.4.1.17270.9225.1.1.40 | awk -F '= ' '{print $2}'` + ControllerId=`snmpwalk -OQ -v 2c -c $snmpCommunityVal 127.0.0.1 1.3.6.1.4.1.17270.9225.1.1.41 | awk -F '= ' '{print $2}'` + VctId=`snmpwalk -OQ -v 2c -c $snmpCommunityVal 127.0.0.1 OC-STB-HOST-MIB::ocStbHostCardVctId.0 | awk -F '= ' '{print $2}'` + vodServerId=`snmpwalk -OQ -v 2c -c $snmpCommunityVal 127.0.0.1 1.3.6.1.4.1.17270.9225.1.1.43 | awk -F '= ' '{print $2}'` + + echo "{\"ChannelMapId\":\"$ChannelMapId\"},{\"ControllerId\":\"$ControllerId\"},{\"VctId\":$VctId},{\"vodServerId\":\"$vodServerId\"}" +} + +# Function to get RF status +## Reatining for future support when net-snmp tools will be enabled in XB3s +getRFStatus(){ + Dwn_RX_pwr='' + Ux_TX_pwr='' + Dx_SNR='' + export MIBS=ALL + export MIBDIRS=/mnt/nfs/bin/target-snmp/share/snmp/mibs + export PATH=$PATH:/mnt/nfs/bin/target-snmp/bin + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/nfs/bin/target-snmp/lib:/mnt/nfs/usr/lib + + snmpCommunityVal=`head -n 1 /tmp/snmpd.conf | awk '{print $4}'` + Dwn_RX_pwr=`snmpwalk -OQ -v 2c -c $snmpCommunityVal 192.168.100.1 DOCS-IF-MIB::docsIfDownChannelPower.3 | awk -F '= ' '{print $2}'` + Ux_TX_pwr=`snmpwalk -OQ -v 2c -c $snmpCommunityVal 192.168.100.1 DOCS-IF-MIB::docsIfCmStatusTxPower.2 | awk -F '= ' '{print $2}'` + Dx_SNR=`snmpwalk -OQ -v 2c -c $snmpCommunityVal 192.168.100.1 DOCS-IF-MIB::docsIfSigQSignalNoise.3 | awk -F '= ' '{print $2}'` + + echo "{\"Dwn_RX_pwr\":\"$Dwn_RX_pwr\"},{\"Ux_TX_pwr\":\"$Ux_TX_pwr\"},{\"Dx_SNR\":\"$Dx_SNR\"}" +} + +processJsonResponse() +{ + FILENAME=$1 + #Condider getting the filename as an argument instead of using global file name + if [ -f "$FILENAME" ]; then + # Start pre-processing the original file + sed -i 's/,"urn:/\n"urn:/g' $FILENAME # Updating the file by replacing all ',"urn:' with '\n"urn:' + sed -i 's/^{//g' $FILENAME # Delete first character from file '{' + sed -i 's/}$//g' $FILENAME # Delete first character from file '}' + echo "" >> $FILENAME # Adding a new line to the file + # Start pre-processing the original file + + OUTFILE=$DCM_SETTINGS_CONF + OUTFILEOPT="$PERSISTENT_PATH/.DCMSettings.conf" + #rm -f $OUTFILE #delete old file + cat /dev/null > $OUTFILE #empty old file + cat /dev/null > $OUTFILEOPT + while read line + do + # Special processing for telemetry + profile_Check=`echo "$line" | grep -ci 'TelemetryProfile'` + if [ $profile_Check -ne 0 ];then + #echo "$line" + echo "$line" | sed 's/"header":"/"header" : "/g' | sed 's/"content":"/"content" : "/g' | sed 's/"type":"/"type" : "/g' >> $OUTFILE + + echo "$line" | sed 's/"header":"/"header" : "/g' | sed 's/"content":"/"content" : "/g' | sed 's/"type":"/"type" : "/g' | sed -e 's/uploadRepository:URL.*","//g' >> $OUTFILEOPT + else + echo "$line" | sed 's/":/=/g' | sed 's/"//g' >> $OUTFILE + fi + done < $FILENAME + else + echo "$FILENAME not found." >> $RTL_LOG_FILE + return 1 + fi +} + +scheduleCron() +{ + echo "schedulecronjob!!" + cron='' + scheduler_Check=`grep '"schedule":' $DCM_SETTINGS_CONF` + if [ -n "$scheduler_Check" ]; then + cron=`grep -i TelemetryProfile $DCM_SETTINGS_CONF | awk -F '"schedule":' '{print $NF}' | awk -F "," '{print $1}' | sed 's/://g' | sed 's/"//g' | sed -e 's/^[ ]//' | sed -e 's/^[ ]//'` + fi + + #During diagnostic mode need to apply the cron schedule value through this custom configuration + DiagnosticMode=`dmcli eRT getv Device.SelfHeal.X_RDKCENTRAL-COM_DiagnosticMode | grep value | cut -f3 -d : | cut -f2 -d" "` + if [ "$DiagnosticMode" == "true" ];then + LogUploadFrequency=`dmcli eRT getv Device.SelfHeal.X_RDKCENTRAL-COM_DiagMode_LogUploadFrequency | grep value | cut -f3 -d : | cut -f2 -d" "` + if [ "$LogUploadFrequency" != "" ]; then + cron='' + cron="*/$LogUploadFrequency * * * *" + echo "$timestamp dca: the default Cron schedule from XCONF is ignored and instead SNMP overriden value is used" >> $RTL_LOG_FILE + fi + fi + + #Check whether cron having empty value if it is empty then need to assign + #15mins by default + if [ -z "$cron" ]; then + echo "$timestamp: dca: Empty cron value so set default as 15mins" + cron="*/15 * * * *" + fi + + if [ -n "$cron" ]; then + # Dump existing cron jobs to a file + crontab -l -c $CRON_SPOOL > $current_cron_file + # Check whether any cron jobs are existing or not + existing_cron_check=`cat $current_cron_file | tail -n 1` + tempfile="$PERSISTENT_PATH/tempfile.txt" + rm -rf $tempfile # Delete temp file if existing + if [ -n "$existing_cron_check" ]; then + rtl_cron_check=`grep -c 'dca_utility.sh' $current_cron_file` + if [ $rtl_cron_check -eq 0 ]; then + echo "$cron nice -n 19 sh $RDK_PATH/dca_utility.sh 1" >> $tempfile + fi + while read line + do + retval=`echo "$line" | grep 'dca_utility.sh'` + if [ -n "$retval" ]; then + echo "$cron nice -n 19 sh $RDK_PATH/dca_utility.sh 1" >> $tempfile + else + echo "$line" >> $tempfile + fi + done < $current_cron_file + else + # If no cron job exists, create one, with the value from DCMSettings.conf file + echo "$cron nice -n 19 sh $RDK_PATH/dca_utility.sh 1" >> $tempfile + fi + # Set new cron job from the file + crontab $tempfile -c $CRON_SPOOL + rm -rf $current_cron_file # Delete temp file + rm -rf $tempfile # Delete temp file + else + echo " `date` Failed to read \"schedule\" cronjob value from DCMSettings.conf." >> $RTL_LOG_FILE + fi +} + +dropbearRecovery() +{ + dropbearPid=`ps | grep -i dropbear | grep "$ATOM_INTERFACE_IP" | grep -v grep` + if [ -z "$dropbearPid" ]; then + DROPBEAR_PARAMS_1="/tmp/.dropbear/dropcfg1$$" + DROPBEAR_PARAMS_2="/tmp/.dropbear/dropcfg2$$" + if [ ! -d '/tmp/.dropbear' ]; then + echo "wan_ssh.sh: need to create dropbear dir !!! " >> $RTL_LOG_FILE + mkdir -p /tmp/.dropbear + fi + echo "wan_ssh.sh: need to create dropbear files !!! " >> $RTL_LOG_FILE + getConfigFile $DROPBEAR_PARAMS_1 + getConfigFile $DROPBEAR_PARAMS_2 + dropbear -r $DROPBEAR_PARAMS_1 -r $DROPBEAR_PARAMS_2 -E -s -p $ATOM_INTERFACE_IP:22 & + sleep 2 + fi + rm -rf /tmp/.dropbear/* +} + +clearTelemetryConfig() +{ + echo_t "dca: Clearing telemetry config and markers" >> $RTL_LOG_FILE + if [ -f $RTL_DELTA_LOG_FILE ]; then + echo_t "dca: Deleting : $RTL_DELTA_LOG_FILE" >> $RTL_LOG_FILE + rm -f $RTL_DELTA_LOG_FILE + fi + + if [ -f $MAP_PATTERN_CONF_FILE ]; then + echo_t "dca: MAP_PATTERN_CONF_FILE : $MAP_PATTERN_CONF_FILE" >> $RTL_LOG_FILE + rm -f $MAP_PATTERN_CONF_FILE + fi + + if [ -f $TEMP_PATTERN_CONF_FILE ]; then + echo_t "dca: TEMP_PATTERN_CONF_FILE : $TEMP_PATTERN_CONF_FILE" >> $RTL_LOG_FILE + rm -f $TEMP_PATTERN_CONF_FILE + fi + + if [ -f $SORTED_PATTERN_CONF_FILE ]; then + echo_t "dca: SORTED_PATTERN_CONF_FILE : $SORTED_PATTERN_CONF_FILE" >> $RTL_LOG_FILE + rm -f $SORTED_PATTERN_CONF_FILE + fi + + # Clear markers with XCONF update as logs will be flushed in case of maintenance window case as well. + # During boot-up no need of maintaining old markers. + if [ -d $TELEMETRY_PATH ]; then + rm -rf $TELEMETRY_PATH + mkdir -p $TELEMETRY_PATH + fi + + if [ -d $TELEMETRY_PATH_TEMP ]; then + rm -rf $TELEMETRY_PATH_TEMP + mkdir -p $TELEMETRY_PATH_TEMP + fi + +} + +## Pass The I/P O/P Files As Arguments +generateTelemetryConfig() +{ + echo_t "dca: Generating telemetry config file." >> $RTL_LOG_FILE + input_file=$1 + output_file=$2 + touch $TEMP_PATTERN_CONF_FILE + if [ -f $input_file ]; then + grep -i 'TelemetryProfile' $input_file | sed 's/=\[/\n/g' | sed 's/},/}\n/g' | sed 's/],.*?/\n/g'| sed -e 's/^[ ]//' > $TEMP_PATTERN_CONF_FILE + fi + + # Create map file from json message file + while read line + do + header_Check=`echo "$line" | grep -c '{"header"'` + if [ $header_Check -ne 0 ];then + polling=`echo "$line" | grep -c 'pollingFrequency'` + if [ $polling -ne 0 ];then + header=`echo "$line" | awk -F '"header" :' '{print $NF}' | awk -F '",' '{print $1}' | sed -e 's/^[ ]//' | sed 's/^"//'` + content=`echo "$line" | awk -F '"content" :' '{print $NF}' | awk -F '",' '{print $1}' | sed -e 's/^[ ]//' | sed 's/^"//'` + logFileName=`echo "$line" | awk -F '"type" :' '{print $NF}' | awk -F '",' '{print $1}' | sed -e 's/^[ ]//' | sed 's/^"//'` + skipInterval=`echo "$line" | sed -e "s/.*pollingFrequency\":\"//g" | sed 's/"}//'` + else + header=`echo "$line" | awk -F '"header" :' '{print $NF}' | awk -F '",' '{print $1}' | sed -e 's/^[ ]//' | sed 's/^"//'` + content=`echo "$line" | awk -F '"content" :' '{print $NF}' | awk -F '",' '{print $1}' | sed -e 's/^[ ]//' | sed 's/^"//'` + logFileName=`echo "$line" | awk -F '"type" :' '{print $NF}' | sed -e 's/^[ ]//' | sed 's/^"//' | sed 's/"}//'` + #default value to 0 + skipInterval=0 + fi + + if [ -n "$header" ] && [ -n "$content" ] && [ -n "$logFileName" ] && [ -n "$skipInterval" ]; then + echo "$header<#=#>$content<#=#>$logFileName<#=#>$skipInterval" >> $MAP_PATTERN_CONF_FILE + fi + fi + done < $TEMP_PATTERN_CONF_FILE + # Sort the config file based on file names to minimise the duplicate delta file generation + if [ -f $MAP_PATTERN_CONF_FILE ]; then + if [ -f $output_file ]; then + rm -f $output_file + fi + awk -F '<#=#>' '{print $3,$0}' $MAP_PATTERN_CONF_FILE | sort -n | cut -d ' ' -f 2- > $output_file + fi + +} + + echo "triggertype------------"$triggerType +# Reschedule the cron based on diagnositic mode +if [ $triggerType -eq 3 ] ; then + echo_t "$timestamp: dca: Processing rescheduleCron job" >> $RTL_LOG_FILE + scheduleCron + ## Telemetry must be invoked only for reschedule cron job + pidCleanup + exit 0 +fi + +# Pull the settings from Telemetry server periodically +estbMacAddress=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_MAC | grep type: | awk '{print $5}'|tr '[:lower:]' '[:upper:]'` +JSONSTR=$estbMacAddress +CURL_CMD="curl '$DCM_LOG_SERVER_URL?estbMacAddress=$JSONSTR&model=$MODEL_NAME' -o $DCMRESPONSE > /tmp/httpcode.txt" + +# Execute curl command +result= eval $CURL_CMD +sleep 5 +echo "sleep for :------------------$timeout" + +# Regenerate config only during boot-up and when there is an update +if [ ! -f $SORTED_PATTERN_CONF_FILE ] || [ $triggerType -eq 1 -a ! -f $TELEMETRY_PREVIOUS_LOG ] ; then +# Start crond daemon for yocto builds + pidof crond + if [ $? -ne 0 ]; then + mkdir -p $CRON_SPOOL + touch $CRON_SPOOL/root + crond -c $CRON_SPOOL -l 9 + fi + + if [ "x$DCA_MULTI_CORE_SUPPORTED" = "xyes" ]; then + while [ ! -f $DCMRESPONSE ] + do + echo "WARNING !!! Unable to locate $DCMRESPONSE .. Retrying " >> $RTL_LOG_FILE + GetConfigFile $PEER_COMM_ID + scp -i $PEER_COMM_ID -r $ARM_INTERFACE_IP:$DCMRESPONSE $DCMRESPONSE > /dev/null 2>&1 + rm -f $PEER_COMM_ID + sleep 10 + done + fi + echo "calling processJsonResponse--------" + processJsonResponse $DCMRESPONSE + echo "after calling processJsonResponse-----------" + clearTelemetryConfig + echo "after calling clearTelemetryConfig-----------" + generateTelemetryConfig $TELEMETRY_PROFILE_PATH $SORTED_PATTERN_CONF_FILE + echo "after calling generateTelemetryConfig--------" + scheduleCron + echo "after calling scheduleCron-------------------" + if [ $triggerType -eq 1 ]; then + bootupTelemetryBackup=true + ## Telemetry must be invoked only via cron and not during boot-up + # pidCleanup + #exit 0 + fi +fi + +mkdir -p $TELEMETRY_PATH_TEMP + +if [ "x$DCA_MULTI_CORE_SUPPORTED" = "xyes" ]; then + dropbearRecovery + mkdir -p $LOG_PATH + TMP_SCP_PATH="/tmp/scp_logs" + mkdir -p $TMP_SCP_PATH + GetConfigFile $PEER_COMM_ID + scp -i $PEER_COMM_ID -r $ARM_INTERFACE_IP:$LOG_PATH/* $TMP_SCP_PATH/ > /dev/null 2>&1 + scp -i $PEER_COMM_ID -r $ARM_INTERFACE_IP:$LOG_SYNC_PATH/$SelfHealBootUpLogFile $ARM_INTERFACE_IP:$LOG_SYNC_PATH/$PcdLogFile $TMP_SCP_PATH/ > /dev/null 2>&1 + rm -f $PEER_COMM_ID + + RPC_RES=`rpcclient $ARM_ARPING_IP "touch $SCP_COMPLETE"` + RPC_OK=`echo $RPC_RES | grep "RPC CONNECTED"` + if [ "$RPC_OK" == "" ]; then + echo_t "RPC touch failed : attemp 1" + + RPC_RES=`rpcclient $ARM_ARPING_IP "touch $SCP_COMPLETE"` + RPC_OK=`echo $RPC_RES | grep "RPC CONNECTED"` + if [ "$RPC_OK" == "" ]; then + echo_t "RPC touch failed : attemp 2" + fi + fi + + ATOM_FILE_LIST=`echo ${ATOM_FILE_LIST} | sed -e "s/{//g" -e "s/}//g" -e "s/,/ /g"` + for file in $ATOM_FILE_LIST + do + if [ -f $TMP_SCP_PATH/$file ]; then + rm -f $TMP_SCP_PATH/$file + fi + done + + if [ -d $TMP_SCP_PATH ]; then + cp -r $TMP_SCP_PATH/* $LOG_PATH/ + rm -rf $TMP_SCP_PATH + fi + + sleep 2 +fi + +#Clear the final result file +rm -f $TELEMETRY_JSON_RESPONSE + + +## Generate output file with pattern to match count values +if [ ! -f $SORTED_PATTERN_CONF_FILE ]; then + echo "WARNING !!! Unable to locate telemetry config file $SORTED_PATTERN_CONF_FILE. Exiting !!!" >> $RTL_LOG_FILE +else + # echo_t "Using telemetry pattern stored in : $SORTED_PATTERN_CONF_FILE.!!!" >> $RTL_LOG_FILE + defaultOutputJSON="{\"searchResult\":[{\"\":\"\"}]}" + echo "nice -n 19 $DCA_BINARY $SORTED_PATTERN_CONF_FILE $previousLogPath" >> $RTL_LOG_FILE + dcaOutputJson=`nice -n 19 $DCA_BINARY $SORTED_PATTERN_CONF_FILE $previousLogPath 2>> $RTL_LOG_FILE` + if [ -z "$dcaOutputJson" ]; + then + dcaOutputJson=$defaultOutputJSON + fi + + echo "dcaoutputjson----!!!!!!!!!!!!----"$dcaOutputJson + singleEntry=true + + # Get the snmp and performance values when enabled + # Need to check only when SNMP is enabled in future + if [ "$snmpCheck" == "true" ] ; then + while read line + do + pattern=`echo "$line" | awk -F '<#=#>' '{print $1}'` + filename=`echo "$line" | awk -F '<#=#>' '{print $2}'` + if [ $filename == "snmp" ] || [ $filename == "SNMP" ]; then + retvalue=$(getSNMPUpdates $pattern) + header=`grep "$pattern<#=#>$filename" $MAP_PATTERN_CONF_FILE | head -n 1 | awk -F '<#=#>' '{print $1}'` + if $singleEntry ; then + tuneData="{\"$header\":\"$retvalue\"}" + outputJson="$outputJson$tuneData" + singleEntry=false + else + tuneData=",{\"$header\":\"$retvalue\"}" + outputJson="$outputJson$tuneData" + fi + fi + done < $SORTED_PATTERN_CONF_FILE + fi + + + ## This interface is not accessible from ATOM, replace value from ARM + estbMac=$(getEstbMac) + firmwareVersion=$(getFWVersion) + firmwareVersion=$(echo $firmwareVersion | sed -e "s/imagename://g") + partnerId=$(getPartnerId) + accountId=$(getAccountId) + erouterIpv4=$(getErouterIpv4) + erouterIpv6=$(getErouterIpv6) + + + if [ "$triggerType" = "1" ]; then + if [ "$erouterIpv4" = "null" ]; then + erouterIpv4="$DEFAULT_IPV4" + fi + if [ "$erouterIpv6" = "null" ]; then + erouterIpv6="$DEFAULT_IPV6" + fi + fi + + cur_time=`date "+%Y-%m-%d %H:%M:%S"` + + if $singleEntry ; then + outputJson="$outputJson{\"Profile\":\"RDKB\"},{\"mac\":\"$estbMac\"},{\"erouterIpv4\":\"$erouterIpv4\"},{\"erouterIpv6\":\"$erouterIpv6\"},{\"PartnerId\":\"$partnerId\"},{\"AccountId\":\"$accountId\"},{\"Version\":\"$firmwareVersion\"},{\"Time\":\"$cur_time\"}" + singleEntry=false + else + outputJson="$outputJson,{\"Profile\":\"RDKB\"},{\"mac\":\"$estbMac\"},{\"erouterIpv4\":\"$erouterIpv4\"},{\"erouterIpv6\":\"$erouterIpv6\"},{\"PartnerId\":\"$partnerId\"},{\"AccountId\":\"$accountId\"},{\"Version\":\"$firmwareVersion\"},{\"Time\":\"$cur_time\"}" + fi + echo "outputjson---------------"$outputJson + + remain="{\"\":\"\"}" + outputJson=`echo "$dcaOutputJson" | sed "s/$remain/$outputJson/"` + echo "outputjson1---------------"$outputJson + echo "$outputJson" > $TELEMETRY_JSON_RESPONSE + sleep 2 + + echo "TELEMETRY_JSON_RESPONSE file is -----------"$TELEMETRY_JSON_RESPONSE + if [ "x$DCA_MULTI_CORE_SUPPORTED" = "xyes" ]; then + echo "Notify ARM to pick the updated JSON message in $TELEMETRY_JSON_RESPONSE and upload to splunk" >> $RTL_LOG_FILE + # Trigger inotify event on ARM to upload message to splunk + GetConfigFile $PEER_COMM_ID + if [ $triggerType -eq 2 ]; then + ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ARM_INTERFACE_IP "/bin/echo 'notifyFlushLogs' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1 + echo_t "notify ARM for dca execution completion" >> $RTL_LOG_FILE + else + if [ -f $TELEMETRY_PREVIOUS_LOG -a $triggerType -eq 1 ];then + ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ARM_INTERFACE_IP "/bin/echo 'previousLog' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1 + echo_t "notify ARM for dca running is for previous log" >> $RTL_LOG_FILE + else + if [ "$bootupTelemetryBackup" = "true" -a $triggerType -eq 1 ];then + ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ARM_INTERFACE_IP "/bin/echo 'bootupBackup' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1 + else + ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ARM_INTERFACE_IP "/bin/echo 'splunkUpload' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1 + fi + fi + fi + rm -f $PEER_COMM_ID + else + if [ $triggerType -eq 2 ]; then + touch $TELEMETRY_EXEC_COMPLETE + fi + if [ $triggerType -eq 1 -a -f $TELEMETRY_PREVIOUS_LOG ]; + then + echo "calling splunkupload----------------------------" + sh /lib/rdk/dcaSplunkUpload.sh logbackup_without_upload & + else + sh /lib/rdk/dcaSplunkUpload.sh & + fi + proUpdel=`cat /tmp/DCMSettings.conf | grep -i uploadRepository:uploadProtocol | tr -dc '"' |wc -c` + echo "number of proUPdel:"$proUpdel + #proUpdel=$((proUpdel - 1)) + uploadProto=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | cut -d '"' -f$proUpdel` + echo "Upload protocol is:"$uploadProto + if [ "$uploadProto" != "TFTP" ]; then + HTTPLOGUPLOADURL=`cat /tmp/DCMSettings.conf | grep -i "urn:settings:LogUploadSettings:RepositoryURL" | cut -d "=" -f2` + if [ "$HTTPLOGUPLOADURL" == "" ]; then + echo "No HTTP URL configured in xconf,going with internal one !!" + HTTPLOGUPLOADURL=$DCM_LA_SERVER_URL + fi + echo "HTTPURL:"$HTTPLOGUPLOADURL + sh $RDK_PATH/uploadSTBLogs.sh $HTTPLOGUPLOADURL 1 1 1 0 0 & + else + delimnr=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | tr -dc ':' |wc -c` + echo "number of deli:"$delimnr + delimnr=$((delimnr - 1)) + TFTPIP=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | cut -d ":" -f$delimnr | cut -d '"' -f 2` + echo "TFTPIP:"$TFTPIP + sh $RDK_PATH/uploadSTBLogs.sh $TFTPIP 1 1 1 0 0 & + fi + fi +fi + +if [ -f $RTL_DELTA_LOG_FILE ]; then + rm -f $RTL_DELTA_LOG_FILE +fi + +if [ -f $TEMP_PATTERN_CONF_FILE ]; then + rm -f $TEMP_PATTERN_CONF_FILE +fi + +if [ $triggerType -eq 2 ]; then + echo_t "forced DCA execution before log upload/reboot. Clearing all markers !!!" >> $RTL_LOG_FILE + # Forced execution before flusing of logs, so clear the markers + if [ -d $TELEMETRY_PATH_TEMP ]; then + rm -rf $TELEMETRY_PATH_TEMP + fi + rm -rf $TELEMETRY_PATH + +fi + +if [ -f $EXEC_COUNTER_FILE ]; then + dcaNexecCounter=`cat $EXEC_COUNTER_FILE` + dcaNexecCounter=`expr $dcaNexecCounter + 1` +else + dcaNexecCounter=0; +fi + +if [ -f $TELEMETRY_PREVIOUS_LOG ]; then + echo_t "dca for previous log done" >> $RTL_LOG_FILE + rm -f $TELEMETRY_PREVIOUS_LOG $SORTED_PATTERN_CONF_FILE + rm -rf $TEMP_NVRAM_LOG_PATH + touch $TELEMETRY_PREVIOUS_LOG_COMPLETE +fi + +echo "$dcaNexecCounter" > $EXEC_COUNTER_FILE +# PID file cleanup +pidCleanup diff --git a/scripts/self_heal_connectivity_test.sh b/scripts/self_heal_connectivity_test.sh index 9093641..d2043c0 100755 --- a/scripts/self_heal_connectivity_test.sh +++ b/scripts/self_heal_connectivity_test.sh @@ -31,7 +31,7 @@ rand_num_old="" WAN_INTERFACE=`sysevent get current_wan_ifname` if [ "$WAN_INTERFACE" = "" ] then - WAN_INTERFACE="erouter0" + WAN_INTERFACE=`syscfg get wan_physical_ifname` fi calcRandom=1 @@ -177,7 +177,8 @@ runPingTest() #If GW IPv6 is missing in both route list and neighbour list checking for Link Local GW ipv6 in neighbour list and #Checking if route list returns Box_IPv6_addr as IPv6_Gateway_addr - Box_IPv6_addr=`ifconfig erouter0 | grep inet6 | grep Global | awk '{print $(NF-1)}' | cut -f1 -d\/` + wan_name=`syscfg get wan_physical_ifname` + Box_IPv6_addr=`ifconfig $wan_name | grep inet6 | grep Global | awk '{print $(NF-1)}' | cut -f1 -d\/` if [ "$IPv6_Gateway_addr" = "" ] || [ "$IPv6_Gateway_addr" = "$Box_IPv6_addr" ] then diff --git a/scripts/uploadSTBLogs.sh b/scripts/uploadSTBLogs.sh new file mode 100644 index 0000000..0da09ff --- /dev/null +++ b/scripts/uploadSTBLogs.sh @@ -0,0 +1,477 @@ +#!/bin/sh +########################################################################## +# If not stated otherwise in this file or this component's Licenses.txt +# file the following copyright and licenses apply: +# +# Copyright 2018 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################## + +. /etc/include.properties +. /etc/device.properties + +. $RDK_PATH/utils.sh +. $RDK_PATH/interfaceCalls.sh +. $RDK_PATH/utils.sh +. $RDK_PATH/logfiles.sh +. $RDK_PATH/commonUtils.sh + +if [ $# -ne 6 ]; then + echo "USAGE: $0 " +fi + +# assign the input arguments +TFTP_SERVER=$1 +FLAG=$2 +DCM_FLAG=$3 +UploadOnReboot=$4 +UploadProtocol=$5 +UploadHttpLink=$6 + +DCM_LOG_PATH=/upload + +if [ $FLAG -eq 0 ]; then + if [ -f $RAMDISK_PATH/.standby ]; then + echo "`/bin/timestamp` Exiting since box is in standby..!" + exit 0 + fi +fi + +# initialize the variables +MAC=`getErouterMacAddress` +HOST_IP=`getIPAddress` +dt=`date "+%m-%d-%y-%I-%M%p"` +LOG_FILE="$MAC_Logs_$dt.tgz" + +#MARKER_FILE=$MAC"_Logs_Marker_$dt.txt" +VERSION="version.txt" +# working folders +PREV_LOG_PATH="$LOG_PATH/PreviousLogs" +PREV_LOG_BACKUP_PATH="$LOG_PATH/PreviousLogs_backup/" +DCM_UPLOAD_LIST="$LOG_PATH/dcm_upload" + +echo "Build Type: $BUILD_TYPE Log file: $LOG_FILE TFTP Server: $TFTP_SERVER Protocol: $UploadProtocol UploadHttpLink: $UploadHttpLink" >> $LOG_PATH/dcmscript.log + +prevUploadFlag=0 + +if [ ! -d $PREV_LOG_PATH ]; then + echo "The Previous Logs folder is missing" >> $LOG_PATH/dcmscript.log + #if [ "true" != "$RDK_EMULATOR" ]; then + # exit 0 + #else + + if [ ! -d $LOG_PATH ]; then mkdir -p $LOG_PATH; fi + if [ ! -d $LOG_PATH/PreviousLogs ]; then mkdir -p $LOG_PATH/PreviousLogs; fi + if [ ! -d $LOG_PATH/PreviousLogs_backup ]; then mkdir -p $LOG_PATH/PreviousLogs_backup; fi + rm -rf $LOG_PATH/PreviousLogs_backup/* + + backupSystemLogFiles cp $LOG_PATH $PREV_LOG_PATH + backupAppBackupLogFiles cp $LOG_PATH $PREV_LOG_PATH + + #fi +else + #if [ "true" != "$RDK_EMULATOR" ]; then + #echo "" + #else + + rm -rf $LOG_PATH/PreviousLogs_backup/* + backupSystemLogFiles cp $LOG_PATH $PREV_LOG_PATH + backupAppBackupLogFiles cp $LOG_PATH $PREV_LOG_PATH + #cp $PREV_LOG_BACKUP_PATH/* $PREV_LOG_PATH/ + #fi +fi + +backupAppLogs() +{ + source=$1 + destn=$2 + if [ -f $source$RILog ] ; then cp $source$RILog $destn; fi + if [ -f $source$XRELog ] ; then cp $source$XRELog $destn; fi + if [ -f $source$WBLog ] ; then cp $source$WBLog $destn; fi + if [ -f $source$SysLog ] ; then cp $source$SysLog $destn; fi +} +renameRotatedLogs() +{ + logPath=$1 + if [ -f $RDK_PATH/renameRotatedLogs.sh ]; then + if [ -f $logPath/ocapri_log.txt ] ; then sh $RDK_PATH/renameRotatedLogs.sh $logPath/ocapri_log.txt; fi + if [ -f $logPath/receiver.log ] ; then sh $RDK_PATH/renameRotatedLogs.sh $logPath/receiver.log; fi + if [ -f $logPath/greenpeak.log ] ; then sh $RDK_PATH/renameRotatedLogs.sh $logPath/greenpeak.log; fi + if [ -f $logPath/gp_init.log ] ; then sh $RDK_PATH/renameRotatedLogs.sh $logPath/gp_init.log; fi + if [ -f $logPath/app_status.log ] ; then sh $RDK_PATH/renameRotatedLogs.sh $logPath/app_status.log; fi + fi +} +processLogsFolder() +{ + srcLogPath=$1 + destnLogPath=$2 + backupAppLogs "$srcLogPath/" "$destnLogPath/" + backupSystemLogFiles "cp" $srcLogPath $destnLogPath + backupAppBackupLogFiles "cp" $srcLogPath $destnLogPath + + if [ -f $RAMDISK_PATH/disk_log.txt ]; then cp $RAMDISK_PATH/disk_log.txt $destnLogPath ; fi + + backupCount=`ls $srcLogPath/logbackup-* 2>/dev/null | wc -l` + if [ $backupCount -gt 0 ]; then + cp -r $srcLogPath/logbackup-* $destnLogPath + fi + + if [ -f $srcLogPath/$rebootLog ]; then cp $srcLogPath/$rebootLog $destnLogPath; fi + if [ -f $srcLogPath/$ablReasonLog ]; then cp $srcLogPath/$ablReasonLog $destnLogPath; fi + if [ -f $srcLogPath/$ueiLog ]; then cp $srcLogPath/$ueiLog $destnLogPath; fi + if [ -f $PERSISTENT_PATH/sventest/p3541_all_csven_AV_health_data_trigger.tar.gz ] ; then + cp $PERSISTENT_PATH/sventest/p3541_all_csven_AV_health_data_trigger.tar.gz $destnLogPath + fi + if [ "$DEVICE_TYPE" != "mediaclient" ]; then + renameRotatedLogs $srcLogPath + fi +} +modifyFileWithTimestamp() +{ + srcLogPath=$1 + ret=`ls $srcLogPath/*.txt | wc -l` + if [ ! $ret ]; then + ret=`ls $srcLogPath/*.log | wc -l` + if [ ! $ret ]; then exit 1; fi + fi + + dt=`date "+%m-%d-%y-%I-%M%p-"` + FILES=*.* + FILES1=".*-[0-9][0-9]AM-.*" + FILES2=".*-[0-9][0-9]PM-.*" + + for f in $FILES + do + test1=0 + test2=0 + test3=0 + test4=0 + + test1=`expr match $f $FILES1` + test2=`expr match $f $FILES2` + test3=`expr match $f $rebootLog` + test4=`expr match $f $ablReasonLog` + + if [ $test1 -gt 0 -o $test2 -gt 0 -o $test3 -gt 0 -o $test4 -gt 0 ]; then + echo "`/bin/timestamp` Processing file...$f" >> $LOG_PATH/dcmscript.log + else + mv $f $dt$f + fi + done + #cp /version.txt ./$dt$VERSION +} + +copyAllFiles () +{ + + EXCLUDE="dcm PreviousLogs_backup PreviousLogs" + cd $LOG_PATH + + for fileName in * + do + COPY_BOOLEAN=true + for excl in $EXCLUDE + do + if [ $excl == $fileName ]; then + COPY_BOOLEAN=false + fi + done + + if $COPY_BOOLEAN; then + cp -R $fileName $DCM_LOG_PATH + fi + done +} +copyOptLogsFiles () +{ + cd $LOG_PATH + cp * $DCM_LOG_PATH >> $LOG_PATH/dcmscript.log 2>&1 +} + +HttpLogUpload() +{ + result=1 + FILENAME='/tmp/httpresult.txt' + HTTP_CODE=/tmp/curl_httpcode + + CLOUD_URL=$UploadHttpLink + #CLOUD_URL="$(UploadHttpLink)filename=$LOG_FILE" + + CURL_CMD="curl -w '%{http_code}\n' -F \"filename=@$1\" -o \"$FILENAME\" \"$CLOUD_URL\" --connect-timeout 10 -m 10" + echo URL_CMD: $CURL_CMD + ret= eval $CURL_CMD > $HTTP_CODE + http_code=$(awk -F\" '{print $1}' $HTTP_CODE) + if [ $http_code -eq 200 ];then + echo "`/timestamp` Done Uploading Logs through HTTP" >> $LOG_PATH/dcmscript.log + result=0 + elif [ $http_code -eq 302 ];then + #Get the url from FILENAME + NewUrl=$(awk -F\" '{print $1}' $FILENAME) + + CURL_CMD="curl -w '%{http_code}\n' -o \"$FILENAME\" \"$NewUrl\" --connect-timeout 10 -m 10" + echo URL_CMD: $CURL_CMD + result= eval $CURL_CMD > $HTTP_CODE + http_code=$(awk -F\" '{print $1}' $HTTP_CODE) + + if [ $http_code -eq 200 ];then + echo "`/timestamp` Done Uploading Logs through - HTTP" >> $LOG_PATH/dcmscript.log + result=0 + else + echo "`/timestamp` Failed Uploading Logs through - HTTP" >> $LOG_PATH/dcmscript.log + fi + fi + echo $result +} + +uploadDCMLogs() +{ + + cd $DCM_LOG_PATH + echo " Uploading Logs through DCM cron job" >> $LOG_PATH/dcmscript.log + modifyFileWithTimestamp $DCM_LOG_PATH >> $LOG_PATH/dcmscript.log 2>&1 + tar -zcvf $LOG_FILE * >> $LOG_PATH/dcmscript.log 2>&1 + sleep 60 + echo "Uploading logs $LOG_FILE onto $TFTP_SERVER" >> $LOG_PATH/dcmscript.log + + retval=1 + + if [ "$UploadProtocol" == "HTTP" ];then + retval=$(HttpLogUpload $LOG_FILE) + fi + if [ $retval -eq 1 ];then #Http upload failed + tftp -p -r $LOG_FILE -l $LOG_FILE $TFTP_SERVER >> $LOG_PATH/dcmscript.log 2>&1 + echo "`/bin/timestamp` Done Uploading Logs through TFTP" >> $LOG_PATH/dcmscript.log + sleep 1 + fi + + rm -rf $DCM_LOG_PATH/ +} +uploadLogOnReboot() +{ + uploadLog=$1 + echo "Sleeping for seven minutes " + if [ "true" != "$RDK_EMULATOR" ]; then + sleep 12 + fi + echo "Done sleeping prev logpath "$PREV_LOG_PATH + ret=`ls $PREV_LOG_PATH/*.txt | wc -l` + if [ ! $ret ]; then + ret=`ls $PREV_LOG_PATH/*.log | wc -l` + if [ ! $ret ]; then exit 1; fi + fi + if [ "$HDD_ENABLED" = "true" ]; then + # Special processing - Permanently backup logs on box delete the logs older than + # 3 days to take care of old filename + sleep 2 + stat=`find /opt/logs -name "*-*-*-*-*M-" -mtime +3 -exec rm -rf {} \;` + # for the new filenames with suffix logbackup + stat=`find /opt/logs -name "*-*-*-*-*M-logbackup" -mtime +3 -exec rm -rf {} \;` + + TIMESTAMP=`date "+%m-%d-%y-%I-%M%p-logbackup"` + PERM_LOG_PATH="$LOG_PATH/$TIMESTAMP" + mkdir -p $PERM_LOG_PATH + + processLogsFolder $PREV_LOG_PATH $PERM_LOG_PATH + fi + echo "ckp100-------------prev log path-------------"$PREV_LOG_PATH + cd $PREV_LOG_PATH + rm $LOG_FILE + modifyFileWithTimestamp $PREV_LOG_PATH >> $LOG_PATH/dcmscript.log 2>&1 + + echo "ckp101---------------------upload log-----"$uploadLog + ls -al + sleep 30 + if $uploadLog; then + echo "ckp101--------------------------" + tar -zcvf $LOG_FILE * >> $LOG_PATH/dcmscript.log 2>&1 + echo "Uploading logs $LOG_FILE onto $TFTP_SERVER" >> $LOG_PATH/dcmscript.log + sleep 60 + #tftp -p -r $LOG_FILE -l $LOG_FILE $TFTP_SERVER >> $LOG_PATH/dcmscript.log 2>&1 + #sleep 1 + #echo "`/bin/timestamp` Done Uploading Logs" >> $LOG_PATH/dcmscript.log + proUpdel=`cat /tmp/DCMSettings.conf | grep -i uploadRepository:uploadProtocol | tr -dc '"' |wc -c` + echo "number of proUPdel2:"$proUpdel + #proUpdel=$((proUpdel - 1)) + uploadProtocolla=`cat /tmp/DCMSettings.conf | grep -i urn:settings:TelemetryProfile | cut -d '"' -f$proUpdel` + echo "Upload protocol logupload is:"$uploadProtocolla + RpiMacAddress=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_MAC | grep type: | awk '{print $5}' | tr '[:upper:]' '[:lower:]'` + cp $LOG_FILE $RpiMacAddress-Logs-$LOG_FILE + if [ "$uploadProtocolla" != "TFTP" ];then + echo "before HTTP log upload" + HTTPLOGUPLOADURL=`cat /tmp/DCMSettings.conf | grep -i "urn:settings:LogUploadSettings:RepositoryURL" | cut -d "=" -f2` + if [ "$HTTPLOGUPLOADURL" == "" ]; then + echo "No HTTP URL configured in xconf,going with internal one !!" + HTTPLOGUPLOADURL=$DCM_LA_SERVER_URL + fi + echo "HTTPLOGUPLOADURL:"$HTTPLOGUPLOADURL + echo "upload log file is:"$LOG_FILE + CURL_CMD="curl -w '%{http_code}\n' -F filename=@$PREV_LOG_PATH/$RpiMacAddress-Logs-$LOG_FILE '$HTTPLOGUPLOADURL' --connect-timeout 100 -m 100" + #echo_t "CURL_CMD http proto log upload: $CURL_CMD" >> $DCM_LOG_FILE + echo "------CURL_CMD2:"$CURL_CMD + HTTP_CODE=`result= eval $CURL_CMD` + http_code=$(echo $HTTP_CODE | cut -d "." -f 2) + echo "http_code is :"$http_code + if [ $http_code -eq 200 ] ; then + echo "HTTP log upload succeded!!!!!!!!!!!!!!!!!" + else + loguploadRetryCount=0 + while [ $loguploadRetryCount -lt 2 ] + do + echo "Trying to upload log file..." + CURL_CMD="curl -w '%{http_code}\n' -F filename=@$PREV_LOG_PATH/$RpiMacAddress-Logs-$LOG_FILE '$HTTPLOGUPLOADURL' --connect-timeout 100 -m 100" + HTTP_CODE=`result= eval $CURL_CMD` + http_code_la=$(echo $HTTP_CODE | cut -d "." -f 2) + echo "http_code is :"$http_code_la + if [ "$http_code_la" != "200" ]; then + echo "Error in uploading log file" + else + echo "logupload succeded in retry" + break + fi + loguploadRetryCount=`expr $loguploadRetryCount + 1` + done + if [ $loguploadRetryCount -eq 2 ]; then + echo "HTTP log upload failed!!!!!!!!!!!!!!!!!" + fi + fi + else + echo "Uploading logs $LOG_FILE onto $TFTP_SERVER" >> $LOG_PATH/dcmscript.log + tftp -p -r $RpiMacAddress-Logs-$LOG_FILE -l $RpiMacAddress-Logs-$LOG_FILE $TFTP_SERVER >> $LOG_PATH/dcmscript.log 2>&1 + ret=$? + echo $ret + if [ "$ret" -eq 1 ]; then + tftplauploadRetryCount=0 + while [ "$tftplauploadRetryCount" -lt 2 ] + do + echo "Trying to upload logs file using tftp again..." + tftp -p -r $RpiMacAddress-Logs-$LOG_FILE -l $RpiMacAddress-Logs-$LOG_FILE $TFTP_SERVER >> $LOG_PATH/dcmscript.log 2>&1 + ret=$? + if [ "$ret" -eq 1 ]; then + echo "error in uploading logs using tftp" + else + echo "tftp upload in retry logs succeded" + ret=0 + break + fi + tftplauploadRetryCount=`expr $tftplauploadRetryCount + 1` + done + if [ "$tftlauploadRetryCount" -eq 2 ]; then + ret=1 + echo "TFTP log upload failed!!!!!!!!!!!!!!!!!" + else + echo "TFTP log upload succeded !!!" + ret=0 + fi + fi + fi + sleep 60 + echo "Done Uploading Logs and removing rtl_json.txt file" + rm -rf $TELEMETRY_JSON_RESPONSE + rm -rf $PERSISTENT_PATH/*TELE* + fi + cd $PREV_LOG_PATH + rm -rf $PREV_LOG_PATH/$LOG_FILE + rm -rf $PREV_LOG_BACKUP_PATH + mkdir -p $PREV_LOG_BACKUP_PATH + if [ "$BUILD_TYPE" = "dev" ] || [ "$HDD_ENABLED" = "false" ]; then + + echo "Moving to Previous Logs Backup Folder " >> $LOG_PATH/dcmscript.log + mv * $PREV_LOG_BACKUP_PATH + else + echo "`/bin/timestamp` Deleting from Previous Logs Folder " >> $LOG_PATH/dcmscript.log + rm -rf * + fi +} +#if [ "$true" != "$RDK_EMULATOR" ]; then +#if [ -d $DCM_LOG_PATH ]; then + # rm -rf $DCM_LOG_PATH/ +#fi +#Remove *.tgz files from /opt/logs +#if [ "true" != "$RDK_EMULATOR" ]; then +#stat=`find $LOG_PATH -name "*.tgz" -exec rm -rf {} \;` + +#Remove files which have timestamp in it filename +#for item in `ls $LOG_PATH/*-*-*-*-*M-* | grep "[0-9]*-[0-9]*-[0-9]*-[0-9]*-M*" | grep -v "logbackup"`;do + # if [ -f "$item" ];then + # echo "`/bin/timestamp` Removing $item" >> $LOG_PATH/dcmscript.log + # rm -rf $item + #fi +#done +#fi +#fi +if [ $DCM_FLAG -eq 0 ] ; then + echo "`/bin/timestamp` Uploading Without DCM" >> $LOG_PATH/dcmscript.log + uploadLogOnReboot true +else + if [ $FLAG -eq 1 ] ; then + if [ $UploadOnReboot -eq 1 ]; then + echo "Uploading Logs with DCM UploadOnReboot set to true" >> $LOG_PATH/dcmscript.log + echo "call uploadLogOnReboot" + uploadLogOnReboot true + + else + echo "`/bin/timestamp` Not Uploading Logs with DCM UploadOnReboot set to false" >> $LOG_PATH/dcmscript.log + uploadLogOnReboot false + echo $PERM_LOG_PATH >> $DCM_UPLOAD_LIST + fi + + else + if [ $UploadOnReboot -eq 0 ]; then + mkdir -p $DCM_LOG_PATH + if [ "$HDD_ENABLED" = "true" ]; then + fileUploadCount=`cat "$DCM_UPLOAD_LIST" | wc -l` + if [ $fileUploadCount -gt 0 ]; then + while read line + do + echo $line + cp -R $line $DCM_LOG_PATH + done < $DCM_UPLOAD_LIST + copyOptLogsFiles + cat /dev/null > $DCM_UPLOAD_LIST + uploadDCMLogs + else + copyOptLogsFiles + uploadDCMLogs + fi + else + if [ -f $PREV_LOG_BACKUP_PATH/uploaded ]; then + copyOptLogsFiles + uploadDCMLogs + else + cd $PREV_LOG_BACKUP_PATH + foldertime=`ls *version.txt | cut -c 1-16` + if [ -z $foldertime ]; then + foldertime=`date +%m-%d-%y-%I-%M%p` + fi + TIMESTAMP=$foldertime-logbackup + PERM_LOG_PATH="/mnt/memory/dcm/$TIMESTAMP" + mkdir -p $PERM_LOG_PATH + cp * $PERM_LOG_PATH + copyOptLogsFiles + uploadDCMLogs + cd $PREV_LOG_BACKUP_PATH + touch uploaded + fi + fi + + else + if [ "$HDD_ENABLED" = "true" ]; then + touch $DCM_INDEX + copyAllFiles + uploadDCMLogs + fi + fi + fi +fi +