def is_writable(file): try: print 'checking for writable file = ' + file sensorhelper.executeCommand('test -w ' + file + ' 2>/dev/null') print 'file writable' return True except: print 'file not writable' return False
def does_exist(file): try: print 'checking for accessible file = ' + file out = sensorhelper.executeCommand('ls ' + file + ' 2>/dev/null') print 'file found = ' + out return True except: print 'file not found' return False
def validateCommand(cmd): try: print 'validating command = ' + cmd path = sensorhelper.executeCommand('command -v ' + cmd + ' 2>/dev/null') print 'path found = ' + path return True except: print 'command not found' return False
def validateCommand(self, cmd): try: log.info('validating command = ' + cmd) path = sensorhelper.executeCommand('command -v ' + cmd + ' 2>/dev/null') log.info('path found = ' + path) return True except: log.info('command not found') return False
def emc_inq(remotePath, fc_vols): try: output = sensorhelper.executeCommand(remotePath + ' -no_dots -wwn') except: log.info(remotePath + ' command failed, halting execution of disk discovery.') return fc_vols for line in output.splitlines(): # TODO look for other valid startswith lines if they exist # found /dev/vx/rdmp/ on gar-jamis if line.startswith('/dev/rdsk/'): s = line.split(':') if len(s) == 4: device = s[0].strip() name = device.split('/')[-1][:-2] # remove s2 from the end vendor = s[1].strip() prod = s[2].strip() # VRAID and RAID 5 products found uuid = s[3] # make sure wwn is in format of a UUID and proper type if len(uuid) == 32 and (prod == 'VPLEX' or (vendor == 'DGC' and 'RAID' in prod)): log.info('Found LUN: ' + line) uuid = uuid.upper() vsv = sensorhelper.newModelObject('cdm:dev.StorageVolume') # ManagedSystemName is SUPPOSED to be reserved for ITM/TMS integration, however the developers # have been using it all over the place as a hack vsv.setManagedSystemName(uuid) if name in fc_vols.keys(): fcv = fc_vols[name] # use existing else: fcv = sensorhelper.newModelObject('cdm:dev.FCVolume') fcv.setName(name) # create relationships bo = sensorhelper.newModelObject('cdm:dev.BasedOnExtent') bo.setSource(fcv) bo.setTarget(vsv) bo.setType( 'com.collation.platform.model.topology.dev.BasedOnExtent' ) fcv.setBasedOn( sensorhelper.getArray([bo], 'cdm:dev.BasedOnExtent')) fc_vols[name] = fcv else: #result.warning('line parse unexpected:' + uuid) log.info('Skipping line:' + line) else: #result.warning('line parse unexpected:' + line) log.warning('line parse unexpected:' + line) return fc_vols
def sg_inq(disk, vol): sg_inq_output = sensorhelper.executeCommand('sudo sg_inq -i ' + disk) if sg_inq_output: # parse out UUID regex = re.compile('\[0x[a-fA-F0-9]{32}\]', re.MULTILINE) uuid_match = regex.search(sg_inq_output) if uuid_match: uuid = uuid_match.group(0).strip() uuid = uuid[3:] # take off [Ox from beginning uuid = uuid[:-1] # take off ] from end uuid = uuid.upper() log.debug('uuid: ' + uuid) if uuid.startswith('6'): return buildVolume(uuid, vol) else: # TODO add result warning that Invista disk not found log.warning('WWN does not start with 6:' + uuid) else: log.warning('Could not find UUID in sq_inq output for ' + disk) return None
def fcinfo(): fc_vols = {} # check if sudo is configured for fcinfo first, this way we won't trigger # a sudo alert if we run it and it fails sudo_list = sensorhelper.executeCommandWithTimeout('sudo -l', 30 * 1000) if sudo_list: if not re.search('.*fcinfo.*', sudo_list): log.info('fcinfo not in sudo') # don't attempt sudo fcinfo return fc_vols else: log.info('fcinfo not in sudo') # don't attempt sudo fcinfo return fc_vols if not helper.does_exist('/usr/sbin/fcinfo'): log.info('/usr/sbin/fcinfo does not exist') return fc_vols try: output = sensorhelper.executeCommand('sudo /usr/sbin/fcinfo hba-port') except: log.info('fcinfo command failed, halting execution of disk discovery.') return fc_vols for hba_line in output.splitlines(): if re.search('HBA Port WWN: [a-fA-F0-9]{16}', hba_line): hba_port_wwn = hba_line.split()[-1] hba_node_wwn = None elif re.search('Node WWN: [a-fA-F0-9]{16}', hba_line): hba_node_wwn = hba_line.split()[-1] log.info('Found HBA Port ' + hba_port_wwn + ' and Node ' + hba_node_wwn) scsi_pc = sensorhelper.newModelObject( 'cdm:dev.SCSIProtocolController') scsi_pc.setName(WorldWideNameUtils.toUniformString(hba_node_wwn)) #scsi_pc.setParent(cs) # parent set later at the end scsi_pe = sensorhelper.newModelObject( 'cdm:dev.SCSIProtocolEndPoint') scsi_pe.setName(WorldWideNameUtils.toUniformString(hba_port_wwn)) scsi_pe.setWorldWideName( WorldWideNameUtils.toUniformString(hba_port_wwn)) scsi_pe.setParent(scsi_pc) scsi_pc.setEndPoints( sensorhelper.getArray([scsi_pe], 'cdm:dev.SCSIProtocolEndPoint')) # continue now that we have the HBA port and node WWN rport_output = sensorhelper.executeCommand( 'sudo /usr/sbin/fcinfo remote-port -ls -p ' + hba_port_wwn) if rport_output: for line in rport_output.splitlines(): if re.search('LUN: [0-9]+', line): lun = line.split()[-1] elif re.search('Vendor: ', line): vendor = line.split()[-1] elif re.search('Product: ', line): product = line.split()[-1] elif re.search('OS Device Name: ', line): dev_name = line.split()[-1] if dev_name.startswith('/dev/rmt/'): log.info('Skipping tape drive: ' + dev_name) continue if dev_name == 'Unknown': log.info('Skipping OS Device Name \'Unknown\'') continue if dev_name.startswith('/devices/'): log.info('Skipping device under /devices: ' + dev_name) continue # build FCVolume log.info('Found LUN ' + lun + ' and device name ' + dev_name) name = dev_name.split('/')[-1][:-2] fcv = sensorhelper.newModelObject('cdm:dev.FCVolume') fcv.setSCSILun(long(lun)) fcv.setFCPLun(int(lun)) fcv.setName(name) fcv.setPortWWN( WorldWideNameUtils.toUniformString(hba_port_wwn)) fcv.setNodeWWN( WorldWideNameUtils.toUniformString(hba_node_wwn)) fcv.setController(scsi_pc) log.debug(str(fcv)) fc_vols[name] = fcv return fc_vols
log.warning('Could not find UUID in sq_inq output for ' + disk) return None ########################################################## # Main # Setup the various objects required for the extension ########################################################## (os_handle, result, computersystem, seed, log) = sensorhelper.init(targets) try: log.info("RDM discovery extension started (written by Mat Davis - [email protected]).") try: output = sensorhelper.executeCommand('lsscsi') except: log.info('lsscsi not found on server, halting execution of RDM discovery.') raise CommandNotFoundError('lsscsi not found') is_vmware = helper.is_vmware(computersystem) # check if there are any EMC Invista or DGC (V)RAID disks if re.search('.*EMC.*', output) or re.search('.*DGC.*', output): # get any previously discovered volumes vols = helper.get_volumes(result, log) try: # check if sg_inq installed if helper.validateCommand('sg_inq') is False: raise Exception()
def __init__(self, value): self.value = value def __str__(self): return repr(self.value) ########################################################## # Main # Setup the various objects required for the extension ########################################################## try: (os_handle, result, computersystem, seed, log) = sensorhelper.init(targets) log.info("HyperVDisks discovery extension started (written by Mat Davis - [email protected]).") try: output = sensorhelper.executeCommand('"C:\Program Files\EMC\PowerPath\Powermt.exe" display dev=all') except: log.info('Powermt.exe not found on server, halting execution of disk discovery.') raise CommandNotFoundError('Powermt.exe not found') disk = None uuid = None vol_name = None vplexes = {} for line in output.splitlines(): if line.startswith('Pseudo name=harddisk'): disk = line.split('=harddisk')[1] if line.startswith('Logical device ID='): if '??' in disk: log.info('Malformed disk number, skipping disk harddisk??') continue
def main(): ########################################################## # Main # Setup the various objects required for the extension ########################################################## global log (os_handle, result, computersystem, seed, log) = sensorhelper.init(targets) try: log.info( "sudo discovery extension started (written by Mat Davis - [email protected])" ) is_virtual = True # assume virtual if computersystem.hasModel( ) and not 'virtual' in computersystem.getModel().lower(): # model is set and does not contain 'virtual' if computersystem.hasVirtual(): if not computersystem.getVirtual(): is_virtual = False # virtual is set to False else: # virtual is not set and model does not contain 'virtual' is_virtual = False log.info('Is server virtual? ' + str(is_virtual)) is_vmware = False if computersystem.hasModel() and computersystem.getModel().startswith( 'VMware Virtual Platform'): is_vmware = True log.info('Is server VMware? ' + str(is_vmware)) xa = {} xa['sudo_hba'] = '' # for collectionengine and fcinfo on Solaris xa['sudo_hba_path'] = '' # verify CE path matches home directory xa['sudo_lsof'] = '' xa['sudo_dmidecode'] = '' xa['sudo_rdm'] = '' val = Validator() if val.validateSudo() is False: # sudo is not set up for this host log.info('sudo is invalid') xa['sudo_verified'] = 'invalid' else: log.info('sudo is valid') xa['sudo_verified'] = 'valid' if val.validateSudo('lsof') is False: xa['sudo_lsof'] = 'invalid' else: xa['sudo_lsof'] = 'valid' log.info('sudo lsof is ' + str(xa['sudo_lsof'])) os_type = get_os_type(os_handle) # if physical host check for collectionengine in sudo if is_virtual is False: log.info( 'Checking for HBA discovery commands on physical server') ce = 'collectionengine' if "Linux" == os_type: ce = 'collectionengine-linux-x86' elif "Sun" == os_type: ce = 'collectionengine-solaris-sparc' # if /etc/hba.conf does not exist, then CE is not deployed hba_conf_exists = helper.does_exist('/etc/hba.conf') # if Sun x86 system, then CE is not deployed sun_x86 = False if "Sun" == os_type and computersystem.hasArchitecture(): if "i86pc" == computersystem.getArchitecture(): sun_x86 = True if val.validateSudo(ce) or not hba_conf_exists: log.info(ce + ' found in sudo or /etc/hba.conf does not exist') # check for fcinfo on Sun required by SolarisFC.py ext if "Sun" == os_type and val.validateSudo( 'fcinfo') is False: log.info( 'fcinfo for SolarisFC.py discovery extension not found in sudo' ) xa['sudo_hba'] = 'invalid' elif "Linux" == os_type and is_virtual is False and helper.validateCommand( '/sbin/powermt' ) and val.validateSudo('powermt') is False: log.info( '/sbin/powermt for powermt.py discovery extension not found in sudo' ) xa['sudo_hba'] = 'invalid' else: xa['sudo_hba'] = 'valid' if hba_conf_exists and not sun_x86: # check collectionengine sudo path against CE directory paths = val.commandPath(ce) ce_path = sensorhelper.executeCommand('pwd').strip() # if CE is under /usr/local/bin, then use this path instead if helper.does_exist('/usr/local/bin/' + ce): ce_path = '/usr/local/bin' xa['sudo_hba_path'] = 'invalid' for path in paths: log.debug('Checking path ' + path + ' against ' + ce_path) log.debug('Split path ' + '/'.join(path.split('/')[:-1])) if '/'.join(path.split('/')[:-1]) == ce_path: xa['sudo_hba_path'] = 'valid' log.info('sudo hba (collectionengine) path is ' + str(xa['sudo_hba_path'])) else: if sun_x86: log.info( 'SunOS is running on x86 hardware, collectionengine not supported' ) else: log.info(ce + ' not found in sudo') xa['sudo_hba'] = 'invalid' log.info('sudo hba (collectionengine) is ' + str(xa['sudo_hba'])) # check for Linux specific if "Linux" == os_type: if val.validateSudo('dmidecode'): xa['sudo_dmidecode'] = 'valid' else: xa['sudo_dmidecode'] = 'invalid' log.info('sudo dmidecode is ' + str(xa['sudo_dmidecode'])) if is_vmware: # VMware Linux VM lsscsi_out = '' try: log.info( 'Running lsscsi on VMware Linux VM to look for RDMs' ) lsscsi_out = sensorhelper.executeCommand('lsscsi') except: log.info('lsscsi command failed') pass if re.search('.*EMC.*', lsscsi_out): log.info( 'Linux VM contains RDM, checking if sg_inq in sudo' ) if val.validateSudo('sg_inq'): xa['sudo_rdm'] = 'valid' else: log.info( 'sg_inq for RDM.py discovery extension not found in sudo' ) # get lsscsi version, 0.26 or higher will work for RDM.py lsscsi_ver = sensorhelper.executeCommand( 'lsscsi -V 2>&1') if lsscsi_ver: version = Decimal(lsscsi_ver.split()[1]) log.info('Found lsscsi version ' + str(version)) if version > Decimal('0.25'): log.info( 'lsscsi version is equal or greater than 0.26, valid' ) xa['sudo_rdm'] = 'valid' else: log.info( 'lsscsi version is less than 0.26, invalid' ) xa['sudo_rdm'] = 'invalid' else: log.info( 'No output for lsscsi version command') xa['sudo_rdm'] = 'invalid' log.info('sudo rdm (sg_inq/lsscsi) is ' + str(xa['sudo_rdm'])) else: log.info('lsscsi output does not contain RDM') helper.setExtendedAttributes(computersystem, xa) log.info("sudo discovery extension ended") except: (ErrorType, ErrorValue, ErrorTB) = sys.exc_info() errMsg = 'Unexpected error occurred during discover: ' + str( ErrorValue) LogError(errMsg) result.warning(errMsg)
# Setup the various objects required for the extension ########################################################## (os_handle, result, computersystem, seed, log) = sensorhelper.init(targets) try: log.info( "Installed applications discovery extension started (written by Mat Davis - [email protected])" ) os_type = get_os_type(os_handle) # Java try: if "Windows" == os_type: version_out = sensorhelper.executeCommand( 'java -version 2>&1').strip() second_line = version_out.splitlines()[1].split() version = version_out.splitlines()[0].split("\"")[1] vendor = version_out.splitlines()[2].split()[0] product = second_line[0] desc = ' '.join(second_line[:4]) #sp = version_out.splitlines()[3] # System Java on Windows does not print the 4th line that has the service pack sp = None path = sensorhelper.executeCommand('where java').strip() if len(path.splitlines()) > 1: path = path.splitlines()[0] else: version = sensorhelper.executeCommand( 'java -version 2>&1 | head -n 1 | awk -F \'"\' \'{print $2}\''
def main(): ########################################################## # Main # Setup the various objects required for the extension ########################################################## try: (os_handle, result, computersystem, seed, log) = sensorhelper.init(targets) global log log.info( "powermt discovery extension started (written by Mat Davis - [email protected])." ) try: if helper.validateCommand('/sbin/powermt'): sudo = Validator() if sudo.validateSudo('/sbin/powermt'): output = sensorhelper.executeCommand( 'sudo /sbin/powermt display dev=all') else: log.info( '/sbin/powermt not in sudo, halting execution of disk discovery.' ) raise CommandNotFoundError('/sbin/powermt not in sudo') else: log.info( '/sbin/powermt not installed, halting execution of disk discovery.' ) raise CommandNotFoundError('/sbin/powermt not installed') except: log.info( 'sudo /sbin/powermt command failed, halting execution of disk discovery.' ) raise CommandNotFoundError('sudo /sbin/powermt command failed') disk = None uuid = None vvol = None fcvolumes = [] for line in output.splitlines(): if line.startswith('Pseudo name='): disk = line.split('=')[1] if line.startswith('Logical device ID='): uuid = line.split('=')[1].split(' ')[0] if len(line.split(' ')) > 3: vvol = line.split(' ')[3].replace('[', '').replace(']', '') elif len(line.split()) > 2: vvol = None else: log.info('Skipping line missing volume information: ' + line) disk = None uuid = None continue if disk: log.info(str(disk) + ' ' + str(uuid) + ' ' + str(vvol)) vsv = sensorhelper.newModelObject('cdm:dev.StorageVolume') if vvol: vsv.setName(vvol) vsv.setVirtual(True) # ManagedSystemName is SUPPOSED to be reserved for ITM/TMS integration, however the developers # have been using it all over the place as a hack vsv.setManagedSystemName(uuid) fcv = sensorhelper.newModelObject('cdm:dev.FCVolume') fcv.setName(disk) fcv.setParent(computersystem) # create relationships bo = sensorhelper.newModelObject('cdm:dev.BasedOnExtent') bo.setSource(fcv) bo.setTarget(vsv) bo.setType( 'com.collation.platform.model.topology.dev.BasedOnExtent' ) fcv.setBasedOn( sensorhelper.getArray([bo], 'cdm:dev.BasedOnExtent')) fcvolumes.append(fcv) # reset all values disk = None uuid = None vvol = None # DANGER! Do not create and store the vplex without updating ALL the virtual volume members on the vplex, you # open up the possibility of the StorageExtentCleanupAgent deleting a bunch of virtual volumes. # if any FC volumes discovered, we continue if len(fcvolumes) > 0: extents = [] # local disks local_disks = os_handle.getLocalDiskVolumes() if local_disks: for local_disk in local_disks: log.info('disk=' + str(local_disk)) match = False for fcv in fcvolumes: if fcv.getName() == local_disk.getName(): log.info('Found matching disk') extents.append(fcv) fcvolumes.remove(fcv) # remove from list match = True break if not match: extents.append(local_disk) # disk partitions partitions = os_handle.getDiskPartitions() if partitions: for partition in partitions: log.info('partition=' + str(partition)) extents.append(partition) # volumes try: volumes = os_handle.getStorageVolumes() if volumes: for volume in volumes: log.info('storage volume=' + str(volume)) extents.append(volume) except: log.info('Unable to find Storage Volumes') # if there are any FC volumes left then add to the end of the list for fcv in fcvolumes: log.info('Adding additional FC volume=' + str(fcv)) extents.append(fcv) computersystem.setStorageExtent( sensorhelper.getArray(extents, 'cdm:dev.StorageExtent')) log.info("powermt discovery extension ended.") except CommandNotFoundError: pass # quietly move on if powermt command is not found except: (ErrorType, ErrorValue, ErrorTB) = sys.exc_info() errMsg = 'Unexpected error occurred during discover: ' + str( ErrorValue) LogError(errMsg) result.warning(errMsg)
# Now we can use these objects to add MORE information to the AppServer object # that has already been found. LogInfo(" ****** STARTING ScheduledTasks.py ******* ") LogInfo("Using sensorhelper version: " + str(sensorhelper.getVersion())) properties_file = coll_home + "/etc/templates/scheduled_tasks.properties" sch_task_dict = {} LogInfo("Using the properties file: " + str(properties_file)) try: task_dict = load_property_file(properties_file) taskList = task_dict['forcedTaskList'].split(';') LogDebug('taskList:' + str(taskList)) output = sensorhelper.executeCommand('SCHTASKS /Query /FO CSV /V') firstFolder = 0 for line in output.splitlines(): columns = line.split('","') if len(columns) > 1: hostName = columns[0][1:] if hostName == 'HostName': if firstFolder: break else: firstFolder = 1 continue task2run = columns[8] taskName = columns[1] status = columns[3]
'Write-Host \'SSAS Backup folder =\' $SSASServer.ServerProperties[\'BackupDir\'].Value; ' \ 'Write-Host \'SSAS Collation =\' $SSASServer.ServerProperties[\'CollationName\'].Value; ' \ 'Write-Host \'SSAS Creation Date =\' $SSASServer.CreatedTimestamp; ' \ 'Write-Host \'SSAS Data directory =\' $SSASServer.ServerProperties[\'DataDir\'].Value; ' \ 'Write-Host \'SSAS ID =\' $SSASServer.ID; ' \ 'Write-Host \'SSAS Language =\' $SSASServer.ServerProperties[\'Language\'].value; ' \ 'Write-Host \'SSAS Last Schema Update =\' $SSASServer.LastSchemaUpdate; ' \ 'Write-Host \'SSAS Log Folder =\' $SSASServer.ServerProperties[\'LogDir\'].Value; ' \ 'Write-Host \'SSAS Product Name =\' $SSASServer.ProductName; ' \ 'Write-Host \'SSAS Mode =\' $SSASServer.ServerMode; ' \ 'Write-Host \'SSAS Temp Folder =\' $SSASServer.ServerProperties[\'TempDir\'].Value; ' \ 'Write-Host \'SSAS Version =\' $SSASServer.Version;}"' try: # run command, get output output = sensorhelper.executeCommand(cmd) except: LogError("Command execution failed") raise ea = {} # look for SSAS edition and parse out edition = None m = re.search('SSAS Edition .*', output) if m is not None: match = str(m.group(0)) split = match.split('=') if len(split) > 1: value = split[1].strip() if value != '': log.debug('Setting extended attribute edition:' +
# that has already been found. LogInfo(" ****** STARTING redhat_cluster.py ******* ") LogInfo("Using sensorhelper version: " + str(sensorhelper.getVersion())) # get cluster.conf file location from collation.properties if exists cluster_conf_file = ScopedProps.getStringProperty('com.collation.discover.agent.command.cluster_conf', 'Linux', os_handle.getSession().getHost()) if cluster_conf_file is None or len(cluster_conf_file) == 0: cluster_conf_file = '/etc/cluster/cluster.conf' multipath_conf_file = '/etc/multipath.conf' modprobe_conf_file = '/etc/modprobe.conf' # only run if OS discovered as RHEL and cluster.conf file exists if server.hasOSRunning() and server.getOSRunning().hasOSVersion() and server.getOSRunning().getOSVersion().startswith('Red Hat Enterprise Linux') and int(sensorhelper.executeCommand('[ -f ' + cluster_conf_file + ' ] && echo "1" || echo "0"')): # get scoped cman_tool command from collation.properties cmanCommand = ScopedProps.getStringProperty('com.collation.discover.agent.command.cman', 'Linux', os_handle.getSession().getHost()) if cmanCommand is None or len(cmanCommand) == 0: cmanCommand = 'cman_tool' # XML document for cluster.conf doc = None try: # grab cluster configuration file, this will throw exception if file is not readable # Note: don't pipe command to anything or it won't throw an exception cluster_conf = str(sensorhelper.executeCommand('cat ' + cluster_conf_file)) dbFactory = DocumentBuilderFactory.newInstance() dBuilder = dbFactory.newDocumentBuilder()
def main(): try: global log (os_handle, result, computersystem, seed, log) = sensorhelper.init(targets) log.info( "Solaris Fibre Channel discovery extension started (written by Mat Davis - [email protected])." ) # build skinny computersystem for storage performance cs = sensorhelper.newModelObject( 'cdm:sys.sun.SunSPARCUnitaryComputerSystem') if computersystem.hasSignature(): cs.setSignature(computersystem.getSignature()) elif computersystem.hasSerialNumber() and computersystem.hasModel( ) and computersystem.hasManufacturer(): cs.setSerialNumber(computersystem.getSerialNumber()) cs.setModel(computersystem.getModel()) cs.setManufacturer(computersystem.getManufacturer()) else: log.info( 'Could not find naming rules to build skinny computer system, storage performance might suffer from using full computer system' ) cs = computersystem fc_vols = fcinfo() # only run EMC INQ if physical is_virtual = True # assume virtual if computersystem.hasModel( ) and not 'virtual' in computersystem.getModel().lower(): # model is set and does not contain 'virtual' if computersystem.hasVirtual(): if not computersystem.getVirtual(): is_virtual = False # virtual is set to False else: # virtual is not set and model does not contain 'virtual' is_virtual = False if is_virtual is False: # EMC inquiry tool can be downloaded from ftp://ftp.emc.com/pub/symm3000/inquiry/ # copy inq to targets inq = 'inq.sol64' path = coll_home + "/etc/templates/commands/extension-scripts/" + inq # TODO verify local path remotePath = os_handle.executeCommand('pwd').strip() if not remotePath.endswith('/'): remotePath = remotePath + '/' remotePath = remotePath + inq os_handle.copyToRemote(path, remotePath) sensorhelper.executeCommand('chmod +x ' + remotePath) # grant execute permission # check if command in sudo sudo = Validator() if sudo.validateSudo(remotePath): log.info(remotePath + ' found in sudoers, using sudo for command') remotePath = 'sudo ' + remotePath #fc_vols = emc_inq(remotePath, fc_vols) else: log.info('Virtual server detected, skipping EMC INQ discovery') # add all the FCVolumes to the extended result for fc_vol in fc_vols.values(): fc_vol.setParent(cs) # set parent if fc_vol.hasController(): fc_vol.getController().setParent(cs) result.addExtendedResult(fc_vol) log.info("Solaris Fibre Channel discovery extension ended.") except: (ErrorType, ErrorValue, ErrorTB) = sys.exc_info() errMsg = 'Unexpected error occurred during discover: ' + str( ErrorValue) LogError(errMsg) result.warning(errMsg)
def main(): try: global log (os_handle, result, computersystem, seed, log) = sensorhelper.init(targets) log.info( "EMC INQ discovery extension started (written by Mat Davis - [email protected])." ) os_type = helper.get_os_type(os_handle) is_vmware = helper.is_vmware(computersystem) # EMC inquiry tool can be downloaded from ftp://ftp.emc.com/pub/symm3000/inquiry/ if os_type == 'Linux': inq = 'inq.LinuxAMD64' if computersystem.hasArchitecture(): if computersystem.getArchitecture() == 'i686': inq = 'inq.linux' elif computersystem.getArchitecture() == 'ia64': inq = 'inq.LinuxIA64' else: # if arch command failed during computersystem discovery try: arch = sensorhelper.executeCommand('uname -m') if 'i686' in arch: inq = 'inq.linux' elif 'ia64' in arch: inq = 'inq.LinuxIA64' except: log.info('uname command failed, using ' + inq + ' as default command') elif os_type == 'Sun': inq = 'inq.sol64' if computersystem.hasArchitecture(): if computersystem.getArchitecture() == 'i86pc': inq = 'inq.solarisx86_64' else: # if arch command failed during computersystem discovery try: arch = sensorhelper.executeCommand('uname -m') if 'i86pc' in arch: inq = 'inq.solarisx86_64' except: log.info('uname command failed, using ' + inq + ' as default command') else: log.info('Unknown OS type') log.info("EMC INQ discovery extension ended.") return remotePath = '/usr/local/bin/' # check if INQ installed in /usr/local/bin/ if not helper.does_exist(remotePath + inq): # make sure home directory is writable before we continue if not helper.is_writable('.'): log.info( 'HOME directory is not writable, discovery cannot continue' ) return # copy inq to targets lpath = coll_home + "/etc/templates/commands/extension-scripts/" + inq # TODO verify local binary exists pwd = os_handle.executeCommand('pwd').strip() if not pwd.endswith('/'): pwd = pwd + '/' os_handle.copyToRemote(lpath, pwd + inq) sensorhelper.executeCommand('chmod +x ' + pwd + inq) # grant execute permission log.info(inq + ' not installed under ' + remotePath + ', binary was staged in ' + pwd) remotePath = pwd # check if command in sudo cmd = remotePath + inq sudo = Validator() cmd_sudo = sudo.validateSudo(cmd) log.info('command in sudo?: ' + str(cmd_sudo)) if cmd_sudo: cmd = 'sudo ' + remotePath + inq # get any previously discovered volumes vols = helper.get_volumes(result, log) try: # output = sensorhelper.executeCommand(cmd + ' -no_dots -vplex_wwn') output = sensorhelper.executeCommand(cmd + ' -no_dots -wwn') for line in output.splitlines(): # if line starts with /dev/ then we use this disk if (os_type == 'Linux' and line.startswith('/dev/')) or ( os_type == 'Sun' and line.startswith('/dev/rdsk/')): s = line.split(':') if len(s) == 4: device = s[0].strip() name = device.split('/')[-1] if os_type == 'Sun': name = name[:-2] # remove s2 from the end vendor = s[1].strip() prod = s[2].strip( ) # VRAID and RAID 5 products found on Solaris uuid = s[3] # make sure wwn is in format of a VPLEX UUID # if len(uuid) == 32: # make sure wwn is in format of a UUID and proper type if len(uuid) == 32 and (prod == 'VPLEX' or (vendor == 'DGC' and 'RAID' in prod)): log.info('Found LUN: ' + line) uuid = uuid.upper() vsv = sensorhelper.newModelObject( 'cdm:dev.StorageVolume') # ManagedSystemName is SUPPOSED to be reserved for ITM/TMS integration, however the developers # have been using it all over the place as a hack vsv.setManagedSystemName(uuid) vol = None if name in vols.keys(): vol = vols[name] # use existing else: cdm_type = 'cdm:dev.FCVolume' # create SCSIVolume if RDM instead of FCVolume if is_vmware: cdm_type = 'cdm:dev.SCSIVolume' vol = sensorhelper.newModelObject(cdm_type) vol.setParent(computersystem) vol.setName(name) result.addExtendedResult(vol) # create relationship bo = sensorhelper.newModelObject( 'cdm:dev.BasedOnExtent') bo.setSource(vol) bo.setTarget(vsv) bo.setType( 'com.collation.platform.model.topology.dev.BasedOnExtent' ) vol.setBasedOn( sensorhelper.getArray([bo], 'cdm:dev.BasedOnExtent')) else: #result.warning('line parse unexpected:' + uuid) log.info('Skipping line:' + line) else: #result.warning('line parse unexpected:' + line) log.warning('line parse unexpected:' + line) if line: log.info('last line: ' + line) else: log.info('last line is empty') xa = {} xa['sudo_emc'] = '' # check if last line is separator line (no output) if '-----' in line: log.info('sudo_emc: no output from command') if cmd_sudo: log.info('sudo_emc: sudo used') xa['sudo_emc'] = 'unexpected' # unexpected, if sudo is used it should produce output else: log.info('sudo_emc: no sudo used') # if physical Sun host, need sudo for command if os_type == 'Sun' and not helper.is_virtual( computersystem): # for ALL physical Sun hosts we want to run the EMC INQ tool log.info('sudo_emc: physical Sun') xa['sudo_emc'] = 'invalid' elif os_type == 'Linux': # EMC INQ is needed only if sg_inq not installed and lsscsi version < 0.26 # otherwise RDM.py can discover if not helper.validateCommand('sg_inq'): if helper.validateCommand('lsscsi'): version = sensorhelper.executeCommand( 'lsscsi -V 2>&1') if version and Decimal( version.split()[1]) < Decimal('0.26'): lsscsi_out = sensorhelper.executeCommand( 'lsscsi') # check if there are any EMC Invista or DGC (V)RAID disks if re.search('.*EMC.*', lsscsi_out) or re.search( '.*DGC.*', lsscsi_out): log.info( 'sg_inq not installed, lsscsi < 0.26, EMC disks found - sudo_emc = invalid' ) xa['sudo_emc'] = 'invalid' else: log.info( 'sg_inq and lsscsi not installed - sudo_emc = invalid' ) xa['sudo_emc'] = 'invalid' else: log.info('sudo_emc: output produced') if cmd_sudo: log.info('sudo_emc: sudo used') xa['sudo_emc'] = 'valid' else: log.info('sudo_emc: no sudo used') # nothing to do helper.setExtendedAttributes(computersystem, xa) except: # strip out sudo to test command executable if 'sudo' in cmd: cmd = cmd.replace('sudo ', '') if helper.is_exec(cmd): log.info( cmd + ' command failed, halting execution of disk discovery.') (ErrorType, ErrorValue, ErrorTB) = sys.exc_info() errMsg = 'Unexpected error occurred during discover: ' + str( ErrorValue) LogError(errMsg) result.warning(errMsg) helper.setExtendedAttributes(computersystem, {'sudo_emc': 'unexpected'}) else: # if command is not executable then we need sudo log.info(cmd + ' command is not executable') helper.setExtendedAttributes(computersystem, {'sudo_emc': 'invalid'}) log.info("EMC INQ discovery extension ended.") except: (ErrorType, ErrorValue, ErrorTB) = sys.exc_info() errMsg = 'Unexpected error occurred during discover: ' + str( ErrorValue) LogError(errMsg) result.warning(errMsg)
if next: catalina_home = t next = False else: catalina_home = t.split("=")[1] catalina_home = catalina_home.replace('"', '') log.info("Catalina Home from command line = " + catalina_home) break if not java_cmd: # Java location for Tableau java_cmd = 'cd "' + '/'.join(catalina_home.split( '/')[:-1]) + '/repository/jre/bin" & .\java' log.info("Setting java command = " + java_cmd) slash = '/' if sensorhelper.targetIsWindows(os_handle): slash = '\\' server_info = sensorhelper.executeCommand( java_cmd + ' -cp ' + '"' + catalina_home + slash + 'lib' + slash + 'catalina.jar" org.apache.catalina.util.ServerInfo') version = re.findall("^Server number:.*", server_info, re.MULTILINE)[0].split()[2].strip() log.info('Setting productVersion to ' + version) appserver.setVendorName('The Apache Group') appserver.setProductName('Tomcat') appserver.setProductVersion(version) except: #Something failed and threw an exception. Call the error logger #so that the stack trace gets logged LogError("unexpected exception discovering Tomcat")
def tag_server(server): # also check to see if server is virtual tag = None tagfile = '.discoverytag-' + server.getName() LogInfo("Using tag file name " + tagfile) try: # /tmp is the 'safest' place to keep it, however /tmp can be cleared out # when a VM is copied which might defeat the purpose cmd = 'cat /tmp/' + tagfile # different command/location for Windows if sensorhelper.targetIsWindows(): cmd = 'type C:\\' + tagfile # put in C:\ you can't use env variables here try: # look for existing tag file tag = sensorhelper.executeCommand(cmd) # if we get a result, set OpenID if tag: tag = tag.strip() LogInfo('Setting OpenID using ' + tag + ' and ' + server.getName()) # feeding in server to OpenId() will set name attribute from server name server.setOpenId( OpenId(server).addId('tag', tag).addId('name', None)) except: # if Linux, also check home directory if not sensorhelper.targetIsWindows(): # look for existing tag file in home directory tag = sensorhelper.executeCommand('cat ' + tagfile) if tag: tag = tag.strip() LogInfo('Setting OpenID using ' + tag + ' and ' + server.getName()) # feeding in server to OpenId() will set name attribute from server name server.setOpenId( OpenId(server).addId('tag', tag).addId('name', None)) else: # use try/except here because if .discoverytag doesn't exist an error is thrown raise Exception() else: # use try/except here because if .discoverytag doesn't exist an error is thrown raise Exception() # make sure tag is synced between /tmp and ~/ for Linux if not sensorhelper.targetIsWindows() and tag: # put tag in /tmp and home directory cmd = 'echo ' + tag + ' | tee /tmp/' + tagfile + ' > ' + tagfile try: # put existing value in both locations sensorhelper.executeCommand(cmd) except: LogError( "Error occurred writing to .discoverytag, duplicate reducer unable to sync tag to both /tmp and home directory" ) except: LogInfo(tagfile + ' is not present or empty') # use current time stamp (in millis) with the DiscoverWorker thread number appended to ensure uniqueness thread_name = Thread.currentThread().getName() if '-' in thread_name: thread_name = thread_name.split('-')[1] elif 'Thread:' in thread_name: thread_name = thread_name.split()[-1] elif thread_name == 'MainThread': thread_name = '0' else: LogInfo('Thread name format unexpected: ' + thread_name) raise Exception() tag = str(System.currentTimeMillis()) + '-' + thread_name LogInfo('setting ' + tagfile + ' to ' + tag) try: # put tag in /tmp and home directory cmd = 'echo ' + tag + ' | tee /tmp/' + tagfile + ' > ' + tagfile if sensorhelper.targetIsWindows(): cmd = 'echo ' + tag + ' > C:\\' + tagfile # put new calculated value back out on the server sensorhelper.executeCommand(cmd) LogInfo('setting OpenID using ' + tag.strip() + ' and ' + server.getName()) # feeding in server to OpenId() will set name attribute from server name server.setOpenId( OpenId(server).addId('tag', tag).addId('name', None)) except: LogError( "Error occurred writing to .discoverytag, duplicate reducer discovery extension failed" )