def _resolve(hostname): '@types: str -> str?' if netutils.isValidIp(hostname): return hostname ip = netutils.getHostAddress(hostname) if ip and not netutils.isLocalIp(ip): return ip
def discoverDB2Windows(shellUtils, dbConnStr, appServerOSH, OSHVResult): db_name = dbConnStr cmd = 'db2cmd /c /w /i db2 list database directory' data = shellUtils.execCmd(cmd)#@@CMD_PERMISION siebel protocol execution params = getParams(data, 'Database name', db_name, 'Node name', None) nodeName = params[0] if nodeName: cmd = 'db2cmd /c /w /i db2 list node directory' data = shellUtils.execCmd(cmd)#@@CMD_PERMISION siebel protocol execution params = getParams(data, 'Node name', nodeName, 'Hostname', 'Service name') hostName = params[0] serviceName = params[1] if hostName: db_sid = db_name # NF: translate serviceName into port number db_port = serviceName db_type='db2' try: host_ip = netutils.getHostAddress(hostName) logger.debug('building DB2 Server OSH: ', db_type, host_ip, db_name, db_port) buildDBObjects(db_type,host_ip,db_port, db_name, db_sid, appServerOSH, OSHVResult) except: logger.errorException('failed to create db2 server on ', hostName, ' - ')
def discoverDB2Unix(siebelRootDir, shellUtils, dsnName, appServerOSH, OSHVResult): params = getODBCiniUnix(siebelRootDir, shellUtils, dsnName) db_name = params[0] clientInstallFolder = getClientInstallFolderUnix(params[1]) if clientInstallFolder == None: logger.error('Can not find db2 client path') else: cmd = '. ' + clientInstallFolder shellUtils.execCmd(cmd)#@@CMD_PERMISION siebel protocol execution cmd = 'db2 list database directory|grep -ip ' + db_name + '|grep -i \'node name\'' data = shellUtils.execCmd(cmd)#@@CMD_PERMISION siebel protocol execution nodeName = getAttribute(data, 'Node name') if nodeName: cmd = 'db2 list node directory|grep -ip ' + nodeName data = shellUtils.execCmd(cmd)#@@CMD_PERMISION siebel protocol execution hostName = getAttribute(data, 'Hostname') serviceName = getAttribute(data, 'Service name') db_port = getServicePortNumberUnix(serviceName, shellUtils) if db_port == None: db_port = '' if hostName != None: db_sid = db_name db_type='db2' try: host_ip = netutils.getHostAddress(hostName) logger.debug('building DB2 Server OSH: ', db_type, host_ip, db_name, db_port) buildDBObjects(db_type, host_ip, db_port, db_name, db_sid, appServerOSH, OSHVResult) except: logger.error('failed to create db2 server on ', hostName, ' - ')
def process(self, context): logger.debug('UcmdbServer8VersionShellPlugin.process') ConfigBasedPlugin.process(self, context) processFolder = self.getProcessFolder(context) try: content = context.client.safecat(processFolder + '../../conf/FndInfra.ini') except: logger.reportWarning('Failed getting HP uCMDB configuration') return hostName = self.getPropertyByRegexp(r'dbHost="(.+)"', content) dbType = self.getPropertyByRegexp(r'dbType="(.+)"', content) port = self.getPropertyByRegexp(r'dbPort="(\d+)"', content) sid = self.getPropertyByRegexp(r'dbSID="(\w+)"', content) if hostName and dbType and port and sid: dbHostIp = netutils.getHostAddress(hostName.strip()) if dbHostIp: self.reportTopology(context, dbType, port, sid, dbHostIp) else: logger.warn('Failed resolving DB host "%s" ip address' % hostName) else: logger.warn('Failed parsing cmdb config file')
def getUrl(WSDLUrl, containerOSH): res = ObjectStateHolderVector() urlIP = None try: url = URL(WSDLUrl) hostName = url.getHost() urlIP = netutils.getHostAddress(hostName, None) if (not netutils.isValidIp(urlIP)) or netutils.isLocalIp(urlIP): urlIP = None except: urlIP = None urlOSH = modeling.createUrlOsh(containerOSH, WSDLUrl, 'wsdl') urlIpOSH = None if urlIP != None: try: urlIpOSH = modeling.createIpOSH(urlIP) except: urlIpOSH = None res.add(urlOSH) if urlIpOSH: res.add(urlIpOSH) urlToIpOSH = modeling.createLinkOSH('depend', urlOSH, urlIpOSH) res.add(urlToIpOSH) return res
def discoverDB2Windows(shellUtils, dbConnStr, appServerOSH, OSHVResult): db_name = dbConnStr cmd = 'db2cmd /c /w /i db2 list database directory' data = shellUtils.execCmd(cmd) #@@CMD_PERMISION siebel protocol execution params = getParams(data, 'Database name', db_name, 'Node name', None) nodeName = params[0] if nodeName: cmd = 'db2cmd /c /w /i db2 list node directory' data = shellUtils.execCmd( cmd) #@@CMD_PERMISION siebel protocol execution params = getParams(data, 'Node name', nodeName, 'Hostname', 'Service name') hostName = params[0] serviceName = params[1] if hostName: db_sid = db_name # NF: translate serviceName into port number db_port = serviceName db_type = 'db2' try: host_ip = netutils.getHostAddress(hostName) logger.debug('building DB2 Server OSH: ', db_type, host_ip, db_name, db_port) buildDBObjects(db_type, host_ip, db_port, db_name, db_sid, appServerOSH, OSHVResult) except: logger.errorException('failed to create db2 server on ', hostName, ' - ')
def resolveHostname(hostname, shellUtils, defaultValue = None): ip = netutils.getHostAddress(hostname, None) if not ip: dnsResolver = netutils.DNSResolver(shellUtils) ipList = dnsResolver.resolveIpByNsLookup(hostname) if ipList: ip = ipList[0] if not ip: ip = defaultValue return ip
def resolveHostname(hostname, shellUtils, defaultValue=None): ip = netutils.getHostAddress(hostname, None) if not ip: dnsResolver = netutils.DNSResolver(shellUtils) ipList = dnsResolver.resolveIpByNsLookup(hostname) if ipList: ip = ipList[0] if not ip: ip = defaultValue return ip
def _resolveHostNameWithCaching(self, hostName): # TODO: use external resolver ip = None if self.__resolveCache.has_key(hostName): ip = self.__resolveCache.get(hostName) else: ip = netutils.getHostAddress(hostName) self.__resolveCache[hostName] = ip if ip and netutils.isValidIp(ip) and not netutils.isLocalIp(ip): return ip
def getAgates(shellUtils, installpath, sapitsOSH, OSHVResult): mapInstanceNameToAgate = HashMap() filePath = installpath + '\\config\\ItsRegistryWGATE.xml' data = shellUtils.safecat(filePath) logger.debug('got ItsRegistryWGATE file') if data == None or error(data): logger.error('Got: [', data, '] when performing command [ safecat ', filePath, '] - terminating script') else: builder = SAXBuilder(0) doc = builder.build(StringReader(data)) root = doc.getRootElement() localWgates = getElementByAttrValue(root, 'key', 'name', 'LocalWgates') wgates = localWgates.getChildren() it = wgates.iterator() while it.hasNext(): wgate = it.next() value = wgate.getAttributeValue('name') if value.find('WGATE_') >= 0: instancesRoot = getElementByAttrValue(wgate, 'key', 'name', 'Instances') instances = instancesRoot.getChildren() itInstances = instances.iterator() while itInstances.hasNext(): instance = itInstances.next() instanceName = instance.getAttributeValue('name') logger.debug(instanceName) agatesRoot = getElementByAttrValue(instance, 'key', 'name', 'Agates') agates = agatesRoot.getChildren() itAgates = agates.iterator() while itAgates.hasNext(): agate = itAgates.next() agateHost = getElementByAttrValue( agate, 'value', 'name', 'Host') host = agateHost.getText() agates = mapInstanceNameToAgate.get(instanceName) if agates == None: agates = ArrayList() mapInstanceNameToAgate.put(instanceName, agates) try: ip = netutils.getHostAddress(host) hostOSH = modeling.createHostOSH(ip) OSHVResult.add(hostOSH) agateOSH = modeling.createApplicationOSH( 'sap_its_agate', 'ITS_AGATE_' + ip, hostOSH) OSHVResult.add(agateOSH) agates.add(agateOSH) except: logger.warn('Failed resolving IP for agate host ', host) return mapInstanceNameToAgate
def parseTNSNames(tns_buffer, db_domain, shell=None): tns_entries = [] tns_buffer = tns_buffer.upper() tns_buffer = stripCommentLines(tns_buffer, '#') logger.debug('tns_buffer') logger.debug(tns_buffer) tns_entries_str = findTNSEntriesStr(tns_buffer) if tns_entries_str == []: return [] # error, no entries startPattern = Pattern('([\w\d.]*)\s*=\s*\(DESCRIPTION') for tns_entry_str in tns_entries_str: host_names = getTNSAttributeList(tns_entry_str, ['HOST']) for host_name in host_names: tns_entry = [] logger.debug('tns_entry_str', tns_entry_str) match = startPattern.matcher(tns_entry_str) if match.find() == 1: tns_name = string.strip(match.group(1)) logger.debug('tns_name', tns_name) tns_entry += [tns_name] logger.debug('host_name', host_name) tns_entry += [host_name] port = getTNSAttribute(tns_entry_str, ['PORT']) logger.debug('port', port) tns_entry += [port] sid = getTNSAttribute(tns_entry_str, ['SID']) if sid == '': sid = getTNSAttribute(tns_entry_str, ['SERVICE_NAME', 'service_name']) if sid == '': sid = getTNSAttribute(tns_entry_str, ['GLOBAL_DBNAME']) tns_name = stripDomain(tns_name, db_domain) sid = stripDomain(sid, db_domain) logger.debug('sid', sid) tns_entry += [sid] tns_entry += [tns_name] host_ip = '' if shell: try: resolver = netutils.DNSResolver(shell) ips = resolver.resolveIpByNsLookup(host_name) host_ip = ips and ips[ 0] or resolver.resolveHostIpByHostsFile(host_name) except: logger.warn('Failed to resolve host ip throught nslookup') host_ip = host_name else: host_ip = netutils.getHostAddress(host_name, host_name) tns_entry += [host_ip] tns_entries += [tns_entry] logger.debug(tns_entry) return tns_entries
def _resolveHostNameWithCaching(self, hostName): # TODO: use external resolver ip = None if self.__resolveCache.has_key(hostName): ip = self.__resolveCache.get(hostName) else: ip = netutils.getHostAddress(hostName) self.__resolveCache[hostName] = ip if ip and netutils.isValidIp(ip) and not netutils.isLocalIp(ip): return ip
def parseTNSNames(tns_buffer, db_domain, shell = None): tns_entries = [] tns_buffer = tns_buffer.upper() tns_buffer = stripCommentLines(tns_buffer, '#') logger.debug('tns_buffer') logger.debug(tns_buffer) tns_entries_str = findTNSEntriesStr(tns_buffer) if tns_entries_str == []: return [] # error, no entries startPattern = Pattern('([\w\d.]*)\s*=\s*\(DESCRIPTION') for tns_entry_str in tns_entries_str: host_names = getTNSAttributeList(tns_entry_str, ['HOST']) for host_name in host_names: tns_entry = [] logger.debug('tns_entry_str', tns_entry_str) match = startPattern.matcher(tns_entry_str) if match.find() == 1: tns_name = string.strip(match.group(1)) logger.debug('tns_name', tns_name) tns_entry += [tns_name] logger.debug('host_name', host_name) tns_entry += [host_name] port = getTNSAttribute(tns_entry_str, ['PORT']) logger.debug('port', port) tns_entry += [port] sid = getTNSAttribute(tns_entry_str, ['SID']) if sid == '': sid = getTNSAttribute(tns_entry_str, ['SERVICE_NAME','service_name']) if sid == '': sid = getTNSAttribute(tns_entry_str, ['GLOBAL_DBNAME']) tns_name = stripDomain(tns_name,db_domain) sid = stripDomain(sid,db_domain) logger.debug('sid', sid) tns_entry += [sid] tns_entry += [tns_name] host_ip = '' if shell: try: resolver = netutils.DNSResolver(shell) ips = resolver.resolveIpByNsLookup(host_name) host_ip = ips and ips[0] or resolver.resolveHostIpByHostsFile(host_name) except: logger.warn('Failed to resolve host ip throught nslookup') host_ip = host_name else: host_ip = netutils.getHostAddress(host_name, host_name) tns_entry += [host_ip] tns_entries += [tns_entry] logger.debug(tns_entry) return tns_entries
def createSqlServer(self,name,oshv,sqlServerId): #here we have the first bug! we should be able to find the relevant sql server #we should define the correct class model, what are we going to do with the instance name issue names = name.split('\\') if len(names)==2: name = names[1] serverName = names[0] host = Util.getHost(serverName) hostAddress = netutils.getHostAddress(serverName) sqlServer = Util.getSqlServer(name,host,sqlServerId) if hostAddress: sqlServer.setAttribute('application_ip',hostAddress) oshv.add(host) return sqlServer
def createSqlServer(self, name, oshv, sqlServerId): #here we have the first bug! we should be able to find the relevant sql server #we should define the correct class model, what are we going to do with the instance name issue names = name.split('\\') if len(names) == 2: name = names[1] serverName = names[0] host = Util.getHost(serverName) hostAddress = netutils.getHostAddress(serverName) sqlServer = Util.getSqlServer(name, host, sqlServerId) if hostAddress: sqlServer.setAttribute('application_ip', hostAddress) oshv.add(host) return sqlServer
def getAgates(shellUtils, installpath, sapitsOSH, OSHVResult): mapInstanceNameToAgate = HashMap() filePath = installpath + '\\config\\ItsRegistryWGATE.xml' data = shellUtils.safecat(filePath) logger.debug('got ItsRegistryWGATE file') if data == None or error(data): logger.error('Got: [', data, '] when performing command [ safecat ', filePath, '] - terminating script') else: builder = SAXBuilder(0) doc = builder.build(StringReader(data)) root = doc.getRootElement() localWgates = getElementByAttrValue(root, 'key', 'name', 'LocalWgates') wgates = localWgates.getChildren() it = wgates.iterator() while it.hasNext(): wgate = it.next() value = wgate.getAttributeValue('name') if value.find('WGATE_') >= 0: instancesRoot = getElementByAttrValue(wgate, 'key', 'name', 'Instances') instances = instancesRoot.getChildren() itInstances = instances.iterator() while itInstances.hasNext(): instance = itInstances.next() instanceName = instance.getAttributeValue('name') logger.debug(instanceName) agatesRoot = getElementByAttrValue(instance, 'key', 'name', 'Agates') agates = agatesRoot.getChildren() itAgates = agates.iterator() while itAgates.hasNext(): agate = itAgates.next() agateHost = getElementByAttrValue(agate, 'value', 'name', 'Host') host = agateHost.getText() agates = mapInstanceNameToAgate.get(instanceName) if agates == None: agates = ArrayList() mapInstanceNameToAgate.put(instanceName, agates) try: ip = netutils.getHostAddress(host) hostOSH = modeling.createHostOSH(ip) OSHVResult.add(hostOSH) agateOSH = modeling.createApplicationOSH('sap_its_agate', 'ITS_AGATE_' + ip, hostOSH) OSHVResult.add(agateOSH) agates.add(agateOSH) except: logger.warn('Failed resolving IP for agate host ', host) return mapInstanceNameToAgate
def buildSQLDBObjects(sqlServer, sqlServerPort, sqlDBName, OSHVResult): db_type = 'sqlserver' db_port = sqlServerPort db_name = sqlDBName host_name = sqlServer db_sid = '' try: hostNameEnd = host_name.find('\\') if hostNameEnd != -1: host_name = host_name[0:hostNameEnd] logger.debug('buildSQLDBObjects: host_name = ', host_name) host_ip = netutils.getHostAddress(host_name) logger.debug('building SQL Server OSH: ', db_type, host_ip, db_name, db_port) buildDBObjects(db_type, host_ip, db_port, db_name, db_sid, OSHVResult) except: logger.error('failed getting host ip for host:', host_name)
def buildSQLDBObjects(sqlServer, sqlServerPort, sqlDBName, OSHVResult): db_type = 'sqlserver' db_port = sqlServerPort db_name = sqlDBName host_name = sqlServer db_sid = '' try: hostNameEnd = host_name.find('\\') if hostNameEnd != -1: host_name = host_name[0:hostNameEnd] logger.debug('buildSQLDBObjects: host_name = ', host_name) host_ip = netutils.getHostAddress(host_name) logger.debug('building SQL Server OSH: ', db_type, host_ip, db_name, db_port) buildDBObjects(db_type, host_ip, db_port, db_name, db_sid, OSHVResult) except: logger.error('failed getting host ip for host:', host_name)
def addFarmMember(self, farmMember): """ Adds farmMember to topology. FarmMember->None @raise SharePointTopologyException: resource already added @raise IpResolveException: host IP not resolved by host name """ if self._hostNameToFarmMember.has_key(farmMember.hostName): raise SharePointTopologyException, 'Host %s already added to the farm' % farmMember.hostName logger.debug('resolving %s' % farmMember.hostName) farmMember.ip = netutils.getHostAddress(farmMember.hostName) if farmMember.ip: logger.debug('resolved %s' % farmMember.ip) self._farmMembers.append(farmMember) self._hostNameToFarmMember[farmMember.hostName] = farmMember for databaseConnection in farmMember.databaseConnections: self.addDatabase(databaseConnection) else: raise IpResolveException, 'Host %s IP address cannot be resolved' % farmMember.hostName
def createShellObj(shellUtils, ip, langBund, language, codePage, hostFqdn=None): regGlobalIp = langBund.getString('global_reg_ip') clientType = "powershell" logger.debug('creating object for obj_name=%s' % clientType) if(not re.match(regGlobalIp, ip)): ip = netutils.getHostAddress(ip, ip) sh_obj = ObjectStateHolder(clientType) sh_obj.setAttribute('application_ip', ip) sh_obj.setAttribute('data_name', clientType) if hostFqdn: sh_obj.setStringAttribute('powershell_fqdn', hostFqdn) if(language): sh_obj.setAttribute('language', language) if(codePage): sh_obj.setAttribute('codepage', codePage) sh_obj.setAttribute('credentials_id', shellUtils.getCredentialId()) return sh_obj
def servers(instanceName, installpath, sapitsOSH, agates, shellUtils, OSHVResult): # cmd = 'type \"' + installpath + '\\' + instanceName + '\\services\\global.srvc\"' file_ = installpath + '\\' + instanceName + '\\services\\global.srvc' # data = client.executeCmd() data = shellUtils.safecat(file_) if data == None or error(data): logger.error('Failed to get file content') else: try: hostname = getAttribute(data, 'appserver') sid = getAttribute(data, 'systemname') instNr = getAttribute(data, 'systemnumber') if hostname and sid and instNr: ip = netutils.getHostAddress(hostname) serverOsh = None if not ip: logger.warn("Failed to resolve: ", hostname) else: hostOSH = modeling.createHostOSH(ip) OSHVResult.add(hostOSH) instBuilder = sap_abap.InstanceBuilder() instRep = sap_abap.InstanceReporter(instBuilder) system = sap.System(sid) hostname = parseHostnameFromFqdn(hostname) serverOsh = instRep.reportNoNameInst( instNr, hostname, system, hostOSH) OSHVResult.add(serverOsh) it = agates.iterator() while it.hasNext(): agateOSH = it.next() routeOSH = modeling.createLinkOSH('depend', agateOSH, sapitsOSH) OSHVResult.add(routeOSH) if serverOsh: routeOSH = modeling.createLinkOSH( 'depend', serverOsh, agateOSH) OSHVResult.add(routeOSH) except: logger.errorException('Failed to get server')
def getListeningIpAddress(self): if self.__dbIpAddress: return self.__dbIpAddress try: if not self.isRacInstance(): self.__dbIpAddress = self._client.getIpAddress() return self.__dbIpAddress direct_ip = self.getOracleServerIP() server_name = self.getOracleServerName( ) or self.getOracleServerNameByInstance() probe_side_ip = None try: raw_probe_side_ip = netutils.getHostAddress(server_name) if netutils.isValidIp( raw_probe_side_ip ) and not netutils.isLoopbackIp(raw_probe_side_ip): probe_side_ip = raw_probe_side_ip except: logger.debugException('') if direct_ip and not probe_side_ip: self.__dbIpAddress = direct_ip if not direct_ip and probe_side_ip: self.__dbIpAddress = probe_side_ip if direct_ip and probe_side_ip: self.__dbIpAddress = probe_side_ip if self.__dbIpAddress: return self.__dbIpAddress raise ValueError('Server ip appeared to be incorrect') except: logger.debugException('') logger.reportWarning( 'Failed to queue oracle server ip. Will report ip used for connection.' ) self.__dbIpAddress = self._client.getIpAddress() return self._client.getIpAddress()
def servers(instanceName, installpath, sapitsOSH, agates, shellUtils, OSHVResult): # cmd = 'type \"' + installpath + '\\' + instanceName + '\\services\\global.srvc\"' file_ = installpath + '\\' + instanceName + '\\services\\global.srvc' # data = client.executeCmd() data = shellUtils.safecat(file_) if data == None or error(data): logger.error('Failed to get file content') else: try: hostname = getAttribute(data, 'appserver') sid = getAttribute(data, 'systemname') instNr = getAttribute(data, 'systemnumber') if hostname and sid and instNr: ip = netutils.getHostAddress(hostname) serverOsh = None if not ip: logger.warn("Failed to resolve: ", hostname) else: hostOSH = modeling.createHostOSH(ip) OSHVResult.add(hostOSH) instBuilder = sap_abap.InstanceBuilder() instRep = sap_abap.InstanceReporter(instBuilder) system = sap.System(sid) hostname = parseHostnameFromFqdn(hostname) serverOsh = instRep.reportNoNameInst(instNr, hostname, system, hostOSH) OSHVResult.add(serverOsh) it = agates.iterator() while it.hasNext(): agateOSH = it.next() routeOSH = modeling.createLinkOSH('depend', agateOSH, sapitsOSH) OSHVResult.add(routeOSH) if serverOsh: routeOSH = modeling.createLinkOSH('depend', serverOsh, agateOSH) OSHVResult.add(routeOSH) except: logger.errorException('Failed to get server')
def discoverDB2Unix(siebelRootDir, shellUtils, dsnName, appServerOSH, OSHVResult): params = getODBCiniUnix(siebelRootDir, shellUtils, dsnName) db_name = params[0] clientInstallFolder = getClientInstallFolderUnix(params[1]) if clientInstallFolder == None: logger.error('Can not find db2 client path') else: cmd = '. ' + clientInstallFolder shellUtils.execCmd(cmd) #@@CMD_PERMISION siebel protocol execution cmd = 'db2 list database directory|grep -ip ' + db_name + '|grep -i \'node name\'' data = shellUtils.execCmd( cmd) #@@CMD_PERMISION siebel protocol execution nodeName = getAttribute(data, 'Node name') if nodeName: cmd = 'db2 list node directory|grep -ip ' + nodeName data = shellUtils.execCmd( cmd) #@@CMD_PERMISION siebel protocol execution hostName = getAttribute(data, 'Hostname') serviceName = getAttribute(data, 'Service name') db_port = getServicePortNumberUnix(serviceName, shellUtils) if db_port == None: db_port = '' if hostName != None: db_sid = db_name db_type = 'db2' try: host_ip = netutils.getHostAddress(hostName) logger.debug('building DB2 Server OSH: ', db_type, host_ip, db_name, db_port) buildDBObjects(db_type, host_ip, db_port, db_name, db_sid, appServerOSH, OSHVResult) except: logger.error('failed to create db2 server on ', hostName, ' - ')
def process(self, context): logger.debug('UcmdbServer8VersionShellPlugin.process') ConfigBasedPlugin.process(self, context) processFolder = self.getProcessFolder(context) try: content = context.client.safecat(processFolder + '../../conf/FndInfra.ini') except: logger.reportWarning('Failed getting HP uCMDB configuration') return hostName = self.getPropertyByRegexp(r'dbHost="(.+)"', content) dbType = self.getPropertyByRegexp(r'dbType="(.+)"', content) port = self.getPropertyByRegexp(r'dbPort="(\d+)"', content) sid = self.getPropertyByRegexp(r'dbSID="(\w+)"', content) if hostName and dbType and port and sid: dbHostIp = netutils.getHostAddress(hostName.strip()) if dbHostIp: self.reportTopology(context, dbType, port, sid, dbHostIp) else: logger.warn('Failed resolving DB host "%s" ip address' % hostName) else: logger.warn('Failed parsing cmdb config file')
def addWebService(self, webService): """ Adds webService to topology. WebService->None @raise IpResolveException: IIS IP not resolved by host name @raise SharePointTopologyException: web service contains not well-formed URL or have no web applications """ if webService and webService.webApplications: url = webService.webApplications[0].urls[0] logger.debug('getting host address for %s' % url) match = re.search('https?://(.+?)(?::|/)',url, re.I) if match: hostName = match.group(1) logger.debug('host name is: %s' % hostName) webService.ip = netutils.getHostAddress(hostName) logger.debug('got IP %s' % webService.ip) if webService.ip: self._webServices.append(webService) return raise IpResolveException, 'IIS host %s cannot be resolved' % hostName raise SharePointTopologyException, 'Not well-formed URL: %s' % url raise SharePointTopologyException, 'web service is null or have no associated web applications'
def getListeningIpAddress(self): if self.__dbIpAddress: return self.__dbIpAddress try: if not self.isRacInstance(): self.__dbIpAddress = self._client.getIpAddress() return self.__dbIpAddress direct_ip = self.getOracleServerIP() server_name = self.getOracleServerName() or self.getOracleServerNameByInstance() probe_side_ip = None try: raw_probe_side_ip = netutils.getHostAddress(server_name) if netutils.isValidIp(raw_probe_side_ip) and not netutils.isLoopbackIp(raw_probe_side_ip): probe_side_ip = raw_probe_side_ip except: logger.debugException('') if direct_ip and not probe_side_ip: self.__dbIpAddress = direct_ip if not direct_ip and probe_side_ip: self.__dbIpAddress = probe_side_ip if direct_ip and probe_side_ip: self.__dbIpAddress = probe_side_ip if self.__dbIpAddress: return self.__dbIpAddress raise ValueError('Server ip appeared to be incorrect') except: logger.debugException('') logger.reportWarning('Failed to queue oracle server ip. Will report ip used for connection.') self.__dbIpAddress = self._client.getIpAddress() return self._client.getIpAddress()
def createShellObj(shellUtils, ip, langBund, language, codePage, hostFqdn=None): regGlobalIp = langBund.getString('global_reg_ip') clientType = "powershell" logger.debug('creating object for obj_name=%s' % clientType) if (not re.match(regGlobalIp, ip)): ip = netutils.getHostAddress(ip, ip) sh_obj = ObjectStateHolder(clientType) sh_obj.setAttribute('application_ip', ip) sh_obj.setAttribute('data_name', clientType) if hostFqdn: sh_obj.setStringAttribute('powershell_fqdn', hostFqdn) if (language): sh_obj.setAttribute('language', language) if (codePage): sh_obj.setAttribute('codepage', codePage) sh_obj.setAttribute('credentials_id', shellUtils.getCredentialId()) return sh_obj
def DiscoveryMain(Framework): try: cmdbServerHost = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) cmdbServerIp = None if netutils.isValidIp(cmdbServerHost): cmdbServerIp = cmdbServerHost else: cmdbServerIp = netutils.getHostAddress(cmdbServerHost, cmdbServerHost) protocol = getNnmProtocol(Framework, cmdbServerIp) cmdbConnection = getCmdbConnectionDetails(Framework, protocol, cmdbServerHost, cmdbServerIp) nnmConnection = getNnmConnectionDetails(Framework, protocol) logger.debug(str(cmdbConnection)) cmdbToNnmIds = getUCMDBIDs(cmdbConnection, nnmConnection.serverIp, Framework) logger.debug(str(nnmConnection)) updateNNM(cmdbToNnmIds, nnmConnection, Framework) except GeneralException, ex: Framework.reportError(str(ex))
def registryLookup(procToPortDict, dbInstanceDict, localClient, wmiRegistryClient): try: # Store all found listening Port activeListenerPorts = [] for pid in procToPortDict.keys(): activeListenerPorts.append( (procToPortDict[pid])[dbconnect_utils.PORT_INDEX]) ## Locals logger.debug('Initial dbInstanceDict %s' % dbInstanceDict) instanceNameList = [] installNameTointernalInstanceName = {} # If SQL Server is present on this box, get instance names installedInstancesKeypath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server' installedInstances = dbconnect_utils.getRegValues( localClient, wmiRegistryClient, installedInstancesKeypath, 'InstalledInstances') if installedInstances == None or str( installedInstances) == '[[], []]' or str( installedInstances) == '{}': if dbInstanceDict != None and len(dbInstanceDict) > 0: instancesString = '' for dbName in dbInstanceDict.keys(): instancesString = instancesString + dbName.upper() + '\n' installedInstances = {} installedInstances.update( {installedInstancesKeypath: instancesString[:-1]}) # chop last \n else: dbconnect_utils.debugPrint( 2, '[' + SCRIPT_NAME + ':registryLookup] SQL Server not installed on this box') return None logger.debug("Discovered installed instances %s" % installedInstances) if installedInstances: ## We have SQL Server dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] SQL Server present on this box <%s>' % installedInstances) installedInstanceNames = installedInstances[ installedInstancesKeypath] if installedInstanceNames.find( '\n') > 0 or installedInstanceNames.find(' _ ') > 0: ## Multiple SQL Server instances installedIstanceNameList = re.split(' _ |\n', installedInstanceNames) else: installedIstanceNameList = [installedInstanceNames] logger.debug('Installed instance name list %s' % installedIstanceNameList) for installedInstanceName in installedIstanceNameList: instanceNameList.append(installedInstanceName.strip()) dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Found SQL Server instance <%s>' % installedInstanceName.strip()) internalInstanceNameKeyPath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL' internalInstanceNameDict = dbconnect_utils.getRegValues( localClient, wmiRegistryClient, internalInstanceNameKeyPath, installedInstanceName) internalInstanceName = internalInstanceNameDict[ internalInstanceNameKeyPath] if internalInstanceName: dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Found registry name <%s> for internal SQL instance name <%s>' % (internalInstanceName, installedInstanceName)) installNameTointernalInstanceName[ installedInstanceName.strip( )] = internalInstanceName.strip() else: installNameTointernalInstanceName[ installedInstanceName.strip( )] = installedInstanceName.strip() logger.debug("installNameTointernalInstanceName %s" % installNameTointernalInstanceName) logger.debug("instanceNameList %s " % instanceNameList) # If we're here, one or more SQL Server instances are present # Look for additional SQL Server information sqlServerDetailKeypaths = [ 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\SuperSocketNetLib\\Tcp', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Setup', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\CurrentVersion', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster' ] sqlServerDetailFilters = [ 'TcpPort', 'SQLPath', 'CurrentVersion', 'ClusterIpAddr', 'ClusterName' ] for instanceName in instanceNameList: sqlServerDetailValues = [] for sqlServerDetailIndex in range(len(sqlServerDetailKeypaths)): sqlServerDetailKeypath = '' ## Replace instance names in registry key path as appropriate if instanceName == 'MSSQLSERVER': if sqlServerDetailKeypaths[sqlServerDetailIndex].find( 'luster') > 0: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get( instanceName)) else: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'Microsoft SQL Server\\iNsTaNcEnAmE', 'MSSQLServer') else: if sqlServerDetailKeypaths[sqlServerDetailIndex].find( 'luster') > 0: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get( instanceName)) else: sqlServerDetailKeypath = string.replace( sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', instanceName) regValues = dbconnect_utils.getRegValues( localClient, wmiRegistryClient, sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex]) if regValues == None or str(regValues) == '[[], []]' or str( regValues) == '{}': dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got nothing for key <%s> with filter <%s>' % (sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) sqlServerDetailValues.insert(sqlServerDetailIndex, None) else: sqlServerDetailValues.insert( sqlServerDetailIndex, regValues[sqlServerDetailKeypath]) dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got value <%s> for key <%s> with filter <%s>' % (sqlServerDetailValues[sqlServerDetailIndex], sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) logger.debug("instanceNameList %s " % instanceNameList) ## We should have all details for this instance now - add it to DB dictionary listenerPort = sqlServerDetailValues[0] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got port <%s> for instance <%s>' % (listenerPort, instanceName)) installPath = sqlServerDetailValues[1] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got path <%s> for instance <%s>' % (installPath, instanceName)) version = sqlServerDetailValues[2] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got version <%s> for instance <%s>' % (version, instanceName)) ipAddress = dbconnect_utils.fixIP(sqlServerDetailValues[3], localClient.getIpAddress()) dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got IP <%s> for instance <%s>' % (ipAddress, instanceName)) clusterName = sqlServerDetailValues[4] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got Cluster Name <%s> for instance <%s>' % (clusterName, instanceName)) if clusterName: clusterIp = netutils.getHostAddress(clusterName) if clusterIp and netutils.isValidIp(clusterIp): ipAddress = clusterIp ## If the instance is already in the DB dict, don't overwrite all values if instanceName == 'MSSQLSERVER': dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Got unnamed SQL Server instance') instanceName = dbconnect_utils.getServerName(localClient) else: instanceName = dbconnect_utils.getServerName( localClient) + '\\' + instanceName.lower() installPath = installPath.lower() if instanceName in dbInstanceDict.keys(): statusFlag = ( dbInstanceDict[instanceName])[dbconnect_utils.STATUS_INDEX] # If port is already populated, don't overwrite it because # port number information from active processes (above) is # guaranteed to be correct and the registry may not be up-to-date if (dbInstanceDict[instanceName] )[dbconnect_utils.PORT_INDEX] != dbconnect_utils.UNKNOWN: if listenerPort not in activeListenerPorts: listenerPort = (dbInstanceDict[instanceName] )[dbconnect_utils.PORT_INDEX] dbInstanceDict[instanceName] = [ 'MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, statusFlag ] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Found known SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) else: dbInstanceDict[instanceName] = [ 'MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, dbconnect_utils.UNKNOWN ] dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Added SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) logger.debug("instanceNameList %s " % instanceNameList) logger.debug("dbInstanceDict %s" % dbInstanceDict) ## Replace dictionary entry of serverName\sqlInstanceName with clusterName\sqlInstanceName if clusterName and instanceName in dbInstanceDict.keys(): if instanceName.find('\\') > 0: newInstanceName = clusterName + '\\' + instanceName[ instanceName.find('\\') + 1:] else: newInstanceName = clusterName dbconnect_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':registryLookup] Replacing SQL Server instance <%s> with <%s> because it is part of a cluster' % (instanceName, newInstanceName)) dbInstanceDict[newInstanceName] = dbInstanceDict[instanceName] del dbInstanceDict[instanceName] logger.debug("dbInstanceDict %s" % dbInstanceDict) #print dbInstanceDict logger.debug("instanceNameList %s " % instanceNameList) except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':registryLookup] Exception: <%s>' % excInfo) pass
def infrastructure(client, OSHVResult, Framework, schemaName = None, viewSchemaName = None): retOSHs = ArrayList(4) retOSHs.add(None) retOSHs.add(None) retOSHs.add(None) retOSHs.add(None) systemOSH = ObjectStateHolder('oraclesystem') systemOSH.setAttribute('data_name', client.getSid()) systemOSH.setAttribute('oraclesystem_dbaddress', client.getIpAddress()) modeling.setAppSystemVendor(systemOSH) webServerOSH = None nameToHostOSH = HashMap() hostToServerOSH = HashMap() hostToIpAddress = HashMap() databasesOSH = HashMap() resultSet = None try: objs = __assocWithSchemaName(['FND_OAM_APP_SYS_STATUS'], schemaName, viewSchemaName) # query a special table that holds Applications System Status related information resultSet = client.executeQuery('SELECT * FROM %s' % objs)#@@CMD_PERMISION sql protocol execution except: logger.debugException('SQL query failure. "SELECT * FROM FND_OAM_APP_SYS_STATUS"') Framework.reportWarning('No Oracle E-Business Suite components found.') if resultSet: OSHVResult.add(systemOSH) retOSHs.set(0, systemOSH) else: return None while resultSet.next(): name = resultSet.getString(1) dbSid = resultSet.getString(4) status = resultSet.getString(6) host = resultSet.getString(7) port = client.getPort() if logger.isDebugEnabled(): logger.debug('-----------------------------') logger.debug('name = ', name) logger.debug('status = ', status) if host != None: logger.debug('host = ', host) else: logger.debug('skipping Application system with None host') continue logger.debug('-----------------------------') hostOSH = nameToHostOSH.get(host) serverOSH = hostToServerOSH.get(host) hostIP = hostToIpAddress.get(host) if not hostIP: hostIP = netutils.getHostAddress(host, host) if hostOSH == None and netutils.isValidIp(hostIP): hostOSH = modeling.createHostOSH(hostIP) OSHVResult.add(hostOSH) nameToHostOSH.put(host,hostOSH) hostToIpAddress.put(host,hostIP) if hostOSH == None: logger.warn('Failed to created host [', host, ']') continue if serverOSH == None: serverOSH = modeling.createJ2EEServer('oracleias', hostIP, None, hostOSH, host) OSHVResult.add(serverOSH) hostToServerOSH.put(host,serverOSH) serverMemberOSH = modeling.createLinkOSH('member', systemOSH, serverOSH) OSHVResult.add(serverMemberOSH) if name.find('WEB_SERVER') == 0 and host != None: webServerOSH = serverOSH serverOSH.setBoolAttribute('oracleias_web', 1) elif name.find('FORMS_SERVER') == 0 and host != None: serverOSH.setBoolAttribute('oracleias_form', 1) elif name.find('ADMIN_SERVER') == 0 and host != None: serverOSH.setBoolAttribute('oracleias_admin', 1) elif name.find('CP_SERVER') == 0 and host != None: serverOSH.setBoolAttribute('oracleias_concurrentprocessing', 1) elif name.find('DATABASE') == 0 and host != None: dbOSH = modeling.createDatabaseOSH('oracle', dbSid, port, hostIP, hostOSH) OSHVResult.add(dbOSH) databasesOSH.put(dbSid,dbOSH) memberOSH = modeling.createLinkOSH('member', systemOSH, dbOSH) OSHVResult.add(memberOSH) resultSet.close() try: systemMetrics(client,systemOSH,webServerOSH, OSHVResult, schemaName, viewSchemaName) except: logger.debug("Failed to get system metrics") retOSHs.set(1, hostToServerOSH) retOSHs.set(2, nameToHostOSH) retOSHs.set(3, databasesOSH) return retOSHs
def infrastructure(client, OSHVResult, Framework, schemaName=None, viewSchemaName=None): retOSHs = ArrayList(4) retOSHs.add(None) retOSHs.add(None) retOSHs.add(None) retOSHs.add(None) systemOSH = ObjectStateHolder('oraclesystem') systemOSH.setAttribute('data_name', client.getSid()) systemOSH.setAttribute('oraclesystem_dbaddress', client.getIpAddress()) modeling.setAppSystemVendor(systemOSH) webServerOSH = None nameToHostOSH = HashMap() hostToServerOSH = HashMap() hostToIpAddress = HashMap() databasesOSH = HashMap() resultSet = None try: objs = __assocWithSchemaName(['FND_OAM_APP_SYS_STATUS'], schemaName, viewSchemaName) # query a special table that holds Applications System Status related information resultSet = client.executeQuery( 'SELECT * FROM %s' % objs) #@@CMD_PERMISION sql protocol execution except: logger.debugException( 'SQL query failure. "SELECT * FROM FND_OAM_APP_SYS_STATUS"') Framework.reportWarning('No Oracle E-Business Suite components found.') if resultSet: OSHVResult.add(systemOSH) retOSHs.set(0, systemOSH) else: return None while resultSet.next(): name = resultSet.getString(1) dbSid = resultSet.getString(4) status = resultSet.getString(6) host = resultSet.getString(7) port = client.getPort() if logger.isDebugEnabled(): logger.debug('-----------------------------') logger.debug('name = ', name) logger.debug('status = ', status) if host != None: logger.debug('host = ', host) else: logger.debug('skipping Application system with None host') continue logger.debug('-----------------------------') hostOSH = nameToHostOSH.get(host) serverOSH = hostToServerOSH.get(host) hostIP = hostToIpAddress.get(host) if not hostIP: hostIP = netutils.getHostAddress(host, host) if hostOSH == None and netutils.isValidIp(hostIP): hostOSH = modeling.createHostOSH(hostIP) OSHVResult.add(hostOSH) nameToHostOSH.put(host, hostOSH) hostToIpAddress.put(host, hostIP) if hostOSH == None: logger.warn('Failed to created host [', host, ']') continue if serverOSH == None: serverOSH = modeling.createJ2EEServer('oracleias', hostIP, None, hostOSH, host) OSHVResult.add(serverOSH) hostToServerOSH.put(host, serverOSH) serverMemberOSH = modeling.createLinkOSH('member', systemOSH, serverOSH) OSHVResult.add(serverMemberOSH) if name.find('WEB_SERVER') == 0 and host != None: webServerOSH = serverOSH serverOSH.setBoolAttribute('oracleias_web', 1) elif name.find('FORMS_SERVER') == 0 and host != None: serverOSH.setBoolAttribute('oracleias_form', 1) elif name.find('ADMIN_SERVER') == 0 and host != None: serverOSH.setBoolAttribute('oracleias_admin', 1) elif name.find('CP_SERVER') == 0 and host != None: serverOSH.setBoolAttribute('oracleias_concurrentprocessing', 1) elif name.find('DATABASE') == 0 and host != None: dbOSH = modeling.createDatabaseOSH('oracle', dbSid, port, hostIP, hostOSH) OSHVResult.add(dbOSH) databasesOSH.put(dbSid, dbOSH) memberOSH = modeling.createLinkOSH('member', systemOSH, dbOSH) OSHVResult.add(memberOSH) resultSet.close() try: systemMetrics(client, systemOSH, webServerOSH, OSHVResult, schemaName, viewSchemaName) except: logger.debug("Failed to get system metrics") retOSHs.set(1, hostToServerOSH) retOSHs.set(2, nameToHostOSH) retOSHs.set(3, databasesOSH) return retOSHs
def getHostKey(host, domain): return netutils.getHostAddress(host) + " " + domain
def mainFunction(Framework): logger.info('Starting NNM_Integration_Utils:mainFunction') ## retrieve Framework data maxPerCall = Framework.getParameter('maxPerCall') maxObjects = Framework.getParameter('maxObjects') nonL2Devices = Framework.getParameter('nonL2Devices') completeHosts = Framework.getParameter('completeHosts') ucmdbServerIp = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) if not netutils.isValidIp(ucmdbServerIp): ucmdbServerIp = netutils.getHostAddress(ucmdbServerIp, ucmdbServerIp) server = Framework.getDestinationAttribute('ip_address') credentialIds = Framework.getAvailableProtocols(ucmdbServerIp, NNM_PROTOCOL) if credentialIds.__len__() == 0: logger.error('NNM Protocol is not defined. Exiting discovery') return ObjectStateHolderVector() elif credentialIds.__len__() > 1: logger.warn('More than one NNM Protocols are defined. Only the last one will be used.') for credentialId in credentialIds: #server = Framework.getProtocolProperty(credentialId, 'nnmprotocol_server') # the nnm server's ip is now retrieved from the trigger port = Framework.getProtocolProperty(credentialId, 'nnmprotocol_port') username = Framework.getProtocolProperty(credentialId, 'nnmprotocol_user') try: password = Framework.getProtocolProperty(credentialId, 'nnmprotocol_password') except: password = '' nnmprotocol = Framework.getProtocolProperty(credentialId, 'nnmprotocol_protocol') logger.debug('Server: %s, Port: %s, Protocol: %s, Username: %s, MaxPerCall: %s, MaxObjects: %s' % (server, port, nnmprotocol, username, maxPerCall, maxObjects)) ## determine whether to discover non-Layer2 devices (servers, printers, load balancers, etc) if notNull(nonL2Devices) and nonL2Devices == 'true': discoverNonL2Devices = 1 else: discoverNonL2Devices = 0 ## determine whether to discover the hosts (switches, routers, servers, etc.) as complete hosts. If this is set to false, it is recommended to have the complete hosts initially discovered in the CMDB if notNull(completeHosts) and completeHosts == 'true': completeHosts = 1 else: completeHosts = 0 ## create an instance of the API stub api = NNMiApi(server, port, username, password, maxPerCall, maxObjects, nnmprotocol, Framework) ## get the filters required to retrieve data based on offset and maxObjects constraints. filters = api.getFilters() ## retrieve NNM data into maps ipMap = getIPAddressObjects(api, filters) ## IP Objects ndMap = getNodeObjects(api, filters) ## Host Objects nwMap = getIPSubnetObjects(api, filters) ## Network Objects ifMap = getInterfaceObjects(api, filters) ## Interface Objects l2Map = getL2ConnectionLinks(api, filters) ## Layer2 Connections ptMap = getPortObjects(api, filters) ## Port Objects vlMap = {} cdMap = {} if len(ptMap) > 0: # only get vlans/card if ports are available vlMap = getVLANObjects(api, filters) ## VLAN Objects cdMap = getCardObjects(api, filters) ## Card Objects ## create map of hosts and it's IPs hostIpMap = createHostIpMap(ipMap, ndMap) ## fix - to only send back one IP address per host hostIpMap = createHostSingleIpMap(hostIpMap) ## create map of hosts and it's interfaces and a second map of host_name[interface_name]=interface_id (the key is the way NNM stores layer2 connections e.g. Host1[If1], Host2[If2], Host3[If3] (nodeIfMap, hostIfMap) = createNodeInterfaceMap(ifMap, ndMap) # map to store MAC Addresses and their hostIDs (used to prevent creation of duplicate interfaces on the same host which have the same mac address) macHostMap = {} ## create the OSHs for hosts, their IPs, interfaces and networks vector1 = create_Hosts_Ips_Interfaces(ipMap, ndMap, ifMap, nwMap, ptMap, vlMap, cdMap, hostIpMap, hostIfMap, completeHosts, discoverNonL2Devices, macHostMap) ## send results back as the objects are created... Framework.sendObjects(vector1) vector1 = None ## create layer 2 connections [HOST-->Interface-->(layer2)<--Interface<--Host or HOST-->Interface-->(layer2)<--Interface<--Concentrator objects and relationships] vector2 = createLayer2Links(ipMap, ndMap, ifMap, l2Map, hostIpMap, nodeIfMap, macHostMap) ## create final result vector and add all other data to it resultVector = ObjectStateHolderVector() resultVector.addAll(vector2) return resultVector
def getHost(hostName): host = netutils.getHostAddress(hostName) if host: return modeling.createHostOSH(host) else: return None
def mainFunction(Framework): SCRIPT = "%s.py:" % __name__ logger.info('%s mainFunction' % SCRIPT) ## retrieve Framework data maxPerCall = Framework.getParameter('maxPerCall') maxObjects = Framework.getParameter('maxObjects') nonL2Devices = Framework.getParameter('nonL2Devices') ucmdbServerIp = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) if not netutils.isValidIp(ucmdbServerIp): ucmdbServerIp = netutils.getHostAddress(ucmdbServerIp, ucmdbServerIp) server = Framework.getDestinationAttribute('ip_address') credentialIds = Framework.getAvailableProtocols(ucmdbServerIp, NNM_PROTOCOL) if credentialIds.__len__() == 0: logger.error('NNM Protocol is not defined. Exiting discovery') return ObjectStateHolderVector() elif credentialIds.__len__() > 1: logger.warn('More than one NNM Protocols are defined. Only the last one will be used.') for credentialId in credentialIds: #server = Framework.getProtocolProperty(credentialId, 'nnmprotocol_server') # the nnm server's ip is now retrieved from the trigger port = Framework.getProtocolProperty(credentialId, 'nnmprotocol_port') username = Framework.getProtocolProperty(credentialId, 'nnmprotocol_user') try: password = Framework.getProtocolProperty(credentialId, 'nnmprotocol_password') except: password = '' nnmprotocol = Framework.getProtocolProperty(credentialId, 'nnmprotocol_protocol') logger.debug('Server: %s, Port: %s, Protocol: %s, Username: %s, MaxPerCall: %s, MaxObjects: %s' % (server, port, nnmprotocol, username, maxPerCall, maxObjects)) ## determine whether to discover non-Layer2 devices (servers, printers, load balancers, etc) if notNull(nonL2Devices) and nonL2Devices == 'true': discoverNonL2Devices = 1 else: discoverNonL2Devices = 0 ## create an instance of the API stub api = NNMiApi(server, port, username, password, maxPerCall, maxObjects, nnmprotocol, Framework) ## get the filters required to retrieve data based on offset and maxObjects constraints. filters = api.getFilters() # initialize attributes createVars() ## retrieve NNM data into maps ipMap = getIPAddressObjects(api, filters) ## IP Objects ndMap = getNodeObjects(api, filters) ## Host Objects nwMap = getIPSubnetObjects(api, filters) ## Network Objects ifMap = getInterfaceObjects(api, filters) ## Interface Objects l2Map = getL2ConnectionLinks(api, filters) ## Layer2 Connections ptMap = getPortObjects(api, filters) ## Port Objects vlMap = {} cdMap = {} if len(ptMap) > 0: # only get vlans/card if ports are available vlMap = getVLANObjects(api, filters) ## VLAN Objects cdMap = getCardObjects(api, filters) ## Card Objects ## create map of hosts and its IPs hostIpMap = createHostIpMap(ipMap, ndMap) ## create map of hosts and its interfaces hostIfMap = createHostInterfaceMap(ifMap, ndMap) ## create map of l2connection and its interfaces connectionIfMap = createConnectionInterfaceMap(l2Map, ifMap) ## create the OSHs for hosts, their IPs, interfaces and networks return processData(ipMap, ndMap, ifMap, nwMap, l2Map, vlMap, ptMap, cdMap, hostIpMap, hostIfMap, connectionIfMap, discoverNonL2Devices, Framework)
def getNetworkDevices(localDbClient, queryChunkSize, ipAddrList, portVlanIdMap, ignoreNodesWithoutIP, allowDnsLookup, localFramework): try: returnOSHV = ObjectStateHolderVector() ## Get total number of network devices in the database numDevices = 0 deviceCountQuery = 'SELECT COUNT(1) FROM lmsdatagrp.NETWORK_DEVICES' deviceCountResultSet = ciscoworks_utils.doQuery(localDbClient, deviceCountQuery) ## Return if query returns no results if deviceCountResultSet == None: logger.warn('[' + SCRIPT_NAME + ':getNetworkDevices] No Network Devices found') return None ## We have query results! while deviceCountResultSet.next(): numDevices = int(ciscoworks_utils.getStringFromResultSet(deviceCountResultSet, 1)) ## Determine chunk count ciscoworks_utils.debugPrint(2, '[' + SCRIPT_NAME + ':getNetworkDevices] Got <%s> Network Devices...' % numDevices) numChunks = int(numDevices/queryChunkSize) + 1 ciscoworks_utils.debugPrint(2, '[' + SCRIPT_NAME + ':getNetworkDevices] Got <%s> chunks...' % numChunks) for chunkIndex in range(0, numChunks): queryStartRow = chunkIndex*queryChunkSize if queryStartRow == 0: queryStartRow = 1 netDeviceQuery = '''SELECT TOP %s START AT %s netdevices.Device_Id, deviceState.NetworkElementID, netdevices.Device_Display_Name, netdevices.Host_Name, netdevices.Device_Category, netdevices.Device_Model, netdevices.Management_IPAddress, deviceState.Global_State FROM lmsdatagrp.NETWORK_DEVICES netdevices JOIN dba.DM_Dev_State deviceState ON netdevices.Device_Id=deviceState.DCR_ID''' % (queryChunkSize, queryStartRow) #netDeviceQuery = '%s WHERE LOWER(netdevices.Device_Display_Name) LIKE \'a%%\'' % netDeviceQuery netDeviceResultSet = ciscoworks_utils.doQuery(localDbClient, netDeviceQuery) ## Return if query returns no results if netDeviceResultSet == None: logger.warn('[' + SCRIPT_NAME + ':getNetworkDevices] No Network Devices found in chunk <%s>' % chunkIndex) return None ## We have query results! while netDeviceResultSet.next(): netDeviceOSH = ipOSH = None ## Get values from result set netDeviceID = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 1) netDeviceElementID = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 2) netDeviceDisplayName = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 3) netDeviceHostName = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 4) netDeviceCategory = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 5) netDeviceModel = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 6) ipAddress = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 7) #netDeviceStateIndex = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 7) ## Set device name based on first available value netDeviceName = netDeviceDisplayName or netDeviceHostName ciscoworks_utils.debugPrint(1, '[' + SCRIPT_NAME + ':getNetworkDevices] Got Device <%s> with ID <%s>' % (netDeviceName, netDeviceElementID)) ## Get enums for net device #deviceStateEnumDict = ciscoworks_utils.getEnum(localDbClient, 'dba.DM_Global_State_Enum') physicalTypeEnumDict = ciscoworks_utils.getEnum(localDbClient, 'dba.PhysicalTypeEnum') ## Initialize variables for additional data netDeviceElementName = netDeviceReportedName = netDeviceDNSDomainName = netDeviceDescription = netDeviceContact = netDeviceLocation = None netDeviceOsName = netDeviceOsVersion = netDeviceManufacturer = netDeviceSerialNumber = None netDeviceDnsName = None ## Get additional details for this device netDeviceAdditionalDataQuery = '''SELECT ne.ElementName, ne.ReportedHostName, ne.DNSDomainName, ne.Description, ne.PrimaryOwnerContact, ne.ElementLocation, os.OSName, os.Version, os.ROMVersion, pe.Manufacturer, pe.SerialNumber FROM dba.OperatingSystem os, dba.PhysicalElement pe, dba.networkelement ne WHERE os.NetworkElementID=%s AND ne.NetworkElementID=%s AND pe.NetworkElementID=%s AND LOWER(pe.PhysicalType)=%s AND pe.PhysicalElementId IN (1, 2)'''\ % (netDeviceElementID, netDeviceElementID, netDeviceElementID, physicalTypeEnumDict['Chassis/Frame']) netDeviceAdditionalDataResultSet = ciscoworks_utils.doQuery(localDbClient, netDeviceAdditionalDataQuery) ## Return if query returns no results if netDeviceAdditionalDataResultSet == None: logger.warn('[' + SCRIPT_NAME + ':getNetworkDevices] No additional data found for network device <%s> with ID <%s>' % (netDeviceName, netDeviceElementID)) return None ## We have query results! while netDeviceAdditionalDataResultSet.next(): ## Get values from result set netDeviceElementName = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 1) netDeviceReportedName = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 2) netDeviceDNSDomainName = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 3) netDeviceDescription = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 4) netDeviceContact = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 5) netDeviceLocation = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 6) netDeviceOsName = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 7) netDeviceOsVersion = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 8) #netDeviceRomVersion = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 9) netDeviceManufacturer = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 10) netDeviceSerialNumber = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 11) ciscoworks_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getNetworkDevices] Got additional information for Net Device <%s> with ID <%s>' % (netDeviceName, netDeviceElementID)) netDeviceAdditionalDataResultSet.close() if not netDeviceName: netDeviceName = netDeviceElementName or netDeviceReportedName if netDeviceDNSDomainName and not netutils.isValidIp(netDeviceName): #netDeviceName = '%s.%s' % (netDeviceName, netDeviceDNSDomainName) #netDeviceDnsName = netDeviceName.lower() netDeviceDnsName = '%s.%s' % (netDeviceName, netDeviceDNSDomainName) ## Determine Net Device CI Type netDeviceCiType = 'netdevice' netDeviceCategoreToCiTypeMap = {'Routers':'router', 'Switches and Hubs':'switch', 'Content Networking':'switch', 'Cisco Interfaces and Modules':'switch', 'Wireless':'netdevice', 'Voice and Telephony':'netdevice', 'Unknown':'netdevice'} if netDeviceCategory in netDeviceCategoreToCiTypeMap.keys(): netDeviceCiType = netDeviceCategoreToCiTypeMap[netDeviceCategory] ## Discard management IP if this is a duplicate if ipAddress and netutils.isValidIp(ipAddress) and ipAddress in ipAddrList: logger.debug('[' + SCRIPT_NAME + ':getNetworkDevices] Duplicate IP address <%s> on Network Device <%s> with ID <%s>!! Discarding IP...' % (ipAddress, netDeviceName, netDeviceElementID)) ipAddress = None else: ipAddrList.append(ipAddress) ## Get the list of IP addresses associated with this device ipSubnetDict = getIpSubnetDict(localDbClient, ipAddrList, netDeviceID, netDeviceElementID, netDeviceName) # Check if an IP address is available to build the host key # If an IP is not available and a DNS name is available, try resolving the IP # If not, skip this device ## If a management IP is not available, use the first IP in the IP list if not ipAddress and ipSubnetDict and len(ipSubnetDict) > 0: ipAddress = ipSubnetDict[0] ## Try DNS lookup if an IP is not available if not (ipAddress and netutils.isValidIp(ipAddress)) and allowDnsLookup and netDeviceDnsName: ciscoworks_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getNetworkDevices] No IP for Device <%s> with DNS name <%s>! Attempting DNS lookup...' % (netDeviceName, netDeviceDnsName)) ipAddress = netutils.getHostAddress(netDeviceDnsName) if not (ipAddress and netutils.isValidIp(ipAddress)) and allowDnsLookup and netDeviceName: ciscoworks_utils.debugPrint(3, '[' + SCRIPT_NAME + ':getNetworkDevices] No IP for Device <%s> with ID <%s>! Attempting DNS lookup...' % (netDeviceName, netDeviceElementID)) ipAddress = netutils.getHostAddress(netDeviceName) ## Check for a valid IP before creating CIs if ipAddress and netutils.isValidIp(ipAddress): netDeviceOSH = modeling.createHostOSH(ipAddress, netDeviceCiType) ipOSH = modeling.createIpOSH(ipAddress, None, netDeviceDnsName, None) elif ignoreNodesWithoutIP: logger.debug('[' + SCRIPT_NAME + ':getNetworkDevices] IP address not available for Network Device <%s> with ID <%s>!! Skipping...' % (netDeviceName, netDeviceElementID)) continue else: logger.debug('[' + SCRIPT_NAME + ':getNetworkDevices] IP address not available for Network Device <%s> with ID <%s>!! Creating Network Device with ID as primary key...' % (netDeviceName, netDeviceElementID)) hostKey = netDeviceElementID + ' (CiscoWorks Network Element ID)' netDeviceOSH = modeling.createCompleteHostOSH(netDeviceCiType, hostKey) netDeviceOSH.setAttribute('data_note', 'IP address unavailable in CiscoWorks LMS - Duplication of this CI is possible') ## Set the real name of the netDevice netDeviceRealName = netDeviceName if netDeviceName and netutils.isValidIp(netDeviceName): netDeviceRealName = '' ## Add more details to the OSH ciscoworks_utils.populateOSH(netDeviceOSH, {'name':netDeviceRealName, 'data_externalid':netDeviceName, 'discovered_description':netDeviceDescription, 'discovered_contact':netDeviceContact, 'discovered_location':netDeviceLocation, 'discovered_os_name':netDeviceOsName, 'discovered_os_version':netDeviceOsVersion, 'discovered_model':netDeviceModel, 'serial_number':netDeviceSerialNumber, 'discovered_vendor':netDeviceManufacturer, 'primary_dns_name':netDeviceDnsName, 'domain_name':netDeviceDNSDomainName}) ## Set node role netDeviceOSH.setListAttribute('node_role', [netDeviceCiType]) returnOSHV.add(netDeviceOSH) returnOSHV.addAll(getNetDevicePortsAndVlans(localDbClient, portVlanIdMap, netDeviceID, netDeviceElementID, netDeviceName, netDeviceOSH)) returnOSHV.addAll(getModules(localDbClient, netDeviceID, netDeviceName, netDeviceOSH)) ## Add IPs to OSHV if ipOSH: returnOSHV.add(ipOSH) returnOSHV.add(modeling.createLinkOSH('containment', netDeviceOSH, ipOSH)) if ipSubnetDict and len(ipSubnetDict) > 0: for ipAddy in ipSubnetDict.keys(): ipOSH = modeling.createIpOSH(ipAddy, ipSubnetDict[ipAddy], netDeviceDnsName, None) returnOSHV.add(ipOSH) returnOSHV.add(modeling.createLinkOSH('containment', netDeviceOSH, ipOSH)) netDeviceResultSet.close() ## Send results to server localFramework.sendObjects(returnOSHV) localFramework.flushObjects() returnOSHV.clear() return returnOSHV except: excInfo = logger.prepareJythonStackTrace('') logger.warn('[' + SCRIPT_NAME + ':getNetworkDevices] Exception: <%s>' % excInfo) pass
def makeAppServer(client, username, enterprise, serverObj, serverDataRow, siteOSH, Framework, OSHVResult): # init return value logger.debug('server:', string.join(serverObj), ' dataRow:', serverDataRow) datalist = serverObj sblsvrName = datalist[0] logger.debug('sblsvrName:', sblsvrName) hostName = datalist[1] installDir = datalist[2] sblmgrPID = datalist[3] serverID = datalist[9] # if no PID, server is not running. send an event on it # the message of the event will be everything that follows # the PID field if string.strip(sblmgrPID) == '': logger.debug('problem server:', serverDataRow) runningServer = 0 logger.debug('app server', sblsvrName, ' is not Running') else: runningServer = 1 # called status, but actually version details status = datalist[8] logger.debug('status:', status) versionTokens = status.split() version = versionTokens[0] build = versionTokens[1] lang = versionTokens[2] # host logger.debug('building host:', hostName) try: ip = netutils.getHostAddress(hostName) logger.debug('found ip:', ip, ' for hostName:', hostName) if ip == None: return None if netutils.isLocalIp(ip): logger.debug('got loopback ip, probably error.') return None appServerHostOSH = modeling.createHostOSH(ip) except: logger.errorException('failed to convert host name:', hostName, ' to IP') return None # siebel application server appServerOSH = modeling.createApplicationOSH('siebel_app_server', sblsvrName, appServerHostOSH, 'Enterprise App', 'oracle_corp') appServerOSH.setAttribute('application_ip', ip) appServerOSH.setAttribute('application_username', username) appServerOSH.setAttribute('install_dir', installDir) appServerOSH.setAttribute('svr_id',serverID) modeling.setAppServerType(appServerOSH) #9.0 workaround versionAsDouble = logger.Version().getVersion(Framework) if versionAsDouble >= 9: appServerOSH.removeAttribute('data_name') appServerOSH.setAttribute('name', sblsvrName) modeling.setApplicationProductName(appServerOSH, 'Siebel Server') OSHVResult.add(appServerHostOSH) OSHVResult.add(appServerOSH) if runningServer: appServerOSH.setAttribute('version', version) appServerOSH.setAttribute('application_version', version) appServerOSH.setAttribute('build', build) appServerOSH.setAttribute('lang', lang) # NOTE: setting the current app server so that all info will be only # for it prompt = client.executeCmd(string.join(['set server ', sblsvrName]), 5000)#@@CMD_PERMISION siebel protocol execution logger.debug(prompt) # get component groups (and components for each group) for this server # NOTE: as far as we know there can't be components that are not under a group # if such a situation can exist we won't find such 'leaf' components # with the current code # # makeComponentGroups(client, appServerOSH, ip, OSHVResult, enterprise, siteOSH) if version[0] == '7' or version[0] == '8': # get DB (Data Source) Attributes # table[0][0][1] means: # [0] - first row (should be only one, we are inside a server context) # [0] - first column: the parsed fields (second column is original row for error purposes) # [1] - second value in the parsed fields try: svrdsconnstrTblTxt = client.executeCmd('list parameter DSConnectString for named subsystem ServerDataSrc')#@@CMD_PERMISION siebel protocol execution svrdsconnstrTbl = siebel_common.makeTable(svrdsconnstrTblTxt) svrdsconnstr = string.upper(svrdsconnstrTbl[0][0][1]) logger.debug('svrdsconnstr:', svrdsconnstr) appServerOSH.setAttribute('srv_ds_conn_str', svrdsconnstr) except: error_message = 'failed to get DSConnectString (to set attribute srv_ds_conn_str) on server' logger.debug(error_message) Framework.reportWarning(error_message) try: svrdstypeTblTxt = client.executeCmd('list parameters DSSQLStyle for named subsystem ServerDataSrc')#@@CMD_PERMISION siebel protocol execution svrdstypeTbl = siebel_common.makeTable(svrdstypeTblTxt) if svrdstypeTbl: svrdstype = svrdstypeTbl[0][0][1] else: svrdstypeTblTxt = client.executeCmd('list parameters DSDLLName for named subsystem ServerDataSrc')#@@CMD_PERMISION siebel protocol execution svrdstypeTbl = siebel_common.makeTable(svrdstypeTblTxt) svrdstype = DLL_TO_SQL_TYPE_MAP[svrdstypeTbl[0][0][1]] logger.debug('svrdstype:', svrdstype) appServerOSH.setAttribute('svr_ds_type', svrdstype) except: error_message = 'failed to get DSSQLStyle (to set attribute svr_ds_type) on server' logger.debugException(error_message) Framework.reportWarning(error_message) serverType = getSiebelServerType(client) if serverType: appServerOSH.setStringAttribute('data_description', serverType) else: logger.warn("Cannot determine the type of server '%s', no required components were found" % sblsvrName) if version[0] == '6': # in Siebel 2000 (tested with 6.3), we can't obtain some of the parameters using command line API # get missing attributes from configuration file logger.info('Datasource parameters are not supported in version ', version) logger.info('Please run SIEBEL_DIS_APP_SERVER_CONFIG pattern to get server datasource attributes') try: odbcDSNTblTxt = client.executeCmd('list param connect')#@@CMD_PERMISION siebel protocol execution odbcDSNTbl = siebel_common.makeTable(odbcDSNTblTxt) odbcDSN = odbcDSNTbl[0][0][1] logger.debug('odbcDSN:', odbcDSN) appServerOSH.setAttribute('odbc_dsn', odbcDSN) except: error_message = 'failed to get ODBC DSN (connect param (to set attribute odbc_dsn) on server' logger.debug(error_message) Framework.reportWarning(error_message) # NOTE: unsetting the current app server prompt = client.executeCmd('unset server', 3000)#@@CMD_PERMISION siebel protocol execution logger.debug(prompt) return appServerOSH
def getNetworkDevices(localDbClient, queryChunkSize, ipAddrList, portVlanIdMap, ignoreNodesWithoutIP, allowDnsLookup, localFramework): try: returnOSHV = ObjectStateHolderVector() ## Get total number of network devices in the database numDevices = 0 deviceCountQuery = 'SELECT COUNT(1) FROM lmsdatagrp.NETWORK_DEVICES' deviceCountResultSet = ciscoworks_utils.doQuery( localDbClient, deviceCountQuery) ## Return if query returns no results if deviceCountResultSet == None: logger.warn('[' + SCRIPT_NAME + ':getNetworkDevices] No Network Devices found') return None ## We have query results! while deviceCountResultSet.next(): numDevices = int( ciscoworks_utils.getStringFromResultSet( deviceCountResultSet, 1)) ## Determine chunk count ciscoworks_utils.debugPrint( 2, '[' + SCRIPT_NAME + ':getNetworkDevices] Got <%s> Network Devices...' % numDevices) numChunks = int(numDevices / queryChunkSize) + 1 ciscoworks_utils.debugPrint( 2, '[' + SCRIPT_NAME + ':getNetworkDevices] Got <%s> chunks...' % numChunks) for chunkIndex in range(0, numChunks): queryStartRow = chunkIndex * queryChunkSize if queryStartRow == 0: queryStartRow = 1 netDeviceQuery = '''SELECT TOP %s START AT %s netdevices.Device_Id, deviceState.NetworkElementID, netdevices.Device_Display_Name, netdevices.Host_Name, netdevices.Device_Category, netdevices.Device_Model, netdevices.Management_IPAddress, deviceState.Global_State FROM lmsdatagrp.NETWORK_DEVICES netdevices JOIN dba.DM_Dev_State deviceState ON netdevices.Device_Id=deviceState.DCR_ID''' % ( queryChunkSize, queryStartRow) #netDeviceQuery = '%s WHERE LOWER(netdevices.Device_Display_Name) LIKE \'a%%\'' % netDeviceQuery netDeviceResultSet = ciscoworks_utils.doQuery( localDbClient, netDeviceQuery) ## Return if query returns no results if netDeviceResultSet == None: logger.warn( '[' + SCRIPT_NAME + ':getNetworkDevices] No Network Devices found in chunk <%s>' % chunkIndex) return None ## We have query results! while netDeviceResultSet.next(): netDeviceOSH = ipOSH = None ## Get values from result set netDeviceID = ciscoworks_utils.getStringFromResultSet( netDeviceResultSet, 1) netDeviceElementID = ciscoworks_utils.getStringFromResultSet( netDeviceResultSet, 2) netDeviceDisplayName = ciscoworks_utils.getStringFromResultSet( netDeviceResultSet, 3) netDeviceHostName = ciscoworks_utils.getStringFromResultSet( netDeviceResultSet, 4) netDeviceCategory = ciscoworks_utils.getStringFromResultSet( netDeviceResultSet, 5) netDeviceModel = ciscoworks_utils.getStringFromResultSet( netDeviceResultSet, 6) ipAddress = ciscoworks_utils.getStringFromResultSet( netDeviceResultSet, 7) #netDeviceStateIndex = ciscoworks_utils.getStringFromResultSet(netDeviceResultSet, 7) ## Set device name based on first available value netDeviceName = netDeviceDisplayName or netDeviceHostName ciscoworks_utils.debugPrint( 1, '[' + SCRIPT_NAME + ':getNetworkDevices] Got Device <%s> with ID <%s>' % (netDeviceName, netDeviceElementID)) ## Get enums for net device #deviceStateEnumDict = ciscoworks_utils.getEnum(localDbClient, 'dba.DM_Global_State_Enum') physicalTypeEnumDict = ciscoworks_utils.getEnum( localDbClient, 'dba.PhysicalTypeEnum') ## Initialize variables for additional data netDeviceElementName = netDeviceReportedName = netDeviceDNSDomainName = netDeviceDescription = netDeviceContact = netDeviceLocation = None netDeviceOsName = netDeviceOsVersion = netDeviceManufacturer = netDeviceSerialNumber = None netDeviceDnsName = None ## Get additional details for this device netDeviceAdditionalDataQuery = '''SELECT ne.ElementName, ne.ReportedHostName, ne.DNSDomainName, ne.Description, ne.PrimaryOwnerContact, ne.ElementLocation, os.OSName, os.Version, os.ROMVersion, pe.Manufacturer, pe.SerialNumber FROM dba.OperatingSystem os, dba.PhysicalElement pe, dba.networkelement ne WHERE os.NetworkElementID=%s AND ne.NetworkElementID=%s AND pe.NetworkElementID=%s AND LOWER(pe.PhysicalType)=%s AND pe.PhysicalElementId IN (1, 2)'''\ % (netDeviceElementID, netDeviceElementID, netDeviceElementID, physicalTypeEnumDict['Chassis/Frame']) netDeviceAdditionalDataResultSet = ciscoworks_utils.doQuery( localDbClient, netDeviceAdditionalDataQuery) ## Return if query returns no results if netDeviceAdditionalDataResultSet == None: logger.warn( '[' + SCRIPT_NAME + ':getNetworkDevices] No additional data found for network device <%s> with ID <%s>' % (netDeviceName, netDeviceElementID)) return None ## We have query results! while netDeviceAdditionalDataResultSet.next(): ## Get values from result set netDeviceElementName = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 1) netDeviceReportedName = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 2) netDeviceDNSDomainName = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 3) netDeviceDescription = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 4) netDeviceContact = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 5) netDeviceLocation = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 6) netDeviceOsName = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 7) netDeviceOsVersion = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 8) #netDeviceRomVersion = ciscoworks_utils.getStringFromResultSet(netDeviceAdditionalDataResultSet, 9) netDeviceManufacturer = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 10) netDeviceSerialNumber = ciscoworks_utils.getStringFromResultSet( netDeviceAdditionalDataResultSet, 11) ciscoworks_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':getNetworkDevices] Got additional information for Net Device <%s> with ID <%s>' % (netDeviceName, netDeviceElementID)) netDeviceAdditionalDataResultSet.close() if not netDeviceName: netDeviceName = netDeviceElementName or netDeviceReportedName if netDeviceDNSDomainName and not netutils.isValidIp( netDeviceName): #netDeviceName = '%s.%s' % (netDeviceName, netDeviceDNSDomainName) #netDeviceDnsName = netDeviceName.lower() netDeviceDnsName = '%s.%s' % (netDeviceName, netDeviceDNSDomainName) ## Determine Net Device CI Type netDeviceCiType = 'netdevice' netDeviceCategoreToCiTypeMap = { 'Routers': 'router', 'Switches and Hubs': 'switch', 'Content Networking': 'switch', 'Cisco Interfaces and Modules': 'switch', 'Wireless': 'netdevice', 'Voice and Telephony': 'netdevice', 'Unknown': 'netdevice' } if netDeviceCategory in netDeviceCategoreToCiTypeMap.keys(): netDeviceCiType = netDeviceCategoreToCiTypeMap[ netDeviceCategory] ## Discard management IP if this is a duplicate if ipAddress and netutils.isValidIp( ipAddress) and ipAddress in ipAddrList: logger.debug( '[' + SCRIPT_NAME + ':getNetworkDevices] Duplicate IP address <%s> on Network Device <%s> with ID <%s>!! Discarding IP...' % (ipAddress, netDeviceName, netDeviceElementID)) ipAddress = None else: ipAddrList.append(ipAddress) ## Get the list of IP addresses associated with this device ipSubnetDict = getIpSubnetDict(localDbClient, ipAddrList, netDeviceID, netDeviceElementID, netDeviceName) # Check if an IP address is available to build the host key # If an IP is not available and a DNS name is available, try resolving the IP # If not, skip this device ## If a management IP is not available, use the first IP in the IP list if not ipAddress and ipSubnetDict and len(ipSubnetDict) > 0: ipAddress = ipSubnetDict[0] ## Try DNS lookup if an IP is not available if not (ipAddress and netutils.isValidIp(ipAddress) ) and allowDnsLookup and netDeviceDnsName: ciscoworks_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':getNetworkDevices] No IP for Device <%s> with DNS name <%s>! Attempting DNS lookup...' % (netDeviceName, netDeviceDnsName)) ipAddress = netutils.getHostAddress(netDeviceDnsName) if not (ipAddress and netutils.isValidIp(ipAddress) ) and allowDnsLookup and netDeviceName: ciscoworks_utils.debugPrint( 3, '[' + SCRIPT_NAME + ':getNetworkDevices] No IP for Device <%s> with ID <%s>! Attempting DNS lookup...' % (netDeviceName, netDeviceElementID)) ipAddress = netutils.getHostAddress(netDeviceName) ## Check for a valid IP before creating CIs if ipAddress and netutils.isValidIp(ipAddress): netDeviceOSH = modeling.createHostOSH( ipAddress, netDeviceCiType) ipOSH = modeling.createIpOSH(ipAddress, None, netDeviceDnsName, None) elif ignoreNodesWithoutIP: logger.debug( '[' + SCRIPT_NAME + ':getNetworkDevices] IP address not available for Network Device <%s> with ID <%s>!! Skipping...' % (netDeviceName, netDeviceElementID)) continue else: logger.debug( '[' + SCRIPT_NAME + ':getNetworkDevices] IP address not available for Network Device <%s> with ID <%s>!! Creating Network Device with ID as primary key...' % (netDeviceName, netDeviceElementID)) hostKey = netDeviceElementID + ' (CiscoWorks Network Element ID)' netDeviceOSH = modeling.createCompleteHostOSH( netDeviceCiType, hostKey) netDeviceOSH.setAttribute( 'data_note', 'IP address unavailable in CiscoWorks LMS - Duplication of this CI is possible' ) ## Set the real name of the netDevice netDeviceRealName = netDeviceName if netDeviceName and netutils.isValidIp(netDeviceName): netDeviceRealName = '' ## Add more details to the OSH ciscoworks_utils.populateOSH( netDeviceOSH, { 'name': netDeviceRealName, 'data_externalid': netDeviceName, 'discovered_description': netDeviceDescription, 'discovered_contact': netDeviceContact, 'discovered_location': netDeviceLocation, 'discovered_os_name': netDeviceOsName, 'discovered_os_version': netDeviceOsVersion, 'discovered_model': netDeviceModel, 'serial_number': netDeviceSerialNumber, 'discovered_vendor': netDeviceManufacturer, 'primary_dns_name': netDeviceDnsName, 'domain_name': netDeviceDNSDomainName }) ## Set node role netDeviceOSH.setListAttribute('node_role', [netDeviceCiType]) returnOSHV.add(netDeviceOSH) returnOSHV.addAll( getNetDevicePortsAndVlans(localDbClient, portVlanIdMap, netDeviceID, netDeviceElementID, netDeviceName, netDeviceOSH)) returnOSHV.addAll( getModules(localDbClient, netDeviceID, netDeviceName, netDeviceOSH)) ## Add IPs to OSHV if ipOSH: returnOSHV.add(ipOSH) returnOSHV.add( modeling.createLinkOSH('containment', netDeviceOSH, ipOSH)) if ipSubnetDict and len(ipSubnetDict) > 0: for ipAddy in ipSubnetDict.keys(): ipOSH = modeling.createIpOSH(ipAddy, ipSubnetDict[ipAddy], netDeviceDnsName, None) returnOSHV.add(ipOSH) returnOSHV.add( modeling.createLinkOSH('containment', netDeviceOSH, ipOSH)) netDeviceResultSet.close() ## Send results to server localFramework.sendObjects(returnOSHV) localFramework.flushObjects() returnOSHV.clear() return returnOSHV except: excInfo = logger.prepareJythonStackTrace('') logger.warn('[' + SCRIPT_NAME + ':getNetworkDevices] Exception: <%s>' % excInfo) pass
def doUddiExplore(uddiAgent, registryOSH, OSHVResult): table = uddiAgent.doTableCommand("") Empty = '' rows = table.getRowCount() logger.debug('XXXXXXXXXXXXXXX There are Business entity:', rows) for row in range(rows): properties = table.getCell(row, 0) #businessEntity entityName = properties.getProperty(UDDIUtil.BUSINESS_ENTITY_NAME, Empty) entityDescription = properties.getProperty( UDDIUtil.BUSINESS_ENTITY_DESC, Empty) bsOSH = ObjectStateHolder('organization') bsOSH.setAttribute('name', entityName) bsOSH.setAttribute('description', entityDescription) bsOSH.setAttribute('organization_type', 'department') logger.debug('XXXXXXXXXXXXXXX add Business entity:', entityName) contacts = properties.get(UDDIUtil.BUSINESS_ENTITY_CONTACTS) contactinfo = [] if contacts != None: itc = contacts.iterator() while itc.hasNext(): contact = itc.next() contactName = contact.getProperty(UDDIUtil.CONTACT_NAME, Empty) contactPhon = contact.getProperty(UDDIUtil.CONTACT_PHONE, Empty) contactEmail = contact.getProperty(UDDIUtil.CONTACT_EMAIL, Empty) contactUse = contact.getProperty(UDDIUtil.CONTACT_USE_TYPE, Empty) contactinfo.append("[") contactinfo.append(contactName) contactinfo.append(" Phone:") contactinfo.append(contactPhon) contactinfo.append(" Email:") contactinfo.append(contactEmail) contactinfo.append(" Use type:") contactinfo.append(contactUse) contactinfo.append("] ") contactInfoData = ''.join(contactinfo) bsOSH.setAttribute('contact_info', contactInfoData) OSHVResult.add(bsOSH) link2Reg = modeling.createLinkOSH('containment', registryOSH, bsOSH) OSHVResult.add(link2Reg) services = properties.get(UDDIUtil.BUSINESS_ENTITY_SERVICES) if services != None: logger.debug('XXXXXXXXXXXXXXX services:', services.size()) its = services.iterator() while its.hasNext(): service = its.next() name = service.getProperty(UDDIUtil.NAME, Empty) description = service.getProperty(UDDIUtil.DESCRIPTION, Empty) key = service.getProperty(UDDIUtil.KEY, Empty) wsdlUrl = service.getProperty(UDDIUtil.WSDL_URL, Empty) url = service.getProperty(UDDIUtil.URL, Empty) namespace = service.getProperty(UDDIUtil.TARGET_NAME_SPACE, Empty) if not wsdlUrl and url: wsdlUrl = url urlIP = None try: url = URL(wsdlUrl) except: logger.warn("Incorrect URL \"%s\" found. Skipped." % wsdlUrl) continue try: hostName = url.getHost() urlIP = netutils.getHostAddress(hostName, None) if (not netutils.isValidIp(urlIP) ) or netutils.isLocalIp(urlIP): urlIP = None except: urlIP = None urlOSH = modeling.createUrlOsh(registryOSH, wsdlUrl, 'wsdl') urlIpOSH = None if urlIP != None: try: urlIpOSH = modeling.createIpOSH(urlIP) except: urlIpOSH = None OSHVResult.add(urlOSH) if urlIpOSH: OSHVResult.add(urlIpOSH) urlToIpOSH = modeling.createLinkOSH( 'dependency', urlOSH, urlIpOSH) OSHVResult.add(urlToIpOSH) wsOSH = ObjectStateHolder('webservice') wsOSH.setAttribute('name', namespace) wsOSH.setAttribute('description', description) wsOSH.setAttribute('service_name', name) wsOSH.setAttribute('wsdl_url', wsdlUrl) OSHVResult.add(wsOSH) urlToWsOSH = modeling.createLinkOSH('dependency', wsOSH, urlOSH) OSHVResult.add(urlToWsOSH) logger.debug('Service Name: ', name) logger.debug('Service Key: ', key) logger.debug('Service Description: ', description) logger.debug('WSDL url: ', wsdlUrl) logger.debug('Service url: ', url) dependOSH = modeling.createLinkOSH('dependency', wsOSH, registryOSH) link2bus = modeling.createLinkOSH('dependency', wsOSH, bsOSH) OSHVResult.add(dependOSH) OSHVResult.add(link2bus) logger.debug('add containment link to Registry ', name)
def parseCfgFileData(data, installPath, sarmLogFolder, shellUtils, webserverOSH, OSHVResult, HOST_ID, Framework): # create siebel web server extension siebelwseOSH = ObjectStateHolder('siebel_wse') siebelwseOSH.setContainer(webserverOSH) siebelwseOSH.setAttribute('data_name', 'Siebel WSE') siebelwseOSH.setAttribute('install_path', installPath) # try to get some general info on the SWE try: parseWSEDefaults(data, siebelwseOSH) except: logger.debug('failed getting wse defaults') OSHVResult.add(siebelwseOSH) configFileOsh = modeling.createConfigurationDocumentOSH( 'eapps.cfg', installPath, data, siebelwseOSH, modeling.MIME_TEXT_PLAIN, None, "Siebel Webserver Extention file") OSHVResult.add(configFileOsh) mapKeyToAppServers = None enableVirtualHosts = getAttribute(data, 'EnableVirtualHosts') if (enableVirtualHosts.lower() == 'true'): virtualHostsFile = getAttribute(data, 'VirtualHostsFile') if virtualHostsFile != None: virtualHostsFileData = None try: virtualHostsFileData = shellUtils.safecat(virtualHostsFile) if not virtualHostsFileData: raise ValueError except: logger.warn("Failed reading virtual host file '%s'" % virtualHostsFile) else: pattern = Pattern('([^\s]*)[\\\/]([^\s.]*).([^\s]*)') matcher = pattern.matcher(virtualHostsFile) if matcher.find() == 1: path = matcher.group(1) filename = matcher.group(2) extension = matcher.group(3) configFileName = "%s.%s" % (filename, extension) configFileOsh = modeling.createConfigurationDocumentOSH( configFileName, path, virtualHostsFileData, siebelwseOSH, modeling.MIME_TEXT_PLAIN, None, 'Load Balancer configuration file') OSHVResult.add(configFileOsh) mapKeyToAppServers = getAttributes(virtualHostsFileData, 'VirtualServer') # get web applications data apps = getApps(data) gatewayIpToOsh = {} siteNameToOsh = {} for app in apps: appName = app[app.find('[/') + 2:app.find(']')] connStr = getAttribute(app, 'ConnectString') # sample line: siebel.TCPIP.None.None://sblgw:2320/siebel/CRAObjMgr_cht/sblapp1_AS # sample line: siebel.TCPIP.None.None://cannon:2320/siebel/ERMObjMgr_chs/cannon gtwyHost = '' gtwyPort = '' siebelSite = '' componentName = '' appSvrName = '' appSvrIP = '' ip = '' tokens = connStr.split('/') numOfTokens = len(tokens) if numOfTokens > 2: if (enableVirtualHosts.lower() == 'true'): appServers = mapKeyToAppServers.get(tokens[2]) if appServers != None: serversStr = appServers.split(';') for serverStr in serversStr: if serverStr != '': serverStrTokens = serverStr.split(':') if appSvrName != '': appSvrName += ',' if appSvrIP != '': appSvrIP += ',' serverName = serverStrTokens[1] appSvrName += serverName appSvrIP += netutils.getHostAddress( serverName, serverName) else: gtwyConn = tokens[2].split(':') gtwyHost = gtwyConn[0] gtwyPort = gtwyConn[1] if not netutils.isValidIp(gtwyHost): ip = resolveHostname(gtwyHost, shellUtils, '') else: ip = gtwyHost if numOfTokens > 3: siebelSite = tokens[3] if numOfTokens > 4: componentName = tokens[4] if numOfTokens > 5: appSvrName = tokens[5] else: if appSvrIP == '': appSvrIP = ip gtwyHost = None if gtwyHost and ip and not gatewayIpToOsh.has_key(ip): gatewayOsh = createGatewayOsh(ip, gtwyPort, OSHVResult, Framework) OSHVResult.add(gatewayOsh) routeLinkOSH = modeling.createLinkOSH('depend', gatewayOsh, siebelwseOSH) OSHVResult.add(routeLinkOSH) gatewayIpToOsh[ip] = gatewayOsh if siebelSite and not siteNameToOsh.has_key(siebelSite): logger.debug('found siebel site:', siebelSite) siteOSH = ObjectStateHolder('siebel_site') siteOSH.setAttribute('gateway_address', ip) siteOSH.setAttribute('data_name', siebelSite) modeling.setAppSystemVendor(siteOSH) OSHVResult.add(siteOSH) siteNameToOsh[siebelSite] = siteOSH # create a siebel application object webappOSH = ObjectStateHolder('siebel_web_app') webappOSH.setAttribute('data_name', appName) webappOSH.setAttribute('site', siebelSite) webappOSH.setAttribute('app_srv_name', appSvrName) webappOSH.setAttribute('app_srv_ip', appSvrIP) webappOSH.setAttribute('component_name', componentName) # application contained in webserver extension webappOSH.setContainer(siebelwseOSH) OSHVResult.add(webappOSH)
def parseCfgFileData(data, installPath, sarmLogFolder, shellUtils, webserverOSH, OSHVResult, HOST_ID, Framework): # create siebel web server extension siebelwseOSH = ObjectStateHolder('siebel_wse') siebelwseOSH.setContainer(webserverOSH) siebelwseOSH.setAttribute('data_name', 'Siebel WSE') siebelwseOSH.setAttribute('install_path', installPath) # try to get some general info on the SWE try: parseWSEDefaults(data, siebelwseOSH) except: logger.debug('failed getting wse defaults') OSHVResult.add(siebelwseOSH) configFileOsh = modeling.createConfigurationDocumentOSH('eapps.cfg', installPath, data, siebelwseOSH, modeling.MIME_TEXT_PLAIN, None, "Siebel Webserver Extention file") OSHVResult.add(configFileOsh) mapKeyToAppServers = None enableVirtualHosts = getAttribute(data, 'EnableVirtualHosts') if (enableVirtualHosts.lower() == 'true'): virtualHostsFile = getAttribute(data, 'VirtualHostsFile') if virtualHostsFile != None: virtualHostsFileData = None try: virtualHostsFileData = shellUtils.safecat(virtualHostsFile) if not virtualHostsFileData: raise ValueError except: logger.warn("Failed reading virtual host file '%s'" % virtualHostsFile) else: pattern = Pattern('([^\s]*)[\\\/]([^\s.]*).([^\s]*)') matcher = pattern.matcher(virtualHostsFile) if matcher.find()== 1: path = matcher.group(1) filename = matcher.group(2) extension = matcher.group(3) configFileName = "%s.%s" % (filename, extension) configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, path, virtualHostsFileData, siebelwseOSH, modeling.MIME_TEXT_PLAIN, None, 'Load Balancer configuration file') OSHVResult.add(configFileOsh) mapKeyToAppServers = getAttributes(virtualHostsFileData,'VirtualServer') # get web applications data apps = getApps(data) gatewayIpToOsh = {} siteNameToOsh = {} for app in apps: appName = app[app.find('[/')+2:app.find(']')] connStr = getAttribute(app, 'ConnectString') # sample line: siebel.TCPIP.None.None://sblgw:2320/siebel/CRAObjMgr_cht/sblapp1_AS # sample line: siebel.TCPIP.None.None://cannon:2320/siebel/ERMObjMgr_chs/cannon gtwyHost = '' gtwyPort = '' siebelSite = '' componentName = '' appSvrName = '' appSvrIP = '' ip = '' tokens = connStr.split('/') numOfTokens = len(tokens) if numOfTokens > 2: if (enableVirtualHosts.lower() == 'true'): appServers = mapKeyToAppServers.get(tokens[2]) if appServers != None: serversStr = appServers.split(';') for serverStr in serversStr: if serverStr != '': serverStrTokens = serverStr.split(':') if appSvrName != '': appSvrName += ',' if appSvrIP != '': appSvrIP += ',' serverName = serverStrTokens[1] appSvrName += serverName appSvrIP += netutils.getHostAddress(serverName, serverName) else: gtwyConn = tokens[2].split(':') gtwyHost = gtwyConn[0] gtwyPort = gtwyConn[1] if not netutils.isValidIp(gtwyHost): ip = resolveHostname(gtwyHost, shellUtils, '') else: ip = gtwyHost if numOfTokens > 3: siebelSite = tokens[3] if numOfTokens > 4: componentName = tokens[4] if numOfTokens > 5: appSvrName = tokens[5] else: if appSvrIP == '': appSvrIP = ip gtwyHost = None if gtwyHost and ip and not gatewayIpToOsh.has_key(ip): gatewayOsh = createGatewayOsh(ip, gtwyPort, OSHVResult, Framework) OSHVResult.add(gatewayOsh) routeLinkOSH = modeling.createLinkOSH('depend', gatewayOsh, siebelwseOSH) OSHVResult.add(routeLinkOSH) gatewayIpToOsh[ip] = gatewayOsh if siebelSite and not siteNameToOsh.has_key(siebelSite): logger.debug('found siebel site:', siebelSite) siteOSH = ObjectStateHolder('siebel_site') siteOSH.setAttribute('gateway_address', ip) siteOSH.setAttribute('data_name', siebelSite) modeling.setAppSystemVendor(siteOSH) OSHVResult.add(siteOSH) siteNameToOsh[siebelSite] = siteOSH # create a siebel application object webappOSH = ObjectStateHolder('siebel_web_app') webappOSH.setAttribute('data_name', appName) webappOSH.setAttribute('site', siebelSite) webappOSH.setAttribute('app_srv_name', appSvrName) webappOSH.setAttribute('app_srv_ip', appSvrIP) webappOSH.setAttribute('component_name', componentName) # application contained in webserver extension webappOSH.setContainer(siebelwseOSH) OSHVResult.add(webappOSH)
def registryLookup(procToPortDict, dbInstanceDict, localClient, wmiRegistryClient): try: # Store all found listening Port activeListenerPorts = [] for pid in procToPortDict.keys(): activeListenerPorts.append((procToPortDict[pid])[dbconnect_utils.PORT_INDEX]) ## Locals logger.debug('Initial dbInstanceDict %s' % dbInstanceDict) instanceNameList = [] installNameTointernalInstanceName = {} # If SQL Server is present on this box, get instance names installedInstancesKeypath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server' installedInstances = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, installedInstancesKeypath, 'InstalledInstances') if installedInstances == None or str(installedInstances) == '[[], []]' or str(installedInstances) == '{}': if dbInstanceDict != None and len(dbInstanceDict) > 0: instancesString = '' for dbName in dbInstanceDict.keys(): instancesString = instancesString + dbName.upper() + '\n' installedInstances = {} installedInstances.update({installedInstancesKeypath:instancesString[:-1]}) # chop last \n else: dbconnect_utils.debugPrint(2, '[' + SCRIPT_NAME + ':registryLookup] SQL Server not installed on this box') return None logger.debug("Discovered installed instances %s" % installedInstances) if installedInstances: ## We have SQL Server dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] SQL Server present on this box <%s>' % installedInstances) installedInstanceNames = installedInstances[installedInstancesKeypath] if installedInstanceNames.find('\n') > 0 or installedInstanceNames.find(' _ ') > 0: ## Multiple SQL Server instances installedIstanceNameList = re.split(' _ |\n', installedInstanceNames) else: installedIstanceNameList = [installedInstanceNames] logger.debug('Installed instance name list %s' % installedIstanceNameList) for installedInstanceName in installedIstanceNameList: instanceNameList.append(installedInstanceName.strip()) dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Found SQL Server instance <%s>' % installedInstanceName.strip()) internalInstanceNameKeyPath = 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL' internalInstanceNameDict = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, internalInstanceNameKeyPath, installedInstanceName) internalInstanceName = internalInstanceNameDict[internalInstanceNameKeyPath] if internalInstanceName: dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Found registry name <%s> for internal SQL instance name <%s>' % (internalInstanceName, installedInstanceName)) installNameTointernalInstanceName[installedInstanceName.strip()] = internalInstanceName.strip() else: installNameTointernalInstanceName[installedInstanceName.strip()] = installedInstanceName.strip() logger.debug("installNameTointernalInstanceName %s" % installNameTointernalInstanceName) logger.debug("instanceNameList %s " % instanceNameList) # If we're here, one or more SQL Server instances are present # Look for additional SQL Server information sqlServerDetailKeypaths = ['SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\SuperSocketNetLib\\Tcp', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Setup', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\MSSQLServer\\CurrentVersion', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster', 'SOFTWARE\\Microsoft\\Microsoft SQL Server\\iNsTaNcEnAmE\\Cluster'] sqlServerDetailFilters = ['TcpPort', 'SQLPath', 'CurrentVersion', 'ClusterIpAddr', 'ClusterName'] for instanceName in instanceNameList: sqlServerDetailValues = [] for sqlServerDetailIndex in range(len(sqlServerDetailKeypaths)): sqlServerDetailKeypath = '' ## Replace instance names in registry key path as appropriate if instanceName == 'MSSQLSERVER': if sqlServerDetailKeypaths[sqlServerDetailIndex].find('luster') > 0: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get(instanceName)) else: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'Microsoft SQL Server\\iNsTaNcEnAmE', 'MSSQLServer') else: if sqlServerDetailKeypaths[sqlServerDetailIndex].find('luster') > 0: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', installNameTointernalInstanceName.get(instanceName)) else: sqlServerDetailKeypath = string.replace(sqlServerDetailKeypaths[sqlServerDetailIndex], 'iNsTaNcEnAmE', instanceName) regValues = dbconnect_utils.getRegValues(localClient, wmiRegistryClient, sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex]) if regValues == None or str(regValues) == '[[], []]' or str(regValues) == '{}': dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got nothing for key <%s> with filter <%s>' % (sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) sqlServerDetailValues.insert(sqlServerDetailIndex, None) else: sqlServerDetailValues.insert(sqlServerDetailIndex, regValues[sqlServerDetailKeypath]) dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got value <%s> for key <%s> with filter <%s>' % (sqlServerDetailValues[sqlServerDetailIndex], sqlServerDetailKeypath, sqlServerDetailFilters[sqlServerDetailIndex])) logger.debug("instanceNameList %s " % instanceNameList) ## We should have all details for this instance now - add it to DB dictionary listenerPort = sqlServerDetailValues[0] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got port <%s> for instance <%s>' % (listenerPort, instanceName)) installPath = sqlServerDetailValues[1] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got path <%s> for instance <%s>' % (installPath, instanceName)) version = sqlServerDetailValues[2] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got version <%s> for instance <%s>' % (version, instanceName)) ipAddress = dbconnect_utils.fixIP(sqlServerDetailValues[3], localClient.getIpAddress()) dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got IP <%s> for instance <%s>' % (ipAddress, instanceName)) clusterName = sqlServerDetailValues[4] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got Cluster Name <%s> for instance <%s>' % (clusterName, instanceName)) if clusterName: clusterIp = netutils.getHostAddress(clusterName) if clusterIp and netutils.isValidIp(clusterIp): ipAddress = clusterIp ## If the instance is already in the DB dict, don't overwrite all values if instanceName == 'MSSQLSERVER': dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Got unnamed SQL Server instance') instanceName = dbconnect_utils.getServerName(localClient) else: instanceName = dbconnect_utils.getServerName(localClient) + '\\' + instanceName.lower() installPath = installPath.lower() if instanceName in dbInstanceDict.keys(): statusFlag = (dbInstanceDict[instanceName])[dbconnect_utils.STATUS_INDEX] # If port is already populated, don't overwrite it because # port number information from active processes (above) is # guaranteed to be correct and the registry may not be up-to-date if (dbInstanceDict[instanceName])[dbconnect_utils.PORT_INDEX] != dbconnect_utils.UNKNOWN: if listenerPort not in activeListenerPorts: listenerPort = (dbInstanceDict[instanceName])[dbconnect_utils.PORT_INDEX] dbInstanceDict[instanceName] = ['MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, statusFlag] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Found known SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) else: dbInstanceDict[instanceName] = ['MicrosoftSQLServer', listenerPort, ipAddress, installPath, version, dbconnect_utils.UNKNOWN] dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Added SQL Server <%s> instance <%s> listening at port <%s> on <%s> and installed in <%s>' % (version, instanceName, listenerPort, ipAddress, installPath)) logger.debug("instanceNameList %s " % instanceNameList) logger.debug("dbInstanceDict %s" % dbInstanceDict) ## Replace dictionary entry of serverName\sqlInstanceName with clusterName\sqlInstanceName if clusterName and instanceName in dbInstanceDict.keys(): if instanceName.find('\\') > 0 : newInstanceName = clusterName + '\\' + instanceName[instanceName.find('\\')+1:] else: newInstanceName = clusterName dbconnect_utils.debugPrint(3, '[' + SCRIPT_NAME + ':registryLookup] Replacing SQL Server instance <%s> with <%s> because it is part of a cluster' % (instanceName, newInstanceName)) dbInstanceDict[newInstanceName] = dbInstanceDict[instanceName] del dbInstanceDict[instanceName] logger.debug("dbInstanceDict %s" % dbInstanceDict) #print dbInstanceDict logger.debug("instanceNameList %s " % instanceNameList) except: excInfo = logger.prepareJythonStackTrace('') dbconnect_utils.debugPrint('[' + SCRIPT_NAME + ':registryLookup] Exception: <%s>' % excInfo) pass
def doUddiExplore(uddiAgent, registryOSH, OSHVResult): table = uddiAgent.doTableCommand("") Empty = '' rows = table.getRowCount() logger.debug('XXXXXXXXXXXXXXX There are Business entity:', rows) for row in range(rows): properties = table.getCell(row, 0) #businessEntity entityName = properties.getProperty(UDDIUtil.BUSINESS_ENTITY_NAME, Empty) entityDescription = properties.getProperty(UDDIUtil.BUSINESS_ENTITY_DESC, Empty) bsOSH = ObjectStateHolder('organization') bsOSH.setAttribute('name', entityName) bsOSH.setAttribute('description', entityDescription) bsOSH.setAttribute('organization_type', 'department') logger.debug('XXXXXXXXXXXXXXX add Business entity:', entityName) contacts = properties.get(UDDIUtil.BUSINESS_ENTITY_CONTACTS) contactinfo = [] if contacts != None: itc = contacts.iterator() while itc.hasNext(): contact = itc.next() contactName = contact.getProperty(UDDIUtil.CONTACT_NAME, Empty) contactPhon = contact.getProperty(UDDIUtil.CONTACT_PHONE, Empty) contactEmail = contact.getProperty(UDDIUtil.CONTACT_EMAIL, Empty) contactUse = contact.getProperty(UDDIUtil.CONTACT_USE_TYPE, Empty) contactinfo.append("[") contactinfo.append(contactName) contactinfo.append(" Phone:") contactinfo.append(contactPhon) contactinfo.append(" Email:") contactinfo.append(contactEmail) contactinfo.append(" Use type:") contactinfo.append(contactUse) contactinfo.append("] ") contactInfoData = ''.join(contactinfo) bsOSH.setAttribute('contact_info', contactInfoData) OSHVResult.add(bsOSH) link2Reg = modeling.createLinkOSH('containment', registryOSH, bsOSH) OSHVResult.add(link2Reg) services = properties.get(UDDIUtil.BUSINESS_ENTITY_SERVICES) if services != None: logger.debug('XXXXXXXXXXXXXXX services:', services.size()) its = services.iterator() while its.hasNext(): service = its.next(); name = service.getProperty(UDDIUtil.NAME, Empty) description = service.getProperty(UDDIUtil.DESCRIPTION, Empty) key = service.getProperty(UDDIUtil.KEY, Empty) wsdlUrl = service.getProperty(UDDIUtil.WSDL_URL, Empty) url = service.getProperty(UDDIUtil.URL, Empty) namespace = service.getProperty(UDDIUtil.TARGET_NAME_SPACE, Empty) if not wsdlUrl and url: wsdlUrl = url urlIP = None try: url = URL(wsdlUrl) except: logger.warn("Incorrect URL \"%s\" found. Skipped." % wsdlUrl) continue try: hostName = url.getHost() urlIP = netutils.getHostAddress(hostName, None); if (not netutils.isValidIp(urlIP)) or netutils.isLocalIp(urlIP): urlIP = None except: urlIP = None urlOSH = modeling.createUrlOsh(registryOSH, wsdlUrl, 'wsdl') urlIpOSH = None if urlIP != None: try: urlIpOSH = modeling.createIpOSH(urlIP) except: urlIpOSH = None OSHVResult.add(urlOSH) if urlIpOSH: OSHVResult.add(urlIpOSH) urlToIpOSH = modeling.createLinkOSH('dependency', urlOSH, urlIpOSH) OSHVResult.add(urlToIpOSH) wsOSH = ObjectStateHolder('webservice') wsOSH.setAttribute('name', namespace) wsOSH.setAttribute('description', description) wsOSH.setAttribute('service_name', name) wsOSH.setAttribute('wsdl_url', wsdlUrl) OSHVResult.add(wsOSH) urlToWsOSH = modeling.createLinkOSH('dependency', wsOSH , urlOSH ) OSHVResult.add(urlToWsOSH) logger.debug('Service Name: ', name) logger.debug('Service Key: ', key) logger.debug('Service Description: ', description) logger.debug( 'WSDL url: ', wsdlUrl) logger.debug( 'Service url: ', url) dependOSH = modeling.createLinkOSH('dependency', wsOSH, registryOSH) link2bus = modeling.createLinkOSH('dependency', wsOSH , bsOSH) OSHVResult.add(dependOSH) OSHVResult.add(link2bus) logger.debug('add containment link to Registry ', name)
def getHost(hostName): host = netutils.getHostAddress(hostName) if host: return modeling.createHostOSH(host) else: return None
def getHostKey(host, domain): return netutils.getHostAddress(host) + " " + domain