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 buildProcessOsh(self, process): if not process: raise ValueError, "process is empty" #shallow copy to not affect original DO cleanProcess = copy.copy(process) self._sanitizer.sanitize(cleanProcess) processOSH = ObjectStateHolder('process') processOSH.setStringAttribute('name', cleanProcess.getName()) if cleanProcess.commandLine: processOSH.setStringAttribute('process_cmdline', cleanProcess.commandLine) if cleanProcess.getPid() is not None: processOSH.setIntegerAttribute('process_pid', cleanProcess.getPid()) if cleanProcess.executablePath: processOSH.setStringAttribute('process_path', cleanProcess.executablePath) if cleanProcess.argumentLine: processOSH.setStringAttribute('process_parameters', cleanProcess.argumentLine) if cleanProcess.owner: processOSH.setStringAttribute('process_user', cleanProcess.owner) if cleanProcess.getStartupTime() is not None: processOSH.setDateAttribute('process_startuptime', cleanProcess.getStartupTime()) if cleanProcess.description is not None: processOSH.setStringAttribute('data_description', cleanProcess.description) return processOSH
def getStoredProcedureFromDB(self, dbName, container, filterInternal): result = ObjectStateHolderVector() if not self.discoveryOptions.discoverProcedures: return result # if we working with master table need to ignore MSSQL internal storage procedure additionalFilter = "" if filterInternal: additionalFilter = self.__genAdditionalFilter() rs = self.connection.getTable( 'SELECT ROUTINE_NAME, ROUTINE_TYPE, CREATED, LAST_ALTERED FROM [%s].information_schema.routines WHERE routine_type = \'PROCEDURE\'%s' % (dbName, additionalFilter)) while rs.next(): name = rs.getString('ROUTINE_NAME') dba_type = rs.getString('ROUTINE_TYPE') created = rs.getTimestamp('CREATED') last_updated = rs.getTimestamp('LAST_ALTERED') if name: storedProcedure = ObjectStateHolder('dbaobjects') storedProcedure.setContainer(container) storedProcedure.setAttribute('name', name) storedProcedure.setAttribute('dbaobjects_owner', dbName) storedProcedure.setAttribute('dbaobjects_type', dba_type) if created: storedProcedure.setDateAttribute('dbaobjects_created', created) if last_updated: storedProcedure.setDateAttribute('dbaobjects_lastddltime', last_updated) result.add(storedProcedure) return result
def getStoredProcedureFromDB(self, dbName, container, filterInternal): result = ObjectStateHolderVector() if not self.discoveryOptions.discoverProcedures: return result # if we working with master table need to ignore MSSQL internal storage procedure additionalFilter = "" if filterInternal: additionalFilter = self.__genAdditionalFilter() rs = self.connection.getTable('SELECT ROUTINE_NAME, ROUTINE_TYPE, CREATED, LAST_ALTERED FROM [%s].information_schema.routines WHERE routine_type = \'PROCEDURE\'%s' % (dbName, additionalFilter)) while rs.next(): name = rs.getString('ROUTINE_NAME') dba_type = rs.getString('ROUTINE_TYPE') created = rs.getTimestamp('CREATED') last_updated = rs.getTimestamp('LAST_ALTERED') if name: storedProcedure = ObjectStateHolder('dbaobjects') storedProcedure.setContainer(container) storedProcedure.setAttribute('name', name) storedProcedure.setAttribute('dbaobjects_owner', dbName) storedProcedure.setAttribute('dbaobjects_type', dba_type) if created: storedProcedure.setDateAttribute('dbaobjects_created', created) if last_updated: storedProcedure.setDateAttribute('dbaobjects_lastddltime', last_updated) result.add(storedProcedure) return result
def build(self, certificate): ''' Build ssl_certificate OSH from X509Certificate @types: X509Certificate -> ObjectStateHolderVector ''' certOsh = ObjectStateHolder('digital_certificate') certOsh.setDateAttribute("valid_to", certificate.expiresOn) certOsh.setDateAttribute("create_on", certificate.createOn) certOsh.setStringAttribute("issuer", unicode(certificate.issuer.raw)) certOsh.setStringAttribute("subject", unicode(certificate.subject.raw)) certOsh.setStringAttribute("serial_number", certificate.sn) if certificate.version: certOsh.setIntegerAttribute("version", certificate.version) if certificate.signatureAlgorithm: certOsh.setStringAttribute("signature_algorithm", certificate.signatureAlgorithm) if certificate.type: certOsh.setStringAttribute("type", certificate.type) organization = certificate.subject.dn.find_first('O') if organization: certOsh.setStringAttribute("organization", organization.value) organization_unit = certificate.subject.dn.lookup('OU') if organization_unit: ou = map(lambda obj: str(obj.value), organization_unit) certOsh.setListAttribute("organization_unit", ou) cnSubject = certificate.subject.dn.find_first('CN') if cnSubject and cnSubject.value: certOsh.setStringAttribute("common_name", cnSubject.value) cnIssuer = certificate.issuer.dn.find_first('CN') oIssuer = certificate.issuer.dn.find_first('O') issuerName = None if cnIssuer and cnIssuer.value: issuerName = cnIssuer.value else: issuerName = oIssuer and oIssuer.value certOsh.setStringAttribute("issuer_name", issuerName) isSelfSigned = certificate.subject.raw == certificate.issuer.raw certOsh.setBoolAttribute("is_self_signed", isSelfSigned) return certOsh
def doFolderTrees(self): queryBuilder = WmiQueryBuilder('Exchange_FolderTree') queryBuilder.addWmiObjectProperties('Name', 'GUID', 'Description', 'CreationTime', 'RootFolderURL', 'AdministrativeNote', 'AdministrativeGroup') Exchange_FolderTrees = self.wmiAgent.getWmiData(queryBuilder) nameToFolderTree = {} for Exchange_FolderTree in Exchange_FolderTrees: administrativeGroupOsh = ObjectStateHolder( 'exchange_administrative_group') administrativeGroupOsh.setAttribute( 'data_name', Exchange_FolderTree.AdministrativeGroup) administrativeGroupOsh.setContainer(self.exchangeSystemOsh) self.add(administrativeGroupOsh) folderTreeOsh = ObjectStateHolder('ms_exchange_folder_tree') folderTreeOsh.setAttribute('data_name', Exchange_FolderTree.Name) folderTreeOsh.setAttribute('data_description', Exchange_FolderTree.Description) folderTreeOsh.setAttribute('root_folder_url', Exchange_FolderTree.RootFolderURL) folderTreeOsh.setAttribute('administrative_note', Exchange_FolderTree.AdministrativeNote) folderTreeOsh.setAttribute('guid', extractId(Exchange_FolderTree.GUID)) folderTreeOsh.setDateAttribute( 'creation_time', parseDate(Exchange_FolderTree.CreationTime)) folderTreeOsh.setContainer(administrativeGroupOsh) self.add(folderTreeOsh) nameToFolderTree[Exchange_FolderTree.Name] = folderTreeOsh self.doPublicFolders(nameToFolderTree)
def processObjects(allObjects, DateParsePattern): vector = ObjectStateHolderVector() iter = allObjects.iterator() #ciList = [[id, type, props]] ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): #attributes = [name, type, key, value] attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: # add the attributes... allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() attKey = attElement.getAttribute('key') attValue = attElement.getText() if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) # create CI or not? Is key empty or none? if attKey == "true": if attValue != None and attValue != "": createCi = 1 else: createCi = 0 #info (concatenate("Id: ", mamId, ", Type: ", cit, ", Properties: ", attributes)) if createCi == 1: ciList.append([mamId, cit, attributes]) #ciDict[mamId] = [mamId, cit, attributes] #print "MAMID = ", mamId, ", CIT = ", cit, ", Attributes = ", attributes for ciVal in ciList: logger.info("\tAdding %s [%s] => [%s]" % (ciVal[1], ciVal[0], ciVal[2]) ) id = ciVal[0] type = ciVal[1] osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container' and prop[3] != "" and ciDict.has_key(prop[3]): containerOsh = ciDict[prop[3]] createContainer = 1 if prop[1] == 'integer': prop[3] and prop[3].isdigit() and osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'long': prop[3] and prop[3].isdigit() and osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'enum': osh.setEnumAttribute(prop[0], int(prop[3])) elif prop[1] == 'boolean': if str(prop[3]).lower == 'false': osh.setBoolAttribute(prop[0], 0) else: osh.setBoolAttribute(prop[0], 1) elif prop[1] == 'date': if DateParsePattern != None and DateParsePattern != "": formatter = SimpleDateFormat(DateParsePattern) osh.setDateAttribute(prop[0], formatter.parseObject(prop[3])) else: osh.setAttribute(prop[0], prop[3]) if createContainer == 1: osh.setContainer(containerOsh) vector.add(osh) ciDict[id] = osh return (vector, ciDict)
def processObjects(allObjects, DateParsePattern): vector = ObjectStateHolderVector() iter = allObjects.iterator() #ciList = [[id, type, props]] ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): #attributes = [name, type, key, value] attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: # add the attributes... allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() attKey = attElement.getAttribute('key') attValue = attElement.getText() if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) # create CI or not? Is key empty or none? if attKey == "true": if attValue != None and attValue != "": createCi = 1 else: createCi = 0 #info (concatenate("Id: ", mamId, ", Type: ", cit, ", Properties: ", attributes)) if createCi == 1: ciList.append([mamId, cit, attributes]) #ciDict[mamId] = [mamId, cit, attributes] #print "MAMID = ", mamId, ", CIT = ", cit, ", Attributes = ", attributes for ciVal in ciList: logger.info("\tAdding %s [%s] => [%s]" % (ciVal[1], ciVal[0], ciVal[2])) id = ciVal[0] type = ciVal[1] osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container' and prop[ 3] != "" and ciDict.has_key(prop[3]): containerOsh = ciDict[prop[3]] createContainer = 1 if prop[1] == 'integer': prop[3] and prop[3].isdigit() and osh.setIntegerAttribute( prop[0], prop[3]) elif prop[1] == 'long': prop[3] and prop[3].isdigit() and osh.setLongAttribute( prop[0], prop[3]) elif prop[1] == 'enum': osh.setEnumAttribute(prop[0], int(prop[3])) elif prop[1] == 'boolean': if str(prop[3]).lower == 'false': osh.setBoolAttribute(prop[0], 0) else: osh.setBoolAttribute(prop[0], 1) elif prop[1] == 'date': if DateParsePattern != None and DateParsePattern != "": formatter = SimpleDateFormat(DateParsePattern) osh.setDateAttribute(prop[0], formatter.parseObject(prop[3])) else: osh.setAttribute(prop[0], prop[3]) if createContainer == 1: osh.setContainer(containerOsh) vector.add(osh) ciDict[id] = osh return (vector, ciDict)