def report_tree(framework, business_object_node, parent_osh): vector = ObjectStateHolderVector() current_osh = business_object_node.create_osh(parent_osh) vector.add(current_osh) for node in business_object_node.get_children(): vector.addAll(report_tree(framework, node, current_osh)) return vector
def testScript(): OSHVResult = ObjectStateHolderVector() DebugMode = 'false' DateParsePattern = 'EEE MMM dd HH:mm:ss z yyyy' userExtDir = 'E:\\data\\Desktop\\Pull_From_Remedy_backup\\' if (DebugMode != None): DebugMode = DebugMode.lower() if DebugMode == "true": logger.info ('[NOTE] UCMDB Integration is running in DEBUG mode. No data will be pushed to the destination server.') return filePathDir = userExtDir + 'TQLExport\\Atrium\\results\\' directory = File(filePathDir) files = directory.listFiles() try: for file in files: if file != None or file != '': builder = SAXBuilder () doc = builder.build(file) logger.info("Start processing CIs to update in the destination server...") allObjects = doc.getRootElement().getChild('data').getChild('objects').getChildren('Object') (objVector, ciDict) = processObjects(allObjects, DateParsePattern) OSHVResult.addAll(objVector) logger.info("Start processing Relationships to update in the destination server...") allLinks = doc.getRootElement().getChild('data').getChild('links').getChildren('link') linkVector = processLinks(allLinks, ciDict) OSHVResult.addAll(linkVector) print OSHVResult.toXmlString() except: stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) logger.info('Failure in processing data %s' % stacktrace) logger.info('Ending Push to UCMDB') #testScript()
def DiscoveryMain(Framework): debugPrint('[DiscoveryMain] Starting...') # General variables OSHVResult = ObjectStateHolderVector() protocolName = 'SQL' sqlClient = None # We need dictionaries for each OSH type since results of # SQL queries will contain multiple rows with the same info datacenterOshDict = {} # Use building name as key rackOshDict = {} # Use rack+building name as key pduOshDict = {} # Use PDU+building name as key rppOshDict = {} # Use RPP+building name as key hostOshDict = {} # Use serial number as key try: # JDBC client sqlClient = Framework.createClient() # Discover... OSHVResult.addAll( getDevices(Framework, sqlClient, datacenterOshDict, rackOshDict, pduOshDict, rppOshDict, hostOshDict)) OSHVResult.addAll( getPowerRoutes(Framework, sqlClient, datacenterOshDict, rackOshDict, pduOshDict, rppOshDict, hostOshDict)) except Exception, ex: strException = str(ex.getMessage()) errormessages.resolveAndReport(strException, protocolName, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() logger.info('Starting HACMP Applications') hostIP = Framework.getDestinationAttribute('ip_address') logger.debug('Host IP: ', hostIP) cluster = Framework.getDestinationAttribute('cluster') hostOS = Framework.getDestinationAttribute('host_os') hostOS = hostOS or 'NA' protocolName = Framework.getDestinationAttribute('Protocol') hostId = Framework.getDestinationAttribute('hostId') ## Get Parameter Section cldisp_command = Framework.getParameter('cldisp_command') or 'cldisp' cllsif_command = Framework.getParameter('cllsif_command') or 'cllsif' try: client = Framework.createClient() shell = ShellUtils(client) # If we get good client connection , run the client commands to get the Application information for the cluster HostOSH = modeling.createOshByCmdbIdString('host', hostId) ClusterOSH = getclusterOSH(cluster) appDictionary = getapplicationInfo(shell, cldisp_command, Framework) resourceDictionary = getresourceinfo(shell, cllsif_command) OSHVResult.addAll( createserviceapplicationOSH(shell, appDictionary, resourceDictionary, HostOSH, ClusterOSH, Framework)) client.close() except JavaException, ex: strException = ex.getMessage() logger.debugException('') errormessages.resolveAndReport(strException, protocolName, Framework)
def reportDatabaseTopology(self, dsnInfo, dependentObject): """ :param dsnInfo: list of all DSN's for which need to report topology :type dsnInfo: odbc.DSNInfo :return: vector which include all osh's for created topology :rtype: appilog.common.system.types.vectors.ObjectStateHolderVector """ vector = ObjectStateHolderVector() try: database_pdo = self.__builder.buildDatabaseServerPdo(dsnInfo) platform = db_platform.findPlatformBySignature(dsnInfo.driver) builder = db_builder.getBuilderByPlatform(platform) db_reporter = db.getReporter(platform, builder) host_descriptor = self.__builder.buildHostDescriptor( dsnInfo.address) host_descriptor = host_descriptor._replace(name=None) reporter = host_topology.Reporter() host_osh, ip_oshs, oshs = reporter.report_host(host_descriptor) server_osh, ipseOsh, database_oshs, topology = db_reporter.reportServerWithDatabases( database_pdo, host_osh, [dependentObject]) vector.addAll(topology) vector.addAll(oshs) return vector except dns_resolver.ResolveException: logger.reportWarning("Cannot resolve ip of node") return ObjectStateHolderVector()
def collectData(self,hostId,sqlServerId, discoverConfigs = 1): self.connection.open() oshv = ObjectStateHolderVector() try: oshv.add(self.getServerProperties(sqlServerId,hostId)) dbMap = self.getDatabases(sqlServerId) #get the databases oshv.addAll(self.sqlDataBaseProps.getDatabases(dbMap,hostId,discoverConfigs)) oshv.addAll(self.sqlDataBaseProps.getStoredProcedures(dbMap)) #get the server configuration: logger.debug('discovering configs') try: oshv.add(self.sqlServerConfig.getServerConfiguration(sqlServerId)) oshv.add(self.sqlServerConfig.getServerStartup(sqlServerId)) self.sqlServerConfig.discoverPlans(oshv,sqlServerId,dbMap) except: logger.debugException(hostId.toString()) if self.discoveryOptions and self.discoveryOptions.discoverDbUser: users = self.getDbUsers(sqlServerId) Util.addFromMap(users,oshv) else: users = LinkedHashMap() oshv.addAll(self.getProcesses(hostId,sqlServerId,dbMap,users)) oshv.addAll(self.clusterConfiguration.collectData(sqlServerId)) #db configuration: oshv.addAll(self.getDbConf(dbMap,hostId,users)) logger.debug("sql db result for hostid:"+hostId.toString()) except: logger.debugException(hostId.toString()) self.connection.close() return oshv
def DiscoveryMain(framework): vector = ObjectStateHolderVector() protocol = 'local_shell' try: zoneNameList, includeOutscopeIPs, ip, reportBrokenAliases = _obtainParams( framework) if not zoneNameList: logger.reportError('List of zones for transfer is not specified') return client = framework.createClient( ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) shell = None try: shell = shellutils.ShellUtils(client) #pass name server IP to the discoverer dnsDiscoverer = dns_discoverer.createDiscovererByShell(shell, ip) zoneTopologies = dns_discoverer.discoverDnsZoneTopologies( dnsDiscoverer, zoneNameList, protocol) vector.addAll( dns_discoverer.reportTopologies(zoneTopologies, includeOutscopeIPs, reportBrokenAliases)) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() CmdbOIDFactory = CmdbObjectID.Factory hostId = CmdbOIDFactory.restoreObjectID(Framework.getDestinationAttribute('hostId')) sqlServerId = CmdbOIDFactory.restoreObjectID(Framework.getDestinationAttribute('id')) try: props = Properties() instance_name = Framework.getDestinationAttribute('instanceName') if instance_name and instance_name != 'NA' and instance_name.find('\\') != -1: props.setProperty('sqlprotocol_dbsid', instance_name[instance_name.find('\\')+1:]) mssqlClient = Framework.createClient(props) connection = SqlServerConnection.ClientSqlServerConnection(mssqlClient) logger.debug("got connection") discoveryOptions = SqlServerDiscoveryOptions() discoveryOptions.discoverConfigs = Boolean.parseBoolean(Framework.getParameter('discoverConfigs')) discoveryOptions.discoverDbUser = Boolean.parseBoolean(Framework.getParameter('discoverDbUser')) discoveryOptions.discoverSqlFile = Boolean.parseBoolean(Framework.getParameter('discoverSqlFile')) discoveryOptions.discoverSqlJob = Boolean.parseBoolean(Framework.getParameter('discoverSqlJob')) discoveryOptions.discoverProcedures = Boolean.parseBoolean(Framework.getParameter('discoverStoredProcedures')) discoveryOptions.discoverInternalProcedures = Boolean.parseBoolean(Framework.getParameter('discoverInternalProcedures')) sqlServer = SqlServer.SqlServer(connection, discoveryOptions) OSHVResult.addAll(sqlServer.collectData(hostId, sqlServerId, discoveryOptions.discoverConfigs)) mssqlClient.close() except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, ClientsConsts.SQL_PROTOCOL_NAME, Framework)
def DiscoveryMain(Framework): resultVector = ObjectStateHolderVector() ipAddress = Framework.getDestinationAttribute(DestinationProperty.IP_ADDRESS) credentialsId = Framework.getDestinationAttribute(DestinationProperty.CREDENTIALS_ID) hypervisorCmdbId = Framework.getDestinationAttribute(DestinationProperty.HYPERVISOR_CMDB_ID) esxCmdbId = Framework.getDestinationAttribute(DestinationProperty.ESX_CMDB_ID) esxBiosUuid = Framework.getDestinationAttribute(DestinationProperty.ESX_BIOS_UUID) if not esxBiosUuid: msg = "ESX BIOS UUID from trigger data is empty" errorObject = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [cim.Protocol.DISPLAY, msg], msg) logger.reportErrorObject(errorObject) logger.error(msg) return resultVector try: unitaryComputerSystem = discoverEsxInventory(ipAddress, credentialsId, esxBiosUuid, Framework) inventoryResultVector = reportEsxInventory(unitaryComputerSystem, esxCmdbId) resultVector.addAll(inventoryResultVector) virtualMachines = discoverEsxVirtualTopology(ipAddress, credentialsId, esxBiosUuid, Framework) if virtualMachines: virtualResultVector = reportVirtualTopology(virtualMachines, hypervisorCmdbId) resultVector.addAll(virtualResultVector) except JException, ex: msg = ex.getMessage() msg = cim_discover.translateErrorMessage(msg) logger.debug(msg) errormessages.resolveAndReport(msg, cim.Protocol.DISPLAY, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None protocol = Framework.getDestinationAttribute('Protocol') switchId = Framework.getDestinationAttribute('hostId') print "Switch id %s" % switchId errorMessage = None try: client = Framework.createClient() try: shellFactory = shellutils.ShellFactory() shell = shellFactory.createShell(client) switchOsh = modeling.createOshByCmdbId('switch', switchId) discoverer = NexusDiscoverer(Framework, shell, '', '', '', '') discoverer.discoverInterfacesAndIps() interfaces_dict = discoverer.hostDataObject.interfaces ports_map = parsePorts(interfaces_dict.values()) vlan_discoverer = layer2_shell_discoverer.VlanDiscoverer(shell) vlans = vlan_discoverer.discoverVlans() layer2_discoverer = layer2_shell_discoverer.Layer2Discoverer(shell) remote_peers_map = layer2_discoverer.discover() OSHVResult.addAll(layer2.reportTopology(switchOsh, interfaces_dict, vlans, remote_peers_map, ports_map)) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: errorMessage = ex.getMessage()
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ipAddress = Framework.getDestinationAttribute('ip_address') credentialsId = Framework.getDestinationAttribute('credentialsId') hostId = Framework.getDestinationAttribute('hostId') hostOsh = modeling.createOshByCmdbIdString('host', hostId) PROTOCOL_NAME = 'PowerShell' try: client = Framework.createClient() shell =shellutils.ShellUtils(client) discoverer = None try: for discovererClass in [msexchange_win_shell.Exchange2007Discoverer, msexchange_win_shell.Exchange2010Discoverer]: try: discoverer = discovererClass(shell) exchangeServers = discoverer.discover() for exchangeServer in exchangeServers: topoBuilder = msexchange.TopologyBuilder(exchangeServer, hostOsh, ipAddress, credentialsId) OSHVResult.addAll(topoBuilder.build()) break except msexchange_win_shell.AddSnapInException: logger.warn('Failed to import Snap-In.') discoverer = None if not discoverer: raise Exception("Failed to discover MS-Exchange. See Logs for details.") finally: shell.closeClient() except JavaException, ex: logger.debugException('') strException = str(ex.getMessage()) errormessages.resolveAndReport(strException, PROTOCOL_NAME, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() # # Write implementation to return new result CIs here... ipList = Framework.getTriggerCIDataAsList('PHYSICAL_IP_ADDRESS') portList = Framework.getTriggerCIDataAsList('PHYSICAL_PORT') service_context = Framework.getDestinationAttribute('SERVICE_CONTEXT') service_type = Framework.getDestinationAttribute('SERVICE_TYPE') application_resource_id = Framework.getDestinationAttribute('APPLICATION_RESOURCE_ID') application_resource_class = Framework.getDestinationAttribute('APPLICATION_RESOURCE_CLASS') junction_id = Framework.getDestinationAttribute('JUNCTION_ID') junction_root_class = Framework.getDestinationAttribute('JUNCTION_CLASS') junction_name = Framework.getDestinationAttribute('JUNCTION_NAME') SCPId = Framework.getDestinationAttribute('id') junctionOsh = modeling.createOshByCmdbIdString(junction_root_class, junction_id) url = urlparse(service_context) if url: # get context root path from url path = url.path if path.startswith(junction_name + '/'): logger.info('Create one consumer-provider link between application and junction') OSHVResult.addAll(scp.createCPLink(application_resource_id, application_resource_class, junction_id, junction_root_class, SCPId, service_context)) for index in range(len(ipList)): scpOsh = scp.createScpOsh(junctionOsh, service_type, ip=ipList[index], port=portList[index], context=service_context) logger.info('Create scp with ip %s and port %s' % (ipList[index], portList[index])) ipOsh = modeling.createIpOSH(ipList[index]) OSHVResult.add(scpOsh) OSHVResult.add(ipOsh) return OSHVResult
def _discoverDatabase(client, baseTopology): r'@types: BaseSapJmxClient, BaseTopology -> oshv' logger.info("Discover DB information") vector = ObjectStateHolderVector() try: dbInfo = _getDatabase(client) except (Exception, JException): logger.warnException("Failed to get DB info using new MBean model") else: if dbInfo: try: logger.info("Resolve DB address: ", dbInfo.hostname) dnsResolver = netutils.JavaDnsResolver() ips = dnsResolver.resolveIpsByHostname(dbInfo.hostname) hostReporter = sap.HostReporter(sap.HostBuilder()) hostOsh, hVector = hostReporter.reportHostWithIps(*ips) vector.addAll(hVector) hVector.clear() except netutils.ResolveException: logger.warn("DB won't be reported as DB addr is not resolved") else: try: logger.info("Discovered: ", dbInfo) systemOsh = baseTopology.systemOsh vector.addAll(sap_db.report_db_info(dbInfo, systemOsh, hostOsh)) except ValueError, ve: logger.warn("%s: %s" % (ve, dbInfo.type))
def processData(ipMap, ndMap, ifMap, nwMap, l2Map, vlMap, ptMap, cdMap, hostIpMap, hostIfMap, connectionIfMap, discoverNonL2Devices, Framework): _vector = ObjectStateHolderVector() ifOshMap = {} portOshMap = {} cardOshMap = {} hostOSH = None for (hostId, hostObj) in ndMap.items(): if hostIpMap.has_key(hostId): ipList = hostIpMap[hostId] if len(ipList) > 0: # if IPs available create host with the first IP hostOSH = createHost(discoverNonL2Devices, hostId, ndMap, '', ipMap[ipList[0]].ipValue) if notNull(hostOSH): _vector.add(hostOSH) # create IP CIs _vector = processIpsAndSubnets(_vector, hostIpMap, hostId, ipMap, nwMap, hostOSH) ## create interfaces (_vector, ifOshMap) = processInterfaces(_vector, ifOshMap, hostIfMap, hostId, ifMap, hostOSH) ## create hardware boards (_vector, cardOshMap) = processCards(_vector, cardOshMap, cdMap, hostOSH, hostId) ## create ports (_vector, portOshMap) = processPorts(_vector, portOshMap, ptMap, ifOshMap, cardOshMap, hostOSH, hostId) # add l2 connection objects _vector.addAll(createL2ConnectionOshv(connectionIfMap, ifOshMap)) # add vlan objects _vector.addAll(createVlanOshv(vlMap, portOshMap, Framework)) return _vector
def DiscoveryMain(Framework): debugPrint('[DiscoveryMain] Starting...') # General variables OSHVResult = ObjectStateHolderVector() protocolName = 'SQL' sqlClient = None # We need dictionaries for each OSH type since results of # SQL queries will contain multiple rows with the same info datacenterOshDict = {} # Use building name as key rackOshDict = {} # Use rack+building name as key pduOshDict = {} # Use PDU+building name as key rppOshDict = {} # Use RPP+building name as key hostOshDict = {} # Use serial number as key try: # JDBC client sqlClient = Framework.createClient() # Discover... OSHVResult.addAll(getDevices(Framework, sqlClient, datacenterOshDict, rackOshDict, pduOshDict, rppOshDict, hostOshDict)) OSHVResult.addAll(getPowerRoutes(Framework, sqlClient, datacenterOshDict, rackOshDict, pduOshDict, rppOshDict, hostOshDict)) except Exception, ex: strException = str(ex.getMessage()) errormessages.resolveAndReport(strException, protocolName, Framework)
def decorator(framework): vector = ObjectStateHolderVector() framework = RichFramework(framework) creds_manager = CredsManager(framework) creds = creds_manager.get_creds_for_destination(proto_name) creds = filter(Fn(is_cred_ok_fn, framework, creds_manager, __), creds) if not creds: logger.reportErrorObject(_create_missed_creds_error(proto_name)) else: connection_exs = [] discovery_exs = [] warnings = [] at_least_once_discovered = False for cred_id in creds: try: oshs, warnings = main_fn(framework, creds_manager, cred_id) vector.addAll(oshs) at_least_once_discovered = True if stop_on_first: break except ConnectionException, ce: logger.debugException(str(ce)) connection_exs.append(ce) except (DiscoveryException, Exception, JException), de: logger.debugException(str(de)) discovery_exs.append(de)
def buildHosts(self): for host in self.hosts.values(): hostOSHV = ObjectStateHolderVector() hostOsh, hostVector = host.buildOshAndIps() hostOSHV.addAll(hostVector) hbaIdToOsh = {} for hba in host.hbas.values(): hbaOsh = hba.build() hbaOsh.setContainer(hostOsh) hbaIdToOsh[hba.hbaId] = hbaOsh self.addWwnOsh(hba.wwn, hbaOsh) hostOSHV.add(hbaOsh) for port in host.ports.values(): portOsh = port.build() portOsh.setContainer(hostOsh) self.portIdToOsh[port.portId] = portOsh if port.nodeId and port.nodeId in hbaIdToOsh.keys(): containmentLinkOsh = modeling.createLinkOSH('containment', hbaIdToOsh[port.nodeId], portOsh) hostOSHV.add(containmentLinkOsh) hostOSHV.add(portOsh) self.addWwnOsh(port.wwn, portOsh) for path in host.paths.values(): localVolumeOsh = self.storageArrays[self.volumeIdToStorageId[path.volumeId]].volumes[path.volumeId].build() localVolumeOsh.setContainer(hostOsh) dependencyLink = modeling.createLinkOSH('dependency', localVolumeOsh, self.volumeIdToOsh[path.volumeId]) hostOSHV.add(dependencyLink) hostOSHV.add(localVolumeOsh) hostOSHV.add(self.volumeIdToOsh[path.volumeId]) self.framework.sendObjects(hostOSHV) self.framework.flushObjects()
def buildSwitches(self): for switch in self.switches.values(): switchOSHV = ObjectStateHolderVector() switchOsh, switchVector = switch.buildOshAndIps() switchOSHV.addAll(switchVector) hbaIdToOsh = {} for hba in switch.fcHBAs.values(): hbaOsh = hba.build() hbaOsh.setContainer(switchOsh) hbaIdToOsh[hba.hbaId] = hbaOsh self.addWwnOsh(hba.wwn, hbaOsh) switchOSHV.add(hbaOsh) for port in switch.fcPorts.values(): portOsh = port.build() portOsh.setContainer(switchOsh) self.portIdToOsh[port.portId] = portOsh if port.nodeId and port.nodeId in hbaIdToOsh.keys(): containmentLinkOsh = modeling.createLinkOSH('containment', hbaIdToOsh[port.nodeId], portOsh) self.OSHVResult.add(containmentLinkOsh) self.addWwnOsh(port.wwn, portOsh) switchOSHV.add(portOsh) if not (str(switch.fabricId) == str(-1)): fabricMembership = modeling.createLinkOSH('membership', self.fabrics[switch.fabricId].build(), switchOsh) switchOSHV.add(fabricMembership) self.framework.sendObjects(switchOSHV) self.framework.flushObjects()
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() jobId = Framework.getDiscoveryJobId() host_id = Framework.getDestinationAttribute('id') host_name = Framework.getTriggerCIData('host_name') dnsServers = Framework.getTriggerCIDataAsList('dnsServers') or None try: host_name = host_name.split(" ") ips = pi_utils.getIPs(host_name[0], Framework) if not ips: raise ValueError() hostOSH = modeling.createOshByCmdbIdString('node', host_id) modeling.addHostAttributes(hostOSH, None, host_name[0]) #OSHVResult.add(hostOSH) for ip in ips: ipRes = pi_utils.getIPOSHV(Framework, ip, None, dnsServers, False, True) if ipRes.size() > 0: OSHVResult.add( modeling.createLinkOSH('containment', hostOSH, modeling.createIpOSH(ip))) OSHVResult.addAll(ipRes) if OSHVResult.size() <= 0: raise ValueError() except Exception, e: msg = logger.prepareJythonStackTrace( "Error getting IPs for %s: " % (host_name), e) errormessages.resolveAndReport(msg, jobId, Framework) logger.error(msg)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() try: client = Framework.createClient() vendor = Framework.getDestinationAttribute("discovered_vendor") hostId = Framework.getDestinationAttribute("hostId") host_osh = modeling.createOshByCmdbId("firewall", hostId) discoverer = firewall_discoverer.getDiscoverer(vendor, client) if not discoverer: raise ValueError("Unsupported device.") firewall_config = discoverer.discover() OSHVResult.addAll(firewall.reportTopology(firewall_config, host_osh)) except: import sys logger.debugException("") error_str = str(sys.exc_info()[1]).strip() logger.reportError(error_str) finally: client and client.close() ## Write implementation to return new result CIs here... if OSHVResult.size() == 0: logger.debug("No data discovered from destination.") logger.reportWarning("No data discovered from destination.") return OSHVResult
def reportDatabaseTopology(self, dsnInfo, dependentObject): """ :param dsnInfo: list of all DSN's for which need to report topology :type dsnInfo: odbc.DSNInfo :return: vector which include all osh's for created topology :rtype: appilog.common.system.types.vectors.ObjectStateHolderVector """ vector = ObjectStateHolderVector() try: database_pdo = self.__builder.buildDatabaseServerPdo(dsnInfo) platform = db_platform.findPlatformBySignature(dsnInfo.driver) builder = db_builder.getBuilderByPlatform(platform) db_reporter = db.getReporter(platform, builder) host_descriptor = self.__builder.buildHostDescriptor(dsnInfo.address) host_descriptor = host_descriptor._replace(name=None) reporter = host_topology.Reporter() host_osh, ip_oshs, oshs = reporter.report_host(host_descriptor) server_osh, ipseOsh, database_oshs, topology = db_reporter.reportServerWithDatabases(database_pdo, host_osh, [dependentObject]) vector.addAll(topology) vector.addAll(oshs) return vector except dns_resolver.ResolveException: logger.reportWarning("Cannot resolve ip of node") return ObjectStateHolderVector()
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() # # Write implementation to return new result CIs here... ipList = Framework.getTriggerCIDataAsList('PHYSICAL_IP_ADDRESS') portList = Framework.getTriggerCIDataAsList('PHYSICAL_PORT') service_context = Framework.getDestinationAttribute('SERVICE_CONTEXT') service_type = Framework.getDestinationAttribute('SERVICE_TYPE') cluster_id = Framework.getDestinationAttribute('CLUSTER_ID') application_resource_id = Framework.getDestinationAttribute('APPLICATION_RESOURCE_ID') cluster_root_class = Framework.getDestinationAttribute('CLUSTER_CLASS') application_resource_class = Framework.getDestinationAttribute('APPLICATION_RESOURCE_CLASS') SCPId = Framework.getDestinationAttribute('id') clusterOsh = modeling.createOshByCmdbIdString(cluster_root_class, cluster_id) OSHVResult.addAll(scp.createCPLink(application_resource_id, application_resource_class, cluster_id, cluster_root_class, SCPId, service_context)) for index in range(len(ipList)): scpOsh = scp.createScpOsh(clusterOsh, service_type, ip=ipList[index], port=portList[index], context=service_context) ipOsh = modeling.createIpOSH(ipList[index]) OSHVResult.add(scpOsh) OSHVResult.add(ipOsh) return OSHVResult
def disGenericUNIX(hostCmdbId, shell): 'str, UnixShell -> OSH vector' logger.debug('Discover users') myVec = ObjectStateHolderVector() r = shell.safecat('/etc/passwd') if r == None: return myVec lines = '' if (re.search('\r\n', r)): lines = r.split('\r\n') elif (re.search('\n', r)): lines = r.split('\n') else: return myVec for line in lines: if (re.match('#', line)): continue token = line.split(':') if (len(token) == 7): myVec.addAll( makeUserOSH(hostCmdbId, token[0], token[4], token[2], token[3], token[5])) return myVec
def reportInstances(instances, sys_, sysOsh, get_inst_creds=None, connectionClientNr=None): r'''@types: list[InstanceInfo], System, osh, callable, str -> dict, oshv @type get_inst_creds: (InstanceInfo, list[_BaseIP] -> str?) @param get_inst_creds: function to get credentials for the specified instance ''' vector = ObjectStateHolderVector() #resolve IP for instance host dnsResolver = dns_resolver.SocketDnsResolver() resolveAddressToIps = fptools.partiallyApply(_resolveInstanceAddressToIps, fptools._, dnsResolver) ipsOfInstances = map(resolveAddressToIps, instances) # report instances oshPerInstance = {} hasIps = second for instInfo, ips in filter(hasIps, zip(instances, ipsOfInstances)): serverOsh, iVector = reportInstanceWithSystem(instInfo, ips, sys_, sysOsh, connectionClientNr) vector.addAll(iVector) oshPerInstance[instInfo.instance] = serverOsh return oshPerInstance, vector
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip = Framework.getDestinationAttribute('ip_address') domain = Framework.getDestinationAttribute('ip_domain') host_id = Framework.getDestinationAttribute('hostId') errorsList = [] protocol = "ldap" credential_ids = Framework.getAvailableProtocols(ip, protocol) lastConnectedCredential = Framework.loadState() lastConnectedCredential and credential_ids.append(lastConnectedCredential) if not credential_ids: msg = errormessages.makeErrorMessage('webseal', pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, ['webseal'], msg) errorsList.append(errobj) client = Framework.createClient() credential_id = find_valid_credential(credential_ids, client, Framework) if credential_id: Framework.saveState(credential_id) OSHVResult.addAll(reportWebSeal(host_id, credential_id)) else: Framework.clearState() msg = errormessages.makeErrorMessage('Shell', pattern=errormessages.ERROR_FAILED_TO_CONNECT_TO_SERVER) errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, ['webseal'], msg) errorsList.append(errobj) for errobj in errorsList: logger.reportErrorObject(errobj) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() # # Write implementation to return new result CIs here... ipList = Framework.getTriggerCIDataAsList('PHYSICAL_IP_ADDRESS') portList = Framework.getTriggerCIDataAsList('PHYSICAL_PORT') service_context = Framework.getDestinationAttribute('SERVICE_CONTEXT') service_type = Framework.getDestinationAttribute('SERVICE_TYPE') cluster_id = Framework.getDestinationAttribute('CLUSTER_ID') application_resource_id = Framework.getDestinationAttribute( 'APPLICATION_RESOURCE_ID') cluster_root_class = Framework.getDestinationAttribute('CLUSTER_CLASS') application_resource_class = Framework.getDestinationAttribute( 'APPLICATION_RESOURCE_CLASS') SCPId = Framework.getDestinationAttribute('id') clusterOsh = modeling.createOshByCmdbIdString(cluster_root_class, cluster_id) OSHVResult.addAll( scp.createCPLink(application_resource_id, application_resource_class, cluster_id, cluster_root_class, SCPId, service_context)) for index in range(len(ipList)): scpOsh = scp.createScpOsh(clusterOsh, service_type, ip=ipList[index], port=portList[index], context=service_context) ipOsh = modeling.createIpOSH(ipList[index]) OSHVResult.add(scpOsh) OSHVResult.add(ipOsh) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() logger.info('Starting HACMP Applications') hostIP = Framework.getDestinationAttribute('ip_address') logger.debug ('Host IP: ',hostIP) cluster = Framework.getDestinationAttribute('cluster') hostOS = Framework.getDestinationAttribute('host_os') hostOS = hostOS or 'NA' protocolName = Framework.getDestinationAttribute('Protocol') hostId = Framework.getDestinationAttribute('hostId') ## Get Parameter Section cldisp_command = Framework.getParameter('cldisp_command') or 'cldisp' cllsif_command = Framework.getParameter('cllsif_command') or 'cllsif' try: client = Framework.createClient() shell = ShellUtils(client) # If we get good client connection , run the client commands to get the Application information for the cluster HostOSH = modeling.createOshByCmdbIdString('host', hostId) ClusterOSH = getclusterOSH(cluster) appDictionary = getapplicationInfo(shell, cldisp_command, Framework) resourceDictionary = getresourceinfo(shell, cllsif_command) OSHVResult.addAll(createserviceapplicationOSH (shell, appDictionary, resourceDictionary, HostOSH, ClusterOSH, Framework)) client.close() except JavaException, ex: strException = ex.getMessage() logger.debugException('') errormessages.resolveAndReport(strException, protocolName, Framework)
def DiscoveryMain(framework): vector = ObjectStateHolderVector() protocol = framework.getDestinationAttribute('Protocol') try: client = framework.createClient() shell = None try: shell = shellutils.ShellUtils(client) dnsDiscoverer = dns_discoverer.createDiscovererByShell(shell) params = _obtainParams(framework) zoneNameList, includeOutscopeIPs, reportBrokenAliases = params zoneTopologies = dns_discoverer.discoverDnsZoneTopologies( dnsDiscoverer, zoneNameList, protocol) vector.addAll( dns_discoverer.reportTopologies(zoneTopologies, includeOutscopeIPs, reportBrokenAliases)) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, framework)
def report_tree(framework, business_object_node, parent_osh): vector = ObjectStateHolderVector() current_osh = business_object_node.create_osh(parent_osh) vector.add(current_osh) for node in business_object_node.get_children(): vector.addAll(report_tree(framework, node, current_osh)) return vector
def reportServerWithDatabases(self, dbServer, container, dependants=None): r""" Report database server with specified container used databases and service end-points @types: db.DatabaseServer, ObjectStateHolder, seq[ObjectStateHolder] -> ObjectStateHolderVector""" if not dbServer: raise ValueError("Database Server is not specified") if not container: raise ValueError("Container for database server is not specified") vector = ObjectStateHolderVector() server_osh = self.reportServer(dbServer, container) vector.add(server_osh) database_oshs = [] for database in dbServer.getDatabases(): database_oshs = list(self.reportDatabase(dbServer, database)) vector.addAll(database_oshs) ipseOsh = None if dbServer.address and dbServer.getPort(): ipseOsh, vector_ = self.reportServerIpServiceEndpoint( dbServer.address, dbServer.getPort(), server_osh, container ) vector.addAll(vector_) for slave in dependants or (): for master in database_oshs or (server_osh,): link = modeling.createLinkOSH("dependency", slave, master) vector.add(link) return server_osh, ipseOsh, database_oshs, list(vector)
def discoverTopology(sapUtils, domain, hostname, connInfo): r'''@types: SapUtils, str, str, ConnectionInfo -> oshv, list[str]''' warnings = [] vector = ObjectStateHolderVector() system_name = getSapSystemName(sapUtils) if system_name: system = sap.System(system_name) isSolMan, tmsDomain, instances = consume(warnings, _discoverIsSolutionManager(sapUtils), _discoverTmsDomain(sapUtils), (_discoverInstances(sapUtils, system.getName()) or ())) # find an instance with ip we are connected to connected_instance = find_instance_with_ip(instances, ip_addr.IPAddress(connInfo.ip)) if connected_instance: logger.info("We have connected to instance %s, adding credentials" % str(connected_instance)) # report currently connected instance system_osh = _reportSystem(sapUtils, system, domain, isSolMan, tmsDomain) connected_osh, additional_vector = sap_abap_discoverer.reportInstanceWithSystem(connected_instance, [ip_addr.IPAddress(connInfo.ip)], system, system_osh, application_ip=ip_addr.IPAddress(connInfo.ip), cred_id=connInfo.credsId) # report all instances vector = second(reportInstances(instances, system, system_osh)) vector.addAll(additional_vector) vector.add(connected_osh) vector.add(system_osh) else: warnings.append('Failed to find destination ip among configured server ips. ' 'No Topology will be reported.') else: warnings.append('Failed to find configured servers. ' 'No Topology will be reported.') return vector, warnings
def disWinOS(host_obj, shell, Framework, langBund, softNameToInstSoftOSH=None): host = modeling.createOshByCmdbIdString("host", host_obj) resultsVector = ObjectStateHolderVector() if not NTCMD_HR_REG_Software_Lib.doSoftware(shell, host, resultsVector, softNameToInstSoftOSH): discoverSoftwareByWmic(shell, host, resultsVector, softNameToInstSoftOSH) wmiProvider = getWmiProvider(shell) hostDiscoverer = WmiHostDiscoverer(wmiProvider) if hostDiscoverer.isWin2008(): softwares = discover2008Hotfixes(wmiProvider, host) for software in softwares: if not software.osh: continue if softNameToInstSoftOSH is not None: if software.name in softNameToInstSoftOSH: continue softNameToInstSoftOSH[software.name] = software.osh resultsVector.add(software.osh) elif hostDiscoverer.isWindows8_2012(): softwares = discover2012Hotfixes(wmiProvider, host) for software in softwares: if not software.osh: continue if softNameToInstSoftOSH is not None: if software.name in softNameToInstSoftOSH: continue softNameToInstSoftOSH[software.name] = software.osh resultsVector.add(software.osh) softwareList = WindowsAppsDiscoverer(shell).discover() softwareOshVector = InstalledSoftwareReporter().reportAll(softwareList, host) resultsVector.addAll(softwareOshVector) return resultsVector
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None protocol = Framework.getDestinationAttribute("Protocol") switchId = Framework.getDestinationAttribute("hostId") print "Switch id %s" % switchId errorMessage = None try: client = Framework.createClient() try: shellFactory = shellutils.ShellFactory() shell = shellFactory.createShell(client) switchOsh = modeling.createOshByCmdbId("switch", switchId) discoverer = NexusDiscoverer(Framework, shell, "", "", "", "") discoverer.discoverInterfacesAndIps() interfaces_dict = discoverer.hostDataObject.interfaces ports_map = parsePorts(interfaces_dict.values()) vlan_discoverer = layer2_shell_discoverer.VlanDiscoverer(shell) vlans = vlan_discoverer.discoverVlans() layer2_discoverer = layer2_shell_discoverer.Layer2Discoverer(shell) remote_peers_map = layer2_discoverer.discover() OSHVResult.addAll(layer2.reportTopology(switchOsh, interfaces_dict, vlans, remote_peers_map, ports_map)) finally: try: shell and shell.closeClient() except: logger.debugException("") logger.error("Unable to close shell") except JException, ex: errorMessage = ex.getMessage()
def DiscoveryMain(Framework): warningsList = [] errorsList = [] oshvector = ObjectStateHolderVector() errobj = errorobject.INTERNAL_ERROR client = None ip_address = Framework.getDestinationAttribute('ip_address') ip_domain = Framework.getDestinationAttribute('ip_domain') credentials = netutils.getAvailableProtocols(Framework, protocolName, ip_address, ip_domain) if len(credentials) == 0: msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg) warningsList.append(errobj) logger.debug(msg) else: try: logger.info('Starting AS400 Connection.') for credential in credentials: client = Framework.createClient(credential) dicoverer = AS400Dicoverer(client) dicoverer.discover() oshvector.addAll(dicoverer.buildTopology()) except NoClassDefFoundError, error: # Trying to catch if as400 java package is not found msg = error.getMessage() if re.search("as400", msg, re.I): processException(errorsList,warningsList,"Third party library is not found. Please read the documentation about prerequisites for this job.") else: processException(errorsList,warningsList, msg) except:
def doDiscovery(Framework, shell, ip, credentialId, codepage, shellName, warningsList, errorsList, uduid = None): vector = ObjectStateHolderVector() try: try: languageName = shell.osLanguage.bundlePostfix langBund = Framework.getEnvironmentInformation().getBundle('langNetwork', languageName) remoteHostnames = dns_resolver.NsLookupDnsResolver(shell).resolve_hostnames(ip) remoteHostFqdn = None if remoteHostnames: remoteHostFqdn = remoteHostnames[0] shellObj = createShellObj(shell, ip, langBund, languageName, codepage, remoteHostFqdn) try: vector.addAll(discover(shell, shellObj, ip, langBund, Framework, uduid)) finally: # create shell OSH if connection established if shellObj and not vector.size(): hostOsh = modeling.createHostOSH(ip) shellObj.setContainer(hostOsh) vector.add(shellObj) except Exception, ex: strException = ex.getMessage() errormessages.resolveAndAddToObjectsCollections(strException, shellName, warningsList, errorsList) except: msg = str(sys.exc_info()[1]) logger.debugException('') errormessages.resolveAndAddToObjectsCollections(msg, shellName, warningsList, errorsList)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() jobId = Framework.getDiscoveryJobId() host_id = Framework.getDestinationAttribute('id') host_name = Framework.getTriggerCIData('host_name') dnsServers = Framework.getTriggerCIDataAsList('dnsServers') or None try: host_name = host_name.split(" ") ips = pi_utils.getIPs(host_name[0], Framework) if not ips: raise ValueError() hostOSH = modeling.createOshByCmdbIdString('node', host_id) modeling.addHostAttributes(hostOSH, None, host_name[0]) #OSHVResult.add(hostOSH) for ip in ips: ipRes = pi_utils.getIPOSHV(Framework, ip, None, dnsServers, False, True) if ipRes.size() > 0: OSHVResult.add(modeling.createLinkOSH('containment',hostOSH,modeling.createIpOSH(ip))) OSHVResult.addAll(ipRes) if OSHVResult.size() <=0: raise ValueError() except Exception, e: msg = logger.prepareJythonStackTrace("Error getting IPs for %s: " % (host_name), e) errormessages.resolveAndReport(msg, jobId, Framework) logger.error(msg)
def reportConnectedEsxTopology(context, unitaryComputerSystem): ''' UnitaryComputersystem -> OSHVector ''' resultVector = ObjectStateHolderVector() unitaryComputerSystemReporter = vmware_cim_report.UnitaryComputerSystemReporter( ) resultVector.addAll( unitaryComputerSystemReporter.reportConnectionTopology( unitaryComputerSystem, context.ipAddress)) esxOsh = unitaryComputerSystem.getOsh( vmware_cim_report.UnitaryComputerSystemReporter.UCS_KEY_HOST) if esxOsh is None: raise ValueError("ESX OSH cannot be found") cimOsh = cim.createCimOsh(context.ipAddress, esxOsh, context.credentialId, vmware_cim_discover.CimCategory.VMWARE) resultVector.add(cimOsh) ipAddressOsh = modeling.createIpOSH(context.ipAddress) resultVector.add(ipAddressOsh) containmentLink = modeling.createLinkOSH('containment', esxOsh, ipAddressOsh) resultVector.add(containmentLink) return resultVector
def getSubnets(neutronApi, regionName, networkOshDict, openstack_osh): vector = ObjectStateHolderVector() subnet_discover = openstack_discoverer.SubnetDiscoverer(neutronApi, regionName) subnets = subnet_discover.discover() for subnet in subnets: vector.addAll(subnet.report(networkOshDict, openstack_osh)) return vector
def getPorts(neutronApi, regionName, serverOshDict, networkOshDict): vector = ObjectStateHolderVector() port_discover = openstack_discoverer.InterfaceDiscoverer(neutronApi, regionName) interfaces = port_discover.discover() for interface in interfaces: vector.addAll(interface.report(serverOshDict, networkOshDict)) return vector
def getVolumes(cinderApi, regionName, region_osh, zoneOshDict, serverOshDict): vector = ObjectStateHolderVector() volume_discoverer = openstack_discoverer.VolumeDiscoverer(cinderApi, regionName) volumes = volume_discoverer.discover() for volume in volumes: vector.addAll(volume.report(region_osh, zoneOshDict, serverOshDict)) return vector
def reportRemotePeer(remote_peer, localInterfaceOsh, local_mac): vector = ObjectStateHolderVector() if remote_peer.peer_ips: hostOsh = modeling.createHostOSH(str(remote_peer.peer_ips[0])) if remote_peer.platform in VIRTUAL_HOST_PLATFORMS: hostOsh.setBoolAttribute('host_isvirtual', 1) vector.add(hostOsh) for ip in remote_peer.peer_ips: ipOsh = modeling.createIpOSH(ip) linkOsh = modeling.createLinkOSH('containment', hostOsh, ipOsh) vector.add(ipOsh) vector.add(linkOsh) else: hostOsh = ObjectStateHolder('node') hostOsh.setBoolAttribute('host_iscomplete', 1) hostOsh.setStringAttribute('name', remote_peer.system_name) if remote_peer.platform in VIRTUAL_HOST_PLATFORMS: hostOsh.setBoolAttribute('host_isvirtual', 1) vector.add(hostOsh) if remote_peer.interface_name or remote_peer.interface_mac: remoteInterfaceOsh = modeling.createInterfaceOSH(mac = remote_peer.interface_mac, hostOSH = hostOsh, name = remote_peer.interface_name) if not remoteInterfaceOsh: return ObjectStateHolderVector() if remote_peer.interface_name: remoteInterfaceOsh.setStringAttribute('name', remote_peer.interface_name) vector.add(remoteInterfaceOsh) l2id = str(hash(':'.join([remote_peer.interface_mac or remote_peer.interface_name, local_mac]))) vector.addAll(reportLayer2Connection(localInterfaceOsh, remoteInterfaceOsh, l2id)) return vector
def iterate_over_args(main_fn, framework, cred_args, proto_name, stop_on_first): ''' @param cred_args: parameters you decided to iterate over ''' vector = ObjectStateHolderVector() framework = flow.RichFramework(framework) creds_manager = flow.CredsManager(framework) # as cred_args possibly generator or iterator, realize only first first_ = first(cred_args) if first_ is None: logger.reportErrorObject(flow._create_missed_creds_error(proto_name)) else: # restore cred_args cred_args = chain((first_,), cred_args) connection_exs = [] discovery_exs = [] warnings = [] at_least_once_discovered = False for args in cred_args: try: oshs, warnings_ = main_fn(framework, creds_manager, *args) warnings.extend(warnings_ or ()) vector.addAll(oshs) at_least_once_discovered = True if stop_on_first: break except flow.ConnectionException, ce: logger.debugException(str(ce)) connection_exs.append(ce) except (flow.DiscoveryException, Exception, JException), de: logger.debugException(str(de)) discovery_exs.append(de)
def decorator(framework): vector = ObjectStateHolderVector() framework = RichFramework(framework) creds_manager = CredsManager(framework) creds = creds_manager.get_creds_for_destination(proto_name) creds = filter(Fn(is_cred_ok_fn, framework, creds_manager, __), creds) if not creds: logger.reportErrorObject(_create_missed_creds_error(proto_name)) else: connection_exs = [] discovery_exs = [] warnings = [] at_least_once_discovered = False for cred_id in creds: try: oshs, warnings = main_fn(framework, creds_manager, cred_id) vector.addAll(oshs) at_least_once_discovered = True if stop_on_first: break except ConnectionException, ce: logger.debugException(str(ce)) connection_exs.append(ce) except (DiscoveryException, Exception, JException), de: logger.debugException(str(de)) discovery_exs.append(de)
def getIMSPrograms(ls, IMSSubSysDict ): vector = ObjectStateHolderVector() # Query the mainframe for IMS Programs for subsystem in IMSSubSysDict.keys(): (sub,prefix,subsystemOSH) = IMSSubSysDict[subsystem] command = concatenate(prefix,_DSP_IMS_TRN_ALL ) output = ls.evExecImsCommand(subsystem, command) if output.isSuccess() and len(output.cmdResponseList) > 0: firstlinelist = [] for line in output.cmdResponseList: if (re.search('TRAN\s+CLS', line) or re.search('IEE600I', line) or re.search('DFS996I', line) or re.search('DFS4444I', line) or re.search('\*\d+\/\d+\*', line)): continue m = re.search('DFS000I',line) if m: #logger.debug (' Non SSI Parsing ') SSIflag = 0 #logger.debug (line) if re.search('PSBNAME:', line): secondlinelist = line.split() programname = secondlinelist[2] vector.addAll (createProgramTransactionOsh(firstlinelist, programname,SSIflag, subsystemOSH)) else: firstlinelist = line.split() else: #logger.debug (' SSI Parsing ') SSIflag = 1 #logger.debug (line) if re.search('PSBNAME:', line): secondlinelist = line.split() programname = secondlinelist[1] vector.addAll (createProgramTransactionOsh(firstlinelist, programname, SSIflag, subsystemOSH)) else: firstlinelist = line.split() return vector
def reportInstanceInfo(instInfo, ips, system, credsId=None, connectionClientNr=None, application_ip=None, system_osh=None): r'@types: InstanceInfo, list[ip_addr._BaseIP, System, str, str -> tuple[ObjectStateHolder, ObjectStateHolderVector]' vector = ObjectStateHolderVector() hostReporter = sap.HostReporter(sap.HostBuilder()) ascsReporter = sap_abap.InstanceReporter(sap_abap.AscsInstanceBuilder()) instReporter = sap_abap.InstanceReporter(sap_abap.InstanceBuilder()) # report host of instInfo hostOsh, iVector = hostReporter.reportHostWithIps(*ips) vector.addAll(iVector) # report SAP system if system_osh: system_osh.setStringAttribute( 'data_note', 'This SAP System link to ' + hostOsh.getAttributeValue('host_key')) vector.add(system_osh) # report r3 server on host applicationIp = application_ip isScs = sap_abap.isCentralServicesInstance(instInfo.instance) serverOsh = None if isScs: pdo = sap_abap.AscsInstanceBuilder.createPdo( instInfo.instance, system, homeDirPath=instInfo.homeDirPath, codePage=instInfo.codePage, versionInfo=instInfo.versionInfo, startDate=instInfo.startDate, applicationIp=applicationIp, credId=credsId, connectionClientNr=connectionClientNr) serverOsh = ascsReporter.reportInstance(pdo, hostOsh) else: isCentral = None pdo = sap_abap.InstanceBuilder.createPdo( instInfo.instance, system, homeDirPath=instInfo.homeDirPath, dbLibraryInfo=instInfo.dbLibraryInfo, codePage=instInfo.codePage, numberOfProcesses=instInfo.numberOfProcesses, versionInfo=instInfo.versionInfo, startDate=instInfo.startDate, machineType=instInfo.host.machineType, osInfo=instInfo.host.osInfo, applicationIp=applicationIp, credId=credsId, connectionClientNr=connectionClientNr, isCentral=isCentral) serverOsh = instReporter.reportInstance(pdo, hostOsh) vector.add(serverOsh) return serverOsh, vector
def DiscoveryMain(framework): vector = ObjectStateHolderVector() if get_ipse_only_ips(framework): vector.addAll(triggered_on_ipse_only(framework)) if get_isam_with_ipse_case_ips(framework): vector.addAll(triggered_on_isam_with_https_ipse(framework)) return vector
def getSubnets(neutronApi, regionName, networkOshDict, openstack_osh): vector = ObjectStateHolderVector() subnet_discover = openstack_discoverer.SubnetDiscoverer( neutronApi, regionName) subnets = subnet_discover.discover() for subnet in subnets: vector.addAll(subnet.report(networkOshDict, openstack_osh)) return vector
def getVolumes(cinderApi, regionName, region_osh, zoneOshDict, serverOshDict): vector = ObjectStateHolderVector() volume_discoverer = openstack_discoverer.VolumeDiscoverer( cinderApi, regionName) volumes = volume_discoverer.discover() for volume in volumes: vector.addAll(volume.report(region_osh, zoneOshDict, serverOshDict)) return vector
def getPorts(neutronApi, regionName, serverOshDict, networkOshDict): vector = ObjectStateHolderVector() port_discover = openstack_discoverer.InterfaceDiscoverer( neutronApi, regionName) interfaces = port_discover.discover() for interface in interfaces: vector.addAll(interface.report(serverOshDict, networkOshDict)) return vector
def getFlavors(novaApi, regionName, region_osh): vector = ObjectStateHolderVector() flavor_discover = openstack_discoverer.FlavorDiscoverer( novaApi, regionName) flavors = flavor_discover.discover() for flavor in flavors: flavor_osh, flavor_vector = flavor.report(region_osh) vector.addAll(flavor_vector) return vector
def getVms(novaApi, regionName, region_osh, serverOshDict): vector = ObjectStateHolderVector() vm_discoverer = openstack_discoverer.VmDiscoverer(novaApi, regionName) vms = vm_discoverer.discover() for vm in vms: vm_osh, vm_vector = vm.report(region_osh) serverOshDict[vm.id] = vm_osh vector.addAll(vm_vector) return vector
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() DebugMode = Framework.getParameter('DebugMode') userExtDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder( ) + '\\' filePathDir = userExtDir + 'TQLExport\\ARIS\\results\\' directory = File(filePathDir) files = directory.listFiles() if files == None: logger.warn( 'Results XML not found. Perhaps no data was received from ARIS or an error occurred in the Pull_From_ARIS script.' ) return try: ## Start the work for file in files: if file != None or file != '': builder = SAXBuilder() doc = builder.build(file) # Process CIs # info( "Start processing CIs to update in the destination server..." ) allObjects = doc.getRootElement().getChild('data').getChild( 'objects').getChildren('Object') (objVector, ciDict) = processObjects(allObjects) OSHVResult.addAll(objVector) # Process Relations # info( "Start processing Relationships to update in the destination server..." ) allLinks = doc.getRootElement().getChild('data').getChild( 'links').getChildren('link') linkVector = processLinks(allLinks, ciDict) OSHVResult.addAll(linkVector) except: stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) info(concatenate('Failure: ():\n', stacktrace)) if (DebugMode != None): DebugMode = DebugMode.lower() if DebugMode == "true": mam_utils.info( '[NOTE] UCMDB Integration is running in DEBUG mode. No data will be pushed to the destination server.' ) print OSHVResult.toXmlString() return None else: #print OSHVResult.toXmlString() return OSHVResult
def reportTopology(switchOsh, interfaces_dict, vlans, remote_peers_map, ports_map): vector = ObjectStateHolderVector() vector.add(switchOsh) interfaceNameToInterfaceOshMap = {} for interfaceDo in interfaces_dict.values(): interfaceDo.build() interfaceOsh = interfaceDo.getOsh() interfaceOsh.setContainer(switchOsh) vector.add(interfaceOsh) interfaceNameToInterfaceOshMap[interfaceDo.getName()] = interfaceOsh portNameToPortOshMap = {} if ports_map: for (port_name, port) in ports_map.items(): portOsh = buidlPort(port, switchOsh) interfaceOsh = interfaceNameToInterfaceOshMap.get( sanitizePort(port_name)) if not (portOsh and interfaceOsh): continue vector.add(portOsh) linkOsh = modeling.createLinkOSH('realization', portOsh, interfaceOsh) vector.add(linkOsh) portNameToPortOshMap[port_name] = portOsh if remote_peers_map: for (interface_name, remote_peers) in remote_peers_map.items(): localInterfaceOsh = interfaceNameToInterfaceOshMap.get( interface_name) if not localInterfaceOsh: continue for remote_peer in remote_peers: vector.addAll( reportRemotePeer(remote_peer, localInterfaceOsh, interface_name)) if vlans: for vlan in vlans: vlanOsh = buildVlan(vlan, switchOsh) if not (vlan and vlanOsh): continue for port_name in vlan.ports: portOsh = portNameToPortOshMap.get(port_name) if not portOsh: continue portOsh.setStringAttribute('port_vlan', str(vlan.id)) linkOsh = modeling.createLinkOSH('membership', vlanOsh, portOsh) vector.add(vlanOsh) vector.add(linkOsh) return vector
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() localHostId = Framework.getDestinationAttribute('localHostId') remoteIds = Framework.getTriggerCIDataAsList('clusteredUcmdbIds') localSoftwareId = Framework.getDestinationAttribute('localSoftwareId') clusteredContainers = Framework.getTriggerCIDataAsList( 'clusteredContainer') softwareName = Framework.getDestinationAttribute('softwareName') className = Framework.getDestinationAttribute('className') discProdName = Framework.getDestinationAttribute('discProdName') productName = Framework.getDestinationAttribute('productName') ipServiceEndpointIds = Framework.getTriggerCIDataAsList( 'ipServiceEndpointIds') or [] for remoteIndex in xrange(len(remoteIds)): remoteId = remoteIds[remoteIndex] clusteredContainer = None try: clusteredContainer = clusteredContainers[remoteIndex] except: logger.debug('Clustered software is related to a single CRG') clusteredContainer = clusteredContainers[0] if not clusteredContainer: raise ValueError( 'Failed to detect Clustered Resource Group for Clustered Software' ) logger.debug('Working with remote Id %s and clustered Container %s' % (remoteId, clusteredContainer)) vector = ObjectStateHolderVector() softwareOsh = modeling.createOshByCmdbId(className, localSoftwareId) hostOsh = modeling.createOshByCmdbId('cluster_resource_group', clusteredContainer) softwareOsh.setContainer(hostOsh) softwareOsh.setStringAttribute('name', softwareName) if discProdName and discProdName != 'NA': softwareOsh.setStringAttribute('discovered_product_name', discProdName) if productName and productName != 'NA': softwareOsh.setStringAttribute('product_name', productName) for ipServiceEndpointId in ipServiceEndpointIds: logger.debug("ip service endpoint id:", ipServiceEndpointId) if not ipServiceEndpointId: continue iseOsh = modeling.createOshByCmdbId('ip_service_endpoint', ipServiceEndpointId) iseOsh.setContainer(hostOsh) vector.add(iseOsh) vector.add(hostOsh) vector.add(softwareOsh) OSHVResult.addAll(vector) return OSHVResult