import StringIO import re from Sensor import FanSensor, TemperatureSensor from ClusterNodeSensorsReadings import ClusterNodeSensorsReadings class IpmiTool202Parser: def parseSensorOutput( self, strOutput, clusterNodeName ): sensorReadings=ClusterNodeSensorsReadings(clusterNodeName) f = StringIO.StringIO(strOutput) line = f.readline() while( len(line) > 0 ): #print line, matchObj = re.match( '^Sensor ID[ ]*\: \'(?P[a-zA-Z 0-9]+)\'', line ) if matchObj: sensorName = matchObj.group('sensorName') # print sensorName # read the entity id line = f.readline() matchObj = re.match( '^ Entity ID[ ]*\: (?P[0-9\.]+)', line ) assert(matchObj) entityId = matchObj.group('entityId') # print entityId # read the sensor type line = f.readline() matchObj = re.match( '^ Sensor Type[\(\)a-zA-Z ]*\: (?P[a-zA-Z \(\)]+)', line ) assert(matchObj) sensorType = matchObj.group('sensorType') #print sensorType if sensorType == 'Fan': rpms = self.parseFanSensorOutput(f) if temperature != None: sensor = FanSensor(sensorName) sensor.m_rpms = rpms elif sensorType == 'Temperature': temperature = self.parseTemperatureSensorOutput(f) if temperature != None: sensor = TemperatureSensor(sensorName) sensor.m_temperature = temperature else: #ignoring other sensors sensor = None if sensor: sensorReadings.addSensor( sensor ) else: None #assert(False) line = f.readline() f.close() def parseFanSensorOutput(self, file): """ reads the fan specific ipdmitool output """ line = file.readline() #print line matchObj = re.match( '^ Sensor Reading[ ]*\: (?P[0-9]+) \(\+/\- (?P[0-9]+)\) RPM', line ) if(matchObj): numRpms = matchObj.group('numRpms') #print numRpms rpms = float( numRpms ) return rpms else: matchObj = re.match( '^ Sensor Reading[ ]*\: Not Present', line ) assert(matchObj) return None def parseTemperatureSensorOutput(self, file): """ reads the temperature specific ipdmitool output """ # Sensor Reading : 36 (+/- 0) degrees C line = file.readline() #print line matchObj = re.match( '^ Sensor Reading[ ]*\: (?P[0-9]+) \(\+/\- (?P[0-9]+)\) degrees C', line ) if(matchObj): temperature = matchObj.group('temperature') temperature = float( temperature ) return temperature else: matchObj = re.match( '^ Sensor Reading[ ]*\: Not Present', line ) assert(matchObj) return None