def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    client = Framework.createClient()
    shell = shellutils.ShellFactory().createShell(client)

    # Image Id -> Image OSH
    imageDict = dict()
    # Container Id -> Container OSH
    containerDict = dict()
    # Container Id -> linked Container Id
    containerLinks = dict()

    # Node from Trigger
    nodeId = Framework.getTriggerCIData('hostId')
    nodeOSH = modeling.createOshByCmdbIdString("node", nodeId)
    OSHVResult.add(nodeOSH)

    # Trigger CI Running Software docker daemon
    dockerId = Framework.getTriggerCIData("triggerId")
    dockerDaemonOSH = modeling.createOshByCmdbIdString("docker_daemon",
                                                       dockerId)
    OSHVResult.add(dockerDaemonOSH)

    # Docker version for docker daemon
    versionOutput = shell.execCmd('docker -v')
    if shell.getLastCmdReturnCode() == 0:
        dockerDaemonOSH.setAttribute('version', versionOutput.strip())
    else:
        Framework.reportError('Failed in command: docker version.')

    #Get Filesystem
    filesystemDict = dict()
    skipDockerVolume = getFilesystem(shell, filesystemDict)

    # Docker
    dockerOSH = ObjectStateHolder('docker')
    dockerOSH.setAttribute('name', 'Docker')
    dockerOSH.setContainer(nodeOSH)
    OSHVResult.add(dockerOSH)
    dockerDaemonLink = modeling.createLinkOSH('membership', dockerOSH,
                                              dockerDaemonOSH)
    OSHVResult.add(dockerDaemonLink)
    dockerNodeLink = modeling.createLinkOSH('dependency', dockerOSH, nodeOSH)
    OSHVResult.add(dockerNodeLink)

    discoverDockerImage(shell, imageDict, nodeOSH, OSHVResult, Framework)

    discoverDockerContainer(shell, skipDockerVolume, filesystemDict,
                            containerDict, containerLinks, imageDict,
                            dockerDaemonOSH, nodeOSH, client, Framework,
                            OSHVResult)

    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    client = Framework.createClient()
    shell = shellutils.ShellFactory().createShell(client)

    # Image Id -> Image OSH
    imageDict = dict()
    # Container Id -> Container OSH
    containerDict = dict()
    # Container Id -> linked Container Id
    containerLinks = dict()

    # Node from Trigger
    nodeId = Framework.getTriggerCIData('hostId')
    nodeOSH = modeling.createOshByCmdbIdString("node", nodeId)
    OSHVResult.add(nodeOSH)

    # Trigger CI Running Software docker daemon
    dockerId = Framework.getTriggerCIData("triggerId")
    dockerDaemonOSH = modeling.createOshByCmdbIdString("docker_daemon", dockerId)
    OSHVResult.add(dockerDaemonOSH)

    # Docker version for docker daemon
    versionOutput = shell.execCmd('docker -v')
    if shell.getLastCmdReturnCode() == 0:
        dockerDaemonOSH.setAttribute('version', versionOutput.strip())
    else:
        Framework.reportError('Failed in command: docker version.')

    #Get Filesystem
    filesystemDict = dict()
    skipDockerVolume = getFilesystem(shell, filesystemDict)

    # Docker
    dockerOSH = ObjectStateHolder('docker')
    dockerOSH.setAttribute('name', 'Docker')
    dockerOSH.setContainer(nodeOSH)
    OSHVResult.add(dockerOSH)
    dockerDaemonLink = modeling.createLinkOSH('membership', dockerOSH, dockerDaemonOSH)
    OSHVResult.add(dockerDaemonLink)
    dockerNodeLink = modeling.createLinkOSH('dependency', dockerOSH, nodeOSH)
    OSHVResult.add(dockerNodeLink)

    discoverDockerImage(shell, imageDict, nodeOSH, OSHVResult, Framework)

    discoverDockerContainer(shell, skipDockerVolume, filesystemDict, containerDict, containerLinks, imageDict, dockerDaemonOSH, nodeOSH, client, Framework, OSHVResult)

    return OSHVResult
Example #3
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    shell = None
    protocol = Framework.getDestinationAttribute('Protocol')
    try:
        try:
            try:
                hostName = Framework.getDestinationAttribute('hostname')
                msMqManagerUcmdbId = Framework.getDestinationAttribute('msmq_id')
                msMqManagerOsh = modeling.createOshByCmdbIdString('msmqmanager', msMqManagerUcmdbId)
                client = Framework.createClient()
                shell = shellutils.ShellUtils(client)
                msMqDiscoverer = MsMqDiscoverer(shell, msMqManagerOsh, hostName)
                if msMqDiscoverer:
                    msMqDiscoverer.discover()
                    msMqDiscoverer.addResultsToVector(OSHVResult)
            finally:
                try:
                    shell and shell.closeClient()
                except:
                    logger.debugException('')
                    logger.error('Unable to close shell')
                if OSHVResult.size() == 0:
                    raise Exception, "Failed getting information about Microsoft Message Queue"

        except JavaException, ex:
            msg =ex.getMessage()
            errormessages.resolveAndReport(msg, protocol, Framework)
    except:
        msg = logger.prepareJythonStackTrace('')
        errormessages.resolveAndReport(msg, protocol, Framework)
    return OSHVResult
Example #4
0
def start_eapps_discovery(Framework, wse_path, shellUtils, OSHVResult,
                          protocol, HOST_ID, WEBSERVER_ID):

    wsefile = Framework.getParameter('eappsCfgPath')
    path = wse_path
    if protocol == 'ntcmd':
        if (wsefile == None or wsefile == ''):
            wsefile = '%s\\BIN\\eapps.cfg' % wse_path
        sarmLogFolder = wse_path + '\\log'
    else:
        if (wsefile == None or wsefile == ''):
            wsefile = '%s/eapps.cfg' % wse_path
        sarmLogFolder = wse_path + '/log'

    data = None
    try:
        data = shellUtils.safecat(wsefile)
        if not data:
            raise ValueError
    except:
        raise ConfigFileNotFoundException

    webserverOSH = modeling.createOshByCmdbIdString('webserver', WEBSERVER_ID)
    if webserverOSH is not None:
        parseCfgFileData(data, path, sarmLogFolder, shellUtils, webserverOSH,
                         OSHVResult, HOST_ID, Framework)
    else:
        raise ValueError, 'failed creating webserver OSH from eapps.cfg'
Example #5
0
def discoverITS(client, installpath, WEBSERVER_ID, OSHVResult):

    shellUtils = ShellUtils(client)

    webserverOSH = modeling.createOshByCmdbIdString('webserver', WEBSERVER_ID)

    sapitsOSH = ObjectStateHolder('sap_its_wgate')
    sapitsOSH.setAttribute('data_name', 'ITS_' + client.getIpAddress())
    sapitsOSH.setContainer(webserverOSH)
    OSHVResult.add(sapitsOSH)

    mapInstanceNameToAgate = getAgates(shellUtils, installpath, sapitsOSH, OSHVResult)

    filePath = installpath + '\\config\\ItsRegistryALL.xml'
    data = shellUtils.safecat(filePath)

    logger.debug('got ItsRegistryALL file')
    # data = stripNtcmdHeaders(data)
    if data == None or error(data):
        logger.error('No data found')
    else:
        builder = SAXBuilder(0)
        doc = builder.build(StringReader(data))
        root = doc.getRootElement()
        keyElem = getElementByAttrValue(root, 'key', 'name', 'AGate')
        instancesRoot = getElementByAttrValue(keyElem, 'key', 'name', 'Instances')
        instances = instancesRoot.getChildren('value')
        it = instances.iterator()
        while it.hasNext():
            instance = it.next()
            name = instance.getText()
            agates = mapInstanceNameToAgate.get(name)
            if agates != None and agates.isEmpty() == 0:
                servers(name, installpath, sapitsOSH, agates, shellUtils, OSHVResult)
Example #6
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    shell = None
    protocol = Framework.getDestinationAttribute('Protocol')
    try:
        try:
            try:
                hostName = Framework.getDestinationAttribute('hostname')
                msMqManagerUcmdbId = Framework.getDestinationAttribute(
                    'msmq_id')
                msMqManagerOsh = modeling.createOshByCmdbIdString(
                    'msmqmanager', msMqManagerUcmdbId)
                client = Framework.createClient()
                shell = shellutils.ShellUtils(client)
                msMqDiscoverer = MsMqDiscoverer(shell, msMqManagerOsh,
                                                hostName)
                if msMqDiscoverer:
                    msMqDiscoverer.discover()
                    msMqDiscoverer.addResultsToVector(OSHVResult)
            finally:
                try:
                    shell and shell.closeClient()
                except:
                    logger.debugException('')
                    logger.error('Unable to close shell')
                if OSHVResult.size() == 0:
                    raise Exception, "Failed getting information about Microsoft Message Queue"

        except JavaException, ex:
            msg = ex.getMessage()
            errormessages.resolveAndReport(msg, protocol, Framework)
    except:
        msg = logger.prepareJythonStackTrace('')
        errormessages.resolveAndReport(msg, protocol, Framework)
    return OSHVResult
def disWinOS(host_obj, shell, Framework, langBund, softNameToInstSoftOSH=None):
    host = modeling.createOshByCmdbIdString("host", host_obj)
    resultsVector = ObjectStateHolderVector()
    if not NTCMD_HR_REG_Software_Lib.doSoftware(shell, host, resultsVector, softNameToInstSoftOSH):
        discoverSoftwareByWmic(shell, host, resultsVector, softNameToInstSoftOSH)

    wmiProvider = getWmiProvider(shell)
    hostDiscoverer = WmiHostDiscoverer(wmiProvider)
    if hostDiscoverer.isWin2008():
        softwares = discover2008Hotfixes(wmiProvider, host)
        for software in softwares:
            if not software.osh:
                continue
            if softNameToInstSoftOSH is not None:
                if software.name in softNameToInstSoftOSH:
                    continue
                softNameToInstSoftOSH[software.name] = software.osh
            resultsVector.add(software.osh)

    elif hostDiscoverer.isWindows8_2012():
        softwares = discover2012Hotfixes(wmiProvider, host)
        for software in softwares:
            if not software.osh:
                continue
            if softNameToInstSoftOSH is not None:
                if software.name in softNameToInstSoftOSH:
                    continue
                softNameToInstSoftOSH[software.name] = software.osh
            resultsVector.add(software.osh)
        softwareList = WindowsAppsDiscoverer(shell).discover()
        softwareOshVector = InstalledSoftwareReporter().reportAll(softwareList, host)
        resultsVector.addAll(softwareOshVector)

    return resultsVector
def start_eapps_discovery(Framework, wse_path, shellUtils, OSHVResult, protocol, HOST_ID, WEBSERVER_ID):

	wsefile = Framework.getParameter('eappsCfgPath')
	path = wse_path
	if protocol == 'ntcmd':
		if (wsefile == None or wsefile == ''):
			wsefile  = '%s\\BIN\\eapps.cfg' % wse_path
		sarmLogFolder = wse_path + '\\log'
	else:
		if (wsefile == None or wsefile == ''):
			wsefile  = '%s/eapps.cfg' % wse_path
		sarmLogFolder = wse_path + '/log'

	data = None
	try:
		data = shellUtils.safecat(wsefile)
		if not data:
			raise ValueError
	except:
		raise ConfigFileNotFoundException

	webserverOSH = modeling.createOshByCmdbIdString('webserver', WEBSERVER_ID)
	if webserverOSH is not None:
		parseCfgFileData(data, path, sarmLogFolder, shellUtils, webserverOSH, OSHVResult, HOST_ID, Framework)
	else:
		raise ValueError, 'failed creating webserver OSH from eapps.cfg'
Example #9
0
def reportDeleteConnectedShell(Framework):
    shellId = Framework.getDestinationAttribute('shellId')
    shellOsh = modeling.createOshByCmdbIdString('shell', shellId)
    Framework.deleteObject(shellOsh)
    Framework.flushObjects()

    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Example #10
0
def disSunOS(hostId, client, Framework=None, langBund=None):
    ''' Discover physical memory and swap memory on SunOs 
    str, Shell, Framework, Properties -> oshVector
    @command: /usr/sbin/prtconf
    @command: swap -l
    '''
    myVec = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)
    output = None
    try:
        output = client.execCmd(
            '/usr/sbin/prtconf',
            120000)  #V@@CMD_PERMISION tty protocol execution
        if not output or client.getLastCmdReturnCode() != 0:
            raise ValueError
    except:
        logger.warn("Failed getting memory size from prtconf")
    else:
        compiled = re.compile('Memory size: (\d+) Megabytes')
        matches = compiled.findall(output)

        totalMemorySizeInMegabytes = 0
        for match in matches:
            totalMemorySizeInMegabytes += int(match)

        if totalMemorySizeInMegabytes:
            memory.report(myVec, hostOsh, totalMemorySizeInMegabytes * 1024)

    # > swap -l
    #swapfile             dev  swaplo blocks   free
    #/dev/dsk/c1t0d0s1   32,25     16 1058288 1021616
    #/swapfile             -       16 7329776 7293968
    try:
        output = client.execAlternateCmds(
            '/usr/sbin/swap -l', '/etc/swap -l',
            'swap -l')  #V@@CMD_PERMISION tty protocol execution
        if not output or client.getLastCmdReturnCode() != 0:
            raise ValueError
    except:
        logger.warn("Failed getting swap size from 'swap'")
    else:
        totalSwapSizeInMegabytes = 0
        lines = output.split('\n')
        for line in lines:
            if line:
                line = line.strip()
                if re.search("swapfile\s+dev\s+swaplo\s+blocks\s+free", line):
                    continue
                matcher = re.match(".*\d+\s+(\d+)\s+\d+$", line)
                if matcher:
                    swapSizeInMegabytes = int(
                        matcher.group(1)) / 2048  # 1 block = 512 bytes
                    totalSwapSizeInMegabytes += swapSizeInMegabytes

        if totalSwapSizeInMegabytes:
            modeling.setHostSwapMemorySizeAttribute(hostOsh,
                                                    totalSwapSizeInMegabytes)

    myVec.add(hostOsh)
    return myVec
Example #11
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    logger.info('Starting HACMP Applications')
    hostIP = Framework.getDestinationAttribute('ip_address')
    logger.debug('Host IP: ', hostIP)
    cluster = Framework.getDestinationAttribute('cluster')
    hostOS = Framework.getDestinationAttribute('host_os')
    hostOS = hostOS or 'NA'
    protocolName = Framework.getDestinationAttribute('Protocol')
    hostId = Framework.getDestinationAttribute('hostId')
    ##  Get Parameter Section
    cldisp_command = Framework.getParameter('cldisp_command') or 'cldisp'
    cllsif_command = Framework.getParameter('cllsif_command') or 'cllsif'

    try:
        client = Framework.createClient()
        shell = ShellUtils(client)
        #   If we get  good client connection , run the client commands to get the Application information for the cluster
        HostOSH = modeling.createOshByCmdbIdString('host', hostId)
        ClusterOSH = getclusterOSH(cluster)
        appDictionary = getapplicationInfo(shell, cldisp_command, Framework)
        resourceDictionary = getresourceinfo(shell, cllsif_command)
        OSHVResult.addAll(
            createserviceapplicationOSH(shell, appDictionary,
                                        resourceDictionary, HostOSH,
                                        ClusterOSH, Framework))
        client.close()
    except JavaException, ex:
        strException = ex.getMessage()
        logger.debugException('')
        errormessages.resolveAndReport(strException, protocolName, Framework)
Example #12
0
def makeUserOSH(hostCmdbId, userName, desc, uid, gid, homeDir):
    'host OSH, str, str, str, str, str -> OSH vector'
    iuid = -1
    igid = -1
    try:
        iuid = Long(uid)
    except:
        iuid = -1

    try:
        igid = Long(gid)
    except:
        igid = -1

    myVec = ObjectStateHolderVector()

    u_obj = ObjectStateHolder('osuser')
    host_objSH = modeling.createOshByCmdbIdString('host', hostCmdbId)
    u_obj.setContainer(host_objSH)

    u_obj.setAttribute('data_name', userName)
    if(len(uid) > 0):
        u_obj.setAttribute('user_id', Long(iuid))
    if(len(gid) > 0):
        u_obj.setAttribute('group_id', Long(igid))
    if(len(desc) > 0):
        u_obj.setAttribute('data_note', desc)
    if(len(homeDir) > 0):
        u_obj.setAttribute('homedir', homeDir)
    myVec.add(u_obj)

    return(myVec)
def DiscoveryMain(Framework):
    version = Framework.getDestinationAttribute('siebelVersion')
    siebelRootDir = Framework.getDestinationAttribute('siebelInstallDir')

    OSHVResult = ObjectStateHolderVector()
    appServerId = Framework.getDestinationAttribute('id')
    appServerOSH = modeling.createOshByCmdbIdString('siebel_app_server',
                                                    appServerId)
    modeling.setAppServerType(appServerOSH)

    client = None
    try:
        client = Framework.createClient()
        discoverConfigFile(siebelRootDir, appServerOSH, client, version,
                           OSHVResult)
    except:
        errmsg = 'Connection failed: %s' % str(sys.exc_info()[1]).strip()
        Framework.reportError(errmsg)
        logger.debugException(errmsg)

    if (client != None):
        try:
            client.close()
        except:
            pass

    return OSHVResult
Example #14
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    try:
        hostId = Framework.getDestinationAttribute('hostId')
        hostOsh = modeling.createOshByCmdbIdString('host_node', hostId)

        snmpClient = Framework.createClient()
        try:
            cssDiscoverer = createCssDiscoverer(snmpClient, Framework,
                                                OSHVResult, hostOsh)
            cssDiscoverer.discoverContentRules()
            cssDiscoverer.discoverServices()
        finally:
            snmpClient.close()
    except NoCssException:
        errobj = errorobject.createError(
            errorcodes.CSS_NOT_FOUND_ON_TARGET_HOST, None,
            'CSS was not found on target host')
        logger.reportErrorObject(errobj)
    except:
        errorMessage = logger.prepareJythonStackTrace('')
        logger.error(errorMessage)
        errormessages.resolveAndReport(errorMessage, 'SNMP', Framework)

    return OSHVResult
Example #15
0
def DiscoveryMain(Framework):

    protocolName = "NTCMD"

    OSHVResult = ObjectStateHolderVector()
    param = Framework.getParameter('discoverSoftware')
    if (param != None) and not Boolean.parseBoolean(param):
        logger.debug(
            'No discovery for software by NTCMD, parameter discoverSoftware is false'
        )
        return OSHVResult

    hostID = Framework.getDestinationAttribute('hostId')

    hostOSH = modeling.createOshByCmdbIdString('host', hostID)

    clientShUtils = None
    try:
        props = Properties()
        props.setProperty(AgentConstants.PROP_NTCMD_AGENT_COMMAND_TIMEOUT,
                          '100000')
        client = Framework.createClient(props)
        if client is None:
            raise Exception, 'Failed to create NTCMD client'
    except Exception, ex:
        strException = ex.getMessage()
        errormessages.resolveAndReport(strException, protocolName, Framework)
Example #16
0
    def _createHostOsh(self):
        ''' method creates containing host OSH depending on settings in XML and discovered data '''

        appComponent = self.getApplicationComponent()

        if appComponent.isClustered():
            # clustered applications should use weak hosts by IP
            hostIp = self._applicationIp

            if hostIp and ip_addr.IPAddress(hostIp).get_is_private():
                hostIp = self.getConnectionIp()

            if not hostIp:
                raise applications.ApplicationSignatureException("Cannot report application since no valid host IP is found")

            logger.debug(" -- clustered application uses host by IP '%s'" % hostIp)

            self.hostOsh = modeling.createHostOSH(hostIp)
        else:
            # non-clustered applications use host by hostId

            self.hostOsh = self.getApplicationComponent().getHostOsh()
            logger.debug(self.hostOsh)

            if self.hostOsh:
                logger.debug(" -- application uses host by Host OSH")
            else:
                logger.debug(" -- application uses host by CMDB ID")
                hostId = self.getApplicationComponent().getHostId()
                if hostId:
                    self.hostOsh = modeling.createOshByCmdbIdString('host', hostId)
Example #17
0
def get_common_topology_context(discoverer, dnsresolver, installpath, config):
    discovererRegistry = {}
    discovererRegistry[baseCits.node] = partial(discoverer.getDeploymentHosts,
                                                Sfn(dnsresolver.resolve_ips))
    discovererRegistry[baseCits.ip] = hana_host.Host.ips.fget
    discovererRegistry[cits.hanadb] = discoverer.getHanaDatabaseServer
    discovererRegistry[cits.hanadbInstance] = lambda host: discoverer.getHanaDatabaseInstance(host.name)
    discovererRegistry[baseCits.configFile] = lambda dbServer: discoverer.getHanaDbConfigFiles()
    discovererRegistry[baseCits.ipServiceEndpoint] = lambda host: discoverer.getHanaDbInstanceEndpoints(host.name)

    discovererRegistry[dbCits.schema] = lambda dbServer: discoverer.getHanaDbSchemas()
    discovererRegistry[dbCits.user] = lambda dbServer: discoverer.getHanaDbUsers()
    discovererRegistry[dbCits.dataFile] = lambda db_instance: discoverer.getHanaDbDataFiles(db_instance)
    discovererRegistry[dbCits.logFile] = lambda db_instance: discoverer.getHanaDbLogFiles(db_instance)
    discovererRegistry[dbCits.traceFile] = lambda db_instance: discoverer.getHanaDbTraceFiles(db_instance)

#        linkage condition
    discovererRegistry[(dbCits.user, baseCits.ownership, dbCits.schema)] = lambda user, schema: schema.owner == user.name
    discovererRegistry[(cits.hanadbInstance, baseCits.usage, baseCits.ipServiceEndpoint)] = lambda hana_instance, endpoint: endpoint.getAddress() == hana_instance.hostname and endpoint.getPortType() == hana.PortTypeEnum.HANA
    discovererRegistry[(cits.hanadb, baseCits.membership, cits.hanadbInstance)] = lambda hanaDb, hanaInstance: True
    discovererRegistry[(baseCits.node, baseCits.containment, baseCits.ip)] = lambda host, ip: ip in host.ips

    pdoBuilderRegistry = {}
    pdoBuilderRegistry[cits.hanadbInstance] = lambda instance: buildDatabaseInstancePdo(instance, installpath, sid=config.sid)
    pdoBuilderRegistry[dbCits.user] = buildDbUserPdoFromDatabaseUser
    pdoBuilderRegistry[baseCits.ipServiceEndpoint] = partial(buildEndpointPdoFromEndpoint, Sfn(dnsresolver.resolve_ips))

    #Should be coming from core hana_topology module
    baseTopologyBuilderRegistry = {
       # ignore the name as it is could be an alias and not a real hostname
       baseCits.node: lambda node_pdo: hana_host.Builder().build_host(node_pdo._replace(name=None)),
       baseCits.ip: modeling.createIpOSH,
       baseCits.configFile: fptools.partiallyApply(modeling.createConfigurationDocumentOshByFile, fptools._, None),
       baseCits.ipServiceEndpoint: netutils.ServiceEndpointBuilder().visitEndpoint
    }

    linkReporter = hana.LinkReporter()
    linkReporterRegistry = {
        baseCits.containment: linkReporter.reportContainment,
        baseCits.composition: linkReporter.reportComposition,
        baseCits.membership: lambda do1, osh1, do2, osh2: linkReporter.reportMembership(osh1, osh2),
        baseCits.ownership: lambda do1, osh1, do2, osh2: linkReporter.reportOwnership(osh1, osh2),
        baseCits.usage: lambda do1, osh1, do2, osh2: linkReporter.reportUsage(osh1, osh2),
        baseCits.replicated: hana.DatabaseTopologyReporter().reportReplication,
    }

    topologyBuilderRegistry = {}
    topologyBuilderRegistry.update(baseTopologyBuilderRegistry)
    topologyBuilderRegistry.update(linkReporterRegistry)

    dbTopologyBuilder = hana.DatabaseTopologyBuilder()
    topologyBuilderRegistry[cits.hanadb] = lambda _: modeling.createOshByCmdbIdString(cits.hanadb, config.hanadb_cmdbid)
    topologyBuilderRegistry[cits.hanadbInstance] = dbTopologyBuilder.buildDatabaseInstanceOsh
    topologyBuilderRegistry[dbCits.schema] = dbTopologyBuilder.buildSchemaOsh
    topologyBuilderRegistry[dbCits.user] = dbTopologyBuilder.buildUserOsh
    topologyBuilderRegistry[dbCits.dataFile] = dbTopologyBuilder.buildDataFileOsh
    topologyBuilderRegistry[dbCits.logFile] = dbTopologyBuilder.buildLogFileOsh
    topologyBuilderRegistry[dbCits.traceFile] = dbTopologyBuilder.buildTraceFileOsh

    return discovererRegistry, pdoBuilderRegistry, topologyBuilderRegistry
Example #18
0
def disLinux(hostId, shell, Framework = None, langBund = None):
    ''' Discover physical memory and swap memory on GNU/Linux 
    str, Shell, Framework, Properties -> oshVector
    @command: /usr/bin/free -m
    '''
    myVec = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)

    output = None
    try:
        output = shell.execCmd('/usr/bin/free -m')#V@@CMD_PERMISION tty protocol execution
        if not output or shell.getLastCmdReturnCode() != 0:
            raise ValueError
    except:
        logger.warn("Failed getting memory size from 'free'")
    else:
        lines = output.split('\n')
        for line in lines:
            if line:
                if re.search('cache', line):
                    continue
                matcher = re.match("Mem:\s+(\d+)\s+", line)
                if matcher:
                    memorySizeInMegabytes = int(matcher.group(1))
                    memorySizeInKilobytes = memorySizeInMegabytes * 1024
                    memory.report(myVec, hostOsh, memorySizeInKilobytes)
                else:
                    matcher = re.match("Swap:\s+(\d+)\s+", line)
                    if matcher:
                        swapMemorySizeInMegabytes = int(matcher.group(1))
                        modeling.setHostSwapMemorySizeAttribute(hostOsh, swapMemorySizeInMegabytes)

    myVec.add(hostOsh)
    return myVec
def reportDeleteConnectedShell(Framework):
    shellId = Framework.getDestinationAttribute('shellId')
    shellOsh = modeling.createOshByCmdbIdString('shell', shellId)
    Framework.deleteObject(shellOsh)
    Framework.flushObjects()

    Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Example #20
0
def checkUpgradeStatus(Framework):
    if Framework.getProperty(
            InventoryUtils.STATE_PROPERTY_AGENT_INSTALLED) is None:
        agentId = Framework.getDestinationAttribute('agentId')
        # in migration job
        if agentId is None or not len(str(agentId).strip()):
            Framework.reportError(
                inventoryerrorcodes.
                INVENTORY_DISCOVERY_FAILED_AGENT_INSTALL_AFTER_UNINTALL, None)
            Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
            return
        logger.debug(
            'Old agent was uninstalled but failed to install new one. Upgrade process failed. Sending to delete UD agent object'
        )
        agentOsh = modeling.createOshByCmdbIdString(
            ClientsConsts.DDM_AGENT_PROTOCOL_NAME, agentId)
        Framework.deleteObject(agentOsh)
        logger.debug("Restore Non UDA Shell since the UDA has been removed.")
        AgentUtils.reportNonUDAShell(Framework)
        Framework.flushObjects()
        Framework.reportError(
            inventoryerrorcodes.
            INVENTORY_DISCOVERY_FAILED_AGENT_INSTALL_AFTER_UNINTALL, None)
        Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
    else:
        logger.debug('Upgrade UDA is successful.')
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Example #21
0
def triggered_on_ipse_only(discoverer, pdadmin, http_executor, dnsresolver,
                           destination_address, protocol, credential_id,
                           ipse_id):
    oshs = []
    warnings = []
    reporter = webseal_topology.Reporter()
    webseal_osh_by_name, warning = flow.discover_or_warn(
        'webseal servers',
        discover_webseal_topology,
        discoverer,
        reporter,
        dnsresolver,
        credential_id,
        protocol_name=protocol)

    if not warning:
        endpoint_osh = modeling.createOshByCmdbIdString(
            'ip_service_endpoint', ipse_id)
        for webseal_osh, _, _, oshs_ in webseal_osh_by_name.values():
            oshs.extend(oshs_)
            oshs.append(
                reporter.link_reporter.report_usage(webseal_osh, endpoint_osh))
    else:
        warnings.append(warning)

    return oshs, warnings
Example #22
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    logger.info ("Starting IMS Discovery")
    DiscoverIMSDB = Boolean.parseBoolean(Framework.getParameter('DiscoverIMSDB'))

    # create LPAR node from the ID passed in
    hostId = Framework.getDestinationAttribute(PARAM_HOST_ID)
    lparOsh = None

    if eview_lib.isNotNull(hostId):
        lparOsh = modeling.createOshByCmdbIdString('host_node', hostId)

    ls = eview_lib.EvShell(Framework)
    IMSSubSysDict = getIMSSubSys(ls, lparOsh)
    OSHVResult.addAll(getIMSActRegions(ls,lparOsh, IMSSubSysDict ))


    if DiscoverIMSDB and len(IMSSubSysDict) > 0:
        databaseAreaDictionary = {}
        databaseDictionary = {}
        OSHVResult.addAll(getIMSDB(ls, IMSSubSysDict,  databaseAreaDictionary , databaseDictionary))
        OSHVResult.addAll(getAREAs(ls, IMSSubSysDict,  databaseAreaDictionary , databaseDictionary))
        OSHVResult.addAll(processPrograms(ls,IMSSubSysDict, Framework))
    ls.closeClient()

    logger.info ("Finished IMS Discovery")
    return OSHVResult
Example #23
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    jobId = Framework.getDiscoveryJobId()
    host_id = Framework.getDestinationAttribute('id')
    host_name = Framework.getTriggerCIData('host_name')
    dnsServers = Framework.getTriggerCIDataAsList('dnsServers') or None

    try:
        host_name = host_name.split(" ")
        ips = pi_utils.getIPs(host_name[0], Framework)

        if not ips:
            raise ValueError()

        hostOSH = modeling.createOshByCmdbIdString('node', host_id)
        modeling.addHostAttributes(hostOSH, None, host_name[0])
        #OSHVResult.add(hostOSH)

        for ip in ips:
            ipRes = pi_utils.getIPOSHV(Framework, ip, None, dnsServers, False,
                                       True)
            if ipRes.size() > 0:
                OSHVResult.add(
                    modeling.createLinkOSH('containment', hostOSH,
                                           modeling.createIpOSH(ip)))
                OSHVResult.addAll(ipRes)
        if OSHVResult.size() <= 0:
            raise ValueError()
    except Exception, e:
        msg = logger.prepareJythonStackTrace(
            "Error getting IPs for %s: " % (host_name), e)
        errormessages.resolveAndReport(msg, jobId, Framework)
        logger.error(msg)
Example #24
0
def build_network_device(device):
    '''
    Build Layer 2 connection end.
    @type param: NetworkDevice -> OSH
    '''
    device_osh = None
    device_ip_address_osh = None
    device_interface_osh = None
    device_member_ip = None
    if device.ucmdb_id:
        device_osh = modeling.createOshByCmdbIdString('node', device.ucmdb_id)
    if device.mac_address:
        if not device_osh:
            device_osh = modeling.createCompleteHostOSH('node', device.mac_address)
        device_interface_osh = modeling.createInterfaceOSH(device.mac_address, device_osh)
    if device.ip_address:
        if not device_osh:
            device_osh = modeling.createHostOSH(device.ip_address)
        device_ip_address_osh = modeling.createIpOSH(device.ip_address)
        device_member_ip = modeling.createLinkOSH('contained', device_osh, device_ip_address_osh)
    if device.port:
        if device_interface_osh:
            device_interface_osh.setAttribute('interface_name', device.port)
        elif device_osh:
            device_interface_osh = ObjectStateHolder('interface')
            device_interface_osh.setContainer(device_osh)
            device_interface_osh.setAttribute('interface_name', device.port)
    return device_osh, device_ip_address_osh, device_interface_osh, device_member_ip
Example #25
0
def makeUserOSH(hostCmdbId, userName, desc, uid, gid, homeDir):
    'host OSH, str, str, str, str, str -> OSH vector'
    iuid = -1
    igid = -1
    try:
        iuid = Long(uid)
    except:
        iuid = -1

    try:
        igid = Long(gid)
    except:
        igid = -1

    myVec = ObjectStateHolderVector()

    u_obj = ObjectStateHolder('osuser')
    host_objSH = modeling.createOshByCmdbIdString('host', hostCmdbId)
    u_obj.setContainer(host_objSH)

    u_obj.setAttribute('data_name', userName)
    if (len(uid) > 0):
        u_obj.setAttribute('user_id', Long(iuid))
    if (len(gid) > 0):
        u_obj.setAttribute('group_id', Long(igid))
    if (len(desc) > 0):
        u_obj.setAttribute('data_note', desc)
    if (len(homeDir) > 0):
        u_obj.setAttribute('homedir', homeDir)
    myVec.add(u_obj)

    return (myVec)
Example #26
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    # # Write implementation to return new result CIs here...
    ipList = Framework.getTriggerCIDataAsList('PHYSICAL_IP_ADDRESS')
    portList = Framework.getTriggerCIDataAsList('PHYSICAL_PORT')
    service_context = Framework.getDestinationAttribute('SERVICE_CONTEXT')
    service_type = Framework.getDestinationAttribute('SERVICE_TYPE')
    cluster_id = Framework.getDestinationAttribute('CLUSTER_ID')
    application_resource_id = Framework.getDestinationAttribute('APPLICATION_RESOURCE_ID')
    cluster_root_class = Framework.getDestinationAttribute('CLUSTER_CLASS')
    application_resource_class = Framework.getDestinationAttribute('APPLICATION_RESOURCE_CLASS')
    SCPId = Framework.getDestinationAttribute('id')

    clusterOsh = modeling.createOshByCmdbIdString(cluster_root_class, cluster_id)

    OSHVResult.addAll(scp.createCPLink(application_resource_id, application_resource_class, cluster_id,
                                       cluster_root_class, SCPId, service_context))
    
    for index in range(len(ipList)):
        scpOsh = scp.createScpOsh(clusterOsh, service_type, ip=ipList[index], port=portList[index], context=service_context)
        ipOsh = modeling.createIpOSH(ipList[index])
        OSHVResult.add(scpOsh)
        OSHVResult.add(ipOsh)           

    return OSHVResult
Example #27
0
def disVMKernel(hostId, shell, Framework = None, langBund = None):
    ''' Discover physical memory on VMKernel 
    str, Shell, Framework, Properties -> oshVector
    @raise ValueError: memory size is not a digit
    @command: esxcfg-info -F xml | sed -n \'/<memory-info>/,/<\/memory-info>/p\'
    '''
    resVec = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)

    xml = shell.execCmd('esxcfg-info -F xml | sed -n \'/<memory-info>/,/<\/memory-info>/p\' | sed -n \'1,/<\/memory-info>/p\'')
    #Cleanup retrieved xml. Sometimes there is some debug info added
    xml = xml[xml.find('<'): xml.rfind('>') + 1]

    builder = SAXBuilder(0)
    document = builder.build(StringReader(xml))
    rootElement = document.getRootElement()

    memory_values = rootElement.getChild('aux-source-memory-stats').getChildren('value')
    for value in memory_values:
        if value.getAttributeValue('name') == 'physical-memory-est.':
            memorySizeInKilobytes = int(value.getText())
            memory.report(resVec, hostOsh, memorySizeInKilobytes)
    #TODO: Implement swap discovery for vmkernel
    resVec.add(hostOsh)
    return resVec
Example #28
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    # # Write implementation to return new result CIs here...
    ipList = Framework.getTriggerCIDataAsList('PHYSICAL_IP_ADDRESS')
    portList = Framework.getTriggerCIDataAsList('PHYSICAL_PORT')
    service_context = Framework.getDestinationAttribute('SERVICE_CONTEXT')
    service_type = Framework.getDestinationAttribute('SERVICE_TYPE')
    cluster_id = Framework.getDestinationAttribute('CLUSTER_ID')
    application_resource_id = Framework.getDestinationAttribute(
        'APPLICATION_RESOURCE_ID')
    cluster_root_class = Framework.getDestinationAttribute('CLUSTER_CLASS')
    application_resource_class = Framework.getDestinationAttribute(
        'APPLICATION_RESOURCE_CLASS')
    SCPId = Framework.getDestinationAttribute('id')

    clusterOsh = modeling.createOshByCmdbIdString(cluster_root_class,
                                                  cluster_id)

    OSHVResult.addAll(
        scp.createCPLink(application_resource_id, application_resource_class,
                         cluster_id, cluster_root_class, SCPId,
                         service_context))

    for index in range(len(ipList)):
        scpOsh = scp.createScpOsh(clusterOsh,
                                  service_type,
                                  ip=ipList[index],
                                  port=portList[index],
                                  context=service_context)
        ipOsh = modeling.createIpOSH(ipList[index])
        OSHVResult.add(scpOsh)
        OSHVResult.add(ipOsh)

    return OSHVResult
Example #29
0
def build_network_device(device):
    '''
    Build Layer 2 connection end.
    @type param: NetworkDevice -> OSH
    '''
    device_osh = None
    device_ip_address_osh = None
    device_interface_osh = None
    device_member_ip = None
    if device.ucmdb_id:
        device_osh = modeling.createOshByCmdbIdString('node', device.ucmdb_id)
    if device.mac_address:
        if not device_osh:
            device_osh = modeling.createCompleteHostOSH(
                'node', device.mac_address)
        device_interface_osh = modeling.createInterfaceOSH(
            device.mac_address, device_osh)
    if device.ip_address:
        if not device_osh:
            device_osh = modeling.createHostOSH(device.ip_address)
        device_ip_address_osh = modeling.createIpOSH(device.ip_address)
        device_member_ip = modeling.createLinkOSH('contained', device_osh,
                                                  device_ip_address_osh)
    if device.port:
        if device_interface_osh:
            device_interface_osh.setAttribute('interface_name', device.port)
        elif device_osh:
            device_interface_osh = ObjectStateHolder('interface')
            device_interface_osh.setContainer(device_osh)
            device_interface_osh.setAttribute('interface_name', device.port)
    return device_osh, device_ip_address_osh, device_interface_osh, device_member_ip
def DiscoveryMain(Framework):
	version = Framework.getDestinationAttribute('siebelVersion')
	siebelRootDir = Framework.getDestinationAttribute('siebelInstallDir')

	OSHVResult = ObjectStateHolderVector()
	appServerId = Framework.getDestinationAttribute('id')
	appServerOSH = modeling.createOshByCmdbIdString('siebel_app_server', appServerId)
	modeling.setAppServerType(appServerOSH)

	client = None
	try:
		client = Framework.createClient()
		discoverConfigFile(siebelRootDir,appServerOSH,client,version,OSHVResult)
	except:
		errmsg = 'Connection failed: %s' % str(sys.exc_info()[1]).strip()
		Framework.reportError(errmsg)
		logger.debugException(errmsg)

	if(client != None):
		try:
			client.close()
		except:
			pass

	return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    hostId = Framework.getDestinationAttribute('hostId')
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)
    PROTOCOL_NAME = 'PowerShell'
    try:
        client = Framework.createClient()
        shell =shellutils.ShellUtils(client)
        discoverer = None
        try:
            for discovererClass in [msexchange_win_shell.Exchange2007Discoverer, msexchange_win_shell.Exchange2010Discoverer]:
                try:
                    discoverer = discovererClass(shell)
                    exchangeServers = discoverer.discover()
                    for exchangeServer in exchangeServers:
                        topoBuilder = msexchange.TopologyBuilder(exchangeServer, hostOsh, ipAddress, credentialsId)
                        OSHVResult.addAll(topoBuilder.build())
                        break
                except msexchange_win_shell.AddSnapInException:
                    logger.warn('Failed to import Snap-In.')
                    discoverer = None
            if not discoverer:
                raise Exception("Failed to discover MS-Exchange. See Logs for details.")
        finally:
            shell.closeClient()
    except JavaException, ex:
        logger.debugException('')
        strException = str(ex.getMessage())
        errormessages.resolveAndReport(strException, PROTOCOL_NAME, Framework)
Example #32
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    jobId = Framework.getDiscoveryJobId()
    host_id    = Framework.getDestinationAttribute('id')
    host_name = Framework.getTriggerCIData('host_name')
    dnsServers = Framework.getTriggerCIDataAsList('dnsServers') or None
        
    try:
        host_name = host_name.split(" ")
        ips = pi_utils.getIPs(host_name[0], Framework)
        
        if not ips:
            raise ValueError()
        
        hostOSH = modeling.createOshByCmdbIdString('node', host_id)
        modeling.addHostAttributes(hostOSH, None, host_name[0])
        #OSHVResult.add(hostOSH)       
        
        for ip in ips:
            ipRes = pi_utils.getIPOSHV(Framework, ip, None, dnsServers, False, True)
            if ipRes.size() > 0:               
                OSHVResult.add(modeling.createLinkOSH('containment',hostOSH,modeling.createIpOSH(ip)))
                OSHVResult.addAll(ipRes)
        if OSHVResult.size() <=0:
            raise ValueError()       
    except Exception, e:
        msg = logger.prepareJythonStackTrace("Error getting IPs for %s: " % (host_name), e)
        errormessages.resolveAndReport(msg, jobId, Framework)
        logger.error(msg)
def DiscoveryMain(Framework):
    resultCollection = ObjectStateHolderVector()

    hostId = Framework.getDestinationAttribute('hostId')
    hostIp = Framework.getDestinationAttribute('ip_address')
    nodeName = Framework.getDestinationAttribute('nodeName')

    client = None
    try:
        client = Framework.createClient()
        catalogUidToSqlMx = _discoverSqlMx(client, nodeName)
        catalogUidToMxSchema = {}
        if catalogUidToSqlMx:
            catalogUidToMxSchema = _discoverSqlMxSchemas(client)
            client.executeCmd('exit;', 0, 1)
        sqlmpList = _discoverSqlMp(client)
        client.executeCmd('exit;', 0, 1)
        hostOsh = modeling.createOshByCmdbIdString('host', hostId)
        resultCollection.add(hostOsh)
        _reportNonStopTopology(resultCollection, hostOsh, hostIp,
                               catalogUidToSqlMx, catalogUidToMxSchema,
                               sqlmpList)
    except Exception, ex:
        exInfo = ex.getMessage()
        errormessages.resolveAndReport(exInfo, ClientsConsts.SSH_PROTOCOL_NAME,
                                       Framework)
Example #34
0
def disVMKernel(hostId, shell, Framework=None, langBund=None):
    ''' Discover physical memory on VMKernel 
    str, Shell, Framework, Properties -> oshVector
    @raise ValueError: memory size is not a digit
    @command: esxcfg-info -F xml | sed -n \'/<memory-info>/,/<\/memory-info>/p\'
    '''
    resVec = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)

    xml = shell.execCmd(
        'esxcfg-info -F xml | sed -n \'/<memory-info>/,/<\/memory-info>/p\' | sed -n \'1,/<\/memory-info>/p\''
    )
    #Cleanup retrieved xml. Sometimes there is some debug info added
    xml = xml[xml.find('<'):xml.rfind('>') + 1]

    builder = SAXBuilder(0)
    document = builder.build(StringReader(xml))
    rootElement = document.getRootElement()

    memory_values = rootElement.getChild(
        'aux-source-memory-stats').getChildren('value')
    for value in memory_values:
        if value.getAttributeValue('name') == 'physical-memory-est.':
            memorySizeInKilobytes = int(value.getText())
            memory.report(resVec, hostOsh, memorySizeInKilobytes)
    #TODO: Implement swap discovery for vmkernel
    resVec.add(hostOsh)
    return resVec
Example #35
0
def disHPUX(host_obj, client, Framework = None, langBund = None, pid2Process = None):
	hostId = Framework.getDestinationAttribute('hostId')
	discoverProcesses = Boolean.parseBoolean(Framework.getParameter('discoverProcesses'))

	myVec = ObjectStateHolderVector()
	
	# Better format, but not supported on all HPUX systems
	#r = client.executeCmd('ps -e -o pid,time,sz,comm,args')
	r = client.execCmd('ps -ef')#V@@CMD_PERMISION tty protocol execution
	if r == None:
		return myVec

	lines = ''
	if(re.search('\r\n',r)):
		lines = r.split('\r\n')
	elif (re.search('\n',r)):
		lines = r.split('\n')
	else:
		return myVec
	processList = []
	pdu = None
	try:
		pdu = processdbutils.ProcessDbUtils(Framework)
		hostOSH = None
		for line in lines:
			## Reg for processes with args
			res = re.search('(\w+)\s+(\d+).*\s\d+\:\d\d\s([0-9a-zA-Z_.\[\]\-+:/]+)\s(.*)',line)
			if(res):
				cleanArgs = res.group(4)
			else:
				## Reg for processes with no args
				res = re.search('(\w+)\s+(\d+).*\s\d+\:\d\d\s([0-9a-zA-Z_.\-+:/]+)',line)
				if(res):
					cleanArgs = ''
			if(res):
				owner = res.group(1)
				commAndPath = res.group(3)
				pid = res.group(2)
				cleanCommand = ''
				if commAndPath.find('/') == -1:
					cleanCommand = commAndPath
				else:
					res2 = re.search('(.*/)([^/]+)',commAndPath)
					if (res2):
						cleanCommand = res2.group(2)
					else:
						continue
				if hostOSH == None:
					hostOSH = modeling.createOshByCmdbIdString('host', hostId)
				
				commandLine = cleanCommand + ' ' + cleanArgs
				addProcess(pdu, hostId, cleanCommand, pid, commandLine, commAndPath, cleanArgs, processList, discoverProcesses, myVec, hostOSH, None, owner)

		pdu.flushHostProcesses(hostId)
		if pid2Process is not None:
			pid2Process.putAll(pdu.getProcessCmdMap())
	finally:
		if pdu != None:
			pdu.close()
	return myVec
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    logger.info('Starting HACMP Applications')
    hostIP = Framework.getDestinationAttribute('ip_address')
    logger.debug ('Host IP: ',hostIP)
    cluster =  Framework.getDestinationAttribute('cluster')
    hostOS = Framework.getDestinationAttribute('host_os')
    hostOS = hostOS or 'NA'
    protocolName = Framework.getDestinationAttribute('Protocol')
    hostId = Framework.getDestinationAttribute('hostId')
    ##  Get Parameter Section
    cldisp_command = Framework.getParameter('cldisp_command') or 'cldisp'
    cllsif_command = Framework.getParameter('cllsif_command') or 'cllsif'

    try:
        client = Framework.createClient()
        shell = ShellUtils(client)
        #   If we get  good client connection , run the client commands to get the Application information for the cluster
        HostOSH = modeling.createOshByCmdbIdString('host', hostId)
        ClusterOSH = getclusterOSH(cluster)
        appDictionary = getapplicationInfo(shell,  cldisp_command,  Framework)
        resourceDictionary = getresourceinfo(shell, cllsif_command)
        OSHVResult.addAll(createserviceapplicationOSH (shell, appDictionary, resourceDictionary, HostOSH, ClusterOSH,   Framework))
        client.close()
    except JavaException, ex:
        strException = ex.getMessage()
        logger.debugException('')
        errormessages.resolveAndReport(strException, protocolName, Framework)
Example #37
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    # # Write implementation to return new result CIs here...
    ipList = Framework.getTriggerCIDataAsList('PHYSICAL_IP_ADDRESS')
    portList = Framework.getTriggerCIDataAsList('PHYSICAL_PORT')
    service_context = Framework.getDestinationAttribute('SERVICE_CONTEXT')
    service_type = Framework.getDestinationAttribute('SERVICE_TYPE')
    application_resource_id = Framework.getDestinationAttribute('APPLICATION_RESOURCE_ID')
    application_resource_class = Framework.getDestinationAttribute('APPLICATION_RESOURCE_CLASS')
    junction_id = Framework.getDestinationAttribute('JUNCTION_ID')
    junction_root_class = Framework.getDestinationAttribute('JUNCTION_CLASS')
    junction_name = Framework.getDestinationAttribute('JUNCTION_NAME')
    SCPId = Framework.getDestinationAttribute('id')

    junctionOsh = modeling.createOshByCmdbIdString(junction_root_class, junction_id)

    url = urlparse(service_context)
    if url:
        # get context root path from url
        path = url.path
        if path.startswith(junction_name + '/'):
            logger.info('Create one consumer-provider link between application and junction')
            OSHVResult.addAll(scp.createCPLink(application_resource_id, application_resource_class, junction_id,
                                               junction_root_class, SCPId, service_context))
            for index in range(len(ipList)):
                scpOsh = scp.createScpOsh(junctionOsh, service_type, ip=ipList[index], port=portList[index], context=service_context)
                logger.info('Create scp with ip %s and port %s' % (ipList[index], portList[index]))
                ipOsh = modeling.createIpOSH(ipList[index])
                OSHVResult.add(scpOsh)
                OSHVResult.add(ipOsh)

    return OSHVResult
Example #38
0
def buildNetDeviceOSHV(localFramework, netDeviceCmdbIdList, netDeviceNameList):
    try:
        returnOSHV = ObjectStateHolderVector()
        ## Check validity of provided lists
        if not netDeviceCmdbIdList:
            localFramework.reportError('Please check adapter parameter <netdevice_cmdbid>')
            return None
        if not netDeviceNameList:
            localFramework.reportError('Please check adapter parameter <netdevice_name>')
            return None
        if len(netDeviceCmdbIdList) != len(netDeviceNameList):
            localFramework.reportError('The lists <netdevice_cmdbid> and <netdevice_name> have different sizes: <%s> and <%s>! Please check adapter input configuration' \
                        % (len(netDeviceCmdbIdList), len(netDeviceNameList)))
            return None

        ## Build OSH and dict
        for netDeviceIndex in range(len(netDeviceCmdbIdList)):
            netDeviceCmdbId = netDeviceCmdbIdList[netDeviceIndex]
            netDeviceName = netDeviceNameList[netDeviceIndex]
            ## Check if attributes are good
            if not netDeviceCmdbId or not netDeviceName:
                logger.debug('Skipping invalid NetDevice name or CMDB ID in adapter input parameter...')
                continue
            ## Build OSH and add to OSHV
            netDeviceOSH = modeling.createOshByCmdbIdString('netdevice', netDeviceCmdbId)
            #netDeviceOSH.setAttribute('name', netDeviceName)
            netDeviceOSH.setAttribute('data_externalid', netDeviceName)
            ciscoworks_utils.debugPrint(4, '[' + SCRIPT_NAME + ':buildNetDeviceOSHV] Built OSH for NetDevice <%s> with CMDB ID <%s>' % (netDeviceName, netDeviceCmdbId))
            returnOSHV.add(netDeviceOSH)
        return returnOSHV
    except:
        excInfo = logger.prepareJythonStackTrace('')
        logger.warn('[' + SCRIPT_NAME + ':buildNetDeviceOSHV] Exception: <%s>' % excInfo)
        pass
Example #39
0
    def _createHostOsh(self):
        ''' method creates containing host OSH depending on settings in XML and discovered data '''

        appComponent = self.getApplicationComponent()

        if appComponent.isClustered():
            # clustered applications should use weak hosts by IP
            hostIp = self._applicationIp

            if hostIp and ip_addr.IPAddress(hostIp).get_is_private():
                hostIp = self.getConnectionIp()

            if not hostIp:
                raise applications.ApplicationSignatureException(
                    "Cannot report application since no valid host IP is found"
                )

            logger.debug(" -- clustered application uses host by IP '%s'" %
                         hostIp)

            self.hostOsh = modeling.createHostOSH(hostIp)
        else:
            # non-clustered applications use host by hostId

            self.hostOsh = self.getApplicationComponent().getHostOsh()
            logger.debug(self.hostOsh)

            if self.hostOsh:
                logger.debug(" -- application uses host by Host OSH")
            else:
                logger.debug(" -- application uses host by CMDB ID")
                hostId = self.getApplicationComponent().getHostId()
                if hostId:
                    self.hostOsh = modeling.createOshByCmdbIdString(
                        'host', hostId)
Example #40
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    ip = Framework.getDestinationAttribute('ip')
    port = Framework.getDestinationAttribute('port')
    scp_id = Framework.getDestinationAttribute('scp_id')
    apache_id = Framework.getDestinationAttribute('apache_id')
    apache_ip = Framework.getDestinationAttribute('apache_ip')
    contexts = Framework.getTriggerCIDataAsList('contexts')
    context_ids = Framework.getTriggerCIDataAsList('context_ids')

    localShell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))
    protocolName = ClientsConsts.HTTP_PROTOCOL_NAME
    connectionFailedMsgs = []
    protocolIds = findProperProtocolIds(ip, netutils.getAvailableProtocols(Framework, protocolName, ip) or [])

    if not protocolIds:
        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        logger.reportErrorObject(errobj)
        return OSHVResult

    httpClient, protocolId, version = findHttpProtocol(Framework, protocolName, protocolIds, ip, connectionFailedMsgs)
    if httpClient:
        apacheOsh = modeling.createOshByCmdbIdString('apache', apache_id)
        # create oam running software
        createOAMRunningSoftwareOsh(scp_id, ip, port, protocolId, version, apacheOsh, OSHVResult)
        # get oam policy content
        policy_content = getPolicyContent(httpClient, ip, protocolId, protocolName, version)
        # parse oam policy, get redirect urls
        authorization_policies = oam_policy_parser.parse_oam_policy(policy_content)
        redirect_policies = oam_policy_parser.get_redirect_policies(authorization_policies)
        # create oam dependency scp
        for index in range(0, len(contexts)):
            context, context_id = contexts[index], context_ids[index]
            if context_id:
                matched_policies = findMatchedRedirectPolicies(context, redirect_policies)
                apacheScpOsh = modeling.createOshByCmdbIdString('scp', context_id)
                for policy in matched_policies:
                    createOAMDependenyScp(localShell, apacheOsh, apacheScpOsh, policy.redirect_url, apache_ip, OSHVResult)

    if not OSHVResult.size():
        for msg in connectionFailedMsgs:
            errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolName], msg)
            logger.reportErrorObject(errobj)

    return OSHVResult
Example #41
0
def makeCPUOSH(hostId, cid, vendor='', speed='', usage='', data_name='',
               coreNumber=0, descr='', is_virtual = False):
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)
    cpuOsh = modeling.createCpuOsh(cid, hostOsh, speed, coreNumber, vendor,
                                   descr, data_name)
    if is_virtual:
        cpuOsh.setBoolAttribute('isvirtual', 1)
    return cpuOsh
Example #42
0
def getSiebelSoftwareInstallPath(shellUtils, HOST_ID):
	installPath = None
	try:
		hostOSH = modeling.createOshByCmdbIdString('host', HOST_ID)
		installPath = NTCMD_HR_REG_Software_Lib.getSoftwareInstallPath(shellUtils, hostOSH, 'SWEApp')
	except:
		logger.debugException('Failed to discover siebel software install path')
	return installPath
def businessProcesses(Framework, solman, component2system, sapsystems, SITE_ID, GET_PROCESS_STEPS, reportCIsInChunks, discoverScenarioProcesses = 0):
    r'''
    @types: ? -> dict[str, list[tuple[str, str]]]
    @return: list of pairs for
    '''
    sap_system_osh = modeling.createOshByCmdbIdString('sap_system', SITE_ID)

    business_objects_tree = _discover_business_objects(Framework, solman, component2system, discoverScenarioProcesses, GET_PROCESS_STEPS, reportCIsInChunks, sap_system_osh)
    report(Framework, business_objects_tree, sap_system_osh)
Example #44
0
def getSiebelSoftwareInstallPath(shellUtils, HOST_ID):
    installPath = None
    try:
        hostOSH = modeling.createOshByCmdbIdString('host', HOST_ID)
        installPath = NTCMD_HR_REG_Software_Lib.getSoftwareInstallPath(
            shellUtils, hostOSH, 'SWEApp')
    except:
        logger.debugException(
            'Failed to discover siebel software install path')
    return installPath
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    businessElementId = Framework.getDestinationAttribute('id')
    urlString = Framework.getDestinationAttribute('url')
    jobId = Framework.getDiscoveryJobId()
    dnsServers = Framework.getParameter('dnsServers') or None
    shell = None

    if dnsServers:
        dnsServers = [
            dnsServer for dnsServer in dnsServers.split(',')
            if dnsServer and dnsServer.strip()
        ] or None
    if dnsServers:
        logger.debug('Using dns servers: ', dnsServers)

    if not urlString:
        msg = "There is no specified URL in the input BusinessElement CI"
        errormessages.resolveAndReport(msg, jobId, Framework)
        return OSHVResult

    try:
        bizOSH = modeling.createOshByCmdbIdString('business_element',
                                                  businessElementId)
        OSHVResult.add(bizOSH)
        urlString = urlString[1:len(urlString) - 1]

        if netutils.isValidIp(urlString):
            productName = Framework.getDestinationAttribute('product')
            OSHVResult.add(
                scp.createScpOsh(bizOSH, 'tcp', urlString, 0, productName))
        else:
            protocol, hostname, port, context = parseUrl(urlString)
            if not hostname:
                raise ValueError("Hostname is not defined in URL '%s'" %
                                 urlString)

            if not protocol:
                raise ValueError(
                    "Failed to resolve the protocol from specified URL")

            shell = shellutils.ShellUtils(
                Framework.createClient(
                    ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))
            OSHVResult.addAll(
                scp.createScpOSHV(bizOSH,
                                  protocol,
                                  hostname,
                                  port,
                                  context,
                                  shell,
                                  dnsServers=dnsServers))

    except ValueError, e:
        errormessages.resolveAndReport(e.message, jobId, Framework)
Example #46
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ip = Framework.getDestinationAttribute('ip_address')
    sid = Framework.getDestinationAttribute('sid')
    port = Framework.getDestinationAttribute('port')

    hostId = Framework.getDestinationAttribute('hostId')

    if (ip == None) or (ip == 'NA'):
        #checked and pass all IPs of given host
        ips = Framework.getTriggerCIDataAsList('host_ips')
    else:
        ips = [ip]
    for currIP in ips:
        if len(currIP) == 0:
            continue
        logger.debug('Checking sqlserver with no user on ipaddress:', currIP)
        protocols = Framework.getAvailableProtocols(
            currIP, ClientsConsts.SQL_PROTOCOL_NAME)
        for protocol in protocols:
            dbClient = None
            try:
                try:
                    if dbutils.protocolMatch(
                            Framework, protocol, 'microsoftsqlserver', sid,
                            port) or dbutils.protocolMatch(
                                Framework, protocol, 'microsoftsqlserverntlm',
                                sid, port):
                        props = Properties()
                        props.setProperty('ip_address', currIP)
                        dbClient = Framework.createClient(protocol, props)

                        hostOSH = modeling.createOshByCmdbIdString(
                            'host', hostId)
                        oracleOSH = modeling.createDatabaseOSH(
                            'sqlserver', sid, str(dbClient.getPort()),
                            dbClient.getIpAddress(), hostOSH, protocol, None,
                            dbClient.getTimeout(), dbClient.getDbVersion(),
                            dbClient.getAppVersion())
                        logger.debug(
                            'Successfully connected to sqlserver object ', sid,
                            ' on ', currIP)
                        OSHVResult.add(oracleOSH)
                        #since this is knownn oracle and we found credentials for it we can finish execution
                        return OSHVResult
                except:
                    if logger.isDebugEnabled():
                        logger.debugException(
                            'Unexpected CreateClient() for sqlserver client Exception:'
                        )
            finally:
                if dbClient != None:
                    dbClient.close()
    Framework.reportWarning('Failed to connect using all protocols')
    return OSHVResult
Example #47
0
def disWinOS(hostId, shell, Framework, langBund):
    ''' Discover physical memory and swap memory on Windows
    str, Shell, Framework, Properties -> oshVector
    '''
    OSHVec = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)
    if not NTCMD_HR_Dis_Memory_Lib.discoverMemoryByWmic(shell, OSHVec, hostOsh):
        NTCMD_HR_Dis_Memory_Lib.discoverMemory(shell, OSHVec, hostOsh)
    NTCMD_HR_Dis_Memory_Lib.discoverSwapSizeByWmic(shell, OSHVec, hostOsh)
    OSHVec.add(hostOsh)
    return OSHVec
Example #48
0
def disSunOS(hostId, client, Framework = None, langBund = None):
    ''' Discover physical memory and swap memory on SunOs 
    str, Shell, Framework, Properties -> oshVector
    @command: /usr/sbin/prtconf
    @command: swap -l
    '''
    myVec = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)
    output = None
    try:
        output = client.execCmd('/usr/sbin/prtconf',120000)#V@@CMD_PERMISION tty protocol execution
        if not output or client.getLastCmdReturnCode() != 0:
            raise ValueError
    except:
        logger.warn("Failed getting memory size from prtconf")
    else:
        compiled = re.compile('Memory size: (\d+) Megabytes')
        matches = compiled.findall(output)
    
        totalMemorySizeInMegabytes = 0
        for match in matches:
            totalMemorySizeInMegabytes += int(match)
        
        if totalMemorySizeInMegabytes:
            memory.report(myVec, hostOsh, totalMemorySizeInMegabytes * 1024)
    
    # > swap -l
    #swapfile             dev  swaplo blocks   free
    #/dev/dsk/c1t0d0s1   32,25     16 1058288 1021616
    #/swapfile             -       16 7329776 7293968
    try:
        output = client.execAlternateCmds('/usr/sbin/swap -l','/etc/swap -l','swap -l')#V@@CMD_PERMISION tty protocol execution
        if not output or client.getLastCmdReturnCode() != 0:
            raise ValueError
    except:
        logger.warn("Failed getting swap size from 'swap'")
    else:
        totalSwapSizeInMegabytes = 0
        lines = output.split('\n')
        for line in lines:
            if line:
                line = line.strip()
                if re.search("swapfile\s+dev\s+swaplo\s+blocks\s+free", line):
                    continue
                matcher = re.match(".*\d+\s+(\d+)\s+\d+$", line)
                if matcher:
                    swapSizeInMegabytes = int(matcher.group(1)) / 2048 # 1 block = 512 bytes
                    totalSwapSizeInMegabytes += swapSizeInMegabytes
        
        if totalSwapSizeInMegabytes:
            modeling.setHostSwapMemorySizeAttribute(hostOsh, totalSwapSizeInMegabytes) 
    
    myVec.add(hostOsh)
    return myVec
Example #49
0
 def createHostOsh(self, rs, prefix):
     hid = rs.getString(prefix + 'hid')
     ipaddr = rs.getString(prefix + 'Addr')
     if ipaddr and netutils.isValidIp(ipaddr):
         hostOsh = modeling.createHostOSH(ipaddr, filter_client_ip=True)
     elif hid:
         hostOsh = modeling.createOshByCmdbIdString('host', hid)
     else:
         logger.debug('Not enough info to create host from network connection data %s' % prefix)
         hostOsh = None
     return hostOsh, hid
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ip = Framework.getDestinationAttribute("ip_address")
    sid = Framework.getDestinationAttribute("sid")
    port = Framework.getDestinationAttribute("port")

    hostId = Framework.getDestinationAttribute("hostId")

    if (ip == None) or (ip == "NA"):
        # checked and pass all IPs of given host
        ips = Framework.getTriggerCIDataAsList("host_ips")
    else:
        ips = [ip]
    for currIP in ips:
        if len(currIP) == 0:
            continue
        logger.debug("Checking sqlserver with no user on ipaddress:", currIP)
        protocols = Framework.getAvailableProtocols(currIP, ClientsConsts.SQL_PROTOCOL_NAME)
        for protocol in protocols:
            dbClient = None
            try:
                try:
                    if dbutils.protocolMatch(
                        Framework, protocol, "microsoftsqlserver", sid, port
                    ) or dbutils.protocolMatch(Framework, protocol, "microsoftsqlserverntlm", sid, port):
                        props = Properties()
                        props.setProperty("ip_address", currIP)
                        dbClient = Framework.createClient(protocol, props)

                        hostOSH = modeling.createOshByCmdbIdString("host", hostId)
                        oracleOSH = modeling.createDatabaseOSH(
                            "sqlserver",
                            sid,
                            str(dbClient.getPort()),
                            dbClient.getIpAddress(),
                            hostOSH,
                            protocol,
                            None,
                            dbClient.getTimeout(),
                            dbClient.getDbVersion(),
                            dbClient.getAppVersion(),
                        )
                        logger.debug("Successfully connected to sqlserver object ", sid, " on ", currIP)
                        OSHVResult.add(oracleOSH)
                        # since this is knownn oracle and we found credentials for it we can finish execution
                        return OSHVResult
                except:
                    if logger.isDebugEnabled():
                        logger.debugException("Unexpected CreateClient() for sqlserver client Exception:")
            finally:
                if dbClient != None:
                    dbClient.close()
    Framework.reportWarning("Failed to connect using all protocols")
    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    ip = Framework.getDestinationAttribute('ip_address')
    credential_id = Framework.getDestinationAttribute('credential_id')
    version = Framework.getDestinationAttribute('version')
    cmdb_id = Framework.getDestinationAttribute('cmdb_id')

    protocol = ProtocolManager.getProtocolById(credential_id)
    host = protocol.getProtocolAttribute('host')
    port = protocol.getProtocolAttribute('protocol_port')

    protocolName = ClientsConsts.HTTP_PROTOCOL_NAME

    if (host and ip != host) or not port:
        msg = errormessages.makeErrorMessage(
            protocolName,
            'Invalid ip address or missing port in HTTP credential',
            pattern=errormessages.ERROR_OPERATION_FAILED)
        errobj = errorobject.createError(errorcodes.OPERATION_FAILED,
                                         [protocolName], msg)
        logger.reportErrorObject(errobj)
    else:
        props = Properties()
        props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID,
                          credential_id)
        props.setProperty('autoAcceptCerts', 'true')
        props.setProperty('host', ip)

        try:
            httpClient = Framework.createClient(props)
            builder = PolicyBuilder(ip, port, version, httpClient)
            doc = builder.createPolicyDoc()

            oamServerOSH = modeling.createOshByCmdbIdString(
                'running_software', cmdb_id)
            policyOSH = modeling.createConfigurationDocumentOSH(
                'policy.xml', '', doc, oamServerOSH)
            linkOSH = modeling.createLinkOSH('composition', oamServerOSH,
                                             policyOSH)
            OSHVResult.add(oamServerOSH)
            OSHVResult.add(policyOSH)
            OSHVResult.add(linkOSH)
        except UnauthorizedException, e:
            msg = 'Failed to authenticate: ' + e.getMessage()
            errobj = errorobject.createError(
                errorcodes.INVALID_USERNAME_PASSWORD, [protocolName], msg)
            logger.reportErrorObject(errobj)
        except JException, e:
            msg = 'URL is not accessable: ' + e.getMessage()
            errobj = errorobject.createError(errorcodes.CONNECTION_FAILED,
                                             [protocolName], msg)
            logger.reportErrorObject(errobj)
Example #52
0
def disWinOS(hostId, shell, Framework, langBund):
    ''' Discover physical memory and swap memory on Windows
    str, Shell, Framework, Properties -> oshVector
    '''
    OSHVec = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbIdString('host', hostId)
    if not NTCMD_HR_Dis_Memory_Lib.discoverMemoryByWmic(
            shell, OSHVec, hostOsh):
        NTCMD_HR_Dis_Memory_Lib.discoverMemory(shell, OSHVec, hostOsh)
    NTCMD_HR_Dis_Memory_Lib.discoverSwapSizeByWmic(shell, OSHVec, hostOsh)
    OSHVec.add(hostOsh)
    return OSHVec
def createClusterTopology(cluster, framework, resultsVector):

    #cluster
    clusterOsh = createClusterObject(cluster, resultsVector)
    
    hostOshByName = {}
    clusterSoftwareOshByName = {}
    resourceGroupOshByName = {}
    
    # connected node
    thisNodeCmdbId = framework.getDestinationAttribute('hostId')
    thisNodeOsh = modeling.createOshByCmdbIdString('host', thisNodeCmdbId)
    hostOshByName[cluster.thisNode.name] = thisNodeOsh
    resultsVector.add(thisNodeOsh)
    
    thisNodeClusterSoftwareOsh = createClusterSoftwareObject(thisNodeOsh, cluster, resultsVector)
    clusterSoftwareOshByName[cluster.thisNode.name] = thisNodeClusterSoftwareOsh
    
    #other nodes
    for nodeName, node in cluster.nodesByName.items():
        if nodeName != cluster.thisNode.name:
            hostOsh = createNodeHostObject(node, resultsVector)
            hostOshByName[nodeName] = hostOsh
            clusterSoftwareOsh = createClusterSoftwareObject(hostOsh, cluster, resultsVector)
            clusterSoftwareOshByName[nodeName] = clusterSoftwareOsh
    
    #member links        
    for clusterSoftwareOsh in clusterSoftwareOshByName.values():
        memberLink = modeling.createLinkOSH('member', clusterOsh, clusterSoftwareOsh)
        resultsVector.add(memberLink)
    
    #groups
    for resourceGroupName, resourceGroup in cluster.resourceGroupsByName.items():
        clusteredServerOsh = createClusteredServerObject(cluster.name, clusterOsh, resourceGroup, resultsVector)
        
        #run, potentially_run links
        createRunLinks(resourceGroup, clusteredServerOsh, clusterSoftwareOshByName, resultsVector)
        
        resourceGroupOsh = createResourceGroupObject(resourceGroup, clusteredServerOsh, resultsVector)
        resourceGroupOshByName[resourceGroupName] = resourceGroupOsh
    
    #resources    
    for resource in cluster.resourcesByName.values():
        resourceGroupOsh = resourceGroupOshByName.get(resource.groupName)
        if resourceGroupOsh is not None:
            createResourceObject(resource, resourceGroupOsh, resultsVector) 
    
    #quorum config
    createQuorumConfigurationObjects(cluster, clusterOsh, resultsVector)
    
    #transport path
    createTransportPathObjects(cluster, hostOshByName, resultsVector, framework)
Example #54
0
def disAIX(hostId, shell, Framework=None, langBund=None):
    ''' Discover physical memory and swap memory on AIX 
    str, Shell, Framework, Properties -> oshVector
    @command: prtconf
    @command: swap -s
    '''
    myVec = ObjectStateHolderVector()

    command = langBund.getString('aix_prtconf_str_memory_cmd')
    str_memory = langBund.getString('aix_prtconf_str_memory')

    hostOsh = modeling.createOshByCmdbIdString('host', hostId)

    output = None
    try:
        output = shell.execCmd(
            command, 180000)  #V@@CMD_PERMISION tty protocol execution
        if not output or shell.getLastCmdReturnCode() != 0:
            raise ValueError
    except:
        logger.warn("Failed getting memory size")
    else:
        regex = "%s\s+(\d+)\s*MB" % str_memory
        matcher = re.search(regex, output)
        if matcher:
            memorySizeInKb = int(
                matcher.group(1)
            ) * 1024  #Multiply by 1024 as using regex we already got the information in MB
            memory.report(myVec, hostOsh, memorySizeInKb)

    # Get swap size
    # alternative: search for 'Total Paging Space: (\d+)MB' in prtconf
    # alternative: lsps -a
    try:
        output = shell.execCmd("swap -s",
                               30000)  #V@@CMD_PERMISION tty protocol execution
        if not output or shell.getLastCmdReturnCode() != 0:
            raise ValueError
    except:
        logger.warn("Failed getting swap size")
    else:
        matcher = re.search("allocated\s+=\s+(\d+)\s+blocks", output)
        if matcher:
            blocks = long(matcher.group(1))
            swapSizeInMegabytes = int(blocks / 256)  # 1 block = 4Kb
            modeling.setHostSwapMemorySizeAttribute(hostOsh,
                                                    swapSizeInMegabytes)
    myVec.add(hostOsh)
    return myVec
Example #55
0
def _report_ipse(config, ip, svcename, container, db_osh):
    oshs = []
    endpoint_osh = None
    if config.ipse_id:
        endpoint_osh = modeling.createOshByCmdbIdString('ip_service_endpoint', config.ipse_id)
        oshs.append(endpoint_osh)
    else:
        port = resolve_svcename_to_port_nr(svcename)
        if port:
            db2_reporter = db2_topology.Reporter()
            link_reporter = db2_topology.LinkReporter()
            endpoint_osh = db2_reporter.reportDb2IpServiceEndpoint(ip, port, container)
            oshs.append(link_reporter.report_usage(db_osh, endpoint_osh))
            oshs.append(endpoint_osh)
    return endpoint_osh, oshs
Example #56
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    lparname = None
    # create LPAR node
    hostId = Framework.getDestinationAttribute(PARAM_HOST_ID)
    lparOsh = None
    if eview_lib.isNotNull(hostId):
        lparOsh = modeling.createOshByCmdbIdString('host_node', hostId)

    ls = eview_lib.EvShell(Framework)
    lparname = Framework.getTriggerCIData('LparName')
    OSHVResult = processDb2Subsystem(ls, Framework, lparOsh, lparname)
    ls.closeClient()

    return OSHVResult
Example #57
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    # create LPAR node
    hostId = Framework.getDestinationAttribute(PARAM_HOST_ID)
    lparOsh = None
    if eview400_lib.isNotNull(hostId):
        lparOsh = modeling.createOshByCmdbIdString('host_node', hostId)

    ls = eview400_lib.EvShell(Framework)
    (iseriesObjectOSHV) = processiSeriesObjects(ls, lparOsh, Framework)
    OSHVResult.addAll(iseriesObjectOSHV)

    ls.closeClient()

    return OSHVResult
Example #58
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    oracleId = Framework.getDestinationAttribute('id')

    credentialsId = Framework.getDestinationAttribute('credentialsId')

    instanceName = Framework.getDestinationAttribute('sid')
    protocolDbSid = Framework.getProtocolProperty(
        credentialsId, CollectorsConstants.SQL_PROTOCOL_ATTRIBUTE_DBSID, 'NA')

    try:
        #in some cases sid does not coinside to the instance name, so real sid should be used
        #e.g. when sid is written down in a world unique identifiing string format <instance name>.fulldomainname
        oracleClient = None
        if protocolDbSid and protocolDbSid != 'NA' and protocolDbSid != instanceName:
            try:
                props = Properties()
                props.setProperty(Protocol.SQL_PROTOCOL_ATTRIBUTE_DBSID,
                                  protocolDbSid)
                oracleClient = Framework.createClient(props)
            except:
                logger.debug(
                    'Failed to connect using sid defined in creds. Will try instance name as sid.'
                )
                oracleClient = None
        if not oracleClient:
            props = Properties()
            props.setProperty(Protocol.SQL_PROTOCOL_ATTRIBUTE_DBSID,
                              instanceName)
            oracleClient = Framework.createClient(props)

        try:
            configFileContent = getConfigFileContent(oracleClient)
        finally:
            oracleClient.close()

        oracleOsh = modeling.createOshByCmdbIdString('oracle', oracleId)
        configFileOsh = modeling.createConfigurationDocumentOSH(
            'init_parameters.ora', 'NA', configFileContent, oracleOsh,
            modeling.MIME_TEXT_PLAIN, None, FILE_DESCRIPTION)
        OSHVResult.add(configFileOsh)

    except Exception, ex:
        logger.debugException('')
        strException = ex.getMessage()
        errormessages.resolveAndReport(strException, SQL_PROTOCOL_NAME,
                                       Framework)
Example #59
0
def businessProcesses(Framework,
                      solman,
                      component2system,
                      sapsystems,
                      SITE_ID,
                      GET_PROCESS_STEPS,
                      reportCIsInChunks,
                      discoverScenarioProcesses=0):
    r'''
    @types: ? -> dict[str, list[tuple[str, str]]]
    @return: list of pairs for
    '''
    sap_system_osh = modeling.createOshByCmdbIdString('sap_system', SITE_ID)

    business_objects_tree = _discover_business_objects(
        Framework, solman, component2system, discoverScenarioProcesses,
        GET_PROCESS_STEPS, reportCIsInChunks, sap_system_osh)
    report(Framework, business_objects_tree, sap_system_osh)