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 mainFunction(Framework, OSHVResult, softNameToInstSoftOSH=None): ''' This function uses registry to provide information about installed software. ''' props = Properties() props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\DEFAULT') wmiClient = None try: try: wmiClient = Framework.createClient(props) hostOSH = createHostOSH(Framework, wmiClient) OSHVResult.add(hostOSH) registryColumns = {'DisplayName': {}, 'InstallLocation': {}, 'DisplayVersion': {}, 'Publisher': {}, 'ProductID': {}, 'InstallDate': {}} keyNames = registryColumns.keys() # These are the Registry sections, where the Software Uninstall information is stored keyPaths = ['SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'] for keyPath in keyPaths: try: result = getRegistrySubkeys(wmiClient, keyPath, keyNames) _mergeDictionaries(registryColumns, result) except JavaException, e: logger.info('Not a 64bit OS: ' + str(e)) # do the work _createSoftware(registryColumns['DisplayName'], registryColumns['InstallLocation'], registryColumns['DisplayVersion'], registryColumns['Publisher'], registryColumns['ProductID'], registryColumns['InstallDate'], hostOSH, OSHVResult, softNameToInstSoftOSH) try: props = Properties() props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\cimv2') client = Framework.createClient(props) wmiProvider = WmiAgentProvider(client) hostDiscoverer = WmiHostDiscoverer(wmiProvider) if hostDiscoverer.isWin2008(): logger.debug('win2008 detected') discoverWin2008HotFixes(wmiProvider, hostOSH, OSHVResult) elif hostDiscoverer.isWindows8_2012(): logger.debug('win 8 or win 2012 detected') discoverWin8_2012HotFixes(wmiProvider, hostOSH, OSHVResult) else: logger.debug('Non-win2008/8/2012 detected') finally: client.close() except JavaException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, 'WMI', Framework)
def mainFunctionWithWbem(Framework, wmiClient, OSHVResult, softNameToInstSoftOSH=None): ''' Discovers installed software and, for Windows 2008, hotfixes This function uses Win32_Product class http://msdn.microsoft.com/en-us/library/windows/desktop/aa394378(v=vs.85).aspx It's available since Windows 2000 In Windows 2003 Server, Win32_Product is not enabled by default, and must be enabled as follows: 1.In Add or Remove Programs, click Add/Remove Windows Components. 2. In the Windows Components Wizard, select Management and Monitoring Tools and then click Details. 3. In the Management and Monitoring Tools dialog box, select WMI Windows Installer Provider and then click OK. 4. Click Next. Cons: It is terribly slow (querying might take up to 10 seconds) It represents information only about software installed using MSI (Microsoft Installer) ''' try: hostOSH = createHostOSH(Framework, wmiClient) OSHVResult.add(hostOSH) wmiProvider = WmiAgentProvider(wmiClient) softwareDiscoverer = SoftwareDiscoverer(wmiProvider) softwareItems = softwareDiscoverer.getInstalledSoftware() for software in softwareItems: softwareOSH = hostresource.createSoftwareOSH( hostOSH, software.name, path=software.path, displayVersion=software.version, publisher=software.vendor, productId=software.productId, installDate=software.installDate) OSHVResult.add(softwareOSH) if softNameToInstSoftOSH != None: softNameToInstSoftOSH[software.name.strip()] = softwareOSH hostDiscoverer = WmiHostDiscoverer(wmiProvider) if hostDiscoverer.isWin2008(): discoverWin2008HotFixes(wmiProvider, hostOSH, OSHVResult) if hostDiscoverer.isWindows8_2012(): discoverWin8_2012HotFixes(wmiProvider, hostOSH, OSHVResult) except JavaException, ex: exInfo = ex.getMessage() pattern = "(Invalid class.?)|(Could not connect to WMI.?)" if (re.match(pattern, exInfo) is not None): logger.debug("Cannot perform regular software discovery (seems that remote 2003 Win server doesn't have appropriate WMI object installed).") logger.debug("Trying to discover installed software from Windows registry") # try to retrieve information by using old (not efficient) method using remote registry wmiClient.close() mainFunction(Framework, OSHVResult, softNameToInstSoftOSH) wmiClient = Framework.createClient() else: errormessages.resolveAndReport(exInfo, 'WMI', Framework)
def discover(shell, powerShellOsh, ipAddress, langBund, Framework, uduid=None): 'Shell, osh, str, Properties, Framework,[str = None, str = None, list(str) = None] -> oshVector' resultVector = ObjectStateHolderVector() hostCmdbid = Framework.getDestinationAttribute('host_cmdbid') hostKey = Framework.getDestinationAttribute('host_key') hostMacs = Framework.getTriggerCIDataAsList('mac_addrs') ipAddrObj = ip_addr.IPAddress(ipAddress) wmiProvider = wmiutils.PowerShellWmiProvider(shell) hostDiscoverer = WmiHostDiscoverer(wmiProvider) hostDo = hostDiscoverer.discover() wmiDnsServersDiscoverer = WmiDnsServersDiscoverer(wmiProvider, ipAddrObj) wmiDnsServersDiscoverer.discover() dnsServersIpList = wmiDnsServersDiscoverer.getResults() wmiWinsServersDiscoverer = WmiWinsServersDiscoverer(wmiProvider, ipAddrObj) wmiWinsServersDiscoverer.discover() winsServersIpList = wmiWinsServersDiscoverer.getResults() dhcpWmiServersDiscoverer = WmiDhcpServersDiscoverer(wmiProvider, ipAddrObj) dhcpWmiServersDiscoverer.discover() dhcpServersIpList = dhcpWmiServersDiscoverer.getResults() interfaceDiscoverer = WmiInterfaceDiscoverer(wmiProvider, ipAddrObj) interfaceDiscoverer.discover() logger.debug('Interfaces successfully discovered via wmic.') try: shellIfaceDiscoverer = IpConfigInterfaceDiscoverer( shell, ipAddrObj, Framework, langBund) shellIfaceDiscoverer.discover() ifaces = shellIfaceDiscoverer.getResults() interfaceDiscoverer.interfacesList.extend(ifaces) except: logger.debugException('') hostDo.ipIsVirtual = interfaceDiscoverer.isIpVirtual() interfacesList = interfaceDiscoverer.getResults() topoBuilder = TopologyBuilder(interfacesList, hostDo, ipAddrObj, powerShellOsh, dnsServersIpList, dhcpServersIpList, winsServersIpList, hostCmdbid, hostKey, hostMacs) topoBuilder.build() # access built host OSH to update UD UID attribute if topoBuilder.hostOsh and uduid: _updateHostUniversalDiscoveryUid(topoBuilder.hostOsh, uduid) topoBuilder.addResultsToVector(resultVector) return resultVector
def discover(shell, powerShellOsh, ipAddress, langBund, Framework, uduid = None): 'Shell, osh, str, Properties, Framework,[str = None, str = None, list(str) = None] -> oshVector' resultVector = ObjectStateHolderVector() hostCmdbid = Framework.getDestinationAttribute('host_cmdbid') hostKey = Framework.getDestinationAttribute('host_key') hostMacs = Framework.getTriggerCIDataAsList('mac_addrs') ipAddrObj = ip_addr.IPAddress(ipAddress) wmiProvider = wmiutils.PowerShellWmiProvider(shell) hostDiscoverer = WmiHostDiscoverer(wmiProvider) hostDo = hostDiscoverer.discover() wmiDnsServersDiscoverer = WmiDnsServersDiscoverer(wmiProvider, ipAddrObj) wmiDnsServersDiscoverer.discover() dnsServersIpList = wmiDnsServersDiscoverer.getResults() wmiWinsServersDiscoverer = WmiWinsServersDiscoverer(wmiProvider, ipAddrObj) wmiWinsServersDiscoverer.discover() winsServersIpList = wmiWinsServersDiscoverer.getResults() dhcpWmiServersDiscoverer = WmiDhcpServersDiscoverer(wmiProvider, ipAddrObj) dhcpWmiServersDiscoverer.discover() dhcpServersIpList = dhcpWmiServersDiscoverer.getResults() interfaceDiscoverer = WmiInterfaceDiscoverer(wmiProvider, ipAddrObj) interfaceDiscoverer.discover() logger.debug('Interfaces successfully discovered via wmic.') try: shellIfaceDiscoverer = IpConfigInterfaceDiscoverer(shell, ipAddrObj, Framework, langBund) shellIfaceDiscoverer.discover() ifaces = shellIfaceDiscoverer.getResults() interfaceDiscoverer.interfacesList.extend(ifaces) except: logger.debugException('') hostDo.ipIsVirtual = interfaceDiscoverer.isIpVirtual() interfacesList = interfaceDiscoverer.getResults() topoBuilder = TopologyBuilder(interfacesList, hostDo, ipAddrObj, powerShellOsh, dnsServersIpList, dhcpServersIpList, winsServersIpList, hostCmdbid, hostKey, hostMacs) topoBuilder.build() # access built host OSH to update UD UID attribute if topoBuilder.hostOsh and uduid: _updateHostUniversalDiscoveryUid(topoBuilder.hostOsh, uduid) topoBuilder.addResultsToVector(resultVector) return resultVector
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 mainFunction(Framework, OSHVResult, softNameToInstSoftOSH=None): ''' This function uses registry to provide information about installed software. ''' props = Properties() props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\DEFAULT') wmiClient = None try: try: wmiClient = Framework.createClient(props) hostOSH = createHostOSH(Framework, wmiClient) OSHVResult.add(hostOSH) registryColumns = { 'DisplayName': {}, 'InstallLocation': {}, 'DisplayVersion': {}, 'Publisher': {}, 'ProductID': {}, 'InstallDate': {} } keyNames = registryColumns.keys() # These are the Registry sections, where the Software Uninstall information is stored keyPaths = [ 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' ] for keyPath in keyPaths: try: result = getRegistrySubkeys(wmiClient, keyPath, keyNames) _mergeDictionaries(registryColumns, result) except JavaException, e: logger.info('Not a 64bit OS: ' + str(e)) # do the work _createSoftware(registryColumns['DisplayName'], registryColumns['InstallLocation'], registryColumns['DisplayVersion'], registryColumns['Publisher'], registryColumns['ProductID'], registryColumns['InstallDate'], hostOSH, OSHVResult, softNameToInstSoftOSH) try: props = Properties() props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\cimv2') client = Framework.createClient(props) wmiProvider = WmiAgentProvider(client) hostDiscoverer = WmiHostDiscoverer(wmiProvider) if hostDiscoverer.isWin2008(): logger.debug('win2008 detected') discoverWin2008HotFixes(wmiProvider, hostOSH, OSHVResult) elif hostDiscoverer.isWindows8_2012(): logger.debug('win 8 or win 2012 detected') discoverWin8_2012HotFixes(wmiProvider, hostOSH, OSHVResult) else: logger.debug('Non-win2008/8/2012 detected') finally: client.close() except JavaException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, 'WMI', Framework)
def mainFunctionWithWbem(Framework, wmiClient, OSHVResult, softNameToInstSoftOSH=None): ''' Discovers installed software and, for Windows 2008, hotfixes This function uses Win32_Product class http://msdn.microsoft.com/en-us/library/windows/desktop/aa394378(v=vs.85).aspx It's available since Windows 2000 In Windows 2003 Server, Win32_Product is not enabled by default, and must be enabled as follows: 1.In Add or Remove Programs, click Add/Remove Windows Components. 2. In the Windows Components Wizard, select Management and Monitoring Tools and then click Details. 3. In the Management and Monitoring Tools dialog box, select WMI Windows Installer Provider and then click OK. 4. Click Next. Cons: It is terribly slow (querying might take up to 10 seconds) It represents information only about software installed using MSI (Microsoft Installer) ''' try: hostOSH = createHostOSH(Framework, wmiClient) OSHVResult.add(hostOSH) wmiProvider = WmiAgentProvider(wmiClient) softwareDiscoverer = SoftwareDiscoverer(wmiProvider) softwareItems = softwareDiscoverer.getInstalledSoftware() for software in softwareItems: softwareOSH = hostresource.createSoftwareOSH( hostOSH, software.name, path=software.path, displayVersion=software.version, publisher=software.vendor, productId=software.productId, installDate=software.installDate) OSHVResult.add(softwareOSH) if softNameToInstSoftOSH != None: softNameToInstSoftOSH[software.name.strip()] = softwareOSH hostDiscoverer = WmiHostDiscoverer(wmiProvider) if hostDiscoverer.isWin2008(): discoverWin2008HotFixes(wmiProvider, hostOSH, OSHVResult) if hostDiscoverer.isWindows8_2012(): discoverWin8_2012HotFixes(wmiProvider, hostOSH, OSHVResult) except JavaException, ex: exInfo = ex.getMessage() pattern = "(Invalid class.?)|(Could not connect to WMI.?)" if (re.match(pattern, exInfo) is not None): logger.debug( "Cannot perform regular software discovery (seems that remote 2003 Win server doesn't have appropriate WMI object installed)." ) logger.debug( "Trying to discover installed software from Windows registry") # try to retrieve information by using old (not efficient) method using remote registry wmiClient.close() mainFunction(Framework, OSHVResult, softNameToInstSoftOSH) wmiClient = Framework.createClient() else: errormessages.resolveAndReport(exInfo, 'WMI', Framework)
def doHPCmd(client, ntcmd_obj, ip_address, langBund, Framework, host_cmdbid=None, host_key=None, host_macs=None, uduid=None, nat_ip=None): 'Shell, osh, str, Properties, Framework, .. -> oshVector' resultVector = ObjectStateHolderVector() ipAddress = ip_addr.IPAddress(ip_address) wmiProvider = wmiutils.WmicProvider(client) hostDiscoverer = WmiHostDiscoverer(wmiProvider) hostDo = hostDiscoverer.discover() hostDiscoverer = HostDiscovererByShell(client, langBund, Framework, hostDo) hostDiscoverer.discover() hostDo = hostDiscoverer.getResults() wmiDnsServersDiscoverer = WmiDnsServersDiscoverer(wmiProvider, ipAddress) wmiDnsServersDiscoverer.discover() dnsServersIpList = wmiDnsServersDiscoverer.getResults() if not dnsServersIpList: dnsServersDiscoverer = DnsServersDiscoverer(client, ipAddress, langBund, Framework) dnsServersDiscoverer.discover() dnsServersIpList = dnsServersDiscoverer.getResults() winsWmiServersDiscoverer = WmiWinsServersDiscoverer(wmiProvider, ipAddress) winsWmiServersDiscoverer.discover() winsServersIpList = winsWmiServersDiscoverer.getResults() if not winsServersIpList: winsServerDiscoverer = WinsServerDicoverer(client, ipAddress, langBund, Framework) winsServerDiscoverer.discover() winsServersIpList = winsServerDiscoverer.getResults() dhcpWmiServersDiscoverer = WmiDhcpServersDiscoverer(wmiProvider, ipAddress) dhcpWmiServersDiscoverer.discover() dhcpServersIpList = dhcpWmiServersDiscoverer.getResults() if not dhcpServersIpList: dhcpServerDiscoverer = DhcpServerDiscoverer(client, ipAddress, langBund, Framework) dhcpServerDiscoverer.discover() dhcpServersIpList = dhcpServerDiscoverer.getResults() interfaceDiscoverer = WmiInterfaceDiscoverer(wmiProvider, ipAddress) try: interfaceDiscoverer.discover() logger.debug('Interfaces successfully discovered via wmic.') try: shellIfaceDiscoverer = IpConfigInterfaceDiscoverer( client, ipAddress, Framework, langBund) shellIfaceDiscoverer.discover() ifaces = shellIfaceDiscoverer.getResults() interfaceDiscoverer.interfacesList.extend(ifaces) except: logger.debugException('') except: msg = logger.prepareFullStackTrace('') logger.debugException(msg) logger.warn( 'Failed getting interfaces information via wmic. Falling back to ipconfig.' ) interfaceDiscoverer = IpConfigInterfaceDiscoverer( client, ipAddress, Framework, langBund) interfaceDiscoverer.discover() hostDo.ipIsVirtual = interfaceDiscoverer.isIpVirtual() hostDo.ipIsNATed = interfaceDiscoverer.isIpNATed(nat_ip) interfacesList = interfaceDiscoverer.getResults() ucmdbversion = modeling.CmdbClassModel().version() topoBuilder = TopologyBuilder(interfacesList, hostDo, ipAddress, ntcmd_obj, dnsServersIpList, dhcpServersIpList, winsServersIpList, host_cmdbid, host_key, host_macs, ucmdbversion) topoBuilder.build() # access built host OSH to update UD UID attribute if topoBuilder.hostOsh and uduid: _updateHostUniversalDiscoveryUid(topoBuilder.hostOsh, uduid) topoBuilder.addResultsToVector(resultVector) return resultVector
def doHPCmd(client, ntcmd_obj, ip_address, langBund, Framework, host_cmdbid=None, host_key=None, host_macs=None, uduid=None, nat_ip = None): 'Shell, osh, str, Properties, Framework, .. -> oshVector' resultVector = ObjectStateHolderVector() ipAddress = ip_addr.IPAddress(ip_address) wmiProvider = wmiutils.WmicProvider(client) hostDiscoverer = WmiHostDiscoverer(wmiProvider) hostDo = hostDiscoverer.discover() hostDiscoverer = HostDiscovererByShell(client, langBund, Framework, hostDo) hostDiscoverer.discover() hostDo = hostDiscoverer.getResults() wmiDnsServersDiscoverer = WmiDnsServersDiscoverer(wmiProvider, ipAddress) wmiDnsServersDiscoverer.discover() dnsServersIpList = wmiDnsServersDiscoverer.getResults() if not dnsServersIpList: dnsServersDiscoverer = DnsServersDiscoverer(client, ipAddress, langBund, Framework) dnsServersDiscoverer.discover() dnsServersIpList = dnsServersDiscoverer.getResults() winsWmiServersDiscoverer = WmiWinsServersDiscoverer(wmiProvider, ipAddress) winsWmiServersDiscoverer.discover() winsServersIpList = winsWmiServersDiscoverer.getResults() if not winsServersIpList: winsServerDiscoverer = WinsServerDicoverer(client, ipAddress, langBund, Framework) winsServerDiscoverer.discover() winsServersIpList = winsServerDiscoverer.getResults() dhcpWmiServersDiscoverer = WmiDhcpServersDiscoverer(wmiProvider, ipAddress) dhcpWmiServersDiscoverer.discover() dhcpServersIpList = dhcpWmiServersDiscoverer.getResults() if not dhcpServersIpList: dhcpServerDiscoverer = DhcpServerDiscoverer(client, ipAddress, langBund, Framework) dhcpServerDiscoverer.discover() dhcpServersIpList = dhcpServerDiscoverer.getResults() interfaceDiscoverer = WmiInterfaceDiscoverer(wmiProvider, ipAddress) try: interfaceDiscoverer.discover() logger.debug('Interfaces successfully discovered via wmic.') try: shellIfaceDiscoverer = IpConfigInterfaceDiscoverer(client, ipAddress, Framework, langBund) shellIfaceDiscoverer.discover() ifaces = shellIfaceDiscoverer.getResults() interfaceDiscoverer.interfacesList.extend(ifaces) except: logger.debugException('') except: msg = logger.prepareFullStackTrace('') logger.debugException(msg) logger.warn('Failed getting interfaces information via wmic. Falling back to ipconfig.') interfaceDiscoverer = IpConfigInterfaceDiscoverer(client, ipAddress, Framework, langBund) interfaceDiscoverer.discover() hostDo.ipIsVirtual = interfaceDiscoverer.isIpVirtual() hostDo.ipIsNATed = interfaceDiscoverer.isIpNATed(nat_ip) interfacesList = interfaceDiscoverer.getResults() ucmdbversion = modeling.CmdbClassModel().version() topoBuilder = TopologyBuilder(interfacesList, hostDo, ipAddress, ntcmd_obj, dnsServersIpList, dhcpServersIpList, winsServersIpList, host_cmdbid, host_key, host_macs, ucmdbversion) topoBuilder.build() # access built host OSH to update UD UID attribute if topoBuilder.hostOsh and uduid: _updateHostUniversalDiscoveryUid(topoBuilder.hostOsh, uduid) topoBuilder.addResultsToVector(resultVector) return resultVector