Example #1
0
    def setHostAttributes(self):
        if self.hostOsh:
            if self.hostDo.hostName:
                self.hostOsh.setAttribute('host_hostname', self.hostDo.hostName)
            if self.hostDo.hostOsName:
                modeling.setHostOsName(self.hostOsh, self.hostDo.hostOsName)
            if self.hostDo.description:
                self.hostOsh = modeling.HostBuilder(self.hostOsh).setDescription(self.hostDo.description).build()
            if self.hostDo.servicePack:
                self.hostOsh.setAttribute('nt_servicepack', self.hostDo.servicePack)
            if self.hostDo.buildNumber:
                self.hostOsh.setAttribute('host_osrelease', self.hostDo.buildNumber)
            if self.hostDo.ntVersion:
                self.hostOsh.setAttribute('host_osversion', self.hostDo.ntVersion)
            if self.hostDo.installType:
                self.hostOsh.setAttribute('host_osinstalltype', self.hostDo.installType)
            if self.hostDo.vendor:
                self.hostOsh.setAttribute('host_vendor', self.hostDo.vendor)
            if self.hostDo.registeredOwner:
                self.hostOsh.setAttribute('nt_registeredowner', self.hostDo.registeredOwner)
            if self.hostDo.organization:
                self.hostOsh.setStringAttribute('nt_registrationorg', self.hostDo.organization)
            if self.hostDo.physicalMemory:
                self.hostOsh.setAttribute('nt_physicalmemory', self.hostDo.physicalMemory)
            if self.hostDo.biosAssetTag:
                self.hostOsh.setStringAttribute('bios_asset_tag', self.hostDo.biosAssetTag)
            if self.hostDo.osDomain:
                self.hostOsh.setStringAttribute('host_osdomain', self.hostDo.osDomain)
            if self.hostDo.winProcessorsNumber:
                self.hostOsh.setIntegerAttribute('nt_processorsnumber', self.hostDo.winProcessorsNumber)

            if self.hostDo.serialNumber:
                modeling.setHostSerialNumberAttribute(self.hostOsh, self.hostDo.serialNumber)
            if self.hostDo.hostModel:
                modeling.setHostModelAttribute(self.hostOsh, self.hostDo.hostModel)
            if self.hostDo.hostManufacturer:
                modeling.setHostManufacturerAttribute(self.hostOsh, self.hostDo.hostManufacturer)
            if self.hostDo.udUniqueId:
                self.hostOsh.setAttribute("ud_unique_id", self.hostDo.udUniqueId)
            if self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in ['1', 'true']:
                self.hostOsh.setBoolAttribute("pae_enabled", 1)
            elif self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in ['0', 'false']:
                self.hostOsh.setBoolAttribute("pae_enabled", 0)
            if self.hostDo.installType and self.hostDo.installType.encode('ascii','ignore').lower().find('ia64') != -1:
                self.hostDo.osArchitecture = 'ia64'
            elif self.hostDo.installType and self.hostDo.installType.encode('ascii','ignore').find('64') != -1:
                self.hostDo.osArchitecture = '64-bit'
            if self.hostDo.osArchitecture:
                self.hostOsh.setStringAttribute('os_architecture', self.hostDo.osArchitecture)

            modeling.setHostBiosUuid(self.hostOsh, self.hostDo.biosUUID)
            modeling.setHostDefaultGateway(self.hostOsh, self.hostDo.defaultGateway)
            modeling.setHostOsFamily(self.hostOsh, self.hostDo.osFamily)
            # fill in list of DNS servers
            if self.dnsServerIpList:
                list_ = StringVector(map(str, self.dnsServerIpList))
                attr = AttributeStateHolder('dns_servers', list_)
                self.hostOsh.setListAttribute(attr)
            self.resultVector.add(self.hostOsh)
    def discoveryLB(self):
        queryBuilder = snmputils.SnmpQueryBuilder(OID_TABLE_NS)
        queryBuilder.addQueryElement(1, 'build')
        queryBuilder.addQueryElement(2, 'ip')
        queryBuilder.addQueryElement(10, 'hardware_version_id')
        queryBuilder.addQueryElement(11, 'hardware_version')
        queryBuilder.addQueryElement(14, 'serial_number')

        data = self.snmpAgent.getSnmpData(queryBuilder)
        if data:
            netscaler = data[0]
            netscalerOsh = modeling.createHostOSH(netscaler.ip, 'lb')
            modeling.setHostManufacturerAttribute(netscalerOsh, 'Citrix')
            modeling.setHostModelAttribute(netscalerOsh, netscaler.hardware_version_id)
            modeling.setHostSerialNumberAttribute(netscalerOsh, netscaler.serial_number)
            netscalerOsh.setStringAttribute('data_note', netscaler.hardware_version)
            return netscalerOsh
        else:
            raise Exception('Failed to query NetScaler SNMP data')
Example #3
0
    def build(self, device):
        if device is None:
            raise ValueError("device is None")

        deviceClass = self.getDeviceClass(device)
        deviceOsh = ObjectStateHolder(deviceClass)
        deviceOsh.setBoolAttribute('host_iscomplete', True)

        deviceOsh = self.setDeviceRoles(device, deviceOsh)

        hostName = device.hostName
        domainName = None

        if hostName and not ip_addr.isValidIpAddress(hostName):
            hostName, domainName = self.getHostNameAndDomain(hostName)

        if hostName:
            deviceOsh.setStringAttribute('name', hostName)
        if domainName:
            deviceOsh.setStringAttribute('host_osdomain', domainName)

        if device.serialNumber:
            modeling.setHostSerialNumberAttribute(deviceOsh,
                                                  device.serialNumber)

        if device.model:
            modeling.setHostModelAttribute(deviceOsh, device.model)

        if device.vendor:
            deviceOsh.setStringAttribute('discovered_vendor', device.vendor)

        if device.softwareVersion:
            deviceOsh.setStringAttribute('discovered_os_version',
                                         device.softwareVersion)

        if device.memory:
            memoryMb = int(device.memory / (1024 * 1024))
            modeling.setHostMemorySizeAttribute(deviceOsh, memoryMb)

        return deviceOsh
Example #4
0
    def discoveryLB(self):
        queryBuilder = snmputils.SnmpQueryBuilder(OID_TABLE_NS)
        queryBuilder.addQueryElement(1, 'build')
        queryBuilder.addQueryElement(2, 'ip')
        queryBuilder.addQueryElement(10, 'hardware_version_id')
        queryBuilder.addQueryElement(11, 'hardware_version')
        queryBuilder.addQueryElement(14, 'serial_number')

        data = self.snmpAgent.getSnmpData(queryBuilder)
        if data:
            netscaler = data[0]
            netscalerOsh = modeling.createHostOSH(netscaler.ip, 'lb')
            modeling.setHostManufacturerAttribute(netscalerOsh, 'Citrix')
            modeling.setHostModelAttribute(netscalerOsh,
                                           netscaler.hardware_version_id)
            modeling.setHostSerialNumberAttribute(netscalerOsh,
                                                  netscaler.serial_number)
            netscalerOsh.setStringAttribute('data_note',
                                            netscaler.hardware_version)
            return netscalerOsh
        else:
            raise Exception('Failed to query NetScaler SNMP data')
Example #5
0
    def build(self, device):
        if device is None:
            raise ValueError("device is None")

        deviceClass = self.getDeviceClass(device)
        deviceOsh = ObjectStateHolder(deviceClass)
        deviceOsh.setBoolAttribute("host_iscomplete", True)

        deviceOsh = self.setDeviceRoles(device, deviceOsh)

        hostName = device.hostName
        domainName = None

        if hostName and not ip_addr.isValidIpAddress(hostName):
            hostName, domainName = self.getHostNameAndDomain(hostName)

        if hostName:
            deviceOsh.setStringAttribute("name", hostName)
        if domainName:
            deviceOsh.setStringAttribute("host_osdomain", domainName)

        if device.serialNumber:
            modeling.setHostSerialNumberAttribute(deviceOsh, device.serialNumber)

        if device.model:
            modeling.setHostModelAttribute(deviceOsh, device.model)

        if device.vendor:
            deviceOsh.setStringAttribute("discovered_vendor", device.vendor)

        if device.softwareVersion:
            deviceOsh.setStringAttribute("discovered_os_version", device.softwareVersion)

        if device.memory:
            memoryMb = int(device.memory / (1024 * 1024))
            modeling.setHostMemorySizeAttribute(deviceOsh, memoryMb)

        return deviceOsh
def doWMI(client, wmiOSH, ip_address, ip_domain, hostForLinkOSH, host_cmdbid=None, host_key=None, host_macs=None, ucmdb_version=None):
    '''@types: WmiClient, ObjectStateHolder, IPAddress, str, ObjectStateHolder, str, str, list[str], int -> ObjectStateHolderVector
    @param ip_address: Destination IP address
    '''
    wmiProvider = wmiutils.getWmiProvider(client)
    hostDiscoverer = host_win_wmi.WmiHostDiscoverer(wmiProvider)
    hostInfo = hostDiscoverer.discoverHostInfo()
    machineName = hostInfo.hostName

    interfacesDiscover = networking_win_wmi.WmiInterfaceDiscoverer(wmiProvider,
                                                ip_address)

    vector = ObjectStateHolderVector()
    interfaceList = interfacesDiscover.getInterfaces()
    parentLinkList = ObjectStateHolderVector()

    isVirtual = 1
    resultEmpty = 1
    interfacesToUpdateList = []
    for interface in interfaceList:
        ips = interface.ips
        MACAddress = interface.macAddress
        masks = interface.masks
        Description = interface.description
        dhcpEnabled = interface.dhcpEnabled

        resultEmpty = 0
        for ipIndex, ipAddress in enumerate(__iterate_valid_ips(ips)):
            IPSubnet = (masks and masks[ipIndex]) or None
            if str(ip_address) == str(ipAddress):
                isVirtual = 0

            ipOSH = modeling.createIpOSH(ipAddress)

            # Test if the same ip and interface are in the list allready

            logger.debug('Found ip address: ', ipAddress, ', MACAddress: ', MACAddress, ', IPSubnet: ', IPSubnet, ', Description: ', Description)
                # create OSH for IP and add it to the list
                # create OSH for Network and add it to the list
            __vector = getIPNetworkMemebrList(ipAddress, IPSubnet, '', dhcpEnabled, Description)
            if __vector.size() > 0:
                vector.addAll(__vector)

            if netutils.isValidMac(MACAddress):
                # create link interface to its ip only it has an ip defined
                interfaceOSH = modeling.createInterfaceOSH(MACAddress, hostForLinkOSH, Description)
                parentLinkList.add(modeling.createLinkOSH('containment', interfaceOSH, ipOSH))
                interfacesToUpdateList.append(interfaceOSH)

    # Check if the Input IP is virtual, we do not want to return the WMI
    if isVirtual == 1:
        logger.warn('Destination is not among discovered IPs assuming virtual. WMI object will not be reported.')
        vIPOSH = modeling.createIpOSH(ip_address)
        vIPOSH.setBoolAttribute('isvirtual', 1)
        vector.add(vIPOSH)

    if resultEmpty == 1:
        logger.warn('WMI was able to connect, but WMI Query returns no results')
        vector.clear()
        return vector

    # create the host and all the objects
    if len(interfaceList) > 0:
        hostOSH = None
        try:
            hostOSH = modeling.createCompleteHostOSHByInterfaceList('nt',
                            interfaceList, 'Windows', machineName, None,
                            host_cmdbid, host_key, host_macs, ucmdb_version)
        except:
            hostOSH = modeling.createHostOSH(str(ip_address), 'nt')
            logger.debugException('Could not find a valid MAC address for key on ip : %s. Creating incomplete host\n' % ip_address)
            logger.warn('Could not find a valid MAC address for key on ip : %s. Creating incomplete host\n' % ip_address)

        # select from Win32_OperatingSystem
        _wmiQuery = 'select Caption,Version,ServicePackMajorVersion,ServicePackMinorVersion,BuildNumber,Organization,RegisteredUser,TotalVisibleMemorySize,LastBootUpTime,OtherTypeDescription,description from Win32_OperatingSystem'
        resultSet = client.executeQuery(_wmiQuery)  # @@CMD_PERMISION wmi protocol execution
        osinstalltype = None
        if resultSet.next():
            Caption = resultSet.getString(1)
            Version = resultSet.getString(2)
            ServicePackMajorVersion = resultSet.getString(3)
            ServicePackMinorVersion = resultSet.getString(4)
            BuildNumber = resultSet.getString(5)
            Organization = resultSet.getString(6)
            RegisteredUser = resultSet.getString(7)
            TotalVisibleMemorySize = resultSet.getString(8)
            LastBootUpTime = resultSet.getString(9)
            OtherTypeDescription = resultSet.getString(10)
            description = resultSet.getString(11)

            (vendor, osName, osinstalltype) = separateCaption(Caption, OtherTypeDescription)
            hostOSH.setAttribute('host_vendor', vendor)
            modeling.setHostOsName(hostOSH, osName)
            hostOSH.setAttribute('host_osinstalltype', osinstalltype)

            setLastBootUpTime(hostOSH, LastBootUpTime)
            biosUUID = getBIOSUUID(client)
            defaultGateway = getDefaultGateway(client)

            hostOSH.setAttribute('host_osversion', Version)
            sp = ServicePackMajorVersion + '.' + ServicePackMinorVersion
            if checkSpVersion(sp):
                hostOSH.setAttribute('nt_servicepack', sp)
            hostOSH.setAttribute('host_osrelease', str(BuildNumber))
            hostOSH.setAttribute('nt_registrationorg', Organization)
            hostOSH.setAttribute('nt_registeredowner', RegisteredUser)
            hostOSH.setAttribute('nt_physicalmemory', TotalVisibleMemorySize)
            hostOSH.setAttribute('host_hostname', machineName)
            modeling.setHostBiosUuid(hostOSH, biosUUID)
            modeling.setHostDefaultGateway(hostOSH, defaultGateway)
            modeling.setHostOsFamily(hostOSH, 'windows')

            hostOSH = HostBuilder(hostOSH).setDescription(description).build()

        _wmiQuery2 = 'select Manufacturer,NumberOfProcessors,Model,Domain from Win32_ComputerSystem'
        resultSet = client.executeQuery(_wmiQuery2)  # @@CMD_PERMISION wmi protocol execution

        if resultSet.next():
            Manufacturer = resultSet.getString(1)
            if ((Manufacturer != None) and (Manufacturer.find('system manufacturer') == -1)):
                modeling.setHostManufacturerAttribute(hostOSH, Manufacturer.strip())
            NumberOfProcessors = resultSet.getString(2)
            hostOSH.setAttribute('nt_processorsnumber', int(NumberOfProcessors))
            Model = resultSet.getString(3)
            modeling.setHostModelAttribute(hostOSH, Model)
            osDomain = resultSet.getString(4)
            hostOSH.setAttribute('host_osdomain', osDomain.strip())

        biosAssetTag = hostDiscoverer.getBiosAssetTag()
        if biosAssetTag:
            hostOSH.setAttribute('bios_asset_tag', biosAssetTag)

        _wmiQuery4 = 'SELECT SerialNumber FROM Win32_BIOS'
        resultSet = client.executeQuery(_wmiQuery4)  # @@CMD_PERMISSION wmi protocol execution
        if resultSet.next():
            serialNumber = processSerialNumber(resultSet.getString(1))
            if not serialNumber:
                wmiBaseBoardSerialNumber = 'SELECT SerialNumber FROM Win32_BaseBoard'
                resultSet = client.executeQuery(wmiBaseBoardSerialNumber)  # @@CMD_PERMISION wmi protocol execution
                serialNumber = processSerialNumber(str(resultSet))
            modeling.setHostSerialNumberAttribute(hostOSH, serialNumber)

        try:
            paeEnabled = getPAEState(client)
            if paeEnabled and paeEnabled.lower() in ['1', 'true']:
                hostOSH.setBoolAttribute('pae_enabled', 1)
            elif paeEnabled and paeEnabled.lower() in ['0', 'false']:
                hostOSH.setBoolAttribute('pae_enabled', 0)
        except Exception, ex:
            logger.warn('Failed getting PAE state. %s' % ex)

        try:
            osArchitecture = getOsArchitecture(client)
            if osinstalltype and osinstalltype.find('64') != -1:
                osArchitecture = '64-bit'
            if osArchitecture:
                hostOSH.setStringAttribute('os_architecture', osArchitecture)
        except Exception, ex:
            logger.warn('Failed getting OS Architecture value. %s' % ex)
Example #7
0
    def setHostAttributes(self):
        if self.hostOsh:
            if self.hostDo.hostName:
                self.hostOsh.setAttribute('host_hostname',
                                          self.hostDo.hostName)
            if self.hostDo.hostOsName:
                modeling.setHostOsName(self.hostOsh, self.hostDo.hostOsName)
            if self.hostDo.description:
                self.hostOsh = modeling.HostBuilder(
                    self.hostOsh).setDescription(
                        self.hostDo.description).build()
            if self.hostDo.servicePack:
                self.hostOsh.setAttribute('nt_servicepack',
                                          self.hostDo.servicePack)
            if self.hostDo.buildNumber:
                self.hostOsh.setAttribute('host_osrelease',
                                          self.hostDo.buildNumber)
            if self.hostDo.ntVersion:
                self.hostOsh.setAttribute('host_osversion',
                                          self.hostDo.ntVersion)
            if self.hostDo.installType:
                self.hostOsh.setAttribute('host_osinstalltype',
                                          self.hostDo.installType)
            if self.hostDo.vendor:
                self.hostOsh.setAttribute('host_vendor', self.hostDo.vendor)
            if self.hostDo.registeredOwner:
                self.hostOsh.setAttribute('nt_registeredowner',
                                          self.hostDo.registeredOwner)
            if self.hostDo.organization:
                self.hostOsh.setStringAttribute('nt_registrationorg',
                                                self.hostDo.organization)
            if self.hostDo.physicalMemory:
                self.hostOsh.setAttribute('nt_physicalmemory',
                                          self.hostDo.physicalMemory)
            if self.hostDo.biosAssetTag:
                self.hostOsh.setStringAttribute('bios_asset_tag',
                                                self.hostDo.biosAssetTag)
            if self.hostDo.osDomain:
                self.hostOsh.setStringAttribute('host_osdomain',
                                                self.hostDo.osDomain)
            if self.hostDo.winProcessorsNumber:
                self.hostOsh.setIntegerAttribute(
                    'nt_processorsnumber', self.hostDo.winProcessorsNumber)

            if self.hostDo.serialNumber:
                modeling.setHostSerialNumberAttribute(self.hostOsh,
                                                      self.hostDo.serialNumber)
            if self.hostDo.hostModel:
                modeling.setHostModelAttribute(self.hostOsh,
                                               self.hostDo.hostModel)
            if self.hostDo.hostManufacturer:
                modeling.setHostManufacturerAttribute(
                    self.hostOsh, self.hostDo.hostManufacturer)
            if self.hostDo.udUniqueId:
                self.hostOsh.setAttribute("ud_unique_id",
                                          self.hostDo.udUniqueId)
            if self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in [
                    '1', 'true'
            ]:
                self.hostOsh.setBoolAttribute("pae_enabled", 1)
            elif self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in [
                    '0', 'false'
            ]:
                self.hostOsh.setBoolAttribute("pae_enabled", 0)
            if self.hostDo.installType and self.hostDo.installType.encode(
                    'ascii', 'ignore').lower().find('ia64') != -1:
                self.hostDo.osArchitecture = 'ia64'
            elif self.hostDo.installType and self.hostDo.installType.encode(
                    'ascii', 'ignore').find('64') != -1:
                self.hostDo.osArchitecture = '64-bit'
            if self.hostDo.osArchitecture:
                self.hostOsh.setStringAttribute('os_architecture',
                                                self.hostDo.osArchitecture)

            modeling.setHostBiosUuid(self.hostOsh, self.hostDo.biosUUID)
            modeling.setHostDefaultGateway(self.hostOsh,
                                           self.hostDo.defaultGateway)
            modeling.setHostOsFamily(self.hostOsh, self.hostDo.osFamily)
            # fill in list of DNS servers
            if self.dnsServerIpList:
                list_ = StringVector(map(str, self.dnsServerIpList))
                attr = AttributeStateHolder('dns_servers', list_)
                self.hostOsh.setListAttribute(attr)
            self.resultVector.add(self.hostOsh)