def _discover(self, domainDto=None): ''' if domainDto is None, domain controllers of self domain will be discovered, else controllers for specified domain will be discovered ''' result = AdDiscoveryResult() dtoToOshMap = result.getMap() siteDtoToOshMap = result.getSiteDtoToOshMap() containerOshMap = result.getContainerOshMap() client = self._daoService.getClient() serverDao = self._daoService.getServerDao() domainDao = self._daoService.getDomainDao() siteDao = self._daoService.getSiteDao() if domainDto is None: domainDto = domainDao.createDto(domainDao.obtainSelfDomainId()) serverDtos = serverDao.obtainServers(domainDto) selfControllerId = serverDao.obtainSelfServerId() for dto in serverDtos: hostOsh = None functionality = None #if this is controller that we are triggered on if selfControllerId == dto.id: dto.fullVersion = serverDao.obtainSelfFullVersion() dto.ipAddress = client.getIpAddress() if self.__isConnectionPortReported: dto.port = client.getPort() dto.username = client.getUserName() dto.credentialId = client.getCredentialId() functionality = serverDao.obtainSelfFunctionality() if self._containerOsh: hostOsh = self._containerOsh else: #determine container host try: dto.ipAddress = InetAddress.getByName( dto.dnsName).getHostAddress() hostOsh = HostBuilder.incompleteByIp(dto.ipAddress).build() except JException: logger.debug('Cannot resolve IP address for fqdn %s' % dto.dnsName) if hostOsh: siteDto = siteDao.createDto(dto.siteName) osh = self.createOsh(dto, hostOsh, functionality) dtoToOshMap[dto] = osh siteDtoToOshMap[siteDto] = osh containerOshMap[dto] = hostOsh return result
def _discover(self, domainDto=None): ''' if domainDto is None, domain controllers of self domain will be discovered, else controllers for specified domain will be discovered ''' result = AdDiscoveryResult() dtoToOshMap = result.getMap() siteDtoToOshMap = result.getSiteDtoToOshMap() containerOshMap = result.getContainerOshMap() client = self._daoService.getClient() serverDao = self._daoService.getServerDao() domainDao = self._daoService.getDomainDao() siteDao = self._daoService.getSiteDao() if domainDto is None: domainDto = domainDao.createDto(domainDao.obtainSelfDomainId()) serverDtos = serverDao.obtainServers(domainDto) selfControllerId = serverDao.obtainSelfServerId() for dto in serverDtos: hostOsh = None functionality = None #if this is controller that we are triggered on if selfControllerId == dto.id: dto.fullVersion = serverDao.obtainSelfFullVersion() dto.ipAddress = client.getIpAddress() if self.__isConnectionPortReported: dto.port = client.getPort() dto.username = client.getUserName() dto.credentialId = client.getCredentialId() functionality = serverDao.obtainSelfFunctionality() if self._containerOsh: hostOsh = self._containerOsh else: #determine container host try: dto.ipAddress = InetAddress.getByName(dto.dnsName).getHostAddress() hostOsh = HostBuilder.incompleteByIp(dto.ipAddress).build() except JException: logger.debug('Cannot resolve IP address for fqdn %s' % dto.dnsName) if hostOsh: siteDto = siteDao.createDto(dto.siteName) osh = self.createOsh(dto, hostOsh, functionality) dtoToOshMap[dto] = osh siteDtoToOshMap[siteDto] = osh containerOshMap[dto] = hostOsh return result
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)
def createVirtHostOsh(config): vHostOsh = modeling.createCompleteHostOSHByInterfaceList( 'host', config.interfaceList) return HostBuilder(vHostOsh).setAsVirtual(1).build()
def __createRouterIncompleteHostByIp(ipAddress): builder = HostBuilder.incompleteByIp(ipAddress) return builder.setAsRouter(1).build()
def createIpsNetworksOSHV(ipList, sysTable, hostId, hostIsComplete): ipsAndNetworksOSHV = ObjectStateHolderVector() isRoute = checkIsRoute(ipList) hostOSH = modeling.createOshByCmdbId(sysTable.sysClass, hostId) builder = HostBuilder(hostOSH) builder.setAsRouter(isRoute, __NOT_SET_ROLE) if str(sysTable.sysModel).lower() != 'unknown': builder.setStringAttribute("host_model", sysTable.sysModel) if str(sysTable.sysOs).lower() != 'unknown': builder.setOsName(sysTable.sysOs) if str(sysTable.sysVendor).lower() != 'unknown': builder.setStringAttribute("host_vendor", sysTable.sysVendor) if sysTable.sysName != None and str(sysTable.sysName).lower() != 'unknown': builder.setStringAttribute("host_snmpsysname", sysTable.sysName) if sysTable.sysNodeName is not None: builder.setStringAttribute("host_hostname", sysTable.sysNodeName) hostOSH = builder.build() ipsAndNetworksOSHV.add(hostOSH) for ip in ipList: if not isValidIP(ip): continue #create ip object ipOSH = modeling.createIpOSH(ip.ipAddr, ip.ipNetMask) #create network object networkOSH = modeling.createNetworkOSH(ip.ipAddr, ip.ipNetMask) if ip.nettype != None and int(ip.nettype) > 0: networkOSH.setEnumAttribute("network_nettype", int(ip.nettype)) #create member link object ( end1(network) and end2(ip) ) memberLinkOSHIpNetwork = modeling.createLinkOSH("member", networkOSH, ipOSH) #create member link object ( end1(network) and end2(host) ) memberLinkOSHHostNetwork = modeling.createLinkOSH("member", networkOSH, hostOSH) #create contained link object ( end1(host) and end2(ip) ) if Boolean.parseBoolean(hostIsComplete): containedLinkOSHIpHost = modeling.createLinkOSH("contained", hostOSH, ipOSH) ipsAndNetworksOSHV.add(containedLinkOSHIpHost) ipsAndNetworksOSHV.add(ipOSH) ipsAndNetworksOSHV.add(networkOSH) ipsAndNetworksOSHV.add(memberLinkOSHIpNetwork) ipsAndNetworksOSHV.add(memberLinkOSHHostNetwork) return ipsAndNetworksOSHV