def reportServerWithDatabases(self, hana_instance, container, dependants=None): r""" Report database server with specified container used databases and service end-points @types: db_buidler.HanaDb.InstancePdo, ObjectStateHolder, seq[ObjectStateHolder] -> ObjectStateHolderVector""" if not hana_instance: raise ValueError("Hana instance pdo is not specified") if not container: raise ValueError("Container for database server is not specified") oshs = [] server_osh = self._builder.buildDatabaseServerOsh(sid=hana_instance.instance) oshs.append(server_osh) ipseOsh = None instance_osh, oshs_ = self.report_database_instance(hana_instance, container) oshs.extend(oshs_) linkosh = modeling.createLinkOSH("membership", server_osh, instance_osh) oshs.append(linkosh) if hana_instance.address and hana_instance.getPort(): ipseOsh, oshs_ = self.reportServerIpServiceEndpoint( hana_instance.address, hana_instance.getPort(), instance_osh, container ) oshs.extend(oshs_) for slave in dependants or (): for master in (server_osh,): link = modeling.createLinkOSH("dependency", slave, master) oshs.append(link) return server_osh, ipseOsh, instance_osh, oshs
def reporterMSCluster(self, vector, ms_cluster, groups, ipDictByGroupName, nodesWithIP): clusterOsh = ms_cluster.create_osh() vector.add(clusterOsh) vector.add(modeling.createLinkOSH('membership', clusterOsh, self.applicationOsh)) for node in nodesWithIP: ips = nodesWithIP[node] hostOsh = (modeling.createHostOSH(str(ips[0]), 'nt') or ObjectStateHolder('nt')) hostOsh.setStringAttribute('name', node) hostOsh.setStringAttribute('os_family', 'windows') for ip_obj in ips: ipOSH = modeling.createIpOSH(ip_obj) vector.add(ipOSH) vector.add(modeling.createLinkOSH('containment', hostOsh, ipOSH)) softwareOsh = modeling.createClusterSoftwareOSH(hostOsh, 'Microsoft Cluster SW', ms_cluster.version) softwareOsh.setAttribute("application_version_number", ms_cluster.version) vector.add(softwareOsh) vector.add(modeling.createLinkOSH('membership', clusterOsh, softwareOsh)) for group in groups: ips = ipDictByGroupName.get(group.name, None) if ips: for ip in ips: groupOsh = group.create_osh() vector.add(groupOsh) vector.add(modeling.createLinkOSH('contained', clusterOsh, groupOsh)) ipOsh = modeling.createIpOSH(ip) vector.add(modeling.createLinkOSH('contained', groupOsh, ipOsh)) vector.add(ipOsh) self.__crgMap[str(ip)] = groupOsh
def createTransportPathObjects(cluster, hostOshByName, resultsVector, framework): for tPath in cluster.transportPaths: sourceInterfaceResult = createTransportInterfaceObject(tPath.fromNode, tPath.fromInterface, cluster, hostOshByName) targetInterfaceResult = createTransportInterfaceObject(tPath.toNode, tPath.toInterface, cluster, hostOshByName) if sourceInterfaceResult and targetInterfaceResult: (sourceInterfaceOsh, sourceAdapter) = sourceInterfaceResult (targetInterfaceOsh, targetAdapter) = targetInterfaceResult resultsVector.add(sourceInterfaceOsh) resultsVector.add(targetInterfaceOsh) versionAsDouble = logger.Version().getVersion(framework) if versionAsDouble >= 9: layer2Osh = ObjectStateHolder('layer2_connection') linkId = "%s:%s" % (sourceAdapter.mac, targetAdapter.mac) linkId = str(hash(linkId)) layer2Osh.setAttribute('layer2_connection_id', linkId) sourceMemberLink = modeling.createLinkOSH('member', layer2Osh, sourceInterfaceOsh) targetMemberLink = modeling.createLinkOSH('member', layer2Osh, targetInterfaceOsh) resultsVector.add(layer2Osh) resultsVector.add(sourceMemberLink) resultsVector.add(targetMemberLink) else: layer2Link = modeling.createLinkOSH('layertwo', sourceInterfaceOsh, targetInterfaceOsh) resultsVector.add(layer2Link)
def build(self): lbcOsh = ObjectStateHolder('loadbalancecluster') lbcOsh.setStringAttribute('name', self.vServer.name) containment_link = modeling.createLinkOSH('containment', lbcOsh, self.crgOsh) membershipLink = modeling.createLinkOSH('membership', lbcOsh, self.netscaler_software_osh) self.osh = lbcOsh return self.newVector(lbcOsh, containment_link, membershipLink)
def build_layer2_connection(net_device_osh, net_device_interface_name, net_device_ip_address, end_node_osh, end_node_mac_address, end_node_interface_osh): ''' Build Layer 2 connection topology. @type param: str,str,osh,str -> OSHV ''' net_device_id = net_device_ip_address or net_device_osh.getCmdbId().toString() end_node_id = end_node_mac_address #is it enough data to build Layer 2 topology if net_device_id and end_node_id and net_device_osh and net_device_interface_name and end_node_osh and end_node_interface_osh: oshv = ObjectStateHolderVector() net_device_interface_osh = ObjectStateHolder('interface') net_device_interface_osh.setContainer(net_device_osh) net_device_interface_osh.setAttribute('interface_name', net_device_interface_name) layer2_osh = ObjectStateHolder('layer2_connection') layer2_osh.setAttribute('layer2_connection_id',str(hash(net_device_id + end_node_id))) layer2_member_net_device_interface_osh = modeling.createLinkOSH('member', layer2_osh, net_device_interface_osh) layer2_member_end_node_interface_osh = modeling.createLinkOSH('member', layer2_osh, end_node_interface_osh) oshv.add(net_device_osh) oshv.add(net_device_interface_osh) oshv.add(end_node_osh) oshv.add(end_node_interface_osh) oshv.add(layer2_osh) oshv.add(layer2_member_net_device_interface_osh) oshv.add(layer2_member_end_node_interface_osh) return oshv
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 getServers(client, username, enterprise, gatewayOSH, siteOSH, Framework, OSHVResult): #serverListing = srvrmgr.sendCommand('list servers') serverListing = client.executeCmd('list servers show SBLSRVR_NAME, HOST_NAME, INSTALL_DIR, SBLMGR_PID, SV_DISP_STATE, SBLSRVR_STATE, START_TIME, END_TIME, SBLSRVR_STATUS, SV_SRVRID')#@@CMD_PERMISION siebel protocol execution serverTbl = siebel_common.makeTable(serverListing) # sample output #SBLSRVR_NAME HOST_NAME INSTALL_DIR SBLMGR_PID SV_DISP_STATE SBLSRVR_STATE START_TIME END_TIME SBLSRVR_STATUS #------------ --------- ------------------ ---------- ------------- ------------- ------------------- -------- -------------------------------- #sblapp1_AS sblapp1 d:\sea752\siebsrvr 1904 Running Running 2004-08-10 15:43:46 7.5.3.3 [16172] LANG_INDEPENDENT #sblapp2 sblapp2 d:\sea752\siebsrvr 1336 Running Running 2004-08-01 03:29:42 7.5.3.3 [16172] LANG_INDEPENDENT #sblapp1 sblapp1 d:\sea752\siebsrvr LIBMsg: No strings available for this language setting # #3 rows returned. svrcount = 0 for serverEntry in serverTbl: try: # jython doesn't have out parameters, so this is a bypass with # and ArrayList return value that has 2 items. serverObj = serverEntry[0] serverDataRow = serverEntry[1] serverOSH = makeAppServer(client, username, enterprise, serverObj, serverDataRow, siteOSH, Framework, OSHVResult) if serverOSH != None: OSHVResult.add(modeling.createLinkOSH('depend', serverOSH,gatewayOSH)) OSHVResult.add(modeling.createLinkOSH('member', siteOSH,serverOSH)) svrcount += 1 except: logger.errorException('Failed to get server') logger.debug('parsed ', str(svrcount), 'app servers')
def buildFabrics(self): for fabric in self.fabrics.values(): fabricOsh = fabric.build() for zoneSet in fabric.zoneSets.values(): zoneSetOsh = zoneSet.build() zoneSetOsh.setContainer(fabricOsh) compositionLink = modeling.createLinkOSH('composition', fabricOsh, zoneSetOsh) if zoneSet.zoneSetId == fabric.activeZoneSet: compositionLink.setAttribute('name', 'Active Zone Set') else: compositionLink.setAttribute('name', 'Inactive Zone Set') for zone in zoneSet.zones: zoneOsh = zone.build() zoneOsh.setContainer(fabricOsh) logger.debug('Have [%s] Members on the Zone [%s] - Processing' % (len(zone.members), zone.name)) for zoneMember in zone.members.values(): memberOsh = self.memberWwnToOsh.get(zoneMember.wwn.lower()) if memberOsh is None: logger.warn("Found ZoneMember with WWN:[%s] on Zone[%s] which doesn't belong to discovered entities" % (zoneMember.wwn, zone.name)) continue memberLink = modeling.createLinkOSH('membership', zoneOsh, memberOsh) self.OSHVResult.add(memberOsh) self.OSHVResult.add(memberLink) self.OSHVResult.add(zoneOsh) self.OSHVResult.add(zoneSetOsh) self.OSHVResult.add(compositionLink) for switch in fabric.switches.values(): switchOsh = switch.build() membershipLink = modeling.createLinkOSH('membership', fabricOsh, switchOsh) self.OSHVResult.add(membershipLink) self.OSHVResult.add(fabricOsh)
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 build_layer2_connection(layer2_connection): ''' Build Layer 2 connection topology. @type param: SNMP_CDP_LLDP.Laer2Connwction -> OSHV ''' oshv = ObjectStateHolderVector() (local_device_osh, local_device_ip_address_osh, local_device_interface_osh, local_device_member_ip_osh) = build_network_device(layer2_connection.local_device) (remote_device_osh, remote_device_ip_address_osh, remote_device_interface_osh, remote_device_member_ip_osh) = build_network_device(layer2_connection.remote_device) if local_device_osh and local_device_interface_osh and remote_device_osh and remote_device_interface_osh: layer2_osh = ObjectStateHolder('layer2_connection') layer2_osh.setAttribute('layer2_connection_id',str(hash(layer2_connection.local_device.address_id + layer2_connection.remote_device.address_id))) layer2_member_local_interface_osh = modeling.createLinkOSH('member', layer2_osh, local_device_interface_osh) layer2_member_remote_interface_osh = modeling.createLinkOSH('member', layer2_osh, remote_device_interface_osh) oshv.add(local_device_osh) oshv.add(local_device_interface_osh) if (local_device_ip_address_osh): oshv.add(local_device_ip_address_osh) oshv.add(local_device_member_ip_osh) oshv.add(remote_device_osh) oshv.add(remote_device_interface_osh) if (remote_device_ip_address_osh): oshv.add(remote_device_ip_address_osh) oshv.add(remote_device_member_ip_osh) oshv.add(layer2_osh) oshv.add(layer2_member_local_interface_osh) oshv.add(layer2_member_remote_interface_osh) return oshv
def osh_createIpOsh(lparOsh, tcpStacks): ipstoexclude = ['127.0.0.1'] # tcpStacks [ip, network, mask, interface name, status, type, mac address]str_name = 'name' str_name = 'name' str_mac_address = 'mac_address' _vector = ObjectStateHolderVector() for mac, tcpentry in tcpStacks.items(): ipAddress = tcpentry[0].strip() if ipAddress not in ipstoexclude: ipOsh = modeling.createIpOSH(ipAddress) probeName = CollectorsParameters.getValue(CollectorsParameters.KEY_COLLECTORS_PROBE_NAME) if isNotNull(probeName): ipOsh.setAttribute('ip_probename', probeName) containedOsh = modeling.createLinkOSH('contained', lparOsh, ipOsh) _vector.add(lparOsh) _vector.add(ipOsh) _vector.add(containedOsh) # create interface ---------------------------------------------------- ifOsh = ObjectStateHolder('interface') interfacename = tcpentry[3].strip() ifOsh.setAttribute(str_name, interfacename) # default the mac address attribute to linkName and update later if MAC found ifOsh.setAttribute(str_mac_address, mac) # if MAC not found for set #linkName as key ifOsh.setContainer(lparOsh) _vector.add(ifOsh) if tcpStacks.has_key(mac): parentLinkOsh = modeling.createLinkOSH('containment', ifOsh, ipOsh) _vector.add(parentLinkOsh) return _vector
def processIpsAndSubnets(_vector, hostIpMap, hostId, ipMap, nwMap, hostOSH): if hostIpMap.has_key(hostId): iplist = hostIpMap[hostId] for ip in iplist: if ipMap.has_key(ip): ipObj = ipMap[ip] ## create IPs and contained links for the rest of the IPs of that host ipOSH = modeling.createIpOSH(ipObj.ipValue) containedLink = modeling.createLinkOSH('contained', hostOSH, ipOSH) _vector.add(ipOSH) _vector.add(containedLink) ## create the network for each IP ipSubnetId = ipObj.ipSubnetId if nwMap.has_key(ipSubnetId): netmaskPrefixLength = nwMap[ipSubnetId].prefixLength if notNull(netmaskPrefixLength): netOSH = modeling.createNetworkOSH(ipObj.ipValue, computeStringNetmaskFromPrefix(netmaskPrefixLength)) _vector.add(netOSH) ## create member link between ip and network memberLink = modeling.createLinkOSH('member', netOSH, ipOSH) _vector.add(memberLink) ## create member link between host and network memberLink = modeling.createLinkOSH('member', netOSH, hostOSH) _vector.add(memberLink) return _vector
def report(self, region_osh, event_osh=None): vector = ObjectStateHolderVector() osh = ObjectStateHolder('host_node') osh.setAttribute('name', self.name) logger.debug("self.id:", self.id) vector.add(osh) if self.ips: for ip in self.ips: ip_osh = modeling.createIpOSH(str(ip)) vector.add(ip_osh) vector.add(modeling.createLinkOSH('contained', osh, ip_osh)) if self.image: imageOsh, image_vector = self.image.report(region_osh) vector.addAll(image_vector) vector.add(modeling.createLinkOSH('dependency', osh, imageOsh)) if self.hypervisorHostName: hypervisorOsh, hypervisor_vector = Hypervisor(self.hypervisorHostName).report(region_osh) vector.addAll(hypervisor_vector) vector.add(modeling.createLinkOSH('execution_environment', hypervisorOsh, osh)) if self.flavor: flavorOsh, flavor_vector = self.flavor.report(region_osh) vector.addAll(flavor_vector) vector.add(modeling.createLinkOSH('dependency', osh, flavorOsh)) if event_osh: vector.add(modeling.createLinkOSH('dependency', osh, event_osh)) return osh, vector
def createOAMRunningSoftwareOsh(scpId, ip, port, protocolId, version, apacheOsh, vector): """ Create OAM osh on oam endpoint, oam node & client server relation """ logger.debug('submit OAM endpoint: %s:%s' % (ip, port)) endpoint = netutils.createTcpEndpoint(ip, port) builder = netutils.ServiceEndpointBuilder() reporter = netutils.EndpointReporter(builder) nodeOsh = reporter.reportHostFromEndpoint(endpoint) endpointOsh = reporter.reportEndpoint(endpoint, nodeOsh) linkOsh = modeling.createLinkOSH('client_server', apacheOsh, endpointOsh) linkOsh.setStringAttribute('clientserver_protocol', 'tcp') oamServerOsh = modeling.createApplicationOSH('running_software', 'Oracle Access Management', nodeOsh, None, 'oracle_corp') oamServerOsh.setStringAttribute('credentials_id', protocolId) oamServerOsh.setStringAttribute('version', version) usageOsh = modeling.createLinkOSH('usage', oamServerOsh, endpointOsh) vector.add(nodeOsh) vector.add(endpointOsh) vector.add(linkOsh) vector.add(oamServerOsh) vector.add(usageOsh) logger.debug("create ownership between runningsoftware and scp") vector.addAll(scp.createOwnerShip(scpId, oamServerOsh)) logger.debug("create consumer-provider link between apache and runningsoftware") reference = 'connection_type=oam, server_host=%s, server_ip=%s, server_port=%s' % (ip, ip, port) vector.addAll(scp.createCPLinkByOsh(apacheOsh, oamServerOsh, scpId, reference))
def report(self, oshVector, interaction): if self.acceptorEngine.accepts(interaction.srcNode) and\ self.acceptorEngine.accepts(interaction.dstNode) and interaction.isClientServerRelationDefined(): client, server, connection = interaction.getClient(), interaction.getServer(), interaction.connection server.serviceAddressOsh = server.serviceAddressOsh or self._buildAndReportServiceAddress(server, connection, self.knownPortsConfigFile, oshVector) client.processOsh = client.processOsh or self._buildAndReportProcess(client, oshVector) serverPortNames = self.getPortNamesByPortNr(server.port, server.ip, connection.protocol, self.knownPortsConfigFile) csLink = None if client.processOsh is not None and server.serviceAddressOsh is not None: csLink = modeling.createLinkOSH('client_server', client.processOsh, server.serviceAddressOsh) elif client.hostOsh is not None and server.serviceAddressOsh is not None: csLink = modeling.createLinkOSH('client_server', client.hostOsh, server.serviceAddressOsh) if not csLink: return csLink.setStringAttribute('clientserver_protocol', connection.protocol == modeling.TCP_PROTOCOL and 'TCP' or 'UDP') if serverPortNames: csLink.setStringAttribute('data_name', first(serverPortNames)) csLink.setLongAttribute('clientserver_destport', int(server.port)) if self.reportTrafficDetails: connection.dPkgs and csLink.setLongAttribute('clientserver_pkts', connection.dPkgs) connection.dOctets and csLink.setLongAttribute('clientserver_octets', connection.dOctets) oshVector.add(csLink)
def discoverContentRules(self): contentRuleQueryBuilder = SnmpQueryBuilder(CNT_OID_OFFSET) contentRuleQueryBuilder.addQueryElement(2, 'cnt_name') contentRuleQueryBuilder.addQueryElement(4, 'ipserver_address') contentRuleQueryBuilder.addQueryElement(5, 'ipport_type') contentRuleQueryBuilder.addQueryElement(6, 'ipport_number') contentRuleQueryBuilder.addQueryElement(68, 'ip_range') snmpRowElements = self.snmpAgent.getSnmpData(contentRuleQueryBuilder) for snmpRowElement in snmpRowElements: virtualServer = modeling.createHostOSH(snmpRowElement.ipserver_address, 'clusteredservice') virtualServerHostKey = virtualServer.getAttributeValue('host_key') virtualServer.setAttribute('data_name', virtualServerHostKey) self.OSHVResult.add(modeling.createLinkOSH('owner', self.css, virtualServer)) self.OSHVResult.add(virtualServer) resourcePool = ObjectStateHolder('loadbalancecluster') resourcePool.setStringAttribute('data_name', snmpRowElement.cnt_name) self.OSHVResult.add(modeling.createLinkOSH('contained', resourcePool, virtualServer)) self.OSHVResult.add(resourcePool) self.resourcePools[snmpRowElement.cnt_name] = resourcePool serviceAddress = modeling.createServiceAddressOsh(virtualServer, snmpRowElement.ipserver_address, snmpRowElement.ipport_number, CNT_PROTOCOL_MAP[snmpRowElement.ipport_type]) serviceAddress.setContainer(virtualServer) self.OSHVResult.add(serviceAddress) # KB specific: fix of port translations self.resourcePoolsToServiceAddress[snmpRowElement.cnt_name] = serviceAddress for i in range(int(snmpRowElement.ip_range)): #TODO: Add all IPs from range pass
def StepMain(Framework): logger.debug('Start dependency mapping') # get result from workflow state workflowState = Framework.getWorkflowState() searchResult = workflowState.getProperty(DependenciesDiscoveryConsts.DEPENDENCIES_DISCOVERY_RESULT) oshv = ObjectStateHolderVector() dependencyCount = 0 if searchResult: providerServiceOsh = None providerDeployable = searchResult.getProviderDeployable() if providerDeployable: providerServiceOsh = providerDeployable.getDeployable() if providerServiceOsh: logger.debug('The search result does not contain a provider object, generate one from destination data instead') triggerId = Framework.getCurrentDestination().getId() providerType = Framework.getDestinationAttribute('PROVIDERTYPE') providerServiceOsh = ObjectStateHolder(providerType, CmdbObjectID.Factory.restoreObjectID(triggerId)) moreProviderOshs = createOtherProviderOshsIfNeed(Framework) for index in range(0, searchResult.size()): deployable = searchResult.get(index) deployableOsh = deployable.getDeployable() if providerServiceOsh.compareTo(deployableOsh): dependencyNames = [] references = [] for dependency in deployable.getDependencies(): dependencyName = dependency.getDependencyName() variables = dependency.getExportVariables() logger.debug('%s export variables found by dependency %s' % (variables.size(), dependencyName)) dependencyNames.append(dependencyName) for var in variables: varName = var.getName() values = var.getValues() logger.debug('Variable %s:%s' % (varName, values)) if varName.lower() == REFERENCES: references += list(values) reference = references and ','.join(references) logger.debug('Found %s link from %s(%s) to %s(%s) by dependency [%s] with reference %s' % ( CONSUMER_PROVIDER_LINK_TYPE, deployableOsh.getObjectClass(), deployableOsh.getCmdbId(), providerServiceOsh.getObjectClass(), providerServiceOsh.getCmdbId(), '/'.join(dependencyNames), reference)) consumerProviderLink = modeling.createLinkOSH(CONSUMER_PROVIDER_LINK_TYPE, deployableOsh, providerServiceOsh) if reference: consumerProviderLink.setAttribute(REFERENCES, reference) oshv.add(consumerProviderLink) dependencyCount += 1 for otherProviderOsh in moreProviderOshs: oshv.add(modeling.createLinkOSH(CONSUMER_PROVIDER_LINK_TYPE, deployableOsh, otherProviderOsh)) else: logger.debug('Ignore self link found on %s(%s)' % (deployableOsh.getObjectClass(), deployableOsh.getCmdbId())) logger.debug('%s consumer-provider link(s) found' % dependencyCount) if dependencyCount: Framework.sendObjects(oshv) Framework.flushObjects() logger.debug("Finished sending results")
def buildTopology(self): ''' Construct as400 node topology @types AS400Client -> ObjectStateHolderVector ''' myvec = ObjectStateHolderVector() ip_address = self.__client.getIpAddress() # create as400 agent OSH interfaceList = self.__interfacesInfo as400HostOsh = None if interfaceList and len(interfaceList) > 0: # Create as400 CIT try: # Get the host_key - lowest mac address of the valid interface list as400HostOsh = modeling.createCompleteHostOSHByInterfaceList('as400_node', interfaceList, 'OS400', self.__sysInfo.hostName) as400HostOsh.setAttribute('host_model', self.__sysInfo.hostModel) as400HostOsh.setAttribute('host_serialnumber', self.__sysInfo.hostSerialNum) as400HostOsh.setAttribute('host_osversion', self.__sysInfo.hostOSVersion) as400HostOsh.setAttribute('host_vendor', 'IBM') myvec.add(as400HostOsh) as400Osh = self.__createAS400AgentOSH(ip_address) as400Osh.setAttribute('credentials_id', self.__client.getCredentialId()) as400Osh.setContainer(as400HostOsh) myvec.add(as400Osh) except: logger.warn('Could not find a valid MAC addresses for key on ip : ', self.__client.getIpAddress()) # add all interfaces to the host if as400HostOsh is not None: for interface in interfaceList: interfaceOsh = modeling.createInterfaceOSH(interface.macAddress, as400HostOsh, interface.description, interface.interfaceIndex, interface.type, interface.adminStatus, interface.adminStatus, interface.speed, interface.name, interface.alias, interface.className) ips = interface.ips masks = interface.masks if interfaceOsh: myvec.add(interfaceOsh) if ips and masks: for i in xrange(len(ips)): ipAddress = ips[i] ipMask = masks[i] ipProp = modeling.getIpAddressPropertyValue(ipAddress, ipMask, interface.dhcpEnabled, interface.description) ipOSH = modeling.createIpOSH(ipAddress, ipMask, ipProp) myvec.add(ipOSH) myvec.add(modeling.createLinkOSH('containment', as400HostOsh, ipOSH)) netOSH = modeling.createNetworkOSH(ipAddress, ipMask) myvec.add(netOSH) myvec.add(modeling.createLinkOSH('member', netOSH, as400HostOsh)) myvec.add(modeling.createLinkOSH('member', netOSH, ipOSH)) myvec.add(modeling.createLinkOSH('containment', interfaceOsh, ipOSH)) else: logger.warn('Parent host wasn\'t created. No interfaces will be reported.') return myvec
def report(self, vector, hostOsh=None, ipOsh=None): if self.osh is not None: vector.add(self.osh) if hostOsh is not None: vector.add(modeling.createLinkOSH("member", self.osh, hostOsh)) if ipOsh is not None: vector.add(modeling.createLinkOSH("member", self.osh, ipOsh))
def report(self, vector, hostOsh=None, interfaceOsh=None): if self.osh is not None: vector.add(self.osh) if hostOsh is not None: vector.add(modeling.createLinkOSH("containment", hostOsh, self.osh)) if interfaceOsh is not None: vector.add(modeling.createLinkOSH("containment", interfaceOsh, self.osh))
def report(self, cloud): vector = ObjectStateHolderVector() vcloudDirectorOsh = self.reportVcloudDirector(cloud, vector) vcloudRootOsh = None systemOrganizationOsh = None if cloud.systemOrganization is not None: if cloud.companyName: vcloudRootOsh = self.reportVcloudRoot(cloud, vector) self.reportVcloudUri(cloud, vcloudRootOsh, vector) systemOrganizationOsh = self.reportSystemOrganization(cloud.systemOrganization, vcloudRootOsh, vector) manageLink = modeling.createLinkOSH('manage', vcloudDirectorOsh, systemOrganizationOsh) vector.add(manageLink) for providerVdc in cloud.providerVdcByName.values(): self.reportProviderVdc(providerVdc, systemOrganizationOsh, vector) for organization in cloud.organizationsByName.values(): organizationOsh = self.reportOrganization(organization, vcloudRootOsh, vector) manageLink = modeling.createLinkOSH('manage', vcloudDirectorOsh, organizationOsh) vector.add(manageLink) for vdc in organization.vdcByName.values(): vdcOsh = self.reportVdc(vdc, organizationOsh, cloud, vector) for vapp in vdc.vappsByName.values(): vappOsh = self.reportVapp(vapp, organizationOsh, vector) for vm in vapp.vmsByName.values(): self.reportVm(vm, vappOsh, vector) for catalog in organization.catalogsByName.values(): catalogOsh = self.reportCatalog(catalog, organizationOsh, vector) for media in catalog.mediaByName.values(): mediaOsh = self.reportMedia(media, catalogOsh, vector) if media._parentVdcReference is not None: mediaParentVdc = organization._vdcByHref.get(media._parentVdcReference.getHref()) if mediaParentVdc is not None: vdcOsh = mediaParentVdc.getOsh() if vdcOsh is not None: usageLink = modeling.createLinkOSH('usage', mediaOsh, vdcOsh) vector.add(usageLink) for vappTemplate in catalog.vappTemplatesByName.values(): self.reportVappTemplate(vappTemplate, catalogOsh, vector) return vector
def build(self): domainName = DomainScopeManager.getDomainByIp(self.vServer.ip) name = '%s:%s %s' % (self.vServer.ip, self.vServer.port, domainName) vServerOsh = modeling.createCompleteHostOSH('cluster_resource_group', name, None, self.vServer.name) ipOSH = modeling.createIpOSH(self.vServer.ip) linkIpOSH = modeling.createLinkOSH('contained', vServerOsh, ipOSH) ownership_link = modeling.createLinkOSH('ownership', self.netscaler_software_osh, vServerOsh) vipServiceOsh = modeling.createServiceAddressOsh(vServerOsh, self.vServer.ip, self.vServer.port, modeling.SERVICEADDRESS_TYPE_TCP, self.vServer.server_type) self.osh = vServerOsh return self.newVector(vServerOsh, ipOSH, ownership_link, linkIpOSH, vipServiceOsh)
def reportLayer2Connection(localInterfaceOsh, remoteInterfaceOsh, l2id): vector = ObjectStateHolderVector() layer2Osh = ObjectStateHolder('layer2_connection') layer2Osh.setAttribute('layer2_connection_id', l2id) vector.add(layer2Osh) linkOsh = modeling.createLinkOSH('member', layer2Osh, localInterfaceOsh) vector.add(linkOsh) linkOsh = modeling.createLinkOSH('member', layer2Osh, remoteInterfaceOsh) vector.add(linkOsh) return vector
def createClientServerDependentLink(self,OSHVResult, clientHostOsh, serverHostOSH, serverPort, portName): ucmdbVersion = modeling.CmdbClassModel().version() if ucmdbVersion >= 9: nodeDependencyLink = modeling.createLinkOSH('node_dependency',clientHostOsh, serverHostOSH) nodeDependencyLink.setAttribute('dependency_name', serverPort) nodeDependencyLink.setAttribute('dependency_source', portName) OSHVResult.add(nodeDependencyLink) else: dependencyLink = modeling.createLinkOSH('dependency', clientHostOsh, serverHostOSH) dependencyLink.setAttribute('dependency_name', serverPort) dependencyLink.setAttribute('dependency_source', portName) OSHVResult.add(dependencyLink)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() exchangeServerId = Framework.getDestinationAttribute('id') exchangeServerOsh = ms_exchange_utils.restoreExchangeServerOSH(exchangeServerId) try: shellClient = Framework.createClient() client = PowerShellClient(shellClient, Framework) try: ExchangeServer = client.executeScenario("Exchange_Server_2007_Discovery.ps1") exchangeSystemName = extractOrganizationNameFromDn(ExchangeServer.ExchangeLegacyDN) exchangeSystemOsh = ObjectStateHolder('exchangesystem') exchangeSystemOsh.setAttribute('data_name', exchangeSystemName) modeling.setAppSystemVendor(exchangeSystemOsh) OSHVResult.add(exchangeSystemOsh) OSHVResult.add(modeling.createLinkOSH('member', exchangeSystemOsh, exchangeServerOsh)) adminGroupName = extractAdminGrouptFromDn(ExchangeServer.ExchangeLegacyDN) if adminGroupName and exchangeSystemOsh: adminGroupOsh = ObjectStateHolder('exchange_administrative_group') adminGroupOsh.setAttribute('data_name' , adminGroupName) adminGroupOsh.setContainer(exchangeSystemOsh) OSHVResult.add(adminGroupOsh) OSHVResult.add(modeling.createLinkOSH('member', adminGroupOsh, exchangeServerOsh)) createServerRoles(exchangeServerOsh, ExchangeServer.ServerRole, OSHVResult) dagList = [] clusteredMailBox = None try: dagList = ExchangeServer.dagList if not dagList: raise ValueError('Failed getting DAG information') except: logger.debugException('') else: OSHVResult.addAll(TopologyBuilder(None, None, None, None).buildDagRelatedTopology(exchangeServerOsh, dagList)) try: clusteredMailBox = ExchangeServer.clusteredMailBox if not clusteredMailBox: raise ValueError('Failed getting Clustered Mailbox') except: logger.debugException('') else: setattr(clusteredMailBox, "exchOrgName", exchangeSystemName) OSHVResult.addAll(TopologyBuilder(None, None, None, None).buildClusteredMailBoxRelatedTopology(exchangeServerOsh, clusteredMailBox)) OSHVResult.add(exchangeServerOsh) finally: client.close() except Exception, ex: logger.debugException('') strException = str(ex.getMessage()) errormessages.resolveAndReport(strException, PROTOCOL_NAME, Framework)
def build(self): #@return: oshv OSHVResult = ObjectStateHolderVector() exchageOsh = self.buildExchangeServerOsh(self.exchangeServer, self.hostOsh, self.ipAddress, self.credentialsId) if self.exchangeServer.organization: exchOrgOsh = self.buildExchangeOrganization(self.exchangeServer.organization) OSHVResult.add(exchOrgOsh) OSHVResult.add(modeling.createLinkOSH('member', exchOrgOsh, exchageOsh)) if self.exchangeServer.organizationalUnit: adminGrOsh = self.buildExchAdminGrOsh(exchOrgOsh, self.exchangeServer.organizationalUnit) OSHVResult.add(adminGrOsh) OSHVResult.add(modeling.createLinkOSH('member', adminGrOsh, exchageOsh)) if self.exchangeServer.dagList: OSHVResult.addAll(self.buildDagRelatedTopology(exchageOsh, self.exchangeServer.dagList)) if self.exchangeServer.clusteredMailBox: self.exchangeServer.clusteredMailBox.exchOrgName = self.exchangeServer.clusteredMailBox.exchOrgName or self.exchangeServer.organization OSHVResult.addAll(self.buildClusteredMailBoxRelatedTopology(exchageOsh, self.exchangeServer.clusteredMailBox)) if self.exchangeServer.mdbList: for mdb in self.exchangeServer.mdbList: containerOsh = None if mdb.relateTo == RELATE_TO_DAG: if self.exchangeServer.dagList: for dag in self.exchangeServer.dagList: if dag.dagName == mdb.containerName: exchOrgOsh = self.buildExchangeOrganization(dag.exchOrgName) containerOsh = self.buildDag(exchOrgOsh, dag) if containerOsh: mdbOsh = self.buildMailboxDatabase(mdb, containerOsh) if mdbOsh: OSHVResult.add(containerOsh) OSHVResult.add(mdbOsh) if mdb.servers: for server in mdb.servers: if server.ips: hostOsh = modeling.createHostOSH(str(server.ips[0])) exchangeServerOsh = modeling.createExchangeServer(hostOsh) linkOsh = modeling.createLinkOSH('ownership', exchangeServerOsh, mdbOsh) OSHVResult.add(exchangeServerOsh) OSHVResult.add(linkOsh) OSHVResult.add(hostOsh) if server.name == mdb.runningServer: linkOsh = modeling.createLinkOSH('run', exchangeServerOsh, mdbOsh) OSHVResult.add(linkOsh) OSHVResult.add(exchageOsh) OSHVResult.addAll(self.buildServerRoles(exchageOsh, self.exchangeServer)) OSHVResult.add(self.hostOsh) return OSHVResult
def reportStorageSystem(hostDo, fsm_osh): vector = ObjectStateHolderVector() storage_osh = buildStorageSystem(hostDo) link_osh = modeling.createLinkOSH('manage', fsm_osh, storage_osh) vector.add(link_osh) if hostDo.ipList: for ip in hostDo.ipList: ip_osh = modeling.createIpOSH(ip) link_osh = modeling.createLinkOSH('containment', storage_osh, ip_osh) vector.add(ip_osh) vector.add(link_osh) vector.add(storage_osh) return vector, storage_osh
def buildStorageArrays(self): for storage in self.storageArrays.values(): storageArrayOSHV = ObjectStateHolderVector() oshDict = storage.build() for name in oshDict.keys(): arrayOsh = storage.oshs[name] ip = storage.ips[name] if ip and netutils.isValidIp(ip): ipOsh = modeling.createIpOSH(storage.ips[name]) containmentOsh = modeling.createLinkOSH('containment', arrayOsh, ipOsh) storageArrayOSHV.add(ipOsh) storageArrayOSHV.add(containmentOsh) storageArrayOSHV.add(arrayOsh) hbaIdToOsh = {} for hba in storage.hbas.values(): hbaOsh = hba.build() if storage.isClustered: for name in storage.names: if hba.name.startswith(name): hbaOsh.setContainer(oshDict[name]) else: hbaOsh.setContainer(oshDict[oshDict.keys()[0]]) hbaIdToOsh[hba.hbaId] = hbaOsh self.addWwnOsh(hba.wwn, hbaOsh) storageArrayOSHV.add(hbaOsh) for port in storage.ports.values(): portOsh = port.build() if storage.isClustered: for name in storage.names: if port.name.startswith(name): portOsh.setContainer(oshDict[name]) else: portOsh.setContainer(oshDict[oshDict.keys()[0]]) if port.nodeId and port.nodeId in hbaIdToOsh.keys(): containmentLinkOsh = modeling.createLinkOSH('containment', hbaIdToOsh[port.nodeId], portOsh) storageArrayOSHV.add(containmentLinkOsh) self.portIdToOsh[port.portId] = portOsh self.addWwnOsh(port.wwn, portOsh) storageArrayOSHV.add(portOsh) for volume in storage.volumes.values(): volumeOsh = volume.build() if storage.isClustered: for name in storage.names: if volume.name.startswith(name): volumeOsh.setContainer(oshDict[name]) else: volumeOsh.setContainer(oshDict[oshDict.keys()[0]]) self.volumeIdToOsh[volume.volumeId] = volumeOsh storageArrayOSHV.add(volumeOsh) self.framework.sendObjects(storageArrayOSHV) self.framework.flushObjects()
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 buildDagRelatedTopology(self, exchangeServerOsh, dagList): OSHVResult = ObjectStateHolderVector() for dag in dagList: exchOrgOsh = self.buildExchangeOrganization(dag.exchOrgName) if exchOrgOsh: exchAdminGrOsh = self.buildExchAdminGrOsh(exchOrgOsh, dag.exchAdminGrName) OSHVResult.add(modeling.createLinkOSH('membership', exchAdminGrOsh, exchangeServerOsh)) dagOsh = self.buildDag(exchOrgOsh, dag) if dagOsh: OSHVResult.add(modeling.createLinkOSH('membership', dagOsh, exchangeServerOsh)) OSHVResult.add(exchOrgOsh) OSHVResult.add(exchAdminGrOsh) OSHVResult.add(dagOsh) return OSHVResult
def reportAvailabilityZoneInRegion(self, region, zone): r'''@types: aws.Regtion, aws.AvailabilityZone -> ObjectStateHolderVector @raise ValueError: Region is not specified or not built @raise ValueError: Zone is not specified ''' if not (region and region.getOsh()): raise ValueError("Region is not specified or not built") if not zone: raise ValueError("Zone is not specified") vector = self._createOshVector() regionOsh = region.getOsh() vector.add(regionOsh) vector.add(zone.build(self.__builder)) vector.add( modeling.createLinkOSH('containment', regionOsh, zone.getOsh())) return vector
def reportStoreDependencyOnDatasource(self, container, store, datasource): r''' Reports linkage between JMS Store and any type of datasource, like JDBC store and database datasource. @note: Store will be built if it wasn't previously @types: entity.HasOsh, jms.Store, entity.HasOsh -> ObjectStateHolderVector @param container: JMS Store container in case if store is not built ''' if not store: raise ValueError("Store is not specified") if not (datasource and datasource.getOsh()): raise ValueError("Datasource is not specified or not built") vector = ObjectStateHolderVector() storeOsh = store.getOsh() or store.build(self.builder()) vector.add( modeling.createLinkOSH('depend', storeOsh, datasource.getOsh())) return vector
def reportJmsServer(self, domain, deploymentScope, server): r'''@types: jee.Domain, entity.HasOsh, jms.Server -> ObjectStateHolderVector @raise ValueError: JMS Server is not specified @raise ValueError: JMS Server container is not specified or not built ''' container = domain if not server: raise ValueError("JMS Server is not specified") vector = ObjectStateHolderVector() if not server.getOsh(): vector.addAll(self._reportJmsServer(container, server)) if deploymentScope and deploymentScope.getOsh(): vector.add( modeling.createLinkOSH('deployed', deploymentScope.getOsh(), server.getOsh())) return vector
def report_client_server(self, client_process_osh, server_ips_osh, server_port_name, server_port, protocol_type=modeling.TCP_PROTOCOL): protocol = protocol_type == modeling.TCP_PROTOCOL and 'TCP' or 'UDP' cs_link = modeling.createLinkOSH('client_server', client_process_osh, server_ips_osh) cs_link.setStringAttribute('clientserver_protocol', protocol) cs_link.setStringAttribute('data_name', server_port_name) if server_port and server_port.isdigit(): cs_link.setLongAttribute('clientserver_destport', int(server_port)) else: logger.debug('Server port is not a numeric: %s' % server_port) return cs_link
def getBackup(self, databases, dbList, hostId): oshv = ObjectStateHolderVector() backupMap = self.getDBBackups(databases, dbList) backupFilesMap = self.getBackupFiles(databases, dbList, hostId, oshv) #create the use link logger.debug("get backup files") for key in backupMap.keySet(): backup = backupMap.get(key) backupFile = backupFilesMap.get(key) if backup is not None and backupFile is not None: oshv.add(backup) oshv.add(backupFile) link = modeling.createLinkOSH("use", backup, backupFile) oshv.add(link) logger.debug("got backup files: ", oshv.size()) return oshv
def reportTopology(self, app_pools_list, web_sites_list, parentOsh, iis_version=None, webservice_ext_filter=[]): """ :param web_sites_list: List of WebSites which was discovered :type web_sites_list: list[iis.Site] :param parentOsh: parent OSH for each website :type parentOsh: ObjectStateHolder :return: list[ObjectStateHolder] :rtype: list[ObjectStateHolder] """ result = [] apppool_map = self.reportAppPools(app_pools_list, parentOsh) sites_map = self.reportWebSites(web_sites_list, parentOsh, iis_version) result.extend(sites_map.values()) result.extend(apppool_map.values()) # report VirtualDir and WebDirs(WebApplication) for site in web_sites_list: web_site_osh = sites_map.get(site.name) if not site.is_ftp(): # report root web dir root_web_dir = iis.WebApplication("Root", "/", site.path, site.config_files) root_osh = self._builder.buildApplication(root_web_dir) root_osh.setContainer(web_site_osh) result.append(root_osh) if apppool_map: app_pool_osh = apppool_map.get(site.app_pool.name) if app_pool_osh: result.append(modeling.createLinkOSH("deployed", root_osh, app_pool_osh)) # report config files result.extend(self.reportConfigFiles(site.config_files, root_osh)) # report virtual dirs report_virtual_dirs = partial(self.reportVirtualDir, parent_osh=root_osh) result.extend(iflatten(ifilter(None, imap(report_virtual_dirs, site.virtual_dirs)))) # report Webdirs = WebApplications report_web_application = partial(self.reportWebDir, parent_osh=root_osh, app_pools_map=apppool_map, webservice_ext_filter=webservice_ext_filter) result.extend(iflatten(ifilter(None, imap(report_web_application, site.web_applications)))) bindings = flatten( ifilter(None, imap(lambda binding: binding[1].lower() in ['http', 'https', 'ftp'] and binding[2], site.bindings))) result.extend(self.reportBindings(bindings, web_site_osh, parentOsh)) return result
def getGroupComponents(client, mapGroupNameToOSH, ip, OSHVResult, enterprise, siteOSH): compsListing = client.executeCmd('list comps')#@@CMD_PERMISION siebel protocol execution compsTbl = siebel_common.makeTable(compsListing) # sample output # SV_NAME CC_ALIAS CC_NAME CT_ALIAS CG_ALIAS CC_RUNMODE CP_DISP_RUN_STATE CP_NUM_RUN_ CP_MAX_TASK CP_ACTV_MTS CP_MAX_MTS_ CP_START_TIME CP_END_TIME CP_STATUS CC_INCARN_NO CC_DESC_TEXT # ------- --------- ------------------ -------- -------- ---------- ----------------- ----------- ----------- ----------- ----------- ------------------- ----------- --------- ------------ ------------ # sblapp2 AsgnSrvr Assignment Manager AsgnMgmt Batch Online 0 20 1 1 2004-08-01 03:29:42 # sblapp2 AsgnBatch Batch Assignment AsgnMgmt Batch Online 0 20 2004-08-01 03:29:42 # # 2 rows returned. cCount = 0 #compsOSHV = ObjectStateHolderVector() for compEntry in compsTbl: try: compObj = compEntry[0] compDataRow = compEntry[1] attrNum = len(compObj) appOSH = None if attrNum > 3: compName = compObj[2] endIndex = compName.find(' Object Manager') if endIndex > 0: appName = compName[0:endIndex] appOSH = ObjectStateHolder('siebel_application') appOSH.setAttribute('data_name', appName) appOSH.setContainer(siteOSH) OSHVResult.add(appOSH) if attrNum > 4: # get Name or Alias cgName = compObj[4] groupOSH = mapGroupNameToOSH.get(cgName) if groupOSH != None: (compOSH, paramsFileOSH) = makeComponent(client, compObj, compDataRow, ip, enterprise) compOSH.setContainer(groupOSH) OSHVResult.add(compOSH) OSHVResult.add(paramsFileOSH) cCount += 1 if appOSH != None and compOSH != None: OSHVResult.add(modeling.createLinkOSH('contains',appOSH, compOSH)) else: logger.warn('Group is not found for component [', cgName, ']') except: logger.warnException('failed making component:', compDataRow) logger.debug('parsed ', str(cCount), ' components')
def report(self, regionOsh): vector = ObjectStateHolderVector() hostOsh = ObjectStateHolder('host_node') hostOsh.setAttribute("name", self.name) hypervisorOsh = ObjectStateHolder('virtualization_layer') if self.type: hypervisorOsh.setStringAttribute('name', self.type) hypervisorOsh.setStringAttribute('discovered_product_name', 'openstack_hypervisor') hypervisorOsh.setAttribute('hypervisor_name', self.name) hypervisorOsh.setContainer(hostOsh) vector.add(hostOsh) vector.add(hypervisorOsh) vector.add(modeling.createLinkOSH("membership", regionOsh, hostOsh)) return hypervisorOsh, vector
def _reportDbToSharePointLinks(self, result, sharepointOsh): """ Generates links between sharepoint software element and databases. Reports ipserver_address, use, clientserver ObjectStateHolderVector, OSH->None """ reportedDatabaseLinks = [] for dbConnection in self._databaseConnections: if dbConnection.name in reportedDatabaseLinks: continue dbOsh = self._dbNameToDbOsh[dbConnection.name] dbUrlOsh = modeling.createUrlOsh(dbOsh, 'sql://'+dbConnection.name) result.add(dbUrlOsh) link = modeling.createLinkOSH('client_server', sharepointOsh, dbUrlOsh) link.setAttribute('clientserver_protocol', 'SQL') result.add(link) reportedDatabaseLinks.append(dbConnection.name)
def addResultsToVector(self, resultsVector): if self.resultVector: resultsVector.addAll(self.resultVector) # when the destination IP is virtual, and it exists in NATIpAddress.xml # Continue to create the shell object other than ignore it if self.hostDo.ipIsVirtual: if self.hostDo.ipIsNATed: vIPOSH = modeling.createIpOSH(self.destinationIp) vIPOSH.setBoolAttribute('isvirtual', 1) resultsVector.add(vIPOSH) resultsVector.add( modeling.createLinkOSH('contained', self.hostOsh, vIPOSH)) else: return self.ntcmdObj.setContainer(self.hostOsh) resultsVector.add(self.ntcmdObj)
def osh_createASPOsh(lparOsh, ASPList, DiskList): spDict = {} str_name = 'name' str_storagepool_poolid = 'storagepool_poolid' str_storagepool_mbavailable = 'storagepool_mbavailable' str_storagepool_mbtotal = 'storagepool_mbtotal' str_storagepool_capacitynum = 'storagepool_capacitynum' str_serial_number = 'serial_number' str_logicalvolume_fstype = 'logicalvolume_fstype' str_logicalvolume_id = 'logicalvolume_id' str_logicalvolume_free = 'logicalvolume_free' str_logicalvolume_size = 'logicalvolume_size' _vector = ObjectStateHolderVector() if isNotNull(ASPList): for asp in ASPList: if isNotNull(asp[0]): aspname = ('ASP' + asp[0]) spOsh = ObjectStateHolder('storagepool') spOsh.setAttribute(str_name, aspname) spOsh.setIntegerAttribute(str_storagepool_poolid, int(asp[0])) spOsh.setDoubleAttribute(str_storagepool_mbavailable, asp[3]) spOsh.setDoubleAttribute(str_storagepool_mbtotal, asp[2]) spOsh.setIntegerAttribute(str_storagepool_capacitynum, asp[1]) spOsh.setContainer(lparOsh) spDict[asp[0]] = spOsh _vector.add(spOsh) if isNotNull(DiskList): for disk in DiskList: if isNotNull(disk[0]): aspid = disk[0] diskOsh = ObjectStateHolder('logical_volume') diskOsh.setAttribute(str_name, disk[4]) diskOsh.setAttribute(str_serial_number, disk[3]) diskOsh.setAttribute(str_logicalvolume_fstype, disk[1]) diskOsh.setIntegerAttribute(str_logicalvolume_id, int(disk[5])) diskOsh.setDoubleAttribute(str_logicalvolume_free, disk[7]) diskOsh.setDoubleAttribute(str_logicalvolume_size, disk[6]) diskOsh.setContainer(lparOsh) _vector.add(diskOsh) if spDict.has_key(aspid): memberOsh = modeling.createLinkOSH('membership', spDict[aspid], diskOsh) _vector.add(memberOsh) return _vector
def reportNode(self, node, resultsVector): nodeOsh = self._nodeBuilder.build(node) resultsVector.add(nodeOsh) node.setOsh(AutoStartReporter.NODE_KEY_HOST, nodeOsh) for nic in node.nicsByName.values(): if nic and nic.ip: try: ipOsh = modeling.createIpOSH(nic.ip) resultsVector.add(ipOsh) containmentLink = modeling.createLinkOSH('containment', nodeOsh, ipOsh) resultsVector.add(containmentLink) except ValueError: logger.warn("Invalid IP during reporting is ignored") return nodeOsh
def populateResult(self, oshv, hostName, userName, dbOSH, clientsCount): if (hostName) and (userName): #create the remote host remoteHost = Util.getHost(hostName) if not remoteHost: logger.debug('RemoteHost osh is None, hostName:%s' % hostName) return oshv.add(remoteHost) #create the remote process program = modeling.createProcessOSH(userName, remoteHost) oshv.add(program) if dbOSH: #create the dblink dbLink = modeling.createLinkOSH('dbclient', dbOSH, program) dbLink.setIntegerAttribute('dbclient_connectioncount',clientsCount) oshv.add(dbLink) else: logger.debug('Database osh is None')
def discoverPlanJobs(self,oshv,sqlServerId,plans,jobById): itr = plans.entrySet().iterator() while(itr.hasNext()): entry = itr.next() name = entry.getKey() plan = entry.getValue() query = Util.replace(self.jobsOfPlanQuery, name) try: rs = self.connection.getTable(query) while(rs.next()): jobId = rs.getString('job_id') job = jobById.get(jobId) if(job is not None): oshv.add(modeling.createLinkOSH('dblink',plan,job)) rs.close() except: logger.debugException("couldn't get jobs for plan:", name) return
def osh_createIBMframeOsh(lparOsh, cecTable): str_name = 'name' str_discovered_model = 'discovered_model' str_serial_number = 'serial_number' isComplete = 1 _vector = ObjectStateHolderVector() cecOsh = ObjectStateHolder('ibm_pseries_frame') # iSeries CEC cecOsh.setAttribute(str_name, 'CEC' + cecTable[0][2]) cecOsh.setBoolAttribute('host_iscomplete', isComplete) cecOsh.setAttribute(str_discovered_model, cecTable[0][1]) # CPC SI cecOsh.setAttribute('host_key', cecTable[0][2]) cecOsh.setAttribute(str_serial_number, cecTable[0][2]) str_membership = 'membership' membershipOsh = modeling.createLinkOSH(str_membership, cecOsh, lparOsh) _vector.add(cecOsh) _vector.add(lparOsh) _vector.add(membershipOsh) return _vector
def reportIpString(self, ipAddress, device, vector, ipMask=None): ''' string, Device, OSHV, string? -> OSH? ''' deviceOsh = device and device.getOsh() or None if ipAddress and deviceOsh: ipOsh = None try: ipOsh = modeling.createIpOSH(ipAddress, ipMask) except ValueError, ex: logger.warn(str(ex)) if ipOsh: vector.add(ipOsh) containmentLink = modeling.createLinkOSH( 'containment', deviceOsh, ipOsh) vector.add(containmentLink) return ipOsh
def reportHostWithIps(self, *ips): r''' Report complete host with containment links to IPs If None among IPs it will be skipped but wrong IP will cause exception @types: ip_addr._BaseIP -> tuple[ObjectStateHolder, ObjectStateHolderVector] @raise ValueError: Host key is not specified @raise ValueError: IPs are not specified ''' ips = filter(None, ips) if not ips: raise ValueError("IPs are not specified") ips = map(ip_addr.IPAddress, ips) vector = ObjectStateHolderVector() hostOsh = self._getBuilder().buildCompleteHost(str(ips[0])) vector.add(hostOsh) for ipOsh in map(modeling.createIpOSH, ips): vector.add(modeling.createLinkOSH('containment', hostOsh, ipOsh)) vector.add(ipOsh) return hostOsh, vector
def modelApplicationPool(context): processes = context.application.getProcessesByName('w3wp.exe') iisOSHV = ObjectStateHolderVector() applicationOsh = context.application.getOsh() for process in processes: procCmdLine = process.commandLine if procCmdLine: poolName = re.match(r".*w3wp.*\-ap\s*\"(.*?)\".*", procCmdLine) if poolName: iisAppPoolOSH = ObjectStateHolder('iisapppool') iisAppPoolOSH.setAttribute('data_name', poolName.group(1).strip()) iisAppPoolOSH.setContainer(applicationOsh) iisOSHV.add(iisAppPoolOSH) linkOSH = createLinkOSH('depend', iisAppPoolOSH, process.getOsh()) iisOSHV.add(linkOSH) return iisOSHV
def createCPLink(clientId, clientClass, serverId, serverClass, scpId, reference=None): OSHVResult = ObjectStateHolderVector() clientOsh = ObjectStateHolder( clientClass, CmdbObjectID.Factory.restoreObjectID(clientId)) serverOsh = ObjectStateHolder( serverClass, CmdbObjectID.Factory.restoreObjectID(serverId)) OSHVResult.addAll(createCPLinkByOsh(clientOsh, serverOsh, scpId, reference)) if clientClass == 'business_application': containmentLink = modeling.createLinkOSH('containment', clientOsh, serverOsh) OSHVResult.add(containmentLink) return OSHVResult
def discoverFarmMembers(self, farmNameToFarm): queryBuilder = SnmpQueryBuilder(CISCO_ACE_OID_TABLE_SERVER) queryBuilder.addQueryElement(1, 'farmName') queryBuilder.addQueryElement(2, 'ipAddress') queryBuilder.addQueryElement(3, 'port') farmMembers = self.snmpAgent.getSnmpData(queryBuilder) for farmMember in farmMembers: farmMemberOsh = modeling.createHostOSH(farmMember.ipAddress, 'host') serviceAddressOsh = modeling.createServiceAddressOsh( farmMemberOsh, farmMember.ipAddress, farmMember.port, modeling.SERVICEADDRESS_TYPE_TCP) self.OSHVResult.add(farmMemberOsh) self.OSHVResult.add(serviceAddressOsh) farmOsh = farmNameToFarm[farmMember.farmName] self.OSHVResult.add( modeling.createLinkOSH('member', farmOsh, serviceAddressOsh))
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() dbFileId = Framework.getDestinationAttribute('dbFileId') dbFilePath = Framework.getDestinationAttribute('dbFilePath') fsIds = Framework.getTriggerCIDataAsList('fsId') mountPoints = Framework.getTriggerCIDataAsList('mountPoints') logger.debug(mountPoints) logger.debug(dbFilePath) (index, mountPoint) = getMountPoint(dbFilePath, mountPoints) if mountPoint: fsOsh = modeling.createOshByCmdbId('file_system', fsIds[index]) dbDatafileOsh = modeling.createOshByCmdbId('dbdatafile', dbFileId) linkOsh = modeling.createLinkOSH('usage', dbDatafileOsh, fsOsh) OSHVResult.add(fsOsh) OSHVResult.add(dbDatafileOsh) OSHVResult.add(linkOsh) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ## Write implementation to return new result CIs here... clientId = Framework.getDestinationAttribute('CLIENT_ID') clientClass = Framework.getDestinationAttribute('CLIENT_CLASS') serverIds = Framework.getTriggerCIDataAsList('SERVER_ID') serverClasses = Framework.getTriggerCIDataAsList('SERVER_CLASS') scpId = Framework.getDestinationAttribute('id') serverIdsHaveLink = Framework.getTriggerCIDataAsList('SERVER_ID_HAVE_LINK') serverIdsShouldHaveLink = Framework.getTriggerCIDataAsList('SERVER_ID_SHOULD_HAVE_LINK') serverClassesHaveLink = Framework.getTriggerCIDataAsList('SERVER_CLASS_HAVE_LINK') clientOsh = ObjectStateHolder(clientClass, clientId) OSHVResult.add(clientOsh) if Framework.getDestinationAttribute('CLIENT_APPLICATION_ID'): buildClientOsh(Framework, clientOsh) index = -1 processed = set() reference = buildReferenceString(Framework) for serverId in serverIds: index += 1 if serverId: if serverId in processed: logger.debug('Ignore duplication link for id:', serverId) continue processed.add(serverId) if serverId == clientId: logger.debug('Ignore self link from id:', serverId) continue logger.debug("creating cp-link for ci:", serverId) serverClass = serverClasses[index] or 'running_software' serverOsh = ObjectStateHolder(serverClass, serverId) OSHVResult.add(serverOsh) OSHVResult.addAll(scp.createCPLinkByOsh(clientOsh, serverOsh, scpId, reference)) if clientClass == 'business_application': containmentLink = modeling.createLinkOSH('containment', clientOsh, serverOsh) OSHVResult.add(containmentLink) logger.debug("check if there is cp link need to be deleted") scp.deleteDependencies(Framework, clientOsh, serverIdsHaveLink, serverIdsShouldHaveLink, serverClassesHaveLink) return OSHVResult
def __reportOracleRac(self, platform, datasource, rac): r'@types: db_platform.Oracle, jdbc.Datasource, db.OracleRac -> ObjectStateHolderVector' logger.info("Report Oracle RAC %s" % rac) # Resolve addresses for all server instances in the RAC resolvedServers = [] for server in rac.getServers(): if not netutils.isValidIp(server.address): try: ips = self.__dnsResolver.resolveIpsByHostname( server.address) server.address = ips[0] resolvedServers.append(server) except (Exception, JException): logger.warnException("Failed to resolve IP for the %s" % server) else: resolvedServers.append(server) # After attempt to resolve addresses of RAC instances we will use only # with resolved address resolvedServers = filter(db.DatabaseServer.getPort, resolvedServers) if not resolvedServers: raise ValueError("None of RAC instances were resolved") # Prepare builders and reporters for RAC and db servers databaseBuilder = db_builder.getBuilderByPlatform(platform) databaseServerReporter = db.TopologyReporter(databaseBuilder) racReporter = db.OracleRacTopologyReporter( db_builder.OracleRacBuilder()) vector = ObjectStateHolderVector() # Report RAC racOsh = racReporter.reportRac(rac) vector.add(racOsh) for server in resolvedServers: # Report each resolved server vector.addAll( databaseServerReporter.reportDatabaseServerFromAddress(server)) # report link between RAC and server vector.add(racReporter.linkRacWithDbServer(racOsh, server.getOsh())) # Report dependency link between datasource and RAC vector.add( modeling.createLinkOSH('depend', datasource.getOsh(), racOsh)) return vector
def process(self, context): webseal_instance_osh = context.application.applicationOsh command_line = self._main_process.commandLine m = re.search('.*-config.+webseald-(\w+)', command_line) if m: logger.debug('Found instance name %s for Webseal Instance' % m.group(1)) webseal_instance_osh.setStringAttribute('name', m.group(1)) config_path = self._parseConfigPath(command_line) if not config_path: logger.warn('Failed to get more info') shell = context.client file_content = self._fetchConfigFileContent(shell, config_path) if not file_content: return master_host = self._parseMasterHostData(file_content) if not master_host: return ip = None if ip_addr.isValidIpAddressNotZero(master_host): ip = master_host else: try: resolver = dns_resolver.create(shell) ips = resolver.resolve_ips(master_host) ip = ips and ips[0] except: logger.debugException('Failed to resolve host name %s' % master_host) if ip: host_osh = modeling.createHostOSH(str(ip)) if host_osh: policy_osh = self.buildPolicyServer(host_osh) link_osh = modeling.createLinkOSH('usage', webseal_instance_osh, policy_osh) vector = context.resultsVector vector.add(host_osh) vector.add(policy_osh) vector.add(link_osh)
def _reportVirtualSwitchBackingInterface(self, switch, domain, vector): if not switch.backingInterfaceName: return hostOsh = domain.getOsh(LdomTopologyReporter._KEY_HOST) switchOsh = switch.getOsh(LdomTopologyReporter._KEY_SWITCH) if hostOsh is None or switchOsh is None: return backingInterfaceOsh = self._virtualSwitchBackingInterfaceBuilder.build(switch) if backingInterfaceOsh is None: return backingInterfaceOsh.setContainer(hostOsh) vector.add(backingInterfaceOsh) switch.setOsh(LdomTopologyReporter._KEY_SWITCH_BACKING_NIC, backingInterfaceOsh) usageLink = modeling.createLinkOSH('usage', switchOsh, backingInterfaceOsh) vector.add(usageLink)
def discoverPlanDbs(self,oshv,plans,dbs): itr = plans.entrySet().iterator() while(itr.hasNext()): entry = itr.next() name = entry.getKey() plan = entry.getValue() try: query = Util.replace(Queries.GET_DATABASE_OF_PLAN,name) rs = self.connection.getTable(query) while(rs.next()): dbName = rs.getString("database_name") db = dbs.get(dbName) if(db is not None): oshv.add(modeling.createLinkOSH('dblink',plan,db)) rs.close() except: logger.debug("couldn't get jobs for plan:", name) return
def report(self, webSphereConfig, resultVector, webServerOsh): self._resolveHostNameToIp(webSphereConfig) for route in webSphereConfig.routes: clusterName = route.clusterName cluster = webSphereConfig.clustersByName.get(clusterName) if not cluster: continue uriGroupName = route.uriGroupName uriGroup = webSphereConfig.uriGroupsByName.get(uriGroupName) for server in cluster.serversByName.values(): for transport in server.transports: if transport.hostIp and transport.port: self._reportDependentWebSphere(server, transport, webServerOsh, resultVector) if uriGroup is not None: for uri in uriGroup.uris: normalizedUri = self._getNormalizedUri( uri.name) if not normalizedUri: continue httpContextOsh = self._createHttpContext( normalizedUri, transport, server.name, webServerOsh) if httpContextOsh is not None: contextConfigOsh = modeling.createConfigurationDocumentOSH( 'httpcontext.txt', '', self._getContextContent( normalizedUri, transport), httpContextOsh) contextConfigLinkOsh = modeling.createLinkOSH( 'usage', httpContextOsh, contextConfigOsh) resultVector.add(contextConfigOsh) resultVector.add(contextConfigLinkOsh) resultVector.add(httpContextOsh)
def _reportBackingDeviceForVolume(self, volume, domain, vector): hostOsh = domain.getOsh(LdomTopologyReporter._KEY_HOST) if hostOsh is None: return volumeOsh = volume.getOsh(LdomTopologyReporter._KEY_VIRTUAL_VOLUME) if volumeOsh is None: return try: backingVolumeOsh = self._virtualVolumeBackingDeviceBuilder.build(volume) backingVolumeOsh.setContainer(hostOsh) vector.add(backingVolumeOsh) volume.setOsh(LdomTopologyReporter._KEY_VIRTUAL_VOLUME_BACKING, backingVolumeOsh) realizationLink = modeling.createLinkOSH('realization', volumeOsh, backingVolumeOsh) vector.add(realizationLink) except ValueError, ex: logger.warn(str(ex))
def start_srvrmgr_discovery(client, ip, port, credentialsId, Framework, OSHVResult): try: logger.debug('connected to gateway') username = client.getUserName() enterprise = client.getEnterprise() srvrmgrPath = client.getServerManagerPath() siebelGatewayOSH = makeSiebelgatewayOSH(client, username, enterprise, srvrmgrPath, credentialsId, ip, port, Framework) siebelsiteOSH = makesiebelsiteOSH(enterprise, credentialsId, ip) enterpriseLink = modeling.createLinkOSH('member', siebelsiteOSH, siebelGatewayOSH) OSHVResult.add(siebelGatewayOSH) OSHVResult.add(siebelsiteOSH) OSHVResult.add(enterpriseLink) except Exception, ex: strException = str(ex.getMessage()) errormessages.resolveAndReport(strException, PROTOCOL_NAME, Framework) logger.debugException('')
def attachToUsers(self, db, users, oshv, dbName=None): if dbName: query = Util.replaceAll(Queries.DATABASE_USERS_DBNAME, dbName) else: query = Queries.DATABASE_USERS rs = None try: rs = self.connection.getTable(query) while (rs.next()): name = rs.getString('name') user = users.get(name) if (user is not None): owner = modeling.createLinkOSH('owner', user, db) oshv.add(owner) rs.close() except: if rs: rs.close() logger.debug("Failed to get database user:", dbName) return