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 getDistributors(self,oshv,sqlServerId): #is there is a chance that we have more than one distributor? rs = self.connection.doCall(Queries.SERVER_DIST_CALL) distributor = None databaseName = None while rs.next(): name = rs.getString('distributor') if(name is None): rs.close() return None databaseName = rs.getString('distribution database') max = int(rs.getInt('max distrib retention')) min = int(rs.getInt('min distrib retention')) history = int(rs.getInt('history retention')) cleanup = String(rs.getString('history cleanup agent')) idx = cleanup.indexOf('Agent history clean up:') if(idx>=0): cleanup=cleanup.substring(len("Agent history clean up:")) distributor = ObjectStateHolder('sqlserverdistributor') sqlServer = self.createSqlServer(name,oshv,sqlServerId) distributor.setContainer(sqlServer) distributor.setAttribute(Queries.DATA_NAME,name) distributor.setIntegerAttribute('maxTxRetention',max) distributor.setIntegerAttribute('minTxRetention',min) distributor.setIntegerAttribute('historyRetention',history) distributor.setAttribute('cleanupAgentProfile',cleanup) oshv.add(sqlServer) oshv.add(distributor) database = self.getDatabase(sqlServer,databaseName) oshv.add(database) oshv.add(modeling.createLinkOSH('use',distributor,database)) rs.close() if(distributor!=None): logger.debug('we got a distributor') return [distributor,databaseName]
def addsoftwaretoclusterOSH(ClusterOSH, myVec, primarynode_ip, primarynode_name, secondarynode_ip, secondarynode_name, serviceOSH): if primarynode_ip and primarynode_name: PrimaryhostOSH = gethostOSH(primarynode_ip, primarynode_name) priclusterSoftwareOSH = ObjectStateHolder('failoverclustersoftware') priclusterSoftwareOSH.setAttribute('data_name', 'HACMP Cluster Software') priclusterSoftwareOSH.setContainer(PrimaryhostOSH) myVec.add(PrimaryhostOSH) myVec.add(priclusterSoftwareOSH) memberOSH = modeling.createLinkOSH('member', ClusterOSH, priclusterSoftwareOSH) myVec.add(memberOSH) runOSH = modeling.createLinkOSH('run', priclusterSoftwareOSH, serviceOSH) myVec.add(runOSH) potrunOSH = modeling.createLinkOSH('potentially_run', priclusterSoftwareOSH, serviceOSH) myVec.add(potrunOSH) if secondarynode_ip and secondarynode_name: SecondaryhostOSH = gethostOSH(secondarynode_ip, secondarynode_name) secclusterSoftwareOSH = ObjectStateHolder('failoverclustersoftware') secclusterSoftwareOSH.setAttribute('data_name', 'HACMP Cluster Software') secclusterSoftwareOSH.setContainer(SecondaryhostOSH) myVec.add(SecondaryhostOSH) myVec.add(secclusterSoftwareOSH) memberOSH = modeling.createLinkOSH('member', ClusterOSH, secclusterSoftwareOSH) myVec.add(memberOSH) potrunOSH = modeling.createLinkOSH('potentially_run', secclusterSoftwareOSH, serviceOSH) myVec.add(potrunOSH) myVec.add(ClusterOSH) containedOSH = modeling.createLinkOSH('contained', ClusterOSH, serviceOSH) myVec.add(containedOSH) return myVec
def buildDataSourceOsh(self, datasource): r'@types: jdbc.Datasource' datasourceOsh = ObjectStateHolder("jdbcdatasource") datasourceOsh.setAttribute('data_name', datasource.getName()) if datasource.jndiName is not None: datasourceOsh.setAttribute('jdbcdatasource_jndiname', datasource.jndiName) if datasource.driverClass is not None: datasourceOsh.setStringAttribute('jdbcdatasource_drivername', datasource.driverClass) initialCapacity = datasource.initialCapacity maxCapacity = datasource.maxCapacity capacityIncrement = datasource.capacityIncrement if initialCapacity and initialCapacity.value() is not None: datasourceOsh.setIntegerAttribute('jdbcdatasource_initialcapacity', initialCapacity.value()) if maxCapacity and maxCapacity.value() is not None: datasourceOsh.setIntegerAttribute('jdbcdatasource_maxcapacity', maxCapacity.value()) if capacityIncrement and capacityIncrement.value() is not None: datasourceOsh.setIntegerAttribute( 'jdbcdatasource_capacityincrement', capacityIncrement.value()) if datasource.testOnRelease is not None: datasourceOsh.setBoolAttribute( 'jdbcdatasource_testconnectionsonrelease', datasource.testOnRelease) logger.debug('Found datasource ', datasource.getName()) if datasource.url: datasourceOsh.setAttribute('jdbcdatasource_url', datasource.url) datasourceOsh.setAttribute("jdbcdatasource_poolname", datasource.url) else: datasourceOsh.setAttribute("jdbcdatasource_poolname", 'None') return datasourceOsh
def buildLogin(self, login): if not login: raise ValueError('DB User is not specified') osh = ObjectStateHolder('dbuser') if login.getName(): osh.setAttribute('data_name', login.getName()) return osh
def build_osh(self): red_hat_cluster_osh = ObjectStateHolder('red_hat_cluster') red_hat_cluster_osh.setAttribute( AttributeStateHolder('data_name', self.__cluster_name)) red_hat_cluster_osh.setAttribute( AttributeStateHolder('version', self.__cluster_version)) return red_hat_cluster_osh
def build(self): osh = ObjectStateHolder('host_node') osh.setAttribute('host_key', self.hostId) osh.setBoolAttribute('host_iscomplete', 1) setAttribute(osh, 'name', self.__hostname) setAttribute(osh, 'primary_dns_name', self.__fqdn) return osh
class Cluster: '''Data Object represents Service Guard Cluster ''' def __init__(self, name, version, ipAddress, propertiesFileContent, quorumServer=None): r'@types: str, str, str, str, QuorumServer' self.name = name self.version = version self.propertiesFileContent = propertiesFileContent self.ipAddress = ipAddress self.osh = None self.nodes = [] self.packages = [] self.quorumServer = quorumServer def build(self): ''' Creates serviceguardcluster OSH @returns: instance of serviceguardcluster OSH ''' if self.name: self.osh = ObjectStateHolder('serviceguardcluster') self.osh.setAttribute('data_name', self.name) modeling.setAppSystemVendor(self.osh) if self.version: self.osh.setStringAttribute('version', self.version) return self.osh
def buildClusteredMailBox(self, orgOsh, clusteredMailBox): if orgOsh and clusteredMailBox and clusteredMailBox.name: osh = ObjectStateHolder('ms_exchange_clustered_mailbox') osh.setAttribute('data_name', clusteredMailBox.name) osh.setAttribute('name', clusteredMailBox.name) osh.setContainer(orgOsh) return osh
def __buildAsStorageProcessor(self): osh = ObjectStateHolder('storageprocessor') if self.ip and not self.ip == '': osh.setAtribute('storageprocessor_ip', self.ip) osh.setAtribute('storageprocessor_wwn', self.wwn) osh.setAttribute('name', self.name) return osh
class OshBuilder(CiBuilder): def __init__(self, targetCiType): self.__type = targetCiType self.__osh = ObjectStateHolder(self.__type) def setCiAttribute(self, name, value): attributeType = self.__getAttributeType(self.__type, name) self.__setValue(name, attributeType, value) def build(self): return self.__osh def __setValue(self, name, attributeType, value): if attributeType == 'string': self.__osh.setStringAttribute(name, value) elif attributeType == 'integer': self.__osh.setIntegerAttribute(name, int(value)) elif attributeType.endswith('enum'): self.__osh.setAttribute(name, value) else: raise ValueError('no setter defined for type %s' % attributeType) def __getAttributeType(self, ciType, attributeName): #TODO: memoize this function try: attributeDefinition = modeling._CMDB_CLASS_MODEL.getAttributeDefinition(ciType, attributeName) return attributeDefinition.getType() except: logger.errorException("%s.%s" % (ciType, attributeName)) raise ValueError("Failed to determine type of %s.%s" % (ciType, attributeName))
def build(self, fcPort): ''' @param fcPort: fcPort DO @return: fcport OSH ''' if not fcPort: raise ValueError("fcPort object is None") fcPortOsh = ObjectStateHolder("fcport") if fcPort.id is not None: fcPortOsh.setIntegerAttribute("fcport_portid", fcPort.id) if fcPort.index is not None: fcPortOsh.setIntegerAttribute("port_index", fcPort.index) wwnFormated = '' try: wwnFormated = str(wwn.parse_from_str(fcPort.wwn)) except: logger.debug('error about fcPort.wwn: %s' % fcPort.wwn) fcPort.wwn and fcPortOsh.setStringAttribute("fcport_wwn", wwnFormated) fcPort.name and fcPortOsh.setStringAttribute("fcport_symbolicname", fcPort.name) fcPort.status and fcPortOsh.setStringAttribute("fcport_status", fcPort.status) fcPort.state and fcPortOsh.setStringAttribute("fcport_state", fcPort.state) fcPort.portType and fcPortOsh.setStringAttribute("fcport_type", fcPort.portType) if fcPort.maxSpeedGbps is not None: fcPortOsh.setAttribute("fcport_maxspeed", fcPort.maxSpeedGbps) if fcPort.speedGbps is not None: fcPortOsh.setAttribute("fcport_speed", fcPort.speedGbps) return fcPortOsh
def createLayer2Topology(interfaceEnd1, interfaceEnd2): OSHV = ObjectStateHolderVector() end1Node = modeling.createCompleteHostOSH('node', str(interfaceEnd1.xHash)) end2Node = modeling.createCompleteHostOSH('node', str(interfaceEnd2.xHash)) interface1 = modeling.createInterfaceOSH( interfaceEnd1.ifMac, end1Node, interfaceEnd1.ifDescr, interfaceEnd1.ifIndex, interfaceEnd1.ifType, interfaceEnd1.ifAdminStatus, interfaceEnd1.ifOperStatus, interfaceEnd1.ifSpeed, interfaceEnd1.ifName, interfaceEnd1.ifAlias) interface2 = modeling.createInterfaceOSH( interfaceEnd2.ifMac, end2Node, interfaceEnd2.ifDescr, interfaceEnd2.ifIndex, interfaceEnd2.ifType, interfaceEnd2.ifAdminStatus, interfaceEnd2.ifOperStatus, interfaceEnd2.ifSpeed, interfaceEnd2.ifName, interfaceEnd2.ifAlias) layer2Osh = ObjectStateHolder('layer2_connection') layer2Osh.setAttribute( 'layer2_connection_id', str(hash(interfaceEnd1.ifMac + interfaceEnd2.ifMac))) member1 = modeling.createLinkOSH('member', layer2Osh, interface1) member2 = modeling.createLinkOSH('member', layer2Osh, interface2) OSHV.add(end1Node) OSHV.add(end2Node) OSHV.add(interface1) OSHV.add(interface2) OSHV.add(layer2Osh) OSHV.add(member1) OSHV.add(member2) return OSHV
def getClusters(self, clustersParentElement): clusterElList = clustersParentElement.getChildren('Cluster') clusters = [] for clusterEl in clusterElList: tomcatClusterOsh = ObjectStateHolder('tomcatcluster') tomcatClusterOsh.setAttribute('data_name', 'Apache Tomcat Cluster') modeling.setAppSystemVendor(tomcatClusterOsh) mcastAddress = '228.0.0.4' mcastPort = '45564' membership = clusterEl.getChild('Membership') if membership is not None: try: address = membership.getAttributeValue('mcastAddr') mcastAddress = address except: logger.debug( 'Failed to fetch mcast address, using default ', mcastAddress) try: port = membership.getAttributeValue('mcastPort') mcastPort = port except: logger.debug('Failed to fetch mcast port, using default ', mcastPort) tomcatClusterOsh.setAttribute('tomcatcluster_multicastaddress', mcastAddress) tomcatClusterOsh.setIntegerAttribute('tomcatcluster_multicastport', mcastPort) self.OSHVResult.add(tomcatClusterOsh) clusters.append(tomcatClusterOsh) return clusters
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 _addWebApp(self, appName, resourcePath, parentOsh, vHostDir, vHostJdbcOshMap, globalJdbcOshMap): webAppOsh = ObjectStateHolder('webapplication') webAppOsh.setAttribute('data_name', appName) webAppOsh.setAttribute('resource_path', resourcePath) webAppOsh.setContainer(parentOsh) self.OSHVResult.add(webAppOsh) appJdbcOshMap = HashMap(vHostJdbcOshMap) #report context and web config files logger.debug("report context and web config file for web application:", appName) for configFileName in ['context.xml', 'web.xml']: configFileToReport = self.createCF( webAppOsh, resourcePath + self.FileSeparator + "WEB-INF" + self.FileSeparator + configFileName) if configFileToReport: logger.debug( "found config file:", resourcePath + self.FileSeparator + "WEB-INF" + self.FileSeparator + configFileName) self.OSHVResult.add(configFileToReport) appContextPath = vHostDir + appName + '.xml' if len(self.fileMonitor.getFilesInPath(vHostDir, appName + '.xml')) == 1: self.getContextJdbcResouces(appContextPath, appJdbcOshMap, globalJdbcOshMap) for appJdbcOsh in appJdbcOshMap.values(): link = modeling.createLinkOSH('usage', webAppOsh, appJdbcOsh) self.OSHVResult.add(link)
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 DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() credentialsId = Framework.getDestinationAttribute('credentialsId') ip_address = Framework.getDestinationAttribute('ip_address') url = Framework.getDestinationAttribute('name') version = Framework.getDestinationAttribute('version') query_chunk_size = Framework.getParameter('query_chunk_size') organization = Framework.getParameter('organization') logger.debug('UDDI_Registry started query_chunk_size', query_chunk_size, ' organization:', organization, ' credentialsId', credentialsId) properties = Properties() properties.setProperty(UDDIAgent.CHUNK_SIZE,str(query_chunk_size)) properties.setProperty('ORGANIZATION',str(organization)) properties.setProperty('uddi_version', version) try: uddiAgent = Framework.getAgent(AgentConstants.UDDI_AGENT, ip_address, credentialsId, properties) registryOSH = ObjectStateHolder('uddiregistry') registryOSH.setAttribute('name', url) registryOSH.setAttribute('version', int(version)) OSHVResult.add(registryOSH) logger.debug('Do Uddi Explore url:', url) doUddiExplore(uddiAgent, registryOSH, OSHVResult) except MissingSdkJarException, ex: logger.debugException(ex.getMessage()) Framework.reportError("UDDI SDK jars are missed. Refer documentation for details")
def build(self, unitaryComputerSystem): if unitaryComputerSystem is None: raise ValueError("unitaryComputerSystem is None") hypervisorOsh = ObjectStateHolder('virtualization_layer') hypervisorOsh.setStringAttribute('data_name', 'Virtualization Layer Software') hypervisorOsh.setStringAttribute('vendor', 'v_mware_inc') if unitaryComputerSystem.elementName: hypervisorOsh.setAttribute('hypervisor_name', unitaryComputerSystem.elementName) software = unitaryComputerSystem._hypervisorSoftwareIdentity if software: if software.elementName: hypervisorOsh.setStringAttribute('data_description', software.elementName) versionTokens = self._getVersionTokens(software) if versionTokens and versionTokens[0]: shortVersion = ".".join(map(str, versionTokens[:3])) longVersion = ".".join(map(str, versionTokens)) hypervisorOsh.setStringAttribute('version', shortVersion) hypervisorOsh.setStringAttribute('application_version', longVersion) return hypervisorOsh
def getClusters(self, clustersParentElement): clusterElList = clustersParentElement.getChildren('Cluster') clusters = [] for clusterEl in clusterElList: tomcatClusterOsh = ObjectStateHolder('tomcatcluster') tomcatClusterOsh.setAttribute('data_name', 'Apache Tomcat Cluster') modeling.setAppSystemVendor(tomcatClusterOsh) mcastAddress = '228.0.0.4' mcastPort = '45564' membership = clusterEl.getChild('Membership') if membership is not None: try: address = membership.getAttributeValue('mcastAddr') mcastAddress = address except: logger.debug('Failed to fetch mcast address, using default ', mcastAddress) try: port = membership.getAttributeValue('mcastPort') mcastPort = port except: logger.debug('Failed to fetch mcast port, using default ', mcastPort) tomcatClusterOsh.setAttribute('tomcatcluster_multicastaddress', mcastAddress) tomcatClusterOsh.setIntegerAttribute('tomcatcluster_multicastport', mcastPort) self.OSHVResult.add(tomcatClusterOsh) clusters.append(tomcatClusterOsh) return clusters
def createVlanOshv(vlMap, portOshMap): vlanHostOshMap = {} oshv = ObjectStateHolderVector() # process VLANs for (vlanId, vlanObj) in vlMap.items(): ports = vlanObj.ports ports.sort() for portId in ports: if notNull(portOshMap) and portOshMap.has_key(portId): vlanOsh = ObjectStateHolder('vlan') vlanOsh.setIntegerAttribute('vlan_number', int(vlanObj.vlanId)) vlanOsh.setAttribute('vlan_aliasname', vlanObj.name) vlanOsh.setAttribute('data_name', vlanObj.vlanId) if vlanHostOshMap.has_key(vlanObj.vlanId): hostOsh = vlanHostOshMap[vlanObj.vlanId] else: hostOsh = portOshMap[portId].getAttributeValue('root_container') oshv.add(vlanOsh) vlanHostOshMap[vlanObj.vlanId] = hostOsh vlanOsh.setContainer(hostOsh) membershipLink = modeling.createLinkOSH("member", portOshMap[portId], vlanOsh) oshv.add(membershipLink) return oshv
def makeUserOSH(hostCmdbId, userName, desc, uid, gid, homeDir): 'host OSH, str, str, str, str, str -> OSH vector' iuid = -1 igid = -1 try: iuid = Long(uid) except: iuid = -1 try: igid = Long(gid) except: igid = -1 myVec = ObjectStateHolderVector() u_obj = ObjectStateHolder('osuser') host_objSH = modeling.createOshByCmdbIdString('host', hostCmdbId) u_obj.setContainer(host_objSH) u_obj.setAttribute('data_name', userName) if (len(uid) > 0): u_obj.setAttribute('user_id', Long(iuid)) if (len(gid) > 0): u_obj.setAttribute('group_id', Long(igid)) if (len(desc) > 0): u_obj.setAttribute('data_note', desc) if (len(homeDir) > 0): u_obj.setAttribute('homedir', homeDir) myVec.add(u_obj) return (myVec)
def getDistributors(self, oshv, sqlServerId): #is there is a chance that we have more than one distributor? rs = self.connection.doCall(Queries.SERVER_DIST_CALL) distributor = None databaseName = None while rs.next(): name = rs.getString('distributor') if (name is None): rs.close() return None databaseName = rs.getString('distribution database') max = int(rs.getInt('max distrib retention')) min = int(rs.getInt('min distrib retention')) history = int(rs.getInt('history retention')) cleanup = String(rs.getString('history cleanup agent')) idx = cleanup.indexOf('Agent history clean up:') if (idx >= 0): cleanup = cleanup.substring(len("Agent history clean up:")) distributor = ObjectStateHolder('sqlserverdistributor') sqlServer = self.createSqlServer(name, oshv, sqlServerId) distributor.setContainer(sqlServer) distributor.setAttribute(Queries.DATA_NAME, name) distributor.setIntegerAttribute('maxTxRetention', max) distributor.setIntegerAttribute('minTxRetention', min) distributor.setIntegerAttribute('historyRetention', history) distributor.setAttribute('cleanupAgentProfile', cleanup) oshv.add(sqlServer) oshv.add(distributor) database = self.getDatabase(sqlServer, databaseName) oshv.add(database) oshv.add(modeling.createLinkOSH('use', distributor, database)) rs.close() if (distributor != None): logger.debug('we got a distributor') return [distributor, databaseName]
def getCICSRegions(ls, subsystemOSH): regiondict = {} str_name = 'name' if UCMDB_VERSION < 9: str_name = 'data_name' vector = ObjectStateHolderVector() # Get the active jobs running on the lpar # Look for the program name , if it is DFHSIP then we have found an active CICS job # The job name is the CICS region output = ls.evSysInfoCmd(_CMD_F_ALL_JOBS,'40') if output.isSuccess() and len(output.cmdResponseList) > 0: for line in output.cmdResponseList: if isNotNull(line): splitline = line.split('|') if len(splitline) == 10: if splitline[9] == 'DFHSIP': region = splitline[0].strip() #logger.debug ('Found region ===> ',region) cicsRegionOSH = ObjectStateHolder('cics_region') cicsRegionOSH.setAttribute(str_name, region) cicsRegionOSH.setContainer(subsystemOSH) addInfoOnRegions(ls, cicsRegionOSH) if not(regiondict.has_key(region)): regiondict[region] = cicsRegionOSH vector.add(cicsRegionOSH) return vector, regiondict
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 _buildWorkProcess(name, numberOfWorkingProcesses): '@types: str, digit -> osh' osh = ObjectStateHolder("sap_work_process") osh.setAttribute("data_name", name) if str(numberOfWorkingProcesses).isdigit(): osh.setAttribute("number_wp", int(numberOfWorkingProcesses)) return osh
def build_network_device(device): ''' Build Layer 2 connection end. @type param: NetworkDevice -> OSH ''' device_osh = None device_ip_address_osh = None device_interface_osh = None device_member_ip = None if device.ucmdb_id: device_osh = modeling.createOshByCmdbIdString('node', device.ucmdb_id) if device.mac_address: if not device_osh: device_osh = modeling.createCompleteHostOSH('node', device.mac_address) device_interface_osh = modeling.createInterfaceOSH(device.mac_address, device_osh) if device.ip_address: if not device_osh: device_osh = modeling.createHostOSH(device.ip_address) device_ip_address_osh = modeling.createIpOSH(device.ip_address) device_member_ip = modeling.createLinkOSH('contained', device_osh, device_ip_address_osh) if device.port: if device_interface_osh: device_interface_osh.setAttribute('interface_name', device.port) elif device_osh: device_interface_osh = ObjectStateHolder('interface') device_interface_osh.setContainer(device_osh) device_interface_osh.setAttribute('interface_name', device.port) return device_osh, device_ip_address_osh, device_interface_osh, device_member_ip
class OshBuilder(CiBuilder): def __init__(self, targetCiType): self.__type = targetCiType self.__osh = ObjectStateHolder(self.__type) def setCiAttribute(self, name, value): attributeType = self.__getAttributeType(self.__type, name) self.__setValue(name, attributeType, value) def build(self): return self.__osh def __setValue(self, name, attributeType, value): if attributeType == 'string': self.__osh.setStringAttribute(name, value) elif attributeType == 'integer': self.__osh.setIntegerAttribute(name, int(value)) elif attributeType.endswith('enum'): self.__osh.setAttribute(name, value) else: raise ValueError('no setter defined for type %s' % attributeType) def __getAttributeType(self, ciType, attributeName): #TODO: memoize this function try: attributeDefinition = modeling._CMDB_CLASS_MODEL.getAttributeDefinition( ciType, attributeName) return attributeDefinition.getType() except: logger.errorException("%s.%s" % (ciType, attributeName)) raise ValueError("Failed to determine type of %s.%s" % (ciType, attributeName))
def getPublishersFromDistributor(self,oshv,distributor, distributorDatabaseName,sqlServerId): #check if i am a distributor first rs = self.connection.doCall('exec sp_helpdistpublisher') publishers = HashMap() sqlServers = HashMap() while(rs.next()): publisherName = rs.getString('name') publisher = ObjectStateHolder('sqlserverpublisher') sqlServer = self.createSqlServer(publisherName,oshv,sqlServerId) publisher.setContainer(sqlServer) publisher.setAttribute(Queries.DATA_NAME,publisherName) publishers.put(publisherName,publisher) sqlServers.put(publisherName,sqlServer) oshv.add(sqlServer) oshv.add(publisher) oshv.add(modeling.createLinkOSH('dblink',publisher,distributor)) #add the dblink between the distributor and the publisher rs.close() if(publishers.size() == 0): return #for each publisher get the published dbs workingDatabase = self.connection.getWorkingDatabase() self.connection.setWorkingDatabase(distributorDatabaseName) itr = publishers.keySet().iterator() while (itr.hasNext()): publisherName = itr.next() publisher = publishers.get(publisherName) sqlServer = sqlServers.get(publisherName) self.getPublications(publisherName,sqlServer,publisher,oshv,sqlServerId) self.connection.setWorkingDatabase(workingDatabase)
def build_network_device(device): ''' Build Layer 2 connection end. @type param: NetworkDevice -> OSH ''' device_osh = None device_ip_address_osh = None device_interface_osh = None device_member_ip = None if device.ucmdb_id: device_osh = modeling.createOshByCmdbIdString('node', device.ucmdb_id) if device.mac_address: if not device_osh: device_osh = modeling.createCompleteHostOSH( 'node', device.mac_address) device_interface_osh = modeling.createInterfaceOSH( device.mac_address, device_osh) if device.ip_address: if not device_osh: device_osh = modeling.createHostOSH(device.ip_address) device_ip_address_osh = modeling.createIpOSH(device.ip_address) device_member_ip = modeling.createLinkOSH('contained', device_osh, device_ip_address_osh) if device.port: if device_interface_osh: device_interface_osh.setAttribute('interface_name', device.port) elif device_osh: device_interface_osh = ObjectStateHolder('interface') device_interface_osh.setContainer(device_osh) device_interface_osh.setAttribute('interface_name', device.port) return device_osh, device_ip_address_osh, device_interface_osh, device_member_ip
def _create_osh(self, parent_osh): osh = ObjectStateHolder('sap_process_step') osh.setAttribute('data_name', self.__name) if self.__component: osh.setAttribute('logical_component', self.__component) osh.setContainer(parent_osh) return osh
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() credentialsId = Framework.getDestinationAttribute('credentialsId') ip_address = Framework.getDestinationAttribute('ip_address') url = Framework.getDestinationAttribute('name') version = Framework.getDestinationAttribute('version') query_chunk_size = Framework.getParameter('query_chunk_size') organization = Framework.getParameter('organization') logger.debug('UDDI_Registry started query_chunk_size', query_chunk_size, ' organization:', organization, ' credentialsId', credentialsId) properties = Properties() properties.setProperty(UDDIAgent.CHUNK_SIZE, str(query_chunk_size)) properties.setProperty('ORGANIZATION', str(organization)) properties.setProperty('uddi_version', version) try: uddiAgent = Framework.getAgent(AgentConstants.UDDI_AGENT, ip_address, credentialsId, properties) registryOSH = ObjectStateHolder('uddiregistry') registryOSH.setAttribute('name', url) registryOSH.setAttribute('version', int(version)) OSHVResult.add(registryOSH) logger.debug('Do Uddi Explore url:', url) doUddiExplore(uddiAgent, registryOSH, OSHVResult) except MissingSdkJarException, ex: logger.debugException(ex.getMessage()) Framework.reportError( "UDDI SDK jars are missed. Refer documentation for details")
def discoverReplication(self, mysqlOsh): """ Tries to find config variables related to mysql replication @param ObjectStateHolder mysqlOsh mysql osh @return list list of OSHs """ masterHostIp = self.getProperty('master-host') if not masterHostIp: return if not netutils.isValidIp(masterHostIp): try: resolver = netutils.DnsResolverByShell(self.shell) masterHostIp = resolver.resolveIpsByHostname(masterHostIp)[0] except netutils.ResolveException: logger.warn('Failed to resolve Master Host into IP') return masterPort = self.getProperty('master-port') mysqlReplicationOsh = ObjectStateHolder('mysql_replication') mysqlReplicationOsh.setAttribute('data_name', 'MySQL Replication') mysqlReplicationOsh.setContainer(mysqlOsh) self.setAttribute(mysqlReplicationOsh, 'master_user', self.REPL_ARGS_MAPPING) self.setAttribute(mysqlReplicationOsh, 'master_connect_retry', self.REPL_ARGS_MAPPING) masterHostOsh = modeling.createHostOSH(masterHostIp) serviceAddressOsh = modeling.createServiceAddressOsh(masterHostOsh, masterHostIp, masterPort, modeling.SERVICEADDRESS_TYPE_TCP) clientServerLink = modeling.createLinkOSH('client_server', mysqlReplicationOsh, serviceAddressOsh) clientServerLink.setStringAttribute('clientserver_protocol', 'TCP') clientServerLink.setLongAttribute('clientserver_destport', int(masterPort)) # masterMysqlOsh = modeling.createDatabaseOSH('mysql', 'MySQL. Port ' + masterPort, masterPort, masterHostIp, masterHostOsh) # useLink = modeling.createLinkOSH('use', masterHostOsh, serviceAddressOsh) return [masterHostOsh, serviceAddressOsh, clientServerLink, mysqlReplicationOsh]
def discoverITS(client, installpath, WEBSERVER_ID, OSHVResult): shellUtils = ShellUtils(client) webserverOSH = modeling.createOshByCmdbIdString('webserver', WEBSERVER_ID) sapitsOSH = ObjectStateHolder('sap_its_wgate') sapitsOSH.setAttribute('data_name', 'ITS_' + client.getIpAddress()) sapitsOSH.setContainer(webserverOSH) OSHVResult.add(sapitsOSH) mapInstanceNameToAgate = getAgates(shellUtils, installpath, sapitsOSH, OSHVResult) filePath = installpath + '\\config\\ItsRegistryALL.xml' data = shellUtils.safecat(filePath) logger.debug('got ItsRegistryALL file') # data = stripNtcmdHeaders(data) if data == None or error(data): logger.error('No data found') else: builder = SAXBuilder(0) doc = builder.build(StringReader(data)) root = doc.getRootElement() keyElem = getElementByAttrValue(root, 'key', 'name', 'AGate') instancesRoot = getElementByAttrValue(keyElem, 'key', 'name', 'Instances') instances = instancesRoot.getChildren('value') it = instances.iterator() while it.hasNext(): instance = it.next() name = instance.getText() agates = mapInstanceNameToAgate.get(name) if agates != None and agates.isEmpty() == 0: servers(name, installpath, sapitsOSH, agates, shellUtils, OSHVResult)
def createOshFromId(ciDict, id, ciClass=None): osh = None object = ciDict[id] # create the container osh if object != None: id = object[0] type = object[1] props = object[2] ciid = object[3] if type in host_types: real_ci_class = ciClass or type osh = modeling.createOshByCmdbId(real_ci_class, ciid) else: osh = ObjectStateHolder(type) if props != None: for prop in props: if prop[1] == 'Integer': osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'Long': osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'Enum': osh.setEnumAttribute(prop[0], int(prop[3])) else: osh.setAttribute(prop[0], prop[3]) return osh
def DiscoveryMain(Framework): credentialsId = Framework.getDestinationAttribute('credentialsId') OSHVResult = ObjectStateHolderVector() matchers = SiebelAgent.SIEBEL_DEFAULT_ENTERPRISE_MATCHERS ip = Framework.getDestinationAttribute('ip_address') port = Framework.getDestinationAttribute('port') if port == 'NA': port = None try: client = None try: client = siebel_common.createClient(Framework, ip, matchers, credentialsId, port) username = client.getUserName() enterprise = client.getEnterprise() siteOSH = ObjectStateHolder('siebel_site') siteOSH.setAttribute('data_name', enterprise) siteOSH.setAttribute('gateway_address', ip) modeling.setAppSystemVendor(siteOSH) start_srvrmgr_discovery(client, ip, username, enterprise, siteOSH, Framework, OSHVResult) finally: if client is not None: client.close() except Exception, ex: strException = str(ex.getMessage()) errormessages.resolveAndReport(strException, PROTOCOL_NAME, Framework) logger.debugException('')
def createOshFromId(ciDict, id, ciClass = None): osh = None object = ciDict[id] # create the container osh if object != None: id = object[0] type = object[1] props = object[2] ciid = object[3] if type in host_types: real_ci_class = ciClass or type osh = modeling.createOshByCmdbId(real_ci_class, ciid) else: osh = ObjectStateHolder(type) if props != None: for prop in props: if prop[1] == 'Integer': osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'Long': osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'Enum': osh.setEnumAttribute(prop[0], int(prop[3])) else: osh.setAttribute(prop[0], prop[3]) return osh
def buildDataSourceOsh(self, datasource): r'@types: jdbc.Datasource' datasourceOsh = ObjectStateHolder("jdbcdatasource") datasourceOsh.setAttribute('data_name', datasource.getName()) if datasource.jndiName is not None: datasourceOsh.setAttribute('jdbcdatasource_jndiname', datasource.jndiName) if datasource.driverClass is not None: datasourceOsh.setStringAttribute('jdbcdatasource_drivername', datasource.driverClass) initialCapacity = datasource.initialCapacity maxCapacity = datasource.maxCapacity capacityIncrement = datasource.capacityIncrement if initialCapacity and initialCapacity.value() is not None: datasourceOsh.setIntegerAttribute('jdbcdatasource_initialcapacity', initialCapacity.value()) if maxCapacity and maxCapacity.value() is not None: datasourceOsh.setIntegerAttribute('jdbcdatasource_maxcapacity',maxCapacity.value()) if capacityIncrement and capacityIncrement.value() is not None: datasourceOsh.setIntegerAttribute('jdbcdatasource_capacityincrement', capacityIncrement.value()) if datasource.testOnRelease is not None: datasourceOsh.setBoolAttribute('jdbcdatasource_testconnectionsonrelease', datasource.testOnRelease) logger.debug('Found datasource ', datasource.getName()) if datasource.url: datasourceOsh.setAttribute('jdbcdatasource_url', datasource.url) datasourceOsh.setAttribute("jdbcdatasource_poolname", datasource.url) else: datasourceOsh.setAttribute("jdbcdatasource_poolname", 'None') return datasourceOsh
def build_osh(self): clustered_file_system_osh = ObjectStateHolder('clustered_file_system') clustered_file_system_osh.setAttribute( AttributeStateHolder('serial_number', self.__uuid)) clustered_file_system_osh.setAttribute( AttributeStateHolder('name', self.__fs_name)) return clustered_file_system_osh
def build(self, domain): if domain is None: raise ValueError("domain is None") ldomConfigOsh = ObjectStateHolder("ldom_config") ldomConfigOsh.setAttribute("name", "LDOM Config") if domain.getName() is not None: ldomConfigOsh.setStringAttribute("ldom_name", domain.getName()) if domain.getMac() is not None: ldomConfigOsh.setStringAttribute("ldom_mac", domain.getMac()) if domain.hostId: ldomConfigOsh.setStringAttribute("ldom_hostid", domain.hostId) if domain.getUuid(): ldomConfigOsh.setStringAttribute("ldom_uuid", domain.getUuid()) ldomConfigOsh.setStringAttribute("ldom_state", domain.state.value().value()) ldomConfigOsh.setIntegerAttribute("ldom_ncpu", domain.ncpu.value()) if domain.memorySize.value() is not None: memorySizeMegabytes = int(domain.memorySize.value() / (1024 * 1024)) ldomConfigOsh.setIntegerAttribute("ldom_memory_size", int(memorySizeMegabytes)) if domain.roles.has(ldom.Domain.ROLE_CONTROL): ldomConfigOsh.setBoolAttribute("ldom_is_control", 1) if domain.roles.has(ldom.Domain.ROLE_IO): ldomConfigOsh.setBoolAttribute("ldom_is_io", 1) if domain.failurePolicy: ldomConfigOsh.setStringAttribute("ldom_failure_policy", domain.failurePolicy) return ldomConfigOsh
def buildUserOsh(self, user): r'@types: db.User -> ObjectStateHolder(dbuser)' osh = ObjectStateHolder('dbuser') osh.setAttribute('name', user.name) user.creationDate and osh.setAttribute('dbuser_created', user.creationDate) return osh
def makeUserOSH(hostCmdbId, userName, desc, uid, gid, homeDir): 'host OSH, str, str, str, str, str -> OSH vector' iuid = -1 igid = -1 try: iuid = Long(uid) except: iuid = -1 try: igid = Long(gid) except: igid = -1 myVec = ObjectStateHolderVector() u_obj = ObjectStateHolder('osuser') host_objSH = modeling.createOshByCmdbIdString('host', hostCmdbId) u_obj.setContainer(host_objSH) u_obj.setAttribute('data_name', userName) if(len(uid) > 0): u_obj.setAttribute('user_id', Long(iuid)) if(len(gid) > 0): u_obj.setAttribute('group_id', Long(igid)) if(len(desc) > 0): u_obj.setAttribute('data_note', desc) if(len(homeDir) > 0): u_obj.setAttribute('homedir', homeDir) myVec.add(u_obj) return(myVec)
def osh_createDb2Tablespace(db2SubsystemOsh, tb): str_name = 'name' if UCMDB_VERSION < 9: str_name = 'data_name' if isNotNull(tb) and isNotNull(tb[0]): tbOsh = ObjectStateHolder('mainframe_db2_tablespace') tbOsh.setAttribute(str_name, tb[0]) tbOsh.setAttribute('dbtablespace_status', tb[1]) tbOsh.setAttribute('type', tb[2]) tbOsh.setAttribute('encoding_scheme', tb[3]) tbOsh.setAttribute('dbtablespace_initialextent', tb[4]) if isNotNull(tb[5]) and isnumeric(tb[5]): tbOsh.setIntegerAttribute('max_dataset_size', int(tb[5])) if isNotNull(tb[6]) and isnumeric(tb[6]): tbOsh.setIntegerAttribute('number_tables', int(tb[6])) if isNotNull(tb[7]) and isnumeric(tb[7]): tbOsh.setIntegerAttribute('number_partitions', int(tb[7])) try: if len(tb[8]) > 19: tb[8] = tb[8][0:18] created = modeling.getDateFromString(tb[8], 'yyyy-MM-dd-kk.mm.ss', None) tbOsh.setDateAttribute('create_date', created) except: logger.debug("Ignoring create_date. Unable to parse date string") tbOsh.setContainer(db2SubsystemOsh) return tbOsh return None
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 getPublishersFromDistributor(self, oshv, distributor, distributorDatabaseName, sqlServerId): #check if i am a distributor first rs = self.connection.doCall('exec sp_helpdistpublisher') publishers = HashMap() sqlServers = HashMap() while (rs.next()): publisherName = rs.getString('name') publisher = ObjectStateHolder('sqlserverpublisher') sqlServer = self.createSqlServer(publisherName, oshv, sqlServerId) publisher.setContainer(sqlServer) publisher.setAttribute(Queries.DATA_NAME, publisherName) publishers.put(publisherName, publisher) sqlServers.put(publisherName, sqlServer) oshv.add(sqlServer) oshv.add(publisher) oshv.add(modeling.createLinkOSH('dblink', publisher, distributor)) #add the dblink between the distributor and the publisher rs.close() if (publishers.size() == 0): return #for each publisher get the published dbs workingDatabase = self.connection.getWorkingDatabase() self.connection.setWorkingDatabase(distributorDatabaseName) itr = publishers.keySet().iterator() while (itr.hasNext()): publisherName = itr.next() publisher = publishers.get(publisherName) sqlServer = sqlServers.get(publisherName) self.getPublications(publisherName, sqlServer, publisher, oshv, sqlServerId) self.connection.setWorkingDatabase(workingDatabase)
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 build(self, domain): if domain is None: raise ValueError("domain is None") ldomConfigOsh = ObjectStateHolder('ldom_config') ldomConfigOsh.setAttribute('name', "LDOM Config") if domain.getName() is not None: ldomConfigOsh.setStringAttribute('ldom_name', domain.getName()) if domain.getMac() is not None: ldomConfigOsh.setStringAttribute('ldom_mac', domain.getMac()) if domain.hostId: ldomConfigOsh.setStringAttribute('ldom_hostid', domain.hostId) if domain.getUuid(): ldomConfigOsh.setStringAttribute('ldom_uuid', domain.getUuid()) ldomConfigOsh.setStringAttribute('ldom_state', domain.state.value().value()) ldomConfigOsh.setIntegerAttribute('ldom_ncpu', domain.ncpu.value()) if domain.memorySize.value() is not None: memorySizeMegabytes = int(domain.memorySize.value() / (1024*1024)) ldomConfigOsh.setIntegerAttribute('ldom_memory_size', int(memorySizeMegabytes)) if domain.roles.has(ldom.Domain.ROLE_CONTROL): ldomConfigOsh.setBoolAttribute("ldom_is_control", 1) if domain.roles.has(ldom.Domain.ROLE_IO): ldomConfigOsh.setBoolAttribute("ldom_is_io", 1) if domain.failurePolicy: ldomConfigOsh.setStringAttribute("ldom_failure_policy", domain.failurePolicy) return ldomConfigOsh