Esempio n. 1
0
def DiscoveryMain(Framework):
    fileName = Framework.getParameter('file_name').replace(
        '%PROBE_MGR_RESOURCES_DIR%',
        CollectorsParameters.PROBE_MGR_RESOURCES_DIR)
    string_list_delimiter = Framework.getParameter('string_list_delimiter')
    integer_list_delimiter = Framework.getParameter('integer_list_delimiter')
    relationship_attr_delimiter = Framework.getParameter(
        'relationship_attr_delimiter')
    set_empty_value_flag = Boolean.parseBoolean(
        Framework.getParameter('set_empty_value'))
    if not (fileName and string_list_delimiter and integer_list_delimiter
            and relationship_attr_delimiter):
        logger.reportError('Not all job parameters are set.')
        return
    try:
        workbook = xlsutils.openXlFile(fileName)
        if workbook:
            classModel = ConfigFilesManagerImpl.getInstance(
            ).getCmdbClassModel()
            classModelUtil = xlsutils.ClassModelUtils(classModel,
                                                      integer_list_delimiter,
                                                      string_list_delimiter)
            importer = WorkSheetImporter(workbook,
                                         classModelUtil,
                                         set_empty_value=set_empty_value_flag)
            return importer.processWorkbook()
    except JavaException, ex:
        logger.reportError(ex.getMessage())
        ex.printStackTrace()
        logger.errorException('')
Esempio n. 2
0
def DiscoveryMain(Framework):
    shell = None
    try:
        try:
            protocolName = __getProtocolName(Framework)
            discoverSharePointUrls = Boolean.parseBoolean(Framework.getParameter('discoverSharePointUrls'))
            reportIntermediateWebService = Framework.getParameter('reportIntermediateWebService')
            if reportIntermediateWebService:
                reportIntermediateWebService = Boolean.parseBoolean(reportIntermediateWebService)
            else:
                #set default value
                reportIntermediateWebService = 1
            relativeCommandTimeoutMultiplier = Framework.getParameter('relativeCommandTimeoutMultiplier')
            relativeCommandTimeoutMultiplier = int(relativeCommandTimeoutMultiplier)
            client = Framework.createClient()
            shell = ShellFactory().createShell(client)
            logger.debug('getting SharePoint discoverer for protocol %s' % protocolName)
            discoverer = sharepoint_win_shell.getDiscoverer(shell, protocolName, relativeCommandTimeoutMultiplier)
            logger.debug('got discoverer')
            resources = _discoverSharePoint(discoverer)
            resources.build()
            return resources.report(discoverSharePointUrls, reportIntermediateWebService)
        except SharePointException:
            logger.reportError()
            logger.debugException('')
        except JavaException, ex:
            strException = ex.getMessage()
            errormessages.resolveAndReport(strException, protocolName, Framework)
        except:
            strException = logger.prepareJythonStackTrace('')
            errormessages.resolveAndReport(strException, protocolName, Framework)
def DiscoveryMain(framework):
    vector = ObjectStateHolderVector()
    protocol = 'local_shell'
    try:
        zoneNameList, includeOutscopeIPs, ip, reportBrokenAliases = _obtainParams(
            framework)
        if not zoneNameList:
            logger.reportError('List of zones for transfer is not specified')
            return
        client = framework.createClient(
            ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
        shell = None
        try:
            shell = shellutils.ShellUtils(client)
            #pass name server IP to the discoverer
            dnsDiscoverer = dns_discoverer.createDiscovererByShell(shell, ip)
            zoneTopologies = dns_discoverer.discoverDnsZoneTopologies(
                dnsDiscoverer, zoneNameList, protocol)
            vector.addAll(
                dns_discoverer.reportTopologies(zoneTopologies,
                                                includeOutscopeIPs,
                                                reportBrokenAliases))
        finally:
            try:
                shell and shell.closeClient()
            except:
                logger.debugException('')
                logger.error('Unable to close shell')
    except JException, ex:
        exInfo = ex.getMessage()
        errormessages.resolveAndReport(exInfo, protocol, framework)
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    try:
        client = Framework.createClient()
        vendor = Framework.getDestinationAttribute("discovered_vendor")
        hostId = Framework.getDestinationAttribute("hostId")
        host_osh = modeling.createOshByCmdbId("firewall", hostId)
        discoverer = firewall_discoverer.getDiscoverer(vendor, client)
        if not discoverer:
            raise ValueError("Unsupported device.")
        firewall_config = discoverer.discover()
        OSHVResult.addAll(firewall.reportTopology(firewall_config, host_osh))
    except:
        import sys

        logger.debugException("")
        error_str = str(sys.exc_info()[1]).strip()
        logger.reportError(error_str)
    finally:
        client and client.close()
    ## Write implementation to return new result CIs here...
    if OSHVResult.size() == 0:
        logger.debug("No data discovered from destination.")
        logger.reportWarning("No data discovered from destination.")
    return OSHVResult
Esempio n. 5
0
 def __initializeSANScreenEndPoint(self):
     try:
         ## Get SANscreen credentials
         sanscreenProtocols = self.framework.getAvailableProtocols(self.sanscreenIpAddress, "sanscreen")
         if sanscreenProtocols == None or len(sanscreenProtocols) < 1:
             logger.reportError("No SANscreen credentials found for [%s] destination" % self.sanscreenIpAddress)
             return None
         else:
             for protocol in sanscreenProtocols:
                 soapPort = self.framework.getProtocolProperty(protocol, CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT) or '80'
                 soapProtocol = self.framework.getProtocolProperty(protocol, 'sanscreenprotocol_protocol')
                 username = self.framework.getProtocolProperty(protocol, CollectorsConstants.PROTOCOL_ATTRIBUTE_USERNAME)
                 password = self.framework.getProtocolProperty(protocol, CollectorsConstants.PROTOCOL_ATTRIBUTE_PASSWORD)
                 ## Should have everything to try connecting...
                 try:
                     ## Try connecting
                     ## Set URL and system properties
                     serviceURL = soapProtocol + '://' + self.sanscreenIpAddress + ':' + soapPort + '/sanscreenapi'
                     return SSApiWrapper().getEndpoint(serviceURL, username, password)
                 except:
                     excInfo = logger.prepareJythonStackTrace('Will try next credential entry (if available) due to exception: ')
                     logger.warn('[initializeSANScreenEndPoint] Exception: <%s>' % excInfo)
                     # Try next credential entry
                     continue
     except:
         excInfo = logger.prepareJythonStackTrace('')
         logger.warn('[initializeSANScreenEndPoint] Exception: <%s>' % excInfo)
         pass
Esempio n. 6
0
def ev2_getIplInfoOutput(ls):
    # process IPL Info ---------------------------------------------------------
    zOsRelease = ''
    ieasymList = ''
    ieasysList = ''
    machineBootDate = ''
    try:
        output = ls.evMvsCmd(_CMD_D_IPLINFO)
        if isNotNull(output) and output.isSuccess() and len(output.cmdResponseList) > 0:
            releaseList = output.getValuesFromLineList('s', output.cmdResponseList, 'RELEASE z/OS', 'LICENSE')
            if len(releaseList) > 0 and len(releaseList[0]) == 3:
                zOsRelease = releaseList[0][1] or ''
            ieasymList = output.getValuesFromLineList('s', output.cmdResponseList, 'IEASYM LIST =')
            if len(ieasymList) > 0 and len(ieasymList[0]) == 2:
                ieasymList = ieasymList[0][1] or ''
            ieasysList = output.getValuesFromLineList('s', output.cmdResponseList, 'IEASYS LIST =')
            if len(ieasymList) > 0 and len(ieasymList[0]) == 2:
                ieasysList = ieasysList[0][1] or ''
            bootList = output.getValuesFromLineList('s', output.cmdResponseList, 'SYSTEM IPLED AT', 'ON')
            if len(bootList) > 0 and len(bootList[0]) == 2:
                bootTime = bootList[0][1] or ''
                bootDate = bootList[0][2] or ''
                if eview_lib.isNotNull(bootDate) and eview_lib.isNotNull(bootTime):
                    machineBootDate = modeling.getDateFromString('%s %s' % (bootDate, bootTime), 'MM/dd/yyyy kk.mm.ss')
        else:
            logger.reportWarning('Unable to get output for command - %s' % _CMD_D_IPLINFO)
    except:
        errMsg = 'Failure in method ev2_getIplInfoOutput()'
        logger.error(errMsg)
        logger.reportError(errMsg)

    return (zOsRelease, ieasymList, ieasysList, machineBootDate)
Esempio n. 7
0
def ev4_getHomelistOutput(ls, tcpStack):
    # process HOMELIST ---------------------------------------------------------
    homeLists = [] # [ADDRESS, LINK, FLG]
    linkList = []
    addrList = []
    flgList = []
    try:
        output = ls.evMvsCmd(_CMD_D_NETSTAT_HOME % tcpStack)
        if isNotNull(output) and output.isSuccess() and len(output.cmdResponseList) > 0:
            linkList = output.getValuesFromLineList('s', output.cmdResponseList, 'LINKNAME:')
            addrList = output.getValuesFromLineList('s', output.cmdResponseList, 'ADDRESS:')
            flgList = output.getValuesFromLineList('s', output.cmdResponseList, 'FLAGS:')
            if len(linkList) > 0:
                for i in range(0, len(linkList)):
                    linkname = linkList[i][1]
                    address = addrList[i][1]
                    if address == '127.0.0.1':
                        continue
                    flag =  flgList[i][1]
                    tempList = [linkname,address,flag]
                    homeLists.append(tempList)

    except:
        errMsg = 'Failure in method ev4_getHomelistOutput()'
        logger.error(errMsg)
        logger.reportError(errMsg)

    return homeLists
def DiscoveryMain(framework):
    vector = ObjectStateHolderVector()
    protocol = 'local_shell'
    try:
        zoneNameList, includeOutscopeIPs, ip, reportBrokenAliases = _obtainParams(framework)
        if not zoneNameList:
            logger.reportError('List of zones for transfer is not specified')
            return
        client = framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
        shell = None
        try:
            shell = shellutils.ShellUtils(client)
            #pass name server IP to the discoverer
            dnsDiscoverer = dns_discoverer.createDiscovererByShell(shell, ip)
            zoneTopologies = dns_discoverer.discoverDnsZoneTopologies(dnsDiscoverer, zoneNameList, protocol)
            vector.addAll(dns_discoverer.reportTopologies(zoneTopologies, includeOutscopeIPs, reportBrokenAliases))
        finally:
            try:
                shell and shell.closeClient()
            except:
                logger.debugException('')
                logger.error('Unable to close shell')
    except JException, ex:
        exInfo = ex.getMessage()
        errormessages.resolveAndReport(exInfo, protocol, framework)
Esempio n. 9
0
def createFsmHostOsh(fsmHost, ipAddress):
    """
    Creates the Object State Holder of the host where IBM HMC Management Sortware runs
    @param fsmHost: discovered host where IBM HMC runs
    @type fsmHost: instance of Host Data Object
    @param ipAddres: the IP Address of the Host
    @type ipAddress: String
    @return: Object State Holde of the UNIX CI instance
    """
    if fsmHost and ipAddress:
        hostOsh = modeling.createHostOSH(ipAddress, 'unix', None, fsmHost.hostname)
        hostOsh.setStringAttribute('vendor', 'ibm_corp')
        hostOsh.setStringAttribute("os_family", 'unix')
        if fsmHost.domainName:
            hostOsh.setStringAttribute('host_osdomain', fsmHost.domainName)
        if fsmHost.fsmSoftware:
            
#            if fsmHost.fsmSoftware.bios:
#                hostOsh.setStringAttribute('bios_serial_number', fsmHost.fsmSoftware.bios)
                
            if fsmHost.fsmSoftware.versionInformation:
                if fsmHost.fsmSoftware.versionInformation.fullVersion:
                    hostOsh.setStringAttribute('host_osrelease', fsmHost.fsmSoftware.versionInformation.fullVersion)
                if fsmHost.fsmSoftware.versionInformation.baseOSVersion:
                    hostOsh.setStringAttribute('discovered_os_version', fsmHost.fsmSoftware.versionInformation.baseOSVersion)
                    
            if fsmHost.fsmSoftware.typeInformation and fsmHost.fsmSoftware.typeInformation.serialNum:
                hostOsh.setStringAttribute('serial_number', fsmHost.fsmSoftware.typeInformation.serialNum)
                
        return hostOsh
    else:
        logger.reportError('Failed to discover FSM Host')
        raise ValueError("Failed to discover FSM Host")
Esempio n. 10
0
def ev1_subsystemOutput(ls):
    db2Subsystems = []  # [name, initrtn, initparm, cmd_prefix]
    output = ls.evGetSubSysCmd()
    if output.isSuccess() and len(output.cmdResponseList) > 0:
        db2InitRoutineRegex = r"DSN\dINI"
        for line in output.cmdResponseList:
            if len(line) == 3 and isNotNull(line[1]):
                m = re.match(db2InitRoutineRegex, line[1], re.IGNORECASE)
                if isNotNull(m) and isNotNull(line[2]):
                    initParm = string.replace(line[2], "'", "")
                    initParmSplit = string.split(initParm, ",")
                    cmd_prefix = ''
                    if isNotNull(initParmSplit) and len(
                            initParmSplit) > 1 and isNotNull(initParmSplit[1]):
                        cmd_prefix = initParmSplit[1]
                    db2Subsystems.append(
                        [line[0], line[1], initParm, cmd_prefix])
    else:
        if isNotNull(output) and isNotNull(
                output.errorDump) and output.errorDump.find(
                    'is not recognized as'):
            errMsg = 'Perl is required on the probe system path for this command to work. \nPlease install Perl as described in the EView agent documentation and retry this discovery'
            logger.error(errMsg)
            logger.reportError(errMsg)
    return db2Subsystems
Esempio n. 11
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    client = None
    layer2_connections_cdp = None
    layer2_connections_lldp = None
    try:
        try:
            client = Framework.createClient()
        except:
            errMsg = 'Exception while creating %s client: %s' % (
                ClientsConsts.SNMP_PROTOCOL_NAME, sys.exc_info()[1])
            errormessages.resolveAndReport(str(sys.exc_info()[1]),
                                           ClientsConsts.SNMP_PROTOCOL_NAME,
                                           Framework)
            logger.debugException(errMsg)
        else:
            host_id = Framework.getDestinationAttribute('hostId')
            discover_cdp_mib = Boolean.parseBoolean(
                Framework.getParameter('discoverCdpMib'))
            discover_lldp_mib = Boolean.parseBoolean(
                Framework.getParameter('discoverLldpMib'))
            local_device_discoverer = LocalDeviceDiscoverer(client, host_id)
            local_devices = local_device_discoverer.get_local_devices()
            if not local_devices or len(local_devices) == 0:
                logger.reportError('Failed to get local device info')

            if discover_cdp_mib:
                cdp_discoverer = CdpDiscoverer(client)
                remote_devices_cdp = cdp_discoverer.get_remote_devices()
                if remote_devices_cdp:
                    layer2_connections_cdp = get_layer2_connections(
                        local_devices, remote_devices_cdp)
                    for layer2_connection in layer2_connections_cdp:
                        OSHVResult.addAll(
                            build_layer2_connection(layer2_connection))

            if discover_lldp_mib:
                lldp_discoverer = LldpDiscoverer(client)
                remote_devices_lldp = lldp_discoverer.get_remote_devices()
                if remote_devices_lldp:
                    layer2_connections_lldp = get_layer2_connections(
                        local_devices, remote_devices_lldp)
                    for layer2_connection in layer2_connections_lldp:
                        OSHVResult.addAll(
                            build_layer2_connection(layer2_connection))

            if (not layer2_connections_cdp or len(layer2_connections_cdp)
                    == 0) and (not layer2_connections_lldp
                               or len(layer2_connections_lldp) == 0):
                logger.reportError('No data collected')

    finally:
        if client != None:
            client.close()
    return OSHVResult
Esempio n. 12
0
def isIPv6Overflow(probeRangesForIPv6):
    from com.hp.ucmdb.discovery.library.communication.downloader.cfgfiles import GeneralSettingsConfigFile
    maxAllowedIPv6Count = GeneralSettingsConfigFile.getInstance().getPropertyIntegerValue('maxPingIPv6Count', DEFAULT_MAX_PING_IPV6_COUNT)

    #only get client ip
    probeRangesForIPv6 = [x for x in probeRangesForIPv6 if x and (x.getType().equals(RangeType.CLIENT) or x.getType().equals('Client'))]
    totalIpCount = 0
    for probeRange in probeRangesForIPv6:
        totalIpCount += probeRange.getRangeSize().longValue()
    if totalIpCount > maxAllowedIPv6Count:
        logger.reportError("Total IPv6 count is %d, exceeds total max IPV6 count %d, give up running the job" % (totalIpCount, maxAllowedIPv6Count))
        return True
    else:
        return False
Esempio n. 13
0
	def __init__(self):
		self.runtime = ''
		self.target = ''
		self.workdir = ''
		cfg = path.join(path.dirname(path.dirname(path.realpath(__file__))), 'config.json')
		global js
		if path.isfile(cfg):
			try:
				cfg_f = open(cfg, 'r')
				js = json.loads(cfg_f.read())
				cfg_f.close()
				loaded = True
			except ValueError:
				cfg_f.close()
				unlink(cfg)
				loaded = False
		else:
			loaded = False
		Screen.close()
		# Screen.reinit()
		super().__init__()
		Screen.title('NaOH launcher')
		Screen.root.resizable(0, 0)
		master = Frame(Screen.root) # Master frame
		master.pack(side='top')
		Label(master, text='NaOH launcher (version %s)' % str(Global.version), justify='center').grid(row=0, columnspan=3, padx=(100, 100))
		Label(master, text='PHP 바이너리 파일: ').grid(row=1, sticky='e')
		Label(master, text='PocketMine-MP: ').grid(row=2, sticky='e')
		Label(master, text='작업 폴더: ').grid(row=3, sticky='e')
		self.runtimeentry = Entry(master)
		self.runtimeentry.grid(row=1, column=1)
		self.targetentry = Entry(master)
		self.targetentry.grid(row=2, column=1)
		self.cwdentry = Entry(master)
		self.cwdentry.grid(row=3, column=1)
		if loaded:
			try:
				self.runtimeentry.insert(0, js['runtime_file'])
				self.targetentry.insert(0, js['pocketmine_code'])
				self.cwdentry.insert(0, js['working_dir'])
			except KeyError as ex:
				Msgbox(str(ex))
				logger.reportError(ex, '파일이 손상된 것 같습니다. 계속 오류가 발생하면 config.json을 지워주세요')

		Button(master, text='설정', command=self.chooseRuntime).grid(row=1, column=2, sticky='w')
		Button(master, text='설정', command=self.chooseTarget).grid(row=2, column=2, sticky='w')
		Button(master, text='설정', command=self.chooseCwd).grid(row=3, column=2, sticky='w')
		Button(master, text='시작!', command=self.start).grid(row=4, column=0, columnspan=2)
		Button(master, text='취소', command=lambda: exit(0)).grid(row=4, column=1, columnspan=2)
Esempio n. 14
0
def ev6_getMemoryOutput(ls):
    # Spencer: Get the total memory of the lpar -------------------------------
    memory = 0
    try:
        output = ls.evMvsCmd(_CMD_D_MSTOR)
        if output.isSuccess() and len(output.cmdResponseList) > 0:
            for line in output.cmdResponseList:
                matches = re.match('^\s*(\d+)M-(\d+)M\s*$', line)
                if (matches != None):
                    memory += int(matches.group(2)) - int(matches.group(1))
    except:
        errMsg = 'Failure in method ev6_getMemoryOutput()'
        logger.error(errMsg)
        logger.reportError(errMsg)
    return memory
def discoverNetscaler(Framework):
    """
    @type Framework: com.hp.ucmdb.discovery.probe.services.dynamic.core.DynamicServiceFrameworkImpl
    """
    client = None
    try:
        client = Framework.createClient()
        snmpAgent = snmputils.SnmpAgent(None, client)
        discoverer = NetScalerDiscover(snmpAgent)
        return discoverer.getTopology()
    except:
        logger.debugException('')
        logger.reportError('Failed to discover netscaler')
    finally:
        if client:
            client.close()
Esempio n. 16
0
def discoverNetscaler(Framework):
    """
    @type Framework: com.hp.ucmdb.discovery.probe.services.dynamic.core.DynamicServiceFrameworkImpl
    """
    client = None
    try:
        client = Framework.createClient()
        snmpAgent = snmputils.SnmpAgent(None, client)
        discoverer = NetScalerDiscover(snmpAgent)
        return discoverer.getTopology()
    except:
        logger.debugException('')
        logger.reportError('Failed to discover netscaler')
    finally:
        if client:
            client.close()
Esempio n. 17
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    client = None
    layer2_connections_cdp = None
    layer2_connections_lldp = None
    try:
        try:
            client = Framework.createClient()
        except:
            errMsg ='Exception while creating %s client: %s' % (ClientsConsts.SNMP_PROTOCOL_NAME, sys.exc_info()[1])
            errormessages.resolveAndReport(str(sys.exc_info()[1]), ClientsConsts.SNMP_PROTOCOL_NAME, Framework)
            logger.debugException(errMsg)
        else:
            host_id = Framework.getDestinationAttribute('hostId')
            discover_cdp_mib = Boolean.parseBoolean(Framework.getParameter('discoverCdpMib'))
            discover_lldp_mib = Boolean.parseBoolean(Framework.getParameter('discoverLldpMib'))
            local_device_discoverer = LocalDeviceDiscoverer(client, host_id)
            local_devices = local_device_discoverer.get_local_devices()
            if not local_devices or len(local_devices) == 0:
                logger.reportError('Failed to get local device info')

            if discover_cdp_mib:
                cdp_discoverer = CdpDiscoverer(client)
                remote_devices_cdp = cdp_discoverer.get_remote_devices()
                if remote_devices_cdp:
                    layer2_connections_cdp = get_layer2_connections(local_devices, remote_devices_cdp)
                    for layer2_connection in layer2_connections_cdp:
                        OSHVResult.addAll(build_layer2_connection(layer2_connection))

            if discover_lldp_mib:
                lldp_discoverer = LldpDiscoverer(client)
                remote_devices_lldp = lldp_discoverer.get_remote_devices()
                if remote_devices_lldp:
                    layer2_connections_lldp = get_layer2_connections(local_devices, remote_devices_lldp)
                    for layer2_connection in layer2_connections_lldp:
                        OSHVResult.addAll(build_layer2_connection(layer2_connection))

            if (not layer2_connections_cdp or len(layer2_connections_cdp) == 0) and (not layer2_connections_lldp or len(layer2_connections_lldp) == 0):
                logger.reportError('No data collected')

    finally:
        if client != None:
            client.close()
    return OSHVResult
Esempio n. 18
0
def ev5_getSymlistOutput(ls):
    # process SYMLIST ----------------------------------------------------------
    symbolsMap = {} # {name:value}
    try:
        output = ls.evMvsCmd(_CMD_D_SYMBOLS)
        if output.isSuccess() and len(output.cmdResponseList) > 0:
            symbolsList = output.getValuesFromLineList('s', output.cmdResponseList, '&', '\.\s+=\s+"', '"')
            for symbols in symbolsList:
                if len(symbols) == 4:
                    symbolName = symbols[1]
                    symbolValue = symbols[2]
                    if isNotNull(symbolName) and isNotNull(symbolValue):
                        symbolsMap[symbolName] = symbolValue
    except:
        errMsg = 'Failure in method ev5_getSymlistOutput()'
        logger.error(errMsg)
        logger.reportError(errMsg)
    return symbolsMap
Esempio n. 19
0
def ev_getDefaultIpOfLpar(ls):
    defaultIp = None
    # Get TCP stacks -----------------------------------------------
    tcpStackList = ev3_getTcpStackNameOutput(ls)
    try:
        if len(tcpStackList) > 0:
            for tcpStack in tcpStackList:
                # Get LPAR default IP address from the first TCP stack -
                homeLists = ev4_getHomelistOutput(ls, tcpStack)
                if len(homeLists) > 1 and eview_lib.isNotNull(homeLists[0][1]):
                    defaultIp = homeLists[0][1]
                    for homeListIndex in range(1, len(homeLists)):
                        if homeLists[homeListIndex][2] == 'PRIMARY' and eview_lib.isNotNull(homeLists[homeListIndex][1]):
                            defaultIp = homeLists[homeListIndex][1]
    except:
        errMsg = 'Failure in method ev_getDefaultIpOfLpar()'
        logger.error(errMsg)
        logger.reportError(errMsg)
    return defaultIp
Esempio n. 20
0
def DiscoveryMain(Framework):
    fileName = Framework.getParameter('file_name').replace('%PROBE_MGR_RESOURCES_DIR%', CollectorsParameters.PROBE_MGR_RESOURCES_DIR)
    string_list_delimiter = Framework.getParameter('string_list_delimiter')
    integer_list_delimiter = Framework.getParameter('integer_list_delimiter')
    relationship_attr_delimiter = Framework.getParameter('relationship_attr_delimiter')
    set_empty_value_flag = Boolean.parseBoolean(Framework.getParameter('set_empty_value'))
    if not (fileName and string_list_delimiter and integer_list_delimiter and relationship_attr_delimiter):
        logger.reportError('Not all job parameters are set.')
        return
    try:
        workbook = xlsutils.openXlFile(fileName)
        if workbook:
            classModel = ConfigFilesManagerImpl.getInstance().getCmdbClassModel()
            classModelUtil = xlsutils.ClassModelUtils(classModel, integer_list_delimiter, string_list_delimiter)
            importer = WorkSheetImporter(workbook, classModelUtil, set_empty_value = set_empty_value_flag)
            return importer.processWorkbook ()
    except JavaException, ex:
        logger.reportError(ex.getMessage())
        ex.printStackTrace()
        logger.errorException('')
Esempio n. 21
0
def ev1_getEviewVersion(ls, task):
    # process EView agent information ------------------------------------------
    eviewVersion = None
    output = ls.evMvsCmd(_CMD_EVIEW_VERSION % task)
    try:
        if output.isSuccess() and len(output.cmdResponseList) > 0:
            logger.debug('Successfully connected to EView Agent')
            eviewVersionLine = output.cmdResponseList[1]
            eviewVersionList = output.getValuesFromLine("s", eviewVersionLine, "EVO607", "Copyright")
            if len(eviewVersionList) == 3:
                eviewVersion = eviewVersionList[1]
                logger.debug('Found EView Agent Version = ', eviewVersion)
        else:
            logger.reportError('Unable to get output for command - %s\nError: %s' % (_CMD_EVIEW_VERSION, output.errorDump))
    except:
        errMsg = 'Failure in method ev1_getEviewVersion()'
        logger.errorException(errMsg)
        logger.reportError("Failed to get version.")

    return eviewVersion
Esempio n. 22
0
def DiscoveryMain(Framework):
    shell = None
    try:
        try:
            protocolName = __getProtocolName(Framework)
            discoverSharePointUrls = Boolean.parseBoolean(
                Framework.getParameter('discoverSharePointUrls'))
            reportIntermediateWebService = Framework.getParameter(
                'reportIntermediateWebService')
            if reportIntermediateWebService:
                reportIntermediateWebService = Boolean.parseBoolean(
                    reportIntermediateWebService)
            else:
                #set default value
                reportIntermediateWebService = 1
            relativeCommandTimeoutMultiplier = Framework.getParameter(
                'relativeCommandTimeoutMultiplier')
            relativeCommandTimeoutMultiplier = int(
                relativeCommandTimeoutMultiplier)
            client = Framework.createClient()
            shell = ShellFactory().createShell(client)
            logger.debug('getting SharePoint discoverer for protocol %s' %
                         protocolName)
            discoverer = sharepoint_win_shell.getDiscoverer(
                shell, protocolName, relativeCommandTimeoutMultiplier)
            logger.debug('got discoverer')
            resources = _discoverSharePoint(discoverer)
            resources.build()
            return resources.report(discoverSharePointUrls,
                                    reportIntermediateWebService)
        except SharePointException:
            logger.reportError()
            logger.debugException('')
        except JavaException, ex:
            strException = ex.getMessage()
            errormessages.resolveAndReport(strException, protocolName,
                                           Framework)
        except:
            strException = logger.prepareJythonStackTrace('')
            errormessages.resolveAndReport(strException, protocolName,
                                           Framework)
Esempio n. 23
0
def ev1_getEviewVersion(ls):
    # process EView agent information ------------------------------------------
    eviewVersion = None
    try:
        output = ls.evClCmd(_CMD_EVIEW_VERSION )    
        if output.isSuccess() and len(output.cmdResponseList) > 0:
            logger.debug('Successfully connected to EView Agent')
            eviewVersionLine = output.cmdResponseList[3]          
            regex = r"(\S+)\s+(.+)"
            eviewVersionList = output.getRegexedValues(eviewVersionLine, regex)          
            if len(eviewVersionList) == 2:
                eviewVersion = eviewVersionList[0]
                logger.debug('Found EView Agent Version = ', eviewVersion)
        else:
            logger.reportError('Unable to get output for command - %s\nError: %s' % (_CMD_EVIEW_VERSION, output.errorDump))
    except:
        errMsg = 'Failure in method ev1_getEviewVersion()'
        logger.errorException(errMsg)
        logger.reportError("Failed to get version.")

    return eviewVersion
Esempio n. 24
0
def ev1_subsystemOutput(ls):
    db2Subsystems = []  # [name, initrtn, initparm, cmd_prefix]
    output = ls.evGetSubSysCmd()
    if output.isSuccess() and len(output.cmdResponseList) > 0:
        db2InitRoutineRegex = r"DSN\dINI"
        for line in output.cmdResponseList:
            if len(line) == 3 and isNotNull(line[1]):
                m = re.match(db2InitRoutineRegex, line[1], re.IGNORECASE)
                if isNotNull(m) and isNotNull(line[2]):
                    initParm = string.replace(line[2], "'", "")
                    initParmSplit = string.split(initParm, ",")
                    cmd_prefix = ''
                    if isNotNull(initParmSplit) and len(initParmSplit) > 1 and isNotNull(initParmSplit[1]):
                        cmd_prefix = initParmSplit[1]
                    db2Subsystems.append([line[0], line[1], initParm, cmd_prefix])
    else:
        if isNotNull(output) and isNotNull(output.errorDump) and output.errorDump.find('is not recognized as'):
            errMsg = 'Perl is required on the probe system path for this command to work. \nPlease install Perl as described in the EView agent documentation and retry this discovery'
            logger.error(errMsg)
            logger.reportError(errMsg)
    return db2Subsystems
Esempio n. 25
0
def createFsmHostOsh(fsmHost, ipAddress):
    """
    Creates the Object State Holder of the host where IBM HMC Management Sortware runs
    @param fsmHost: discovered host where IBM HMC runs
    @type fsmHost: instance of Host Data Object
    @param ipAddres: the IP Address of the Host
    @type ipAddress: String
    @return: Object State Holde of the UNIX CI instance
    """
    if fsmHost and ipAddress:
        hostOsh = modeling.createHostOSH(ipAddress, 'unix', None,
                                         fsmHost.hostname)
        hostOsh.setStringAttribute('vendor', 'ibm_corp')
        hostOsh.setStringAttribute("os_family", 'unix')
        if fsmHost.domainName:
            hostOsh.setStringAttribute('host_osdomain', fsmHost.domainName)
        if fsmHost.fsmSoftware:

            #            if fsmHost.fsmSoftware.bios:
            #                hostOsh.setStringAttribute('bios_serial_number', fsmHost.fsmSoftware.bios)

            if fsmHost.fsmSoftware.versionInformation:
                if fsmHost.fsmSoftware.versionInformation.fullVersion:
                    hostOsh.setStringAttribute(
                        'host_osrelease',
                        fsmHost.fsmSoftware.versionInformation.fullVersion)
                if fsmHost.fsmSoftware.versionInformation.baseOSVersion:
                    hostOsh.setStringAttribute(
                        'discovered_os_version',
                        fsmHost.fsmSoftware.versionInformation.baseOSVersion)

            if fsmHost.fsmSoftware.typeInformation and fsmHost.fsmSoftware.typeInformation.serialNum:
                hostOsh.setStringAttribute(
                    'serial_number',
                    fsmHost.fsmSoftware.typeInformation.serialNum)

        return hostOsh
    else:
        logger.reportError('Failed to discover FSM Host')
        raise ValueError("Failed to discover FSM Host")
Esempio n. 26
0
def ev1_getEviewVersion(ls):
    # process EView agent information ------------------------------------------
    eviewVersion = None
    try:
        output = ls.evClCmd(_CMD_EVIEW_VERSION)
        if output.isSuccess() and len(output.cmdResponseList) > 0:
            logger.debug('Successfully connected to EView Agent')
            eviewVersionLine = output.cmdResponseList[3]
            regex = r"(\S+)\s+(.+)"
            eviewVersionList = output.getRegexedValues(eviewVersionLine, regex)
            if len(eviewVersionList) == 2:
                eviewVersion = eviewVersionList[0]
                logger.debug('Found EView Agent Version = ', eviewVersion)
        else:
            logger.reportError(
                'Unable to get output for command - %s\nError: %s' %
                (_CMD_EVIEW_VERSION, output.errorDump))
    except:
        errMsg = 'Failure in method ev1_getEviewVersion()'
        logger.errorException(errMsg)
        logger.reportError("Failed to get version.")

    return eviewVersion
Esempio n. 27
0
def ev3_getTcpStackNameOutput(ls):
    # get the running TCP stacks -----------------------------------------
    tcpStackList = []
    output = ls.evMvsCmd(_CMD_D_TCPIP)
    try:
        if isNotNull(output) and output.isSuccess() and len(output.cmdResponseList) > 0:
            headerColumns = ['COUNT', 'TCPIP NAME', 'VERSION', 'STATUS']
            tableBeginPattern = 'EZAOP50I TCPIP STATUS REPORT'
            tableEndPattern = 'END TCPIP STATUS REPORT'
            firstColumnPaddingChar = ' '
            includeRegexPattern = ''
            ignorePatterns = ['------']
            stacks = output.getTableValues(output.cmdResponseList, headerColumns, tableBeginPattern, tableEndPattern, firstColumnPaddingChar, includeRegexPattern, ignorePatterns)
            for i in range(1, len(stacks)):
                if len(stacks[i]) == 4 and eview_lib.isNotNull(stacks[i][1]):
                    tcpStackList.append(stacks[i][1])
        else:
            logger.reportWarning('Unable to get output for command - %s' % _CMD_D_TCPIP)
    except:
        errMsg = 'Failure in method ev3_getTcpStackNameOutput()'
        logger.error(errMsg)
        logger.reportError(errMsg)

    return tcpStackList
def DiscoveryMain(Framework):

    ip = Framework.getDestinationAttribute("ip") or None
    port = Framework.getDestinationAttribute("https_port") or None
    hostCmdbId = Framework.getDestinationAttribute("host_id") or None
    oshvector = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('node', hostCmdbId.strip())
    if not (hostOsh and ip and port):
        logger.error("Incorrect input data: %s" % hostCmdbId.strip())
        logger.reportError("Incorrect input data")
        return oshvector

    localShell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))

    dnsResolver = dns_resolver.FallbackResolver([dns_resolver.SocketDnsResolver(),
                                                 dns_resolver.NsLookupDnsResolver(localShell)])
    hosts = dnsResolver.resolve_hostnames(ip)
    logger.debug("Host names to check: %s" % hosts)
    errors = []
    discoverResult = {}
    for hostname in hosts:
        try:
            logger.info("Getting certificate from %s:%s" % (hostname, port))
            certificates = ssl_cert_discoverer.openSslSession(hostname, port, ssl_cert_discoverer.discoverCertificates)
            if certificates:
                logger.info("Got %s certificates" % len(certificates))
                discoverResult[hostname] = certificates
            else:
                logger.warn("There are no any certificates on the %s:%s" % (hostname, port))
                logger.reportError("There are no any certificates on the target host")
        except JException,ex:
            logger.debugException(ex.getMessage())
            errors.append(ex.getMessage())
        except Exception, ex:
            logger.debugException(ex.message)
            errors.append(ex.message)
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    try:
        client = Framework.createClient()
        vendor = Framework.getDestinationAttribute('discovered_vendor')
        hostId = Framework.getDestinationAttribute('hostId')
        host_osh = modeling.createOshByCmdbId('firewall', hostId)
        discoverer = firewall_discoverer.getDiscoverer(vendor, client)
        if not discoverer:
            raise ValueError('Unsupported device.')
        firewall_config = discoverer.discover()
        OSHVResult.addAll(firewall.reportTopology(firewall_config, host_osh))
    except:
        import sys
        logger.debugException('')
        error_str = str(sys.exc_info()[1]).strip()
        logger.reportError(error_str)
    finally:
        client and client.close()
    ## Write implementation to return new result CIs here...
    if OSHVResult.size() == 0:
        logger.debug('No data discovered from destination.')
        logger.reportWarning('No data discovered from destination.')
    return OSHVResult
Esempio n. 30
0
def openXlFile (xlFileName):
    '''
    Go get the input XLS file
    str->POI workBook
    @raise POI exception: no drivers or opening error
    '''
    logger.debug ('Excel file to process:%s' % xlFileName)
    workBook = None

    # Grab the Workbook contained within the Excel (xls, xlsx) file
    f = File(xlFileName)
    if f.exists():
        logger.debug('file %s exists' % xlFileName)
        if str(xlFileName.encode('utf-8')).endswith('.xls'):
            logger.debug('Excel 97-2003 format')
            workBook = HSSFWorkbook(FileInputStream(xlFileName))
        elif str(xlFileName.encode('utf-8')).endswith('.xlsx'):
            logger.debug('OXML excel format')
            workBook = XSSFWorkbook(FileInputStream(xlFileName))
    else:
        logger.debug('file %s does not exist' % xlFileName)
        logger.reportError('Source file not found.')

    return workBook
Esempio n. 31
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    try:
        client = Framework.createClient()
        shell = shellutils.ShellFactory().createShell(client)
        reportHostName = Framework.getParameter('reportLparNameAsHostName')
        
        if not reportHostName:
            reportHostName = 'false'
            
        fsm_id = Framework.getDestinationAttribute('fsmId')
        fsm_osh = modeling.createOshByCmdbId('ibm_fsm', fsm_id)
        
        #do dsscovery part
        supported_types = ibm_fsm_discoverer.getAvailableSupportedEntityTypes(shell)
        logger.debug('Found following supported types %s. Will proceed to discovery' % supported_types)
        
        chassis_discoverer = ibm_fsm_discoverer.ChassisDiscoverer(shell)
        chassis = chassis_discoverer.discover()
        #logger.debug('Discovered chassis %s' % chassis)
        
        farm_discoverer = ibm_fsm_discoverer.FarmDiscoverer(shell)
        farms = farm_discoverer.discover()
        
        server_discoverer = ibm_fsm_discoverer.ServerDiscoverer(shell)
        servers, vms = server_discoverer.discover()
        #logger.debug('Discovered servers %s' % servers)
        #logger.debug('Discovered vms %s' % vms)
        
        system_pool_discoverer = ibm_fsm_discoverer.SystemPoolDiscoverer(shell)
        system_pools = system_pool_discoverer.discover()       
   
        switch_discoverer = ibm_fsm_discoverer.SwitchDiscoverer(shell)
        switches = switch_discoverer.discover()
    
        storage_discoverer = ibm_fsm_discoverer.StorageDiscoverer(shell)
        storages = storage_discoverer.discover()
        #logger.debug('Discovered storage systems %s ' % storages)
        
        managed_system_details_discoverer = ibm_fsm_discoverer.ManagedSystemDiscoverer(shell, servers)
        servers = managed_system_details_discoverer.discover()
        
        #lpar_details_discoverer = ibm_fsm_discoverer.LParDiscoverer(shell)
        #for server in servers:
        #    server.lpars_dict = lpar_details_discoverer.discover(server.managedSystem)
        
        for server in servers:
            if not server.managedSystem:
                logger.debug('Skipping %s, since it is not fully discoverable.' % server)
                continue
            managedSystemName = server.managedSystem.genericParameters.name
            
            '''Command will fail on the target device if its state is 'Incomplete', skip them'''
            if server.managedSystem.genericParameters.state == 'Incomplete':
                continue
            
            server.managedSystem.lparProfilesDict = ibm_fsm_discoverer.LParDiscoverer(shell).discover(server.managedSystem)
            server.managedSystem.cpuPoolList = ibm_fsm_discoverer.ProcessorPoolDiscoverer(shell).discover(managedSystemName)
            server.managedSystem.vScsiList = ibm_fsm_discoverer.ScsiDiscoverer(shell).discover(managedSystemName)
            server.managedSystem.vEthList = ibm_fsm_discoverer.EthernetDiscoverer(shell).discover(managedSystemName)
        ibm_fsm_discoverer.discoverIoSlots(shell, servers)
        ibm_fsm_discoverer.discoverVirtIoSlots(shell, servers)

        #do topology reporting
        OSHVResult = ibm_fsm.ReportTopology(chassis, servers, system_pools, vms, switches, storages, fsm_osh, reportHostName)
    except:
        logger.debugException('')
        logger.reportError('Failed to discover FSM see logs for details')
    return OSHVResult
Esempio n. 32
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    try:
        client = Framework.createClient()
        shell = shellutils.ShellFactory().createShell(client)
        reportHostName = Framework.getParameter('reportLparNameAsHostName')

        if not reportHostName:
            reportHostName = 'false'

        fsm_id = Framework.getDestinationAttribute('fsmId')
        fsm_osh = modeling.createOshByCmdbId('ibm_fsm', fsm_id)

        #do dsscovery part
        supported_types = ibm_fsm_discoverer.getAvailableSupportedEntityTypes(
            shell)
        logger.debug(
            'Found following supported types %s. Will proceed to discovery' %
            supported_types)

        chassis_discoverer = ibm_fsm_discoverer.ChassisDiscoverer(shell)
        chassis = chassis_discoverer.discover()
        #logger.debug('Discovered chassis %s' % chassis)

        farm_discoverer = ibm_fsm_discoverer.FarmDiscoverer(shell)
        farms = farm_discoverer.discover()

        server_discoverer = ibm_fsm_discoverer.ServerDiscoverer(shell)
        servers, vms = server_discoverer.discover()
        #logger.debug('Discovered servers %s' % servers)
        #logger.debug('Discovered vms %s' % vms)

        system_pool_discoverer = ibm_fsm_discoverer.SystemPoolDiscoverer(shell)
        system_pools = system_pool_discoverer.discover()

        switch_discoverer = ibm_fsm_discoverer.SwitchDiscoverer(shell)
        switches = switch_discoverer.discover()

        storage_discoverer = ibm_fsm_discoverer.StorageDiscoverer(shell)
        storages = storage_discoverer.discover()
        #logger.debug('Discovered storage systems %s ' % storages)

        managed_system_details_discoverer = ibm_fsm_discoverer.ManagedSystemDiscoverer(
            shell, servers)
        servers = managed_system_details_discoverer.discover()

        #lpar_details_discoverer = ibm_fsm_discoverer.LParDiscoverer(shell)
        #for server in servers:
        #    server.lpars_dict = lpar_details_discoverer.discover(server.managedSystem)

        for server in servers:
            if not server.managedSystem:
                logger.debug(
                    'Skipping %s, since it is not fully discoverable.' %
                    server)
                continue
            managedSystemName = server.managedSystem.genericParameters.name
            '''Command will fail on the target device if its state is 'Incomplete', skip them'''
            if server.managedSystem.genericParameters.state == 'Incomplete':
                continue

            server.managedSystem.lparProfilesDict = ibm_fsm_discoverer.LParDiscoverer(
                shell).discover(server.managedSystem)
            server.managedSystem.cpuPoolList = ibm_fsm_discoverer.ProcessorPoolDiscoverer(
                shell).discover(managedSystemName)
            server.managedSystem.vScsiList = ibm_fsm_discoverer.ScsiDiscoverer(
                shell).discover(managedSystemName)
            server.managedSystem.vEthList = ibm_fsm_discoverer.EthernetDiscoverer(
                shell).discover(managedSystemName)
        ibm_fsm_discoverer.discoverIoSlots(shell, servers)
        ibm_fsm_discoverer.discoverVirtIoSlots(shell, servers)

        #do topology reporting
        OSHVResult = ibm_fsm.ReportTopology(chassis, servers, system_pools,
                                            vms, switches, storages, fsm_osh,
                                            reportHostName)
    except:
        logger.debugException('')
        logger.reportError('Failed to discover FSM see logs for details')
    return OSHVResult
Esempio n. 33
0
def processEviewConfFiles(Framework, localshell):
    _vector = ObjectStateHolderVector()
    fileMonitor = file_mon_utils.FileMonitor(Framework, localshell, ObjectStateHolderVector(), None, None)
    folder = Framework.getParameter('EViewInstallationFolder')
    if isNull(folder):
        logger.reportError('Job parameter - EViewInstallationFolder is empty. Set the path to the EView client installation root and rerun job.')
        return _vector

    appPath = fileMonitor.rebuildPath(folder) + "\\bin\\ev390hostcmd.exe"
    confFolder = fileMonitor.rebuildPath(folder) + "\\conf\\"
    confFiles = None
    try:
        confFiles = fileMonitor.listFilesWindows(confFolder, EViewConfFileNameFilter())
    except:
        logger.reportError('Unable to get EView configuration files from folder: %s' % confFolder)
        return _vector

    # Create zOS & EView agent objects -----------------------------------------
    if isNull(confFiles):
        logger.reportError('Unable to get EView configuration files from folder: %s' % confFolder)
        return _vector
    elif len(confFiles) < 1:
        logger.reportError('Unable to get EView configuration files from folder: %s' % confFolder)
        return _vector
    else:
        for file in confFiles:

            nodeName = file[13:len(file)]   # The name of the configuration file is ev390_config_<NODE_NAME>
            if eview_lib.isNotNull(nodeName):

                #===================================================================
                # connect to each node with configuration and only
                # create EView CI for the ones that connect
                #===================================================================
                ls = eview_lib.EvShell(Framework, nodeName, appPath)
                # Get EView agent version ------------------------------------------
                task = Framework.getParameter('EViewStartedTask')
                if isNull(task):
                    task = 'VP390'
                eviewVersion = ev1_getEviewVersion(ls, task)
                if eview_lib.isNotNull(eviewVersion):
                    logger.debug('Successfully executed command against EView agent on node: ', nodeName)

                    # Get IPL info -------------------------------------------------
                    (zOsRelease, ieasymList, ieasysList, machineBootDate) = ev2_getIplInfoOutput(ls)
                    
                    # Spencer: Get memory info -------------------------------------
                    memory = ev6_getMemoryOutput(ls)

                    # Get the default IP of the LPAR -------------------------------
                    defaultIp = ev_getDefaultIpOfLpar(ls)

                    if isNull(defaultIp):
                        logger.reportWarning('Unable to get IP Address of LPAR: %s. Continuing with next LPAR.' % nodeName)
                        continue
                    else:
                        # Get Symbols --------------------------------------------------
                        symbolsMap = ev5_getSymlistOutput(ls)   # {symbolName:symbolValue}
                        
                        # CPU List Command ---------------------------------------------------------
                        (cpuLists, cpcSi, cpcId, cpcName) = ev7_getCpulistOutput(ls)
                        
                        # Create zOS OSH ---------------------------------
                        zOsOsh = osh_createZOsOsh(defaultIp, zOsRelease, ieasymList, ieasysList, machineBootDate, symbolsMap, memory, cpcSi)
                        _vector.add(zOsOsh)

                        if isNotNull(zOsOsh):
                            # Create IP OSH and link it to zOS OSH -------------------------
                            _vector.addAll(osh_createIpOsh(zOsOsh, defaultIp))

                            # Create EView Agent OSH and link it to the zOS OSH ------------
                            eviewOSH = osh_createEviewOsh(localshell, zOsOsh, appPath, confFolder, file, nodeName, eviewVersion, defaultIp)
                            _vector.add(eviewOSH)
                else:
                    warnMsg = 'Unable to connect to: %s' % nodeName
                    logger.warn(warnMsg)
                    warnObj = errorobject.createError(errorcodes.CONNECTION_FAILED, None, warnMsg)
                    logger.reportWarningObject(warnObj)

    return _vector
Esempio n. 34
0
        zones = zoneList or dnsDiscoverer.listZones()
        isError = 0
        for zone in zones:
            if (dns.isLocalhostZone(zone)
                or dns.isReverseZone(zone)
                or dns.isRootZone(zone)):
                continue
            topology = ZoneTopology(zone)
            try:
                logger.debug('transfer zone: %s' % zone)
                types = (RecordType.A,      # IPv4 address
                         RecordType.CNAME,  # Alias
                         RecordType.AAAA)   # IPv6 address
                records = dnsDiscoverer.transferZone(zone, *types)
                topology.records.extend(records)
            except dns.DiscoveryException, dde:
                logger.warn('Failed to transfer zone "%s"' % zone)
                logger.debugException(str(dde))
                isError = 1
            else:
                topologies.append(topology)
        if isError:
            errCode = errorcodes.FAILED_TRANSFER_DNS_ZONE
            message = "Failed to transfer zone records for one or more zones"
            errobj = errorobject.createError(errCode, [protocolName], message)
            logger.reportWarningObject(errobj)
    except dns.ZoneListException, ex:
        logger.error("No zone found. %s" % str(ex))
        logger.reportError(str(ex))
    return topologies
Esempio n. 35
0
from java.io import File, FileInputStream, FileOutputStream, StringReader, BufferedWriter, FileWriter
from org.apache.log4j import FileAppender, PatternLayout, Logger, Level, SimpleLayout
from org.jdom import Document, Element, Attribute
from org.jdom.input import SAXBuilder
from org.jdom.output import XMLOutputter
from com.hp.ucmdb.discovery.library.common import CollectorsParameters
from com.hp.ucmdb.discovery.library.credentials.dictionary import ProtocolDictionaryManager
from appilog.common.system.types.vectors import ObjectStateHolderVector
from com.hp.ucmdb.discovery.probe.util.jython import ClassLoaderUtils
''' BMC Imports '''
try:
    from com.bmc.cmdb.api import *
    from com.bmc.arsys.api import *
except:
    logger.reportError(
        'BMC Remedy/Atrium JARs were not found on the probe classpath. \nRefer to integration documentation for JAR/DLL files required for this integration.'
    )

#Set default encoding to UTF-8
reload(sys)
sys.setdefaultencoding('UTF-8')
'''
Initialize variables
'''
ADAPTER_NAME = "AtriumPushAdapter"
FILE_SEPARATOR = "\\"
WORK_DIR = "work"
PUSH_PROPERTIES_FILE = "push.properties"
IGNORE = 'ignore'
INSERT = 'insert'
UPDATE = 'update'
Esempio n. 36
0
def startDiscovery(Framework):
    time_start = time.time()
    initParameters(Framework)
    OSHVResult = ObjectStateHolderVector()
    source = Framework.getTriggerCIData(CollectorsConstants.DESTINATION_DATA_ID)
    logger.debug("The arp source is:", source)
    client = getClient(Framework)
    if client is None:
        logger.debug("No snmp client available")
        logger.reportWarning("No snmp client available")
        return OSHVResult
    else:
        logger.debug("Get client:", client)
    ipMacList = []
    try:
        logger.debug("Begin query...")
        startTime = time.time()
        arp4Table = SNMP_Networking_Utils.discoverIPv4NetToMediaTable(client)
        if arp4Table:
            ipv4List = processIPv4NetToMediaTable(arp4Table, source)
            logger.debug("size of ipv4 list:", len(ipv4List))
            if ipv4List:
                ipMacList.extend(ipv4List)

        arp6Table = SNMP_Networking_Utils.discoverIPv6NetToMediaTable(client)
        if arp6Table:
            ipv6List = processIPv6NetToMediaTable(arp6Table, source)
            logger.debug("size of ipv6 list:", len(ipv6List))
            if ipv6List:
                ipMacList.extend(ipv6List)

        ipNetToPhysicalTable = SNMP_Networking_Utils.discoverIPNetToPhysicalTable(client)
        if ipNetToPhysicalTable:
            ipMixList = processIpNetToPhysicalTable(ipNetToPhysicalTable, source)
            logger.debug("size of mix ip list:", len(ipMixList))
            if ipMixList:
                ipMacList.extend(ipMixList)

        ciscoIpNetToPhysicalTable = SNMP_Networking_Utils.discoverCiscoIPNetToMediaTable(client)
        if ciscoIpNetToPhysicalTable:
            cIpMacList = processCiscoIpNetToPhysicalTable(ciscoIpNetToPhysicalTable, source)
            logger.debug("size of cisco ip mac list:", len(cIpMacList))
            if cIpMacList:
                ipMacList.extend(cIpMacList)

        logger.debug("Done query.")
        logger.debug("Total valid ip records:", len(ipMacList))
        totalTime = time.time() - startTime
        logger.debug('Total time(s):', totalTime)
        if totalTime:
            logger.debug('Average speed record(s)/second:', len(ipMacList) / totalTime)
    except:
        lastExceptionStr = str(sys.exc_info()[1]).strip()
        logger.debugException('Unexpected SNMP query exception:', lastExceptionStr)
        logger.reportError()
        return OSHVResult
    finally:
        logger.debug('Closing snmp client')
        client.close()

    if ipMacList:
        service = getIPMacService()
        try:
            macs = []
            tmp = []
            [(macs.append(x.macAddress), tmp.append(x)) for x in ipMacList if x.macAddress not in macs]
            ipMacList = tmp
            reportIPMacPairs(Framework, service, ipMacList, source)
        except:
            lastExceptionStr = str(sys.exc_info()[1]).strip()
            logger.debugException('Job failed by:', lastExceptionStr)
            logger.reportError()
    logger.debug("The job finished in %ds." % int((time.time() - time_start)))
    return OSHVResult
Esempio n. 37
0
from org.jdom import *
from org.jdom.input import *
from org.jdom.output import *

from java.io import *
from java.io import File, FileOutputStream
from appilog.common.utils import Protocol
from com.hp.ucmdb.discovery.library.common import CollectorsParameters

''' BMC Imports '''
try:
    from com.bmc.cmdb.api import *
    from com.bmc.arsys.api import *
except:
    msg = 'BMC Remedy/Atrium JARs were not found on the probe classpath. \nRefer to integration documentation for JAR/DLL files required for this integration.'
    logger.reportError(msg)

from com.hp.ucmdb.adapters.push9 import *

## Globals
SCRIPT_NAME='atrium_query.py'
DEBUGLEVEL = 5 ## Set between 0 and 5 (Default should be 0), higher numbers imply more log messages
theFramework = None

## Logging helper
def debugPrint(*debugStrings):
    try:
        logLevel = 1
        logMessage = '[atrium_query.py logger] '
        if type(debugStrings[0]) == type(DEBUGLEVEL):
            logLevel = debugStrings[0]
Esempio n. 38
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ips = Framework.getTriggerCIDataAsList('ip_address')
    ip_ids = Framework.getTriggerCIDataAsList('ip_id')
    host_id = Framework.getTriggerCIData('host_id')
    host_name = Framework.getTriggerCIData('host_name')
    hostOSH = modeling.createOshByCmdbIdString('node', host_id)
    dnsServers = Framework.getParameter('dnsServers') or None
    localShell = None

    if dnsServers:
        dnsServers = [
            dnsServer for dnsServer in dnsServers.split(',')
            if dnsServer and dnsServer.strip()
        ] or None

    if dnsServers:
        localShell = shellutils.ShellUtils(
            Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))

    smallIp = '255.255.255.255'
    smallIpDns = None
    smallPublicIpDns = None
    primary_dns_name_candidates = []
    index = 0
    for ip in ips:

        ip_id = ip_ids[index]
        index = index + 1

        if dnsServers:
            dnsName = resolveHostNameByDnsList(ip, localShell, dnsServers)
        else:
            dnsName = netutils.getHostName(ip, None)
        logger.debug('dns, %s:%s' % (ip, dnsName))
        if dnsName == None:
            continue
        else:
            # Set ip DNS by dnsName
            ipOSH = modeling.createOshByCmdbIdString('ip_address', ip_id)
            ipOSH.setAttribute('name', ip)
            ipOSH.setAttribute('authoritative_dns_name', dnsName)
            containmentLink = modeling.createLinkOSH('containment', hostOSH,
                                                     ipOSH)
            OSHVResult.add(containmentLink)
            OSHVResult.add(ipOSH)

            if host_name and dnsName.split(
                    '.')[0] == host_name:  #share same short name
                primary_dns_name_candidates.append(dnsName)

            if netutils.convertIpToInt(ip) < netutils.convertIpToInt(smallIp):
                smallIp = ip
                smallIpDns = dnsName
                if not netutils.isPrivateIp(ip):
                    smallPublicIpDns = dnsName

    logger.debug("Primary candidates:", primary_dns_name_candidates)
    if smallPublicIpDns:
        logger.debug("Set public dns", smallPublicIpDns)
        smallIpDns = smallPublicIpDns
    if smallIpDns and (not primary_dns_name_candidates
                       or smallIpDns in primary_dns_name_candidates):
        # Set host DNS smallIpDns
        logger.debug("Set host DNS smallIpDns:", smallIpDns)
        hostOSH.setAttribute('primary_dns_name', smallIpDns)
        OSHVResult.add(hostOSH)
    else:
        if primary_dns_name_candidates:
            #if there are multiple candidates, we can only choose one without any prefer
            logger.debug("Set first primary dns:",
                         primary_dns_name_candidates[0])
            hostOSH.setAttribute('primary_dns_name',
                                 primary_dns_name_candidates[0])
            OSHVResult.add(hostOSH)

    if not OSHVResult.size():
        logger.reportError("Cannot resolve host from DNS")

    if localShell is not None:
        try:
            localShell.close()
            localShell = None
        except:
            pass
    return OSHVResult
Esempio n. 39
0
from java.lang import *
from org.jdom import *
from org.jdom.input import *
from org.jdom.output import *

from java.io import *
from java.io import File, FileOutputStream
from appilog.common.utils import Protocol
from com.hp.ucmdb.discovery.library.common import CollectorsParameters
''' BMC Imports '''
try:
    from com.bmc.cmdb.api import *
    from com.bmc.arsys.api import *
except:
    msg = 'BMC Remedy/Atrium JARs were not found on the probe classpath. \nRefer to integration documentation for JAR/DLL files required for this integration.'
    logger.reportError(msg)

from com.hp.ucmdb.adapters.push9 import *

## Globals
SCRIPT_NAME = 'atrium_query.py'
DEBUGLEVEL = 5  ## Set between 0 and 5 (Default should be 0), higher numbers imply more log messages
theFramework = None


## Logging helper
def debugPrint(*debugStrings):
    try:
        logLevel = 1
        logMessage = '[atrium_query.py logger] '
        if type(debugStrings[0]) == type(DEBUGLEVEL):
Esempio n. 40
0
from java.io import File, FileInputStream, FileOutputStream, StringReader, BufferedWriter, FileWriter
from org.apache.log4j import FileAppender, PatternLayout, Logger, Level, SimpleLayout
from org.jdom import Document, Element, Attribute
from org.jdom.input import SAXBuilder
from org.jdom.output import XMLOutputter
from com.hp.ucmdb.discovery.library.common import CollectorsParameters
from com.hp.ucmdb.discovery.library.credentials.dictionary import ProtocolDictionaryManager
from appilog.common.system.types.vectors import ObjectStateHolderVector
from com.hp.ucmdb.discovery.probe.util.jython import ClassLoaderUtils

''' BMC Imports '''
try:
    from com.bmc.cmdb.api import *
    from com.bmc.arsys.api import *
except:
    logger.reportError('BMC Remedy/Atrium JARs were not found on the probe classpath. \nRefer to integration documentation for JAR/DLL files required for this integration.')

#Set default encoding to UTF-8
reload(sys)
sys.setdefaultencoding('UTF-8')

'''
Initialize variables
'''
ADAPTER_NAME          = "AtriumPushAdapter"
FILE_SEPARATOR        = "\\"
WORK_DIR              = "work"
PUSH_PROPERTIES_FILE  = "push.properties"
IGNORE                = 'ignore'
INSERT                = 'insert'
UPDATE                = 'update'
Esempio n. 41
0
 def handleFailure(self, result):
     if result.returnCode == 9009 or result.returnCode == 127:
         logger.reportError('failed to find "xuser" command')
     return ()
Esempio n. 42
0
def DiscoveryMain(Framework):
    OshvResult = ObjectStateHolderVector()
    hostOsh = None

    ## Destination data
    hostId = Framework.getDestinationAttribute('hostId') or None
    processRootId = Framework.getDestinationAttribute('processRootId') or None
    processPath = Framework.getDestinationAttribute('processPath') or None
    processCmdLine = Framework.getDestinationAttribute('processCmdLine') or None
    protocol = Framework.getDestinationAttribute('Protocol')
    ipAddress = Framework.getDestinationAttribute('ip_address')
    raw_paths = Framework.getParameter('emsadmin_tool_absolute_paths') or ''
    default_paths = [x.strip() for x in raw_paths.split(',')]
    ## Pattern parameters
    isJmsQueueDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discover_queues'))
    isJmsTopicDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discover_topics'))

    ## Container HOST OSH
    if hostId:
        hostOsh = modeling.createOshByCmdbIdString('host', hostId.strip())
        OshvResult.add(hostOsh)
        logger.debug('[' + __name__ + ':DiscoveryMain] Got HOSTID <%s>' % hostId)

    ## EMS OSH
    if processRootId:
        processOsh = modeling.createOshByCmdbIdString('process', processRootId.strip())
        OshvResult.add(processOsh)
        logger.debug('[' + __name__ + ':DiscoveryMain] Got Process ID <%s>' % processRootId)
    else:
        errMsg = "Invalid Tibco EMS Server CI ID received from server. This EMS server will not be processed"
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OshvResult

    emsTopology = []
    # Attempt to create a shell client
    try:
        client = Framework.createClient()
        shell = shellutils.ShellFactory().createShell(client)
        fallbackDnsResolver = tibco_discoverer.FallbackResolver([netutils.JavaDnsResolver(), netutils.DnsResolverByShell(shell)])
        dnsResolver = tibco_discoverer.CachedResolver(fallbackDnsResolver)

        fs = file_system.createFileSystem(shell)
        emsShellDiscoverer = tibco_discoverer.EmsDiscovererByShell(shell, fs)

        pathUtils = file_system.getPath(fs)
        emsPath = "%s/" % pathUtils.dirName(processPath)
        default_paths.insert(0, emsPath)
        # find out whether emsadmin tool exists and config path present in command line
        for ems_path in default_paths:
            configPath = emsShellDiscoverer.discoverConfigPath(ems_path, processCmdLine)
            if configPath:
                emsPath = ems_path
                logger.debug('Found ems admin utility path %s' % emsPath)
                logger.debug('Found ems config file path %s' % configPath)
                break
        if not emsPath:
            raise ValueError('Failed to discover ems admin utility path. No discovery possible.')
        listenUrls = emsShellDiscoverer.getListenUrls(configPath)
        credList = Framework.getAvailableProtocols(ipAddress, tibco.TIBCO_PROTOCOL)
        # Check if exists any credentials for TIBCO
        if credList:
            for cred in credList:
                for listenUrl in listenUrls:
                    try:
                        emsAdminCommand = tibco_discoverer.EmsAdminCommand(client, cred, emsPath, listenUrl)
                        if testConnection(emsAdminCommand):
                            emsDiscoverer = tibco_discoverer.EmsDiscovererByAdminCommand(emsAdminCommand)
                            emsServer = emsDiscoverer.getEmsServerInfo()
                            jmsServer = emsDiscoverer.extractJmsServerInfoFromUrl(listenUrl)

                            if jmsServer:
                                hostname = jmsServer.hostname
                                try:
                                    ip = dnsResolver.resolveIpsByHostname(hostname)
                                    jmsServer.hostname = netutils.getLowestIp(ip)
                                except:
                                    logger.debug("Cannot resolve %s host" % hostname)
                            if emsServer:
                                emsQueues = isJmsQueueDiscoveryEnabled and emsDiscoverer.getQueues()
                                emsTopics = isJmsTopicDiscoveryEnabled and emsDiscoverer.getTopics()
                            destinations = []
                            if emsQueues or emsTopics:
                                emsQueues and destinations.extend(emsQueues)
                                emsTopics and destinations.extend(emsTopics)
                            emsDataItem = tibco_discoverer.EmsTopology(emsServer, jmsServer, destinations)
                            emsTopology.append(emsDataItem)
                    except tibco_discoverer.TibcoDiscovererException, ex:
                        reportError(str(ex), tibco.TIBCO_PROTOCOL, Framework)
                    except Exception, ex:
                        reportError(str(ex), protocol, Framework)
                    except JException, ex:
                        msg = ex.getMessage()
                        logger.debugException(msg)
                        errormessages.resolveAndReport(msg, protocol, Framework)
Esempio n. 43
0
        zones = zoneList or dnsDiscoverer.listZones()
        isError = 0
        for zone in zones:
            if (dns.isLocalhostZone(zone) or dns.isReverseZone(zone)
                    or dns.isRootZone(zone)):
                continue
            topology = ZoneTopology(zone)
            try:
                logger.debug('transfer zone: %s' % zone)
                types = (
                    RecordType.A,  # IPv4 address
                    RecordType.CNAME,  # Alias
                    RecordType.AAAA)  # IPv6 address
                records = dnsDiscoverer.transferZone(zone, *types)
                topology.records.extend(records)
            except dns.DiscoveryException, dde:
                logger.warn('Failed to transfer zone "%s"' % zone)
                logger.debugException(str(dde))
                isError = 1
            else:
                topologies.append(topology)
        if isError:
            errCode = errorcodes.FAILED_TRANSFER_DNS_ZONE
            message = "Failed to transfer zone records for one or more zones"
            errobj = errorobject.createError(errCode, [protocolName], message)
            logger.reportWarningObject(errobj)
    except dns.ZoneListException, ex:
        logger.error("No zone found. %s" % str(ex))
        logger.reportError(str(ex))
    return topologies
Esempio n. 44
0
 def handleFailure(self, result):
     if result.returnCode == 9009 or result.returnCode == 127:
         logger.reportError('failed to find "xuser" command')
     return ()
Esempio n. 45
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    client = None
    hostOsh = None
    shell = None

    ## Destination data
    hostId = Framework.getDestinationAttribute('hostId') or None
    bwId = Framework.getDestinationAttribute('bwId') or None
    bwPath = Framework.getDestinationAttribute('bwPath') or None
    protocol = Framework.getDestinationAttribute('Protocol')
    ip_address = Framework.getDestinationAttribute('ip_address')
    tmpDirPath = Framework.getParameter('temp_directory') or '/tmp'
    isDiscoverJms = Framework.getParameter('discover_jms_topology') or "true"
    isDiscoverJms = Boolean.valueOf(isDiscoverJms)

    ## Container HOST OSH
    if hostId:
        hostOsh = modeling.createOshByCmdbIdString('node', hostId.strip())
        OSHVResult.add(hostOsh)
        logger.debug('[' + __name__ +
                     ':DiscoveryMain] Got HOSTID <%s>' % hostId)

    ## Pre-discovered Business Works CI
    bwOsh = None
    if bwId:
        bwOsh = modeling.createOshByCmdbIdString('tibco_business_works',
                                                 bwId.strip())
        logger.debug('[' + __name__ + ':DiscoveryMain] Got bwId <%s>' % bwId)
    else:
        errMsg = '[' + __name__ + ':DiscoveryMain] Invalid TibcoBusinessWorks CI ID received from server. This BW will not be processed'
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OSHVResult

    if not tmpDirPath:
        errMsg = '[' + __name__ + ':DiscoveryMain] temp_directory parameter has not been set correctly. Discovery cannot continue until this parameter is set with a remote directory with write permissions.'
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OSHVResult

    try:
        try:
            client = Framework.createClient()
            shell = shellutils.ShellFactory().createShell(client)
            credList = Framework.getAvailableProtocols(ip_address,
                                                       tibco.TIBCO_PROTOCOL)
            logger.info("Found tibco credentials: %s" % len(credList))

            fs = tibco_discoverer.createFileSystem(shell)

            bw = tibco_discoverer.BusinessWorksDiscoverer(
            ).findBWVersionFromPath(bwPath)
            domains = tibco_discoverer.BusinessWorksDomainDiscoverer(
                shell, fs).discover(bwPath)
            traHomeDiscoverer = tibco_discoverer.TicboTraHomeDiscoverer(shell)
            traHomes = traHomeDiscoverer.discover()
            fallbackDnsResolver = tibco_discoverer.FallbackResolver([
                netutils.JavaDnsResolver(),
                netutils.DnsResolverByShell(shell)
            ])
            dnsResolver = tibco_discoverer.CachedResolver(fallbackDnsResolver)

            if traHomes and bw:
                traPath = traHomes[0]
                for domain in domains:
                    logger.info("Visit %s" % domain)
                    try:
                        applications = None
                        # Check if we have any credential for TIBCO
                        if credList:
                            for credId in credList:
                                adminCommand = tibco_discoverer.AppManageAdminCommand(
                                    client, credId, "./")
                                adapterDiscoverer = tibco_discoverer.TibcoAdapterDiscoverer(
                                    dnsResolver)
                                appDiscoverer = tibco_discoverer.BusinessWorksApplicationDiscoverer(
                                    shell, fs, adminCommand, adapterDiscoverer)
                                applications = appDiscoverer.discover(
                                    domain.getName(),
                                    traPath,
                                    tmpDirPath,
                                    discoverJmsTopology=isDiscoverJms)
                            if applications:
                                tibco.each(domain.addApplication, applications)
                        else:
                            msg = errormessages.makeErrorMessage(
                                tibco.TIBCO_PROTOCOL,
                                pattern=errormessages.ERROR_NO_CREDENTIALS)
                            errobj = errorobject.createError(
                                errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP,
                                [tibco.TIBCO_PROTOCOL], msg)
                            logger.reportErrorObject(errobj)

                        bw.addDomain(domain)
                    except tibco_discoverer.TibcoDiscovererException, exc:
                        logger.debugException(str(exc))
                        errorobj = errorobject.createError(
                            errorcodes.
                            FAILED_RUNNING_DISCOVERY_WITH_CLIENT_TYPE,
                            ['tibco', 'error: %s' % str(exc)], str(exc))
                        logger.reportErrorObject(errorobj)
        except:
            logger.debugException('')
            exInfo = logger.prepareJythonStackTrace(
                '[' + __name__ + ':DiscoveryMain] Error connecting: ')
            errormessages.resolveAndReport(exInfo, protocol, Framework)
        else:
            # Reporting
            logger.debug("--- Start reporting ---")
            reporter = tibco.TopologyReporter(tibco.TopologyBuilder())
            bwOsh = reporter.reportBusinessWorks(bw, hostOsh, bwId)
            OSHVResult.add(bwOsh)
            endpointReporter = netutils.EndpointReporter(
                netutils.ServiceEndpointBuilder())

            for domain in domains:
                domainOsh = reporter.reportBusinessWorksDomain(domain)
                OSHVResult.add(domainOsh)
                OSHVResult.add(reporter.reportBWAndDomainLink(
                    domainOsh, bwOsh))
                for app in domain.getApplications():
                    appOsh = reporter.reportBusinessWorksApp(app, bwOsh)
                    OSHVResult.add(appOsh)
                    if app.getJmsServers():
                        for jmsServer in app.getJmsServers():

                            # Trying to resolver host name
                            try:
                                ip = netutils.getLowestIp(
                                    dnsResolver.resolveIpsByHostname(
                                        jmsServer.hostname))
                                if ip:
                                    jmsServer.hostname = ip
                            except Exception, ex:
                                logger.debugException(str(ex))

                            if netutils.isValidIp(
                                    jmsServer.hostname
                            ) and not netutils.isLoopbackIp(
                                    jmsServer.hostname):
                                jmsHostOsh = modeling.createHostOSH(
                                    jmsServer.hostname)
                                emsServerOsh = reporter.reportEMSServer(
                                    tibco.EmsServer(), jmsHostOsh)
                                jmsServerOsh = reporter.reportJmsServer(
                                    jmsServer, emsServerOsh)
                                endpoint = netutils.createTcpEndpoint(
                                    jmsServer.hostname, jmsServer.getPort())
                                serviceOsh = endpointReporter.reportEndpoint(
                                    endpoint, jmsHostOsh)
                                linkOsh = reporter.reportEmsServerServiceAddressLink(
                                    emsServerOsh, serviceOsh)
                                OSHVResult.add(emsServerOsh)
                                OSHVResult.add(jmsHostOsh)
                                OSHVResult.add(jmsServerOsh)
                                OSHVResult.add(serviceOsh)
                                OSHVResult.add(linkOsh)
                                for jmsQueue in app.getJmsQueues():
                                    OSHVResult.addAll(
                                        reporter.reportJmsDestinationTopology(
                                            jmsQueue, jmsServerOsh, appOsh))
                                for jmsTopic in app.getJmsTopics():
                                    OSHVResult.addAll(
                                        reporter.reportJmsDestinationTopology(
                                            jmsTopic, jmsServerOsh, appOsh))
                    if app.getAdapters():
                        for adapter in app.getAdapters():
                            OSHVResult.addAll(
                                reporter.reportAdapterTopology(
                                    adapter, appOsh))

    finally:
        if shell:
            ## Close shell connection
            shell.closeClient()

    return OSHVResult
Esempio n. 46
0
def processEviewConfFiles(Framework, localshell):
    _vector = ObjectStateHolderVector()
    fileMonitor = file_mon_utils.FileMonitor(Framework, localshell,
                                             ObjectStateHolderVector(), None,
                                             None)
    folder = Framework.getParameter('EViewInstallationFolder')
    if isNull(folder):
        logger.reportError(
            'Job parameter - EViewInstallationFolder is empty. Set the path to the EView client installation root and rerun job.'
        )
        return _vector

    appPath = fileMonitor.rebuildPath(folder) + "\\bin\\ev400hostcmd.exe"
    confFolder = fileMonitor.rebuildPath(folder) + "\\conf\\"
    confFiles = None
    try:
        confFiles = fileMonitor.listFilesWindows(confFolder,
                                                 EViewConfFileNameFilter())
    except:
        logger.reportError(
            'Unable to get EView configuration files from folder: %s' %
            confFolder)
        return _vector

    # Create iSeries & EView agent objects -----------------------------------------
    if isNull(confFiles):
        logger.reportError(
            'Unable to get EView configuration files from folder: %s' %
            confFolder)
        return _vector
    elif len(confFiles) < 1:
        logger.reportError(
            'Unable to get EView configuration files from folder: %s' %
            confFolder)
        return _vector
    else:
        for file in confFiles:

            nodeName = file[13:len(
                file
            )]  # The name of the configuration file is ev400_config_<NODE_NAME>
            logger.debug('Node = ', nodeName)
            if eview400_lib.isNotNull(nodeName):

                #===================================================================
                # connect to each node with configuration and only
                # create EView CI for the ones that connect
                #===================================================================

                ls = eview400_lib.EvShell(Framework, nodeName, appPath)
                # Get EView agent version ------------------------------------------

                eviewVersion = ev1_getEviewVersion(ls)
                if eview400_lib.isNotNull(eviewVersion):
                    logger.debug(
                        'Successfully executed command against EView agent on node: ',
                        nodeName)

                    # Get the iSeries  info -------------------------------------------------
                    (model, serialnbr, osversion,
                     sysname) = ev2_getiSeriesOutput(ls)

                    # Get the default IP of the LPAR -------------------------------
                    defaultIp, macAddress = ev_getIPofLpar(ls)

                    if isNull(defaultIp):
                        logger.reportWarning(
                            'Unable to get IP Address of LPAR: %s. Continuing with next LPAR.'
                            % nodeName)
                        continue
                    else:

                        # Create iSeries OSH ---------------------------------
                        iSeriesOsh = osh_createiSeriesOsh(
                            defaultIp, model, osversion, serialnbr, sysname,
                            macAddress)
                        _vector.add(iSeriesOsh)

                        if isNotNull(iSeriesOsh):
                            # Create IP OSH and link it to zOS OSH -------------------------
                            _vector.addAll(
                                osh_createIpOsh(iSeriesOsh, defaultIp))

                            # Create EView Agent OSH and link it to the zOS OSH ------------
                            eviewOSH = osh_createEviewOsh(
                                localshell, iSeriesOsh, appPath, confFolder,
                                file, nodeName, eviewVersion, defaultIp)
                            _vector.add(eviewOSH)
                else:
                    warnMsg = 'Unable to connect to: %s' % nodeName
                    logger.warn(warnMsg)
                    warnObj = errorobject.createError(
                        errorcodes.CONNECTION_FAILED, None, warnMsg)
                    logger.reportWarningObject(warnObj)

    return _vector
Esempio n. 47
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ips      = Framework.getTriggerCIDataAsList('ip_address')
    ip_ids    = Framework.getTriggerCIDataAsList('ip_id')
    host_id    = Framework.getTriggerCIData('host_id')
    host_name = Framework.getTriggerCIData('host_name')
    hostOSH = modeling.createOshByCmdbIdString('node', host_id)
    dnsServers = Framework.getParameter('dnsServers') or None
    localShell = None
    
    if dnsServers:
        dnsServers = [dnsServer for dnsServer in dnsServers.split(',') if dnsServer and dnsServer.strip()] or None
    
    if dnsServers:
        localShell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))        

    smallIp = '255.255.255.255'
    smallIpDns = None
    smallPublicIpDns = None
    primary_dns_name_candidates = []
    index=0
    for ip in ips:

        ip_id    = ip_ids[index]
        index    = index+1

        if dnsServers:
            dnsName = resolveHostNameByDnsList(ip,localShell,dnsServers)
        else:
            dnsName = netutils.getHostName(ip, None)
        logger.debug('dns, %s:%s'%(ip,dnsName))
        if dnsName == None:
            continue
        else:
            # Set ip DNS by dnsName
            ipOSH = modeling.createOshByCmdbIdString('ip_address', ip_id)
            ipOSH.setAttribute('name', ip)
            ipOSH.setAttribute('authoritative_dns_name', dnsName)
            containmentLink = modeling.createLinkOSH('containment',hostOSH,ipOSH)
            OSHVResult.add(containmentLink)
            OSHVResult.add(ipOSH)

            if host_name and dnsName.split('.')[0] == host_name:    #share same short name
                primary_dns_name_candidates.append(dnsName)

            if netutils.convertIpToInt(ip) < netutils.convertIpToInt(smallIp):
                smallIp = ip
                smallIpDns = dnsName
                if not netutils.isPrivateIp(ip):
                    smallPublicIpDns = dnsName

    logger.debug("Primary candidates:", primary_dns_name_candidates)
    if smallPublicIpDns:
        logger.debug("Set public dns", smallPublicIpDns)
        smallIpDns = smallPublicIpDns
    if smallIpDns and (not primary_dns_name_candidates or smallIpDns in primary_dns_name_candidates):
        # Set host DNS smallIpDns
        logger.debug("Set host DNS smallIpDns:", smallIpDns)
        hostOSH.setAttribute('primary_dns_name', smallIpDns)
        OSHVResult.add(hostOSH)
    else:
        if primary_dns_name_candidates:
            #if there are multiple candidates, we can only choose one without any prefer
            logger.debug("Set first primary dns:", primary_dns_name_candidates[0])
            hostOSH.setAttribute('primary_dns_name', primary_dns_name_candidates[0])
            OSHVResult.add(hostOSH)

    if not OSHVResult.size():
        logger.reportError("Cannot resolve host from DNS")

    if localShell is not None:
        try:
            localShell.close()
            localShell = None
        except:
            pass
    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    endpoint = Framework.getDestinationAttribute('endpoint')
    ip = Framework.getDestinationAttribute('ip')
    protocols = Framework.getAvailableProtocols(ip, "http")

    if len(protocols) == 0:
        msg = 'Protocol not defined or IP out of protocol network range'
        logger.reportWarning(msg)
        logger.error(msg)
        return OSHVResult

    novaApi = None
    cinderApi = None
    glanceApi = None
    neutronApi = None

    zoneOshDict = {}
    serverOshDict = {}
    networkOshDict = {}

    for protocol in protocols:
        try:
            username = Framework.getProtocolProperty(protocol, CollectorsConstants.PROTOCOL_ATTRIBUTE_USERNAME)
            credential = Framework.getProtocolProperty(protocol, CollectorsConstants.PROTOCOL_ATTRIBUTE_PASSWORD)

            keystoneApi = buildApi('openstack-keystone', endpoint, username, credential, KeystoneApi)
            logger.debug('keystoneApi:', keystoneApi)

            tenant_discover = openstack_discoverer.TenantDiscoverer(keystoneApi)
            tenants = tenant_discover.discover()
            if tenants:
                openstack_software = openstack.OpenStack(ip)
                openstack_osh, openstack_vector = openstack_software.report()
                OSHVResult.addAll(openstack_vector)
            else:
                continue

            for tenant in tenants:
                try:
                    logger.debug("connecting to tenant:", tenant.name)
                    tenant_osh = tenant.report()
                    OSHVResult.add(tenant_osh)
                    OSHVResult.add(modeling.createLinkOSH("composition", openstack_osh, tenant_osh))

                    identity = tenant.name + ":" + username

                    novaApi = buildApi('openstack-nova', endpoint, identity, credential, NovaApi)
                    cinderApi = buildApi('openstack-cinder', endpoint, identity, credential, CinderApi)
                    glanceApi = buildApi('openstack-glance', endpoint, identity, credential, GlanceApi)
                    neutronApi = buildApi('openstack-neutron', endpoint, identity, credential, NeutronApi)

                    regions = novaApi.getConfiguredRegions()
                    if regions:
                        tenant_osh.setStringAttribute('credentials_id', protocol)

                    for tmp_region in regions:
                        logger.debug("region:", tmp_region)
                        region = openstack.Region(tmp_region)
                        region_osh = region.report(tenant_osh)
                        OSHVResult.add(region_osh)

                        OSHVResult.addAll(getZones(novaApi, region.name, region_osh, zoneOshDict))
                        logger.debug("zoneOshDict:", zoneOshDict)

                        OSHVResult.addAll(getImages(glanceApi, region.name, region_osh))
                        OSHVResult.addAll(getHypervisors(novaApi, region.name, region_osh))
                        OSHVResult.addAll(getVms(novaApi, region.name, region_osh, serverOshDict))

                        OSHVResult.addAll(getVolumes(cinderApi, region.name, region_osh, zoneOshDict, serverOshDict))
                        logger.debug("serverOshDict:", serverOshDict)

                        OSHVResult.addAll(getNetworks(neutronApi, region.name, region_osh, networkOshDict, openstack_osh))
                        logger.debug("networkOshDict:", networkOshDict)

                        OSHVResult.addAll(getPorts(neutronApi, region.name, serverOshDict, networkOshDict))

                        OSHVResult.addAll(getSubnets(neutronApi, region.name, networkOshDict, openstack_osh))

                        OSHVResult.addAll(getFlavors(novaApi, region.name, region_osh))
                except:
                    strException = str(sys.exc_info()[1])
                    excInfo = logger.prepareJythonStackTrace('')
                    logger.debug(strException)
                    logger.debug(excInfo)
                    pass
        except:
            strException = str(sys.exc_info()[1])
            excInfo = logger.prepareJythonStackTrace('')
            logger.debug(strException)
            logger.debug(excInfo)
            pass
        finally:
            if novaApi:
                Closeables.close(novaApi, True)
            if cinderApi:
                Closeables.close(cinderApi, True)
            if glanceApi:
                Closeables.close(glanceApi, True)
            if neutronApi:
                Closeables.close(neutronApi, True)

    reportError = OSHVResult.size() == 0
    if reportError:
        msg = 'Failed to connect using all protocols'
        logger.reportError(msg)
        logger.error(msg)
    return OSHVResult
Esempio n. 49
0
def DiscoveryMain(Framework):
    """
    Discovers MaxDb instances

    Available job parameters are:
    - dbProgPath
    - dbDataPath
    - processParams
    """
    vector = ObjectStateHolderVector()
    processPath = Framework.getDestinationAttribute('processPath')
    if not processPath:
        logger.reportError('Process path is empty')
        return vector
    ipaddress = Framework.getDestinationAttribute('ip_address')
    dbport = Framework.getDestinationAttribute('dbPort')
    protocol = Framework.getDestinationAttribute('Protocol')
    dbName = Framework.getDestinationAttribute('dbSid')
    shell = None
    try:
        try:
            client = Framework.createClient()
            shell = shellutils.ShellUtils(client)
            fs = file_system.createFileSystem(shell)
            xUserWithPath = maxdb_xuser.findXuserPath(fs, processPath, dbName)
            xUserCmd = maxdb_xuser.getXUserCmd(shell, xUserWithPath)
            xUserKey = maxdb_xuser.findXUser(xUserCmd, dbName)
            dbmCliWithPath = maxdb_discoverer.findDbmCliPath(fs, processPath)
            mdbCli = maxdb_discoverer.getDbmCli(shell, dbmCliWithPath)

            (state, schedulerState, autoextend) = discoverOrWarn(
                ('the operational state of the database instance',
                 mdbCli.db_state, xUserKey, dbName),
                ('whether the scheduler function is activated or deactivated',
                 mdbCli.scheduler_state, xUserKey, dbName),
                ('whether the automatic extension of data area is enabled',
                 mdbCli.auto_extend_show, xUserKey, dbName))

            sqlCliPath = maxdb_discoverer.findSqlCliPath(
                fs, processPath, dbName)
            sqlCli = maxdb_discoverer.getSqlCli(shell, sqlCliPath=sqlCliPath)

            autosave = None
            op_state = state and state.operationalState
            if op_state and maxdb_discoverer.DbStateEnum.is_online(op_state):
                (autosave, ) = discoverOrWarn((
                    'whether the automatic log backup function is activated or deactivated',
                    mdbCli.autolog_show, xUserKey, dbName), )

            (
                parameters, backupFiles, dataFiles, users, schemas
            ) = discoverOrWarn((
                'database parameters of the current database instance with their values',
                mdbCli.param_directgetall, xUserKey, dbName),
                               ('backup files', mdbCli.backup_history_list,
                                xUserKey, dbName),
                               ('data files', mdbCli.param_getvolsall,
                                xUserKey, dbName),
                               ('users',
                                ((sqlCli.sql_user_get, xUserKey),
                                 (mdbCli.user_getall, xUserKey, dbName))),
                               ('schemas', sqlCli.sql_schemas_get, xUserKey))
            database = maxdb.MaxDatabase(address=ipaddress,
                                         port=dbport,
                                         instance=dbName,
                                         state=op_state,
                                         autosave=autosave and autosave.state,
                                         scheduler=schedulerState
                                         and schedulerState.state,
                                         autoextend=autoextend
                                         and autoextend.state)

            add = vector.add
            addAll = vector.addAll

            maxDbTopologyBuilder = maxdb.MaxDb()
            databaseOsh = maxDbTopologyBuilder.buildDatabaseServerOsh(database)
            add(databaseOsh)

            if users:
                users = [
                    maxdb.MaxDbUser(user.userName, createdBy=user.dbOwner)
                    for user in users
                ]
                addAll(maxDbTopologyBuilder.buildUsersOsh(users, databaseOsh))
            if schemas:
                for item in schemas:
                    schema = maxdb.MaxDbSchema(item.schemaName,
                                               creationDate=item.createDate,
                                               createdBy=item.schemaOwner)
                    addAll(
                        maxDbTopologyBuilder.buildSchemaTopology(
                            schema, databaseOsh))

            if parameters:
                add(
                    maxDbTopologyBuilder.buildConfigFile(
                        parameters.parametersString, databaseOsh))
            if dataFiles:
                dataFiles = [
                    db.DataFile(dataFile.name, dataFile.size)
                    for dataFile in dataFiles
                ]
                addAll(
                    maxDbTopologyBuilder.buildDatafiles(
                        dataFiles, databaseOsh))

            if backupFiles:
                backupFiles = [
                    maxdb.BackupFile(backupFile.name, backupFile.start,
                                     backupFile.stop)
                    for backupFile in backupFiles
                ]
                addAll(
                    maxDbTopologyBuilder.buildBackupFiles(
                        backupFiles, databaseOsh))
        except JavaException, ex:
            logger.debugException('')
            strException = ex.getMessage()
            errormessages.resolveAndReport(strException, protocol, Framework)
        except:
            logger.debugException('')
            strException = str(sys.exc_info()[1])
            errormessages.resolveAndReport(strException, protocol, Framework)