def getSensorTemp()

in platform/broadcom/sonic-platform-modules-juniper/qfx5200/utils/juniper_qfx5200_monitor.py [0:0]


    def getSensorTemp(self):
        global isPlatformAFI
        global PrevASICValue

        sensor_str = ''

        #AFI
        if (isPlatformAFI == True):
            temp_policy = temp_policy_AFI
        else:
        #AFO
            temp_policy = temp_policy_AFO

        """ Dictionary where 
            key = thermal id index starting from 0. 0 is the sensor 1 ...
            value = Different temp ranges """
        SensorFlag = {
            0: [0,0,0,0,0,0,0,0,0,0,0,0],
            1: [0,0,0,0,0,0,0,0,0,0,0,0],
            2: [0,0,0,0,0,0,0,0,0,0,0,0],
            3: [0,0,0,0,0,0,0,0,0,0,0,0],
            4: [0,0,0,0,0,0,0,0,0,0,0,0],
            5: [0,0,0,0,0,0,0,0,0,0,0,0],
            6: [0,0,0,0,0,0,0,0,0,0,0,0],
            7: [0,0,0,0,0,0,0,0,0,0,0,0],
            8: [0,0,0,0,0,0,0,0,0,0,0,0],
            9: [0,0,0,0,0,0,0,0,0,0,0,0],
            10: [0,0,0,0,0,0,0,0,0,0,0,0],
            11: [0,0,0,0,0,0,0,0,0,0,0,0],
        }    

        for x in range(self.SENSOR_CORETEMP_NUM_ON_MAIN_BOARD):
            SEN_str = 'SEN'

            if x < self.SENSOR_NUM_ON_MAIN_BOARD:
                value = self._get_sensor_node_val(x)
	        if ( x < 2):
		   SEN_str += `x + 2`
	        else:
		   SEN_str += `x + 3`

                sensor_str += SEN_str + ':' + str(value) + ', '

            elif x == self.CORETEMP_INDEX_ON_MAIN_BOARD:
                value = self.get_coretempValue()
	        sensor_str += 'CPU:' + str(value) + ', '

            else:
                proc = subprocess.Popen("bcmcmd \"show temp\" | grep \"maximum peak temperature\" | awk '{ print $5 }' > /var/log/asic_value 2>&1 & ",shell=True)
                time.sleep(2)
                cmd = ["kill", "-9", proc.pid]
                getstatusoutput_noshell(cmd)
                
                if os.stat("/var/log/asic_value").st_size == 0:
                    value = PrevASICValue
                else:
                    with open('/var/log/asic_value', 'r') as f:
                        value1 = f.readline()
                    value2 = float(value1)
                    value1 = value2 * 1000
                    value = int(value1)
                    PrevASICValue = value

		sensor_str += 'BRCM TH:' + str(value)    
	    	
            # 35% Duty Cycle
            if value > temp_policy[x][0][1] and value <= temp_policy[x][0][2]:
                SensorFlag[x][0] = True

            # 35% Prev Duty Cycle
            elif value > temp_policy[x][1][1] and value < temp_policy[x][1][2]:
                SensorFlag[x][1] = True

            # 55% Duty Cycle
            elif value == temp_policy[x][2][1]:
                SensorFlag[x][2] = True

            # 55% Prev Duty Cycle
            elif value > temp_policy[x][3][1] and value < temp_policy[x][3][2]:
                SensorFlag[x][3] = True

            # 75% Duty Cycle
            elif value == temp_policy[x][4][1]:
                SensorFlag[x][4] = True

            # 75% Prev Duty Cycle
            elif value > temp_policy[x][5][1] and value < temp_policy[x][5][2]:
                SensorFlag[x][5] = True

            # 90% Duty Cycle
            elif value == temp_policy[x][6][1]:
                SensorFlag[x][6] = True

            # 90% Prev Duty Cycle
            elif value > temp_policy[x][7][1] and value < temp_policy[x][7][2]:
                SensorFlag[x][7] = True

            #100% Duty Cycle
            elif value >= temp_policy[x][8][1]:
                SensorFlag[x][8] = True
            
            else:
                pass

            # Yellow Alarm
            if value >= temp_policy[x][9][1] and value < temp_policy[x][9][2]:
                SensorFlag[x][9] = True

            # Red Alarm
            elif value >= temp_policy[x][10][1] and value < temp_policy[x][10][2]:
                SensorFlag[x][10] = True

            # Fire Shut down    
            elif value >= temp_policy[x][11][1]:
                SensorFlag[x][11] = True
         
        logging.debug('Sensor values : %s', sensor_str)
        fan = QFX5200_FanUtil()
        # CHECK IF ANY TEMPERATURE SENSORS is running at Soft shutdown temperature
        if (SensorFlag[0][11] or SensorFlag[1][11] or SensorFlag[2][11] or SensorFlag[3][11] or SensorFlag[4][11] or SensorFlag[5][11] or SensorFlag[6][11] or SensorFlag[7][11]
            or SensorFlag[8][11] or SensorFlag[9][11] or SensorFlag[10][11] or SensorFlag[11][11]):

            logging.debug('Fire Threshold reached: System is going to shutdown now')
            self.write_file('CRITICAL: Fire Threshold reached: System is going to shutdown now', "/dev/console")


            logging.debug('Executing poweroff command')

            time.sleep(1)

            try:
                monitorlog_file = open(self.MONITORLOG_PATH)
            except IOError as e:
                logging.error('get_Sensor_temp: unable to open file:  %s', str(e))
                return False

            monitorlog_file.close()

            cmd = ["poweroff"]
        subprocess.call(cmd)
            
        # CHECK IF ANY TEMPERATURE SENSORS is running at RED warning , IF YES, SET THE ALARM LED TO 'RED'
        elif (SensorFlag[0][10] or SensorFlag[1][10] or SensorFlag[2][10] or SensorFlag[3][10] or SensorFlag[4][10] or SensorFlag[5][10] or SensorFlag[6][10] or SensorFlag[7][10]
            or SensorFlag[8][10] or SensorFlag[9][10] or SensorFlag[10][10] or SensorFlag[11][10]):
  
            self.set_alarm_led_brightness(2)

            logging.debug('Setting Red Alarm')

        # CHECK IF ANY TEMPERATURE SENSORS is running at Yellow warning, IF YES, SET THE ALARM LED TO 'YELLOW'
        elif (SensorFlag[0][9] or SensorFlag[1][9] or SensorFlag[2][9] or SensorFlag[3][9] or SensorFlag[4][9] or SensorFlag[5][9] or SensorFlag[6][9] or SensorFlag[7][9]
            or SensorFlag[8][9] or SensorFlag[9][9] or SensorFlag[10][9] or SensorFlag[11][9]):

            self.set_alarm_led_brightness(1)

            logging.debug('Setting Yellow Alarm')