Esempio n. 1
0
def disLinux(host_obj, client, Framework = None, langBund = None, packageToCmdLine = None, pid2Process = None):
	hostId = Framework.getDestinationAttribute('hostId')
	protocol = Framework.getDestinationAttribute('Protocol')
	discoverProcesses = Boolean.parseBoolean(Framework.getParameter('discoverProcesses'))

	myVec = ObjectStateHolderVector()
	
	timezone = None
	try:
		timezone = getTimezone(client)
	except ValueError, ex:
		msg = str(ex)
		errobj = errormessages.resolveError(msg, 'shell')
		logger.reportWarningObject(errobj)
Esempio n. 2
0
def DiscoveryMain(Framework):
    vector = ObjectStateHolderVector()
    codePage = Framework.getCodePage()

    props = Properties()
    props.setProperty(BaseAgent.ENCODING, codePage)

    shell = None
    try:
        client = Framework.createClient(props)
        shell = shellutils.ShellFactory().createShell(client)
        dnsResolver = dns_resolver.NsLookupDnsResolver(shell)

        language = shell.osLanguage
        logger.debug("Using '%s' language bundle" % language.bundlePostfix)
        bundle = shellutils.getLanguageBundle('langMsCluster',
            language, Framework)
        clusterCmd = ms_cluster_discoverer.createClusterCmd(shell, bundle)
        if clusterCmd.isUsingCmd():
            bundle = clusterCmd.detectLangBandle(Framework)
        clusterCmd.setBundle(bundle)
        vector.addAll(_discoverTopology(clusterCmd, bundle,
            dnsResolver))
    except NoInstanceFound:
        errobj = errorobject.createError(
            errorcodes.MS_CLUSTER_INSTANCES_NOT_FOUND,
            None, 'MS cluster instances not found in discovery')
        logger.reportWarningObject(errobj)
    except:
        msg = str(sys.exc_info()[1])
        logger.debugException(msg)
        if (msg.lower().find('timeout') > -1):
            errobj = errorobject.createError(
                errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL,
                None,
                'Connection timed out - reactivate with larger timeout value')
            logger.reportErrorObject(errobj)
            logger.debugException('Connection timed out')
        else:
            errobj = errormessages.resolveError(msg, 'ntcmd')
            logger.reportErrorObject(errobj)
            logger.errorException(msg)
    try:
        shell and shell.closeClient()
    except:
        logger.debugException()
        logger.error("Unable to close shell")
    return vector
Esempio n. 3
0
def DiscoveryMain(Framework):
    vector = ObjectStateHolderVector()
    codePage = Framework.getCodePage()

    props = Properties()
    props.setProperty(BaseAgent.ENCODING, codePage)

    shell = None
    try:
        client = Framework.createClient(props)
        shell = shellutils.ShellFactory().createShell(client)
        dnsResolver = dns_resolver.NsLookupDnsResolver(shell)

        language = shell.osLanguage
        logger.debug("Using '%s' language bundle" % language.bundlePostfix)
        bundle = shellutils.getLanguageBundle('langMsCluster', language,
                                              Framework)
        clusterCmd = ms_cluster_discoverer.createClusterCmd(shell, bundle)
        if clusterCmd.isUsingCmd():
            bundle = clusterCmd.detectLangBandle(Framework)
        clusterCmd.setBundle(bundle)
        vector.addAll(_discoverTopology(clusterCmd, bundle, dnsResolver))
    except NoInstanceFound:
        errobj = errorobject.createError(
            errorcodes.MS_CLUSTER_INSTANCES_NOT_FOUND, None,
            'MS cluster instances not found in discovery')
        logger.reportWarningObject(errobj)
    except:
        msg = str(sys.exc_info()[1])
        logger.debugException(msg)
        if (msg.lower().find('timeout') > -1):
            errobj = errorobject.createError(
                errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL, None,
                'Connection timed out - reactivate with larger timeout value')
            logger.reportErrorObject(errobj)
            logger.debugException('Connection timed out')
        else:
            errobj = errormessages.resolveError(msg, 'ntcmd')
            logger.reportErrorObject(errobj)
            logger.errorException(msg)
    try:
        shell and shell.closeClient()
    except:
        logger.debugException()
        logger.error("Unable to close shell")
    return vector
Esempio n. 4
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    try:
        snmpClient = Framework.createClient()
        try:
            a10Discoverer = createA10Discoverer(snmpClient, Framework, OSHVResult)
            a10Discoverer.getTopology(ipAddress)
        finally:
            snmpClient.close()
    except NoA10Exception:
        logger.reportWarning("No A10 vThunder found on the remote machine")
    except:
        #TODO: use errormessages here
        msg = logger.prepareFullStackTrace('')
        errobj = errormessages.resolveError(msg, 'snmp')
        logger.reportErrorObject(errobj)
        logger.debugException('')

    return OSHVResult
Esempio n. 5
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    try:
        snmpClient = Framework.createClient()
        try:
            f5Discoverer = createF5Discoverer(snmpClient, Framework, OSHVResult)
            f5Discoverer.getTopology(ipAddress)
        finally:
            snmpClient.close()
    except NoF5Exception:
        logger.reportWarning("No F5 LTM found on the remote machine")
    except:
        #TODO: use errormessages here
        msg = logger.prepareFullStackTrace('')
        errobj = errormessages.resolveError(msg, 'snmp')
        logger.reportErrorObject(errobj)
        logger.debugException('')
            
    return OSHVResult
Esempio n. 6
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    try:
        snmpClient = Framework.createClient()
        snmpAgent = SnmpAgent(CISCO_ACE_OID_BASE, snmpClient, Framework)
        try:
            cisco_Discoverer = Cisco_Discoverer(snmpAgent, OSHVResult,
                                                Framework)
            cisco_Discoverer.getTopology(ipAddress)
        finally:
            snmpClient.close()
    except NO_CISCO_ACE_Exception:
        logger.reportWarning("No Cisco ACE found on the remote machine")
    except:
        #TODO: use errormessages here
        msg = logger.prepareFullStackTrace('')
        errobj = errormessages.resolveError(msg, 'snmp')
        logger.reportErrorObject(errobj)
        logger.debugException('')

    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    cmclconfig_path = getParameter(Framework, 'cmclconfig_path', '/etc/cmcluster/')
    cmclconfig_files_pattern = getParameter(Framework, 'cmclconfig_file', 'ascii')

    client = None
    try:
        try:
            client = Framework.createClient()
            shell = ShellUtils(client)

            clusterDiscoverer = ServiceGuardClusterDiscoverer(shell)
            cluster = clusterDiscoverer.discover()

            if cluster.packages:
                # in case any running packages were discovered,
                # try to discover package mount points, ips and networks
                # which do not appear in cmview command output
                addPkgInfoDiscoverer = AdditionalPackageResourcesDiscoverer(shell)
                packageNameToPackageMap = addPkgInfoDiscoverer.discover(cmclconfig_path, cluster)
                #merging data into the stored packages DO
                for package in cluster.packages:
                    addPackage = packageNameToPackageMap.get(package.name)
                    if addPackage:
                        package.mountPoints = addPackage.mountPoints
                        package.additionalIpList = addPackage.additionalIpList
                        package.ipNetworkList = addPackage.ipNetworkList

            endpointReporter = netutils.EndpointReporter(
                                        netutils.ServiceEndpointBuilder())
            quorumServerReporter = service_guard.QuorumServerReporter(
                                        service_guard.QuorumServerBuilder(),
                                        endpointReporter)
            vector = Reporter(quorumServerReporter).report(cluster)
            OSHVResult.addAll(vector)

            softwareInformationList = []
            for discoverer in (OracleDiscoverer(shell),
                               OracleIasDiscoverer(shell)):
                try:
                    softwareInformationList.extend(discoverer.discover())
                except:
                    logger.debugException('')

            if softwareInformationList:
                relationsBuilder = PackageToRunningSoftwareTopologyBuilder(cluster)
                OSHVResult.addAll(relationsBuilder.build(softwareInformationList))

            if cluster.osh != None:
                discoverConfigFiles(Framework, cluster.osh, shell,
                        cmclconfig_path, cmclconfig_files_pattern, OSHVResult)
            else:
                errobj = errorobject.createError(
                    errorcodes.SERVICE_GUARD_CLUSTER_NOT_FOUND,
                    None, 'Service Guard Cluster not found in discovery')
                logger.reportWarningObject(errobj)
        except:
            msg = sys.exc_info()[1]
            strmsg = '%s' % msg
            if (strmsg.lower().find('timeout') > -1):
                errobj = errorobject.createError(
                    errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL, None,
                    'Connection timed out')
                logger.reportErrorObject(errobj)
                logger.debugException('Connection timed out')
            else:
                errobj = errormessages.resolveError(strmsg, 'shell')
                logger.reportErrorObject(errobj)
                logger.errorException(strmsg)

    finally:
        if client != None:
            client.close()
    return OSHVResult
Esempio n. 8
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    cmclconfig_path = getParameter(Framework, 'cmclconfig_path',
                                   '/etc/cmcluster/')
    cmclconfig_files_pattern = getParameter(Framework, 'cmclconfig_file',
                                            'ascii')

    client = None
    try:
        try:
            client = Framework.createClient()
            shell = ShellUtils(client)

            clusterDiscoverer = ServiceGuardClusterDiscoverer(shell)
            cluster = clusterDiscoverer.discover()

            if cluster.packages:
                # in case any running packages were discovered,
                # try to discover package mount points, ips and networks
                # which do not appear in cmview command output
                addPkgInfoDiscoverer = AdditionalPackageResourcesDiscoverer(
                    shell)
                packageNameToPackageMap = addPkgInfoDiscoverer.discover(
                    cmclconfig_path, cluster)
                #merging data into the stored packages DO
                for package in cluster.packages:
                    addPackage = packageNameToPackageMap.get(package.name)
                    if addPackage:
                        package.mountPoints = addPackage.mountPoints
                        package.additionalIpList = addPackage.additionalIpList
                        package.ipNetworkList = addPackage.ipNetworkList

            endpointReporter = netutils.EndpointReporter(
                netutils.ServiceEndpointBuilder())
            quorumServerReporter = service_guard.QuorumServerReporter(
                service_guard.QuorumServerBuilder(), endpointReporter)
            vector = Reporter(quorumServerReporter).report(cluster)
            OSHVResult.addAll(vector)

            softwareInformationList = []
            for discoverer in (OracleDiscoverer(shell),
                               OracleIasDiscoverer(shell)):
                try:
                    softwareInformationList.extend(discoverer.discover())
                except:
                    logger.debugException('')

            if softwareInformationList:
                relationsBuilder = PackageToRunningSoftwareTopologyBuilder(
                    cluster)
                OSHVResult.addAll(
                    relationsBuilder.build(softwareInformationList))

            if cluster.osh != None:
                discoverConfigFiles(Framework, cluster.osh, shell,
                                    cmclconfig_path, cmclconfig_files_pattern,
                                    OSHVResult)
            else:
                errobj = errorobject.createError(
                    errorcodes.SERVICE_GUARD_CLUSTER_NOT_FOUND, None,
                    'Service Guard Cluster not found in discovery')
                logger.reportWarningObject(errobj)
        except:
            msg = sys.exc_info()[1]
            strmsg = '%s' % msg
            if (strmsg.lower().find('timeout') > -1):
                errobj = errorobject.createError(
                    errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL, None,
                    'Connection timed out')
                logger.reportErrorObject(errobj)
                logger.debugException('Connection timed out')
            else:
                errobj = errormessages.resolveError(strmsg, 'shell')
                logger.reportErrorObject(errobj)
                logger.errorException(strmsg)

    finally:
        if client != None:
            client.close()
    return OSHVResult
Esempio n. 9
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    hostIp = Framework.getDestinationAttribute('ip_address')
    hostIdString = Framework.getDestinationAttribute('hostId')
    ports = Framework.getTriggerCIDataAsList('port_number')
    '''
    Retrieving a list of LDAP ports we strive to connect to domain controller in
    member role first. So we have to choose the lowest port number in the list.
    '''
    if ports:
        ports = map(lambda port: int(port), ports)
        ports.sort()
    else:
        raise Exception("No LDAP ports provided to connect")

    protocol = "ldap"
    credentialIds = Framework.getAvailableProtocols(hostIp, protocol)
    client = None
    warningList = []

    defiscoveryPassed = 0
    connectedOnce = 0

    if not len(credentialIds):
        msg = 'Protocol not defined or IP out of protocol network range'
        Framework.reportError(msg)
    else:  #go over all protocols and for each protocol try all available ports
        for credentialsId in credentialIds:
            portsToIterate = None
            protocolPort = Framework.getProtocolProperty(
                credentialsId, "protocol_port")
            if str(protocolPort).isdigit():
                portsToIterate = [protocolPort]
            else:
                portsToIterate = ports
            for port in portsToIterate:
                try:  # build environment and connect
                    try:
                        envBuilder = LdapEnvironmentBuilder(port)
                        client = Framework.createClient(
                            credentialsId, envBuilder.build())
                        connectedOnce = 1
                        baseDn = active_directory_utils.getBaseDnFromJobsParameters(
                            Framework)
                        daoService = LdapDaoService(client, baseDn)
                        # discover domain controller
                        warningList = []
                        hostOsh = modeling.createOshByCmdbIdString(
                            'host', hostIdString)
                        discoverer = AdDomainControllerDiscoverer(
                            daoService, hostOsh)
                        OSHVResult = discoverer.discover()
                        #add container hosts for domain controllers to the result vector
                        containerOshs = discoverer.getResult(
                        ).getContainerOshMap().values()
                        for osh in containerOshs:
                            OSHVResult.add(osh)
                        #skip other ports
                        defiscoveryPassed = 1
                        break
                    except:
                        msg = logger.prepareFullStackTrace('')
                        warning = errormessages.resolveError(msg, protocol)
                        warningList.append(warning)
                finally:
                    client and client.close()
            #skip other protocols in case when discovery passed for current one
            if defiscoveryPassed:
                break

    if not connectedOnce:
        warning = errorobject.createError(
            errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS,
            ['Tried all protocols'] * 2,
            'Failed to connect using all protocols')
        warningList = [warning]

    #print collected warning message
    for warning in warningList:
        logger.reportWarningObject(warning)

    return OSHVResult
Esempio n. 10
0
def doSnmp(client, isClient, snmpOSH, ip_address, ip_domain, Framework, host_cmdbid, host_key, host_macs):
    '''SnmpClient, osh, str, str, Framework, str, str, list(str) -> ObjectStateHolderVector
    @deprecated
    '''
    networkList = []
    vector = ObjectStateHolderVector()
    ucmdb_version = modeling.CmdbClassModel().version()
    # system table
    snmpQuery = '1.3.6.1.2.1.1.1,1.3.6.1.2.1.1.2,string,1.3.6.1.2.1.1.2,string,1.3.6.1.2.1.1.5,string'
    table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution

    sysname = None
    oid = None
    description = None
    try:
        if table.next():
            description = table.getString(2)
            oid = table.getString(3)
            sysname = table.getString(4)
    except:
        logger.debugException('')

    node_description = description or ''

    sysObjId = oid
    className, vendorName, hostOsName, hostModel, serialNumberOid, serialNumberSNMPMethod = getNodeDetails(description, oid)
    logger.debug("Node details:%s, %s, %s, %s, %s, %s"%(className, vendorName, hostOsName, hostModel, serialNumberOid, serialNumberSNMPMethod))
    if className == 'netprinter':
        sysname = getNetPrinterName(client) or sysname
    hostVersion, hostRelease = getOsVersionAndBuild(hostOsName, description)

# since sysUpTime returns a time since the snmp was re-initialized, this
# time doesn't provide us correct answer, therefore this code is disabled
#    snmpQuery = '1.3.6.1.2.1.1.3,1.3.6.1.2.1.1.4,string'
#    upTime = client.executeQuery(snmpQuery)

    if oid != None:
        snmpOSH.setAttribute('snmp_oid', oid)
    if((sysname != None) and (sysname != '') and (sysname != 'unknown')):
        snmpOSH.setAttribute('snmp_sysname', sysname)
    if description != None:
        snmpOSH.setAttribute('snmp_description', description)

    logger.debug('ip_address: ', ip_address, ', sysname: ' , sysname, ', className: ', className, ', oid: ', oid, ', description: ', description)

    #dicovery arp cache available
    arp_available = SNMP_Networking_Utils.isArpCacheAvailable(client)
    snmpOSH.setBoolAttribute('arp_cache_available', arp_available)

    # indx, description & mac

    interfaceList = []
    interfaceDictionary = {}

    ifList = SNMP_Networking_Utils.discoverInterfaceData(client, None)

    for nic in ifList:
        if nic.ifType and int(nic.ifType) == 24:
            continue

        macAddress = str(nic.ifMac).upper()
        if nic.ifIndex != None and nic.ifIndex != '':
            inrfcindex = nic.ifIndex
        description = _stripVirtualMiniportInfo(nic.ifDescr)

        if interfaceDictionary.has_key(inrfcindex):
            logger.debug('this mac was already reported, skip it ... : inrfcindex: ', inrfcindex, ', descrition: ', description, ', macAddress: ', macAddress)
            continue

        logger.debug('inrfcindex: ', inrfcindex, ', description: ', description, ', macAddress: ', macAddress)

        interfaceDictionary[inrfcindex] = macAddress
        networkinterface = modeling.NetworkInterface(description, macAddress, None, None, inrfcindex)
        networkinterface.type = nic.ifType
        networkinterface.adminStatus = nic.ifAdminStatus
        networkinterface.operStatus = nic.ifOperStatus
        networkinterface.speed = nic.ifSpeed
        networkinterface.name = nic.ifName
        networkinterface.alias = nic.ifAlias
        if not networkinterface.name:
            m = re.match('(lan[\d\:\.]+)', description)
            if m:
                networkinterface.name = m.group(1)
                networkinterface.description = None
        interfaceList.append(networkinterface)

    # create the host and all the objects
    if len(interfaceList) > 0:
        macToInterfaceListMap = {}
        for interface in interfaceList:
            macToInterfaceListMap.setdefault(interface.macAddress, []).append(interface)

        for ifaceList in macToInterfaceListMap.values():
            if ifaceList and len(ifaceList) < 2:
                continue
            try:
                iface = reduce(lambda x,y: x.interfaceIndex > y.interfaceIndex and x or y, ifaceList)
                iface.role = 'aggregate_interface'
            except:
                logger.debugException('')
        hostOSH = None

        try:
            # Get the host_key - lowest mac address of the valid interface list
            hostOSH = modeling.createCompleteHostOSHByInterfaceList(className, interfaceList, None, None, None, host_cmdbid, host_key, host_macs, ucmdb_version)
            if (className in netDeviceClasses) and (sysname != None) and (sysname != '') and ((host_cmdbid in ['NA','',None]) or (host_key and (host_key.lower() == sysname.lower()))):
                # JEO @ Fidelity: use SNMP system name for host key of network devices unless its null
                hostOSH.setAttribute('host_key', sysname)

        except:
            logger.debug('Could not find a valid MAC address for key on ip : ', ip_address)
            if (className in netDeviceClasses) and (sysname != None) and (sysname != '') and (host_cmdbid in ['NA','',None]):
                logger.debug('Network device, hostkey is sysname...')
                hostOSH = modeling.createCompleteHostOSH(className, sysname)
            else:
                logger.debug('Creating incomplete host...')
                hostOSH = modeling.createHostOSH(ip_address, className)

        logger.debug('Created [' + className + '] strong key=[' + hostOSH.getAttributeValue('host_key') + ']')

        if((sysname != None) and (sysname != '') and (sysname != 'unknown')):
            hostOSH.setAttribute('snmp_sys_name', sysname)
            # set hostname to SNMP system name less domain suffix which is typical of other data sources
            hostname = sysname.split('.')[0].lower()
            hostOSH.setAttribute('name', hostname)
            logger.debug("hostname=" + hostname)

        defaultGateway = getDefaultGateway(client)
        modeling.setHostDefaultGateway(hostOSH, defaultGateway)
        modeling.setHostOsFamily(hostOSH, None, className)
        if sysObjId and sysObjId.startswith('.') != -1:
            sysObjId = "." + sysObjId
        modeling.setSNMPSysObjectId(hostOSH, sysObjId)

        if((hostOsName != None) and (hostOsName != '') and (hostOsName != 'unknown')):
            modeling.setHostOsName(hostOSH, hostOsName)
        if((vendorName != None) and (vendorName != '') and (vendorName != 'unknown')):
            hostOSH.setAttribute('discovered_os_vendor', vendorName)
        if((hostModel != None) and (hostModel != '') and (hostModel != 'unknown')):
            hostOSH.setAttribute('discovered_model', hostModel)
        if hostRelease is not None:
            hostOSH.setAttribute('host_osrelease', hostRelease)
        if hostVersion is not None:
            hostOSH.setAttribute('discovered_os_version', hostVersion)

# since sysUpTime returns a time since the snmp was re-initialized, this
# time doesn't provide us correct answer, therefore this code is disabled
#        if upTime:
#            today = Calendar.getInstance().getTime()
#            setLastBootDate(hostOSH, upTime, today, Framework)

        vector.add(modeling.finalizeHostOsh(hostOSH))
        snmpOSH.setContainer(hostOSH)
        if className == 'mainframe':
            modeling.setHostOsFamily(hostOSH, 'mainframe')

        interfaceOshToIndex = {}
        roleManager = networking_win.InterfaceRoleManager()
        try:
            reportInterfaceName = Boolean.parseBoolean(Framework.getParameter('reportInterfaceName'))
        except:
            logger.warn('Failed to parse reportInterfaceName parameter falue. Not a Boolean type.')
            reportInterfaceName = True
        for nic in interfaceList:
            if netutils.isValidMac(nic.macAddress):
                nic.osh = modeling.createInterfaceOSH(nic.macAddress, hostOSH, nic.description,
                            nic.interfaceIndex, nic.type, nic.adminStatus, nic.operStatus,
                            nic.speed, nic.name, nic.alias, reportInterfaceName)
                roleManager.assignInterfaceRole(nic)
                interfaceOshToIndex[nic.interfaceIndex] = nic.osh
                vector.add(nic.osh)
            else:
                logger.debug('MAC %s is invalid (name: %s, description: %s, index: %s)' %
                             (nic.macAddress, nic.name, nic.description, nic.interfaceIndex))

        # create the ip's
        logger.debug("create the ip's")
        snmpQuery = '1.3.6.1.2.1.4.20.1.1, 1.3.6.1.2.1.4.20.1.2, string'
        table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution
        ips = table.asTable()
        snmpQuery = '1.3.6.1.2.1.4.20.1.2, 1.3.6.1.2.1.4.20.1.3, string'
        table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution
        ifindexes = table.asTable()
        snmpQuery = '1.3.6.1.2.1.4.20.1.3, 1.3.6.1.2.1.4.20.1.4, string'
        table = client.executeQuery(snmpQuery)#@@CMD_PERMISION snmp protocol execution
        ipmasks = table.asTable()
        try:
            rfcIpV6Query = '1.3.6.1.2.1.55.1.8.1.1,1.3.6.1.2.1.55.1.8.1.5, string'
            rfcIpV6Result = client.executeQuery(rfcIpV6Query)#@@CMD_PERMISION snmp protocol execution
            results = rfcIpV6Result.asTable()
        except:
            logger.warn('Failed to get or process IPv6 MIB results.')

        #try to collect IPv6 addresses from IPv6 address table and connect them to corresponding interface
        logger.debug("Begin to discovery IPv6 related info")
        try:
            ipv6Map = {}
            ipv6AddressTable = SNMP_Networking_Utils.discoverIPv6AddressTable(client)
            if ipv6AddressTable:
                for row in ipv6AddressTable:
                    if row.ipv6AddrStatus != '1':# 1 means valid ip address in arp cache
                        continue
                    ifIndex, ipAddress = _parseIPv6FromIndex(row.ipv6AddrAddress)
                    if ifIndex and ipAddress:
                        try:
                            formatedIP = getValidIP(ipAddress)
                            if formatedIP:
                                ipv6Map[ifIndex] = formatedIP
                        except:
                            pass
            mixedIPAddressTable = SNMP_Networking_Utils.discoverMixedIPAddressTable(client)
            if mixedIPAddressTable:
                for row in mixedIPAddressTable:
                    if row.ipAddressStatus != '1' or row.ipAddressRowStatus != '1':# 1 means valid ip address in arp cache
                        continue
                    ifIndex = row.ipAddressIfIndex
                    ipAddress = _parseMixedIPFromIndex(row.ipAddressAddr)
                    if ifIndex and ipAddress:
                        try:
                            formatedIP = getValidIP(ipAddress)
                            if formatedIP and formatedIP.version == 6:
                                ipv6Map[ifIndex] = formatedIP
                        except:
                            pass

            if ipv6Map and interfaceOshToIndex:
                for ifIndex in ipv6Map.keys():
                    ipv6 = ipv6Map[ifIndex]
                    logger.debug("Discovered IPv6:", ipv6)
                    ipOSH = modeling.createIpOSH(ipv6)
                    vector.add(ipOSH)
                    interfaceOsh = interfaceOshToIndex.get(str(ifIndex))
                    if not interfaceOsh and isClient:
                        logger.info('client ip is not associated with an interface')
                        msg = "Can not find the related interface for client IP: %s" % ip_address
                        logger.reportWarningObject(errormessages.resolveError(msg, 'SNMP'))
                        continue
                    if interfaceOsh:
                        parent = modeling.createLinkOSH('containment', interfaceOsh, ipOSH)
                        vector.add(parent)
                        interfaceMacAddress = interfaceOsh.getAttributeValue('mac_address')
                        if (isClient == TRUE):
                            ipOSH.setAttribute('arp_mac', interfaceMacAddress)
                            if (
                            ipv6 == ip_addr_util.IPAddress(ip_address)):#compare ipv6 by the formatting to avoid same IPv6 with different format
                                snmpOSH.setAttribute('arp_mac', interfaceMacAddress)

                    isCompleteAttribute = hostOSH.getAttribute('host_iscomplete')
                    if isCompleteAttribute is not None and isCompleteAttribute.getBooleanValue() == 1:
                        contained = modeling.createLinkOSH('contained', hostOSH, ipOSH)
                        vector.add(contained)
        except:
            logger.debug(str(sys.exc_info()))

        index = 0
        if len(ips) > 0 and len(ifindexes) > 0:
            for ip in ips:
                try:
                    ip_addr = ip[1]
                    #logger.debug('candidate ip_addr: ', ip_addr)
                    ifIndex = ifindexes[index][1]
                    mask = ipmasks[index][1]
                    index += 1

                    interfaceOsh = interfaceOshToIndex.get(ifIndex)

                    ''' this commented out block should be removed
                    # no such thing as netmask IPs, there are broadcast IPs which have .255 in them
                    # but we would definitely want to discover and nic which was asssigned
                    # such an address -
                    #if(ip_addr.find('255.') == 0 ):
                        #exclude netmask ip
                        #continue
                    '''

                    if netutils.isValidIp(ip_addr) and (not netutils.isLocalIp(ip_addr)):
                        '''
                        netutils.isLocalIp is not finding all local addresses
                        127.0.0.0 through 127.255.255.255 are local
                        additional if clause can be removed when this is fixed
                        see http://www.tcpipguide.com/free/t_IPReservedPrivateandLoopbackAddresses.htm
                        '''
                        # ip is valid and not local (i.e. 0.0.0.0, 127.0.0.1)
                        ipOSH = modeling.createIpOSH(ip_addr, mask)
                    else:
                        # loopbacks are standard; don't complain about them in the logs
                        continue
                    logger.debug('ip_addr: ', ip_addr, ', mask: ', mask)

                    netOSH = modeling.createNetworkOSH(ip_addr, mask)

                    strNetAddr = str(netOSH.getAttribute('network_netaddr'))
                    strNetMask = str(netOSH.getAttribute('network_netMask'))
                    currNet = strNetAddr + strNetMask

                    broadcastIp = netOSH.getAttributeValue('network_broadcastaddress')
                    if ip_address == broadcastIp:
                        raise BroadcastIpDiscoveryException()
                    if not interfaceOsh and isClient:
                        logger.info('client ip is not associated with an interface')
                        msg = "Can not find the related interface for client IP: " + ip_addr
                        logger.reportWarningObject(errormessages.resolveError(msg, 'SNMP'))
                        continue
                    if interfaceOsh:
                        parent = modeling.createLinkOSH('containment', interfaceOsh, ipOSH)
                        vector.add(parent)
                        interfaceMacAddress = interfaceOsh.getAttributeValue('mac_address')
                        if (isClient == TRUE):
                            ipOSH.setAttribute('arp_mac', interfaceMacAddress)
                            if (ip_addr == ip_address):
                                snmpOSH.setAttribute('arp_mac', interfaceMacAddress)

                    member1 = modeling.createLinkOSH('member', netOSH, ipOSH)
                    member2 = modeling.createLinkOSH('member', netOSH, hostOSH)

                    if currNet in networkList:
                        pass
                    else:
                        networkList.append(currNet)
                        vector.add(netOSH)
                        vector.add(member2)

                    vector.add(ipOSH)
                    vector.add(member1)

                    # link IPs to host only in case host is complete
                    # otherwise reconciliation may fail
                    isCompleteAttribute = hostOSH.getAttribute('host_iscomplete')
                    if isCompleteAttribute is not None and isCompleteAttribute.getBooleanValue() == 1:
                        contained = modeling.createLinkOSH('contained', hostOSH, ipOSH)
                        vector.add(contained)

                    if interfaceOsh:
                        parent = modeling.createLinkOSH('containment', interfaceOsh, ipOSH)
                        vector.add(parent)
                except BroadcastIpDiscoveryException, ex:
                    raise ex
                except:
                    pass
Esempio n. 11
0
def mainFunction(Framework, isClient, ip_address = None):
    _vector = ObjectStateHolderVector()
    errStr = ''
    ip_domain  = Framework.getDestinationAttribute('ip_domain')
    host_cmdbid = Framework.getDestinationAttribute('host_cmdbid')
    host_key = Framework.getDestinationAttribute('host_key')
    host_macs = Framework.getTriggerCIDataAsList('mac_addrs')
    ip_arp_mac = Framework.getDestinationAttribute('ip_mac')

    # try to get ip address by mac address from ARP Cache
    foundIp = clientdiscoveryutils.getIPAddressOnlyFromMacAddress(ip_arp_mac)
    if foundIp:
        ip_address = foundIp

    if (ip_address == None):
        ip_address = Framework.getDestinationAttribute('ip_address')
    if (ip_domain == None):
        ip_domain = DomainScopeManager.getDomainByIp(ip_address, None)

    protocols = netutils.getAvailableProtocols(Framework, ClientsConsts.SNMP_PROTOCOL_NAME, ip_address, ip_domain)
    if len(protocols) == 0:
        errStr = 'No credentials defined for the triggered ip'
        logger.debug(errStr)
        errObj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [ClientsConsts.SNMP_PROTOCOL_NAME], errStr)
        return (_vector, errObj)

    connected = 0
    for protocol in protocols:
        client = None
        try:
            try:
                logger.debug('try to get snmp agent for: %s:%s' % (ip_address, ip_domain))
                if (isClient == TRUE):
                    properties = Properties()
                    properties.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, ip_address)
                    properties.setProperty(CollectorsConstants.DESTINATION_DATA_IP_DOMAIN, ip_domain)
                    client = Framework.createClient(protocol, properties)
                else:
                    properties = Properties()
                    properties.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, ip_address)
                    client = Framework.createClient(protocol, properties)
                logger.debug('Running test connection queries')
                testConnection(client)
                Framework.saveState(protocol)
                logger.debug('got snmp agent for: %s:%s' % (ip_address, ip_domain))
                isMultiOid = client.supportMultiOid()
                logger.debug('snmp server isMultiOid state=%s' %isMultiOid)
                # create snmp OSH
                snmpOSH = modeling.createSnmpOSH(ip_address, client.getPort())
                snmpOSH.setAttribute('application_timeout', client.getTimeout())
                snmpOSH.setAttribute('snmp_port', client.getPort())
                snmpOSH.setAttribute('credentials_id', client.getCredentialId())
                snmpOSH.setAttribute('snmp_retry', client.getRetries())
                snmpOSH.setAttribute('snmp_timeout', client.getTimeout())
                #obtain SNMP protocol version
                snmpVersion = definedSnmpProtocolVersion(protocol, Framework)
                snmpOSH.setAttribute('application_version_number', snmpVersion)
                if ip_arp_mac and ip_arp_mac != 'NA':
                    snmpOSH.setAttribute('arp_mac', ip_arp_mac)

                if isMultiOid == 1:
                    snmpOSH.setBoolAttribute('snmp_supportmultioid', 1)
                else:
                    snmpOSH.setBoolAttribute('snmp_supportmultioid', 0)

                _vector = doSnmp(client, isClient, snmpOSH, ip_address, ip_domain, Framework, host_cmdbid, host_key, host_macs)
                client.close()
                client = None

                if _vector.size() > 0:
                    connected = 1

                    break
            except BroadcastIpDiscoveryException:
                msg = "Job has been triggered on broadcast IP, no results will be reported"
                errObj = errorobject.createError(errorcodes.NO_RESULTS_WILL_BE_REPORTED, ["Job has been triggered on broadcast IP"], msg)
                if client != None:
                    client.close()
                    client = None
                return (_vector, errObj)
            except:
                if client != None:
                    client.close()
                    client = None
                logger.debugException('Unexpected SNMP_AGENT Exception:')
                lastExceptionStr = str(sys.exc_info()[1]).strip()
        finally:
            if client != None:
                client.close()
                client = None

    error = errorobject.INTERNAL_ERROR
    if (not connected):
        errStr = errormessages.makeErrorMessage('SNMP', pattern=errormessages.ERROR_CONNECTION_FAILED)
        error = errorobject.createError(errorcodes.CONNECTION_FAILED, ['SNMP'], errStr)
        logger.debug(errStr)
        Framework.clearState()
    elif (_vector.size() == 0):
        error = errormessages.resolveError(lastExceptionStr, 'SNMP')
    return (_vector, error)
Esempio n. 12
0
                        contained = modeling.createLinkOSH('contained', hostOSH, ipOSH)
                        vector.add(contained)

                    if interfaceOsh:
                        parent = modeling.createLinkOSH('containment', interfaceOsh, ipOSH)
                        vector.add(parent)
                except BroadcastIpDiscoveryException, ex:
                    raise ex
                except:
                    pass
        #the ip table is not managed by SNMP agent
        else:
            logger.info('ip table is not managed by SNMP agent')
            if isClient == TRUE:
                msg = "The IP table is not managed by SNMP agent. IP: " + ip_address
                logger.reportWarningObject(errormessages.resolveError(msg, 'SNMP'))
            else:
                ipOSH = modeling.createIpOSH(ip_address)
                link = modeling.createLinkOSH('contained', hostOSH, ipOSH)
                vector.add(ipOSH)
                vector.add(link)

        if className != 'mainframe':
            vector.add(snmpOSH)
    # no interfaces on this snmp agent
    # create incomplete host
    # and send event on it
    else:
        logger.debug('Interface table is empty on snmp agent of ', ip_address)
        vector = ObjectStateHolderVector()
        if isClient == TRUE:
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    
    protocol = Framework.getDestinationAttribute('Protocol')
    
    DEFAULT_MAIN_FC_PATH = ''
    #this default value would be used as last resort in case the file main.cf will not be found
    if protocol == 'ntcmd':
        DEFAULT_MAIN_FC_PATH = 'c:\\program Files\\VERITAS\\cluster server\\conf\config\\'
    else:
        DEFAULT_MAIN_FC_PATH = '/etc/VRTSvcs/conf/config/'

    # take the following parameter from the section 'destinationData name' ${PARAMETERS.<paramname>) defined in the pattern's xml file
    main_cf_path = Framework.getParameter('main_cf_path')

    properties = Properties()

    # Set codepage
    codePage = Framework.getCodePage()
    properties.put( BaseAgent.ENCODING, codePage)

    try:
        # Connect to the SSH/TELNET/NTCMD agent
        client = Framework.createClient(properties)
        clientShUtils = shellutils.ShellUtils(client)
    except:
        msg = sys.exc_info()[1]
        strmsg = '%s' % msg
        if (strmsg.lower().find('timeout') > -1):
            errobj = errorobject.createError(errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL, None, 'Connection timed out - reactivate with larger timeout value')
            logger.reportErrorObject(errobj)
            logger.debugException('Connection timed out')
        else:
            errobj = errormessages.resolveError(strmsg, 'shell')
            logger.reportErrorObject(errobj)
            logger.errorException(strmsg)
    else:
        # Get main.cf path
        if ((main_cf_path == None) or (main_cf_path == 'NA')) and (protocol != 'ntcmd'):
            main_cf_path = getMainCFPath(clientShUtils)
            if (main_cf_path == None) or (main_cf_path == 'NA'):
                main_cf_path = DEFAULT_MAIN_FC_PATH
        if ((main_cf_path == None) or (main_cf_path == 'NA')) and (protocol == 'ntcmd'):
            main_cf_path = DEFAULT_MAIN_FC_PATH
        
        # Assemble the main.cf command
        cfFullPath = main_cf_path + 'main.cf'
        try:
            resBuffer = clientShUtils.safecat(cfFullPath)
        except:
            errorMessage = 'Failed to get configuration file:' + cfFullPath
            logger.debugException(errorMessage)
            errobj = errorobject.createError(errorcodes.FAILED_FINDING_CONFIGURATION_FILE, [cfFullPath], errorMessage)
            logger.reportErrorObject(errobj)
        else:        
            if resBuffer.find('Permission denied') > -1:
                errobj = errorobject.createError(errorcodes.PERMISSION_DENIED_NO_PROTOCOL_WITH_DETAILS, ['User has no permissions to read main.cf file'], 'User has no permissions to read main.cf file')
                logger.reportErrorObject(errobj)
            else:
                lastUpdateTime = file_ver_lib.getFileLastModificationTime(clientShUtils, cfFullPath)
                mainFunction(resBuffer, main_cf_path, clientShUtils, OSHVResult, protocol, Framework, lastUpdateTime)

        try:
            clientShUtils and clientShUtils.closeClient()
        except:
            logger.debugException('')
            logger.error('Unable to close shell')
    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    hostIp = Framework.getDestinationAttribute("ip_address")
    hostIdString = Framework.getDestinationAttribute("hostId")
    ports = Framework.getTriggerCIDataAsList("port_number")
    """
    Retrieving a list of LDAP ports we strive to connect to domain controller in
    member role first. So we have to choose the lowest port number in the list.
    """
    if ports:
        ports = map(lambda port: int(port), ports)
        ports.sort()
    else:
        raise Exception("No LDAP ports provided to connect")

    protocol = "ldap"
    credentialIds = Framework.getAvailableProtocols(hostIp, protocol)
    client = None
    warningList = []

    defiscoveryPassed = 0
    connectedOnce = 0

    if not len(credentialIds):
        msg = "Protocol not defined or IP out of protocol network range"
        Framework.reportError(msg)
    else:  # go over all protocols and for each protocol try all available ports
        for credentialsId in credentialIds:
            portsToIterate = None
            protocolPort = Framework.getProtocolProperty(credentialsId, "protocol_port")
            if str(protocolPort).isdigit():
                portsToIterate = [protocolPort]
            else:
                portsToIterate = ports
            for port in portsToIterate:
                try:  # build environment and connect
                    try:
                        envBuilder = LdapEnvironmentBuilder(port)
                        client = Framework.createClient(credentialsId, envBuilder.build())
                        connectedOnce = 1
                        baseDn = active_directory_utils.getBaseDnFromJobsParameters(Framework)
                        daoService = LdapDaoService(client, baseDn)
                        # discover domain controller
                        warningList = []
                        hostOsh = modeling.createOshByCmdbIdString("host", hostIdString)
                        discoverer = AdDomainControllerDiscoverer(daoService, hostOsh)
                        OSHVResult = discoverer.discover()
                        # add container hosts for domain controllers to the result vector
                        containerOshs = discoverer.getResult().getContainerOshMap().values()
                        for osh in containerOshs:
                            OSHVResult.add(osh)
                        # skip other ports
                        defiscoveryPassed = 1
                        break
                    except:
                        msg = logger.prepareFullStackTrace("")
                        warning = errormessages.resolveError(msg, protocol)
                        warningList.append(warning)
                finally:
                    client and client.close()
            # skip other protocols in case when discovery passed for current one
            if defiscoveryPassed:
                break

    if not connectedOnce:
        warning = errorobject.createError(
            errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS,
            ["Tried all protocols"] * 2,
            "Failed to connect using all protocols",
        )
        warningList = [warning]

    # print collected warning message
    for warning in warningList:
        logger.reportWarningObject(warning)

    return OSHVResult
Esempio n. 15
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    protocol = Framework.getDestinationAttribute('Protocol')

    DEFAULT_MAIN_FC_PATH = ''
    #this default value would be used as last resort in case the file main.cf will not be found
    if protocol == 'ntcmd':
        DEFAULT_MAIN_FC_PATH = 'c:\\program Files\\VERITAS\\cluster server\\conf\config\\'
    else:
        DEFAULT_MAIN_FC_PATH = '/etc/VRTSvcs/conf/config/'

    # take the following parameter from the section 'destinationData name' ${PARAMETERS.<paramname>) defined in the pattern's xml file
    main_cf_path = Framework.getParameter('main_cf_path')

    properties = Properties()

    # Set codepage
    codePage = Framework.getCodePage()
    properties.put(BaseAgent.ENCODING, codePage)

    try:
        # Connect to the SSH/TELNET/NTCMD agent
        client = Framework.createClient(properties)
        clientShUtils = shellutils.ShellUtils(client)
    except:
        msg = sys.exc_info()[1]
        strmsg = '%s' % msg
        if (strmsg.lower().find('timeout') > -1):
            errobj = errorobject.createError(
                errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL, None,
                'Connection timed out - reactivate with larger timeout value')
            logger.reportErrorObject(errobj)
            logger.debugException('Connection timed out')
        else:
            errobj = errormessages.resolveError(strmsg, 'shell')
            logger.reportErrorObject(errobj)
            logger.errorException(strmsg)
    else:
        # Get main.cf path
        if ((main_cf_path == None) or
            (main_cf_path == 'NA')) and (protocol != 'ntcmd'):
            main_cf_path = getMainCFPath(clientShUtils)
            if (main_cf_path == None) or (main_cf_path == 'NA'):
                main_cf_path = DEFAULT_MAIN_FC_PATH
        if ((main_cf_path == None) or
            (main_cf_path == 'NA')) and (protocol == 'ntcmd'):
            main_cf_path = DEFAULT_MAIN_FC_PATH

        # Assemble the main.cf command
        cfFullPath = main_cf_path + 'main.cf'
        try:
            resBuffer = clientShUtils.safecat(cfFullPath)
        except:
            errorMessage = 'Failed to get configuration file:' + cfFullPath
            logger.debugException(errorMessage)
            errobj = errorobject.createError(
                errorcodes.FAILED_FINDING_CONFIGURATION_FILE, [cfFullPath],
                errorMessage)
            logger.reportErrorObject(errobj)
        else:
            if resBuffer.find('Permission denied') > -1:
                errobj = errorobject.createError(
                    errorcodes.PERMISSION_DENIED_NO_PROTOCOL_WITH_DETAILS,
                    ['User has no permissions to read main.cf file'],
                    'User has no permissions to read main.cf file')
                logger.reportErrorObject(errobj)
            else:
                lastUpdateTime = file_ver_lib.getFileLastModificationTime(
                    clientShUtils, cfFullPath)
                mainFunction(resBuffer, main_cf_path, clientShUtils,
                             OSHVResult, protocol, Framework, lastUpdateTime)

        try:
            clientShUtils and clientShUtils.closeClient()
        except:
            logger.debugException('')
            logger.error('Unable to close shell')
    return OSHVResult
def _getDocument(framework, httpEndpoint):
    address = httpEndpoint.getAddress()
    port = httpEndpoint.getPort()
    document = None
    errors = []
    warnings = []
    protocolName = 'sapjmxprotocol'
    protocolLabel = errormessages.protocolNames[protocolName]
    protocols = framework.getAvailableProtocols(address, protocolName)
    if not protocols:
        msg = errormessages.makeErrorMessage(protocolName,
                                             pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP,
                                         [protocolLabel], msg)
        warnings.append(errobj)
    else:
        for protocol in protocols:
            logger.debug('Using protocol %s' % protocol)

            with _create_client(framework.createClient, 'http',
                                protocol, address, port) as httpClient:
                protocol_type = framework.getDestinationAttribute('ip_service_name')
                if not protocol_type:
                    try:
                        protocol_type = framework.getProtocolProperty(protocol, 'protocol')
                    except:
                        protocol_type = 'http'
                if protocol_type in ('http', 'sap_http'):
                    sapMonitoringCommands = sap_jee_discoverer.SapMonitoringCommandsPlain
                elif protocol_type == 'sap_jmx':
                    sapMonitoringCommands = sap_jee_discoverer.SapMonitoringCommands
                else:
                    sapMonitoringCommands = sap_jee_discoverer.SapMonitoringCommandsHttps
                    
                for sapMonitoringCommand in sapMonitoringCommands:
                    try:
                        cmd = sapMonitoringCommand()
                        urlDomainPart = _getUrlDomainByIp(address)
                        result = cmd.getSystemInfo(urlDomainPart, port) | HttpExecutorCmdlet(httpClient)

                        document = result | command.cmdlet.produceResult
                        if document:
                            return document, [], []
                    except UnauthorizedException, ex:
                        msg = errormessages.makeErrorMessage(protocolName,
                                                 pattern=errormessages.ERROR_HTTP_UNAUTHORIZED)
                        errobj = errorobject.createError(errorcodes.HTTP_UNAUTHORIZED,
                                             [protocolLabel], msg)
                        warnings.append(errobj)

                    except PageNotFoundException, ex:
                        msg = errormessages.makeErrorMessage(protocolName,
                                                 pattern=errormessages.ERROR_HTTP_PAGE_NOT_FOUND)
                        errobj = errorobject.createError(errorcodes.HTTP_PAGE_NOT_FOUND,
                                             [protocolLabel], msg)
                        warnings.append(errobj)

                    except SSLHandshakeException, ex:
                        msg = ex.getMessage()
                        msg = removeIp(msg, ' to ')
                        errobj = errormessages.resolveError(msg, protocolName)
                        warnings.append(errobj)

                    except SAXParseException, ex:
                        msg = errormessages.makeErrorMessage(protocolName,
                                                 pattern=errormessages.ERROR_INVALID_RESPONSE)
                        errobj = errorobject.createError(errorcodes.INVALID_RESPONSE,
                                             [protocolLabel], msg)
                        errors.append(errobj)

                    except (JException, Exception), ex:
                        msg = str(ex)
                        errormessages.resolveAndAddToObjectsCollections(msg,
                                                                        protocolName,
                                                                        errors,
                                                                        warnings)