def collectAndClearEventLog(self, couch): log = {} # OIDs to retrieve oids = ['BLADE-MIB::readEnhancedEventLogAttribute', 'BLADE-MIB::readEnhancedEventLogMessage'] # Get the mapping of blade serial numbers to blade document ids serialNumberToDocId = Blade.serialNumberToDocId(couch) for oid in oids: # Start async snmpwalk. This call returns immediately # and spawns a background thread to perform the SNMPWalk snmpWalk = SNMPWalk.withConfigFile(self.host, oid) # While the snmpwalk is running while not snmpWalk.eof: # Get snmp oid/value pairs off the queue while not snmpWalk.queue.empty(): (oid, value) = snmpWalk.queue.get() (mibName, oidBase, lastOctet) = snmpWalk.extractOidParts(oid) if oidBase != 'readEnhancedEventLogNumber': # Start with an empty dictionary dict = {} # Get the existing log entry, if it exists if log.has_key(lastOctet): dict = log[lastOctet] # Update the dictionary with this line from the snmpwalk if oidBase == 'readEnhancedEventLogAttribute': dict.update(self.parseEventLogAttribute(value, serialNumberToDocId)) else: match = re.search('^Text:(.*)$', value) if match: value = match.group(1) dict.update({'message': value}) # Update the log entry list log[lastOctet] = dict # On the final snmp walk command, create CouchDB objects if dict and oidBase == 'readEnhancedEventLogMessage': logEntry = LogEntry(dict) logEntry.persist(couch) # Join snmpwalk background thread snmpWalk.join() snmp = SNMP.withConfigFile(self.host) snmp.set('BLADE-MIB::clearEventLog.0', 'i', '1') Log.info('%s system log entries collected from %s' % (len(log), self.name))
def powerOnOffSlot(self, slot, func): """ Power on a single slot Params ------ slot : int The slot number func: int 0 = off, 1 = on, 2 = soft off """ snmp = SNMP.withConfigFile(self.host) snmp.set('BLADE-MIB::powerOnOffBlade.%d' % slot, 'i', str(func))
def collectInfoAndPersist(self, couch): """ Collect blade info for this chassis via SNMP, and persist those blades and slots and this Chassis object to CouchDB when done """ if not self.ping(): Log.info('%s not pingable, not collecting SNMP info' % self.host) else: Log.debug(5, '%s is pingable' % self.host) self.isPingable = 1 snmp = SNMP.withConfigFile(self.host) self.collectChassisInfo(snmp) self.collectFanPackInfo() bladesCommunicating = bitarray(self.bladesCommunicating) bladesInstalled = bitarray(self.bladesInstalled) oids = {'mac0': 'BLADE-MIB::bladeMACAddress1Vpd', 'mac1': 'BLADE-MIB::bladeMACAddress2Vpd', 'biosVersion': 'BLADE-MIB::bladeBiosVpdRevision', 'bmcVersion': 'BLADE-MIB::bladeSysMgmtProcVpdRevision', 'diagVersion': 'BLADE-MIB::bladeDiagsVpdRevision', 'serialNumber': 'BLADE-MIB::bladeBiosVpdName', 'healthState': 'BLADE-MIB::bladeHealthState', 'healthSummarySeverity': 'BLADE-MIB::bladeHealthSummarySeverity', 'healthSummaryDescription': 'BLADE-MIB::bladeHealthSummaryDescription', } blade = {} for (attr, oid) in oids.items(): values = self.bladeInfo(snmp, oid) if values: for (slot, value) in values: if not blade.has_key(slot): blade[slot] = {} blade[slot][attr] = value if len(blade) > 0: self.collectedSNMP = 1 for (slotNum, params) in blade.items(): Log.debug(10, 'chassis %d slot %s blade params: %s' % (self.num, slotNum, params)) nodeNum = (int(slotNum) - 1) + self.firstNode nodeName = self.nodeNameFormat % nodeNum blade = Blade(params) slotInt = int(slotNum) slotParams = {'num': slotInt, 'nodeName': nodeName, 'chassisDocId': self.docId, 'bladeDocId': blade.mac0, 'bladeInstalled': bladesInstalled[slotInt - 1], 'bladeCommunicating': bladesCommunicating[slotInt - 1], } slot = Slot(slotParams) # This appears to be pointless. We shouldn't save any information about blades that # are not available # if blade.mac0 == 'not available': # blade.mac0 = '%s-%s' % (blade.mac0, slot.docId) slot.persist(couch) if blade.validMac0: blade.persist(couch) self.persist(couch)
def powerCycleSlot(self, slot): snmp = SNMP.withConfigFile(self.host) snmp.set('BLADE-MIB::restartBlade.%d' % slot, 'i', '1')
def collectAndClearEventLog(self, couch): log = {} # OIDs to retrieve oids = [ 'BLADE-MIB::readEnhancedEventLogAttribute', 'BLADE-MIB::readEnhancedEventLogMessage' ] # Get the mapping of blade serial numbers to blade document ids serialNumberToDocId = Blade.serialNumberToDocId(couch) for oid in oids: # Start async snmpwalk. This call returns immediately # and spawns a background thread to perform the SNMPWalk snmpWalk = SNMPWalk.withConfigFile(self.host, oid) # While the snmpwalk is running while not snmpWalk.eof: # Get snmp oid/value pairs off the queue while not snmpWalk.queue.empty(): (oid, value) = snmpWalk.queue.get() (mibName, oidBase, lastOctet) = snmpWalk.extractOidParts(oid) if oidBase != 'readEnhancedEventLogNumber': # Start with an empty dictionary dict = {} # Get the existing log entry, if it exists if log.has_key(lastOctet): dict = log[lastOctet] # Update the dictionary with this line from the snmpwalk if oidBase == 'readEnhancedEventLogAttribute': dict.update( self.parseEventLogAttribute( value, serialNumberToDocId)) else: match = re.search('^Text:(.*)$', value) if match: value = match.group(1) dict.update({'message': value}) # Update the log entry list log[lastOctet] = dict # On the final snmp walk command, create CouchDB objects if dict and oidBase == 'readEnhancedEventLogMessage': logEntry = LogEntry(dict) logEntry.persist(couch) # Join snmpwalk background thread snmpWalk.join() snmp = SNMP.withConfigFile(self.host) snmp.set('BLADE-MIB::clearEventLog.0', 'i', '1') Log.info('%s system log entries collected from %s' % (len(log), self.name))
def collectInfoAndPersist(self, couch): """ Collect blade info for this chassis via SNMP, and persist those blades and slots and this Chassis object to CouchDB when done """ if not self.ping(): Log.info('%s not pingable, not collecting SNMP info' % self.host) else: Log.debug(5, '%s is pingable' % self.host) self.isPingable = 1 snmp = SNMP.withConfigFile(self.host) self.collectChassisInfo(snmp) self.collectFanPackInfo() bladesCommunicating = bitarray(self.bladesCommunicating) bladesInstalled = bitarray(self.bladesInstalled) oids = { 'mac0': 'BLADE-MIB::bladeMACAddress1Vpd', 'mac1': 'BLADE-MIB::bladeMACAddress2Vpd', 'biosVersion': 'BLADE-MIB::bladeBiosVpdRevision', 'bmcVersion': 'BLADE-MIB::bladeSysMgmtProcVpdRevision', 'diagVersion': 'BLADE-MIB::bladeDiagsVpdRevision', 'serialNumber': 'BLADE-MIB::bladeBiosVpdName', 'healthState': 'BLADE-MIB::bladeHealthState', 'healthSummarySeverity': 'BLADE-MIB::bladeHealthSummarySeverity', 'healthSummaryDescription': 'BLADE-MIB::bladeHealthSummaryDescription', } blade = {} for (attr, oid) in oids.items(): values = self.bladeInfo(snmp, oid) if values: for (slot, value) in values: if not blade.has_key(slot): blade[slot] = {} blade[slot][attr] = value if len(blade) > 0: self.collectedSNMP = 1 for (slotNum, params) in blade.items(): Log.debug( 10, 'chassis %d slot %s blade params: %s' % (self.num, slotNum, params)) nodeNum = (int(slotNum) - 1) + self.firstNode nodeName = self.nodeNameFormat % nodeNum blade = Blade(params) slotInt = int(slotNum) slotParams = { 'num': slotInt, 'nodeName': nodeName, 'chassisDocId': self.docId, 'bladeDocId': blade.mac0, 'bladeInstalled': bladesInstalled[slotInt - 1], 'bladeCommunicating': bladesCommunicating[slotInt - 1], } slot = Slot(slotParams) # This appears to be pointless. We shouldn't save any information about blades that # are not available # if blade.mac0 == 'not available': # blade.mac0 = '%s-%s' % (blade.mac0, slot.docId) slot.persist(couch) if blade.validMac0: blade.persist(couch) self.persist(couch)