def testScript(): userExtUcmdbDir = 'E:\\data\\Desktop\\Pull_From_Remedy_backup\\' + 'TQLExport\\Atrium\\' inputFilesDirectory = File(userExtUcmdbDir + 'inter\\') inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + 'results\\' directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if (files != None): for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName) - 4:].lower() == '.xml' and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn( 'Intermediate XML not found or invalid. Perhaps no data was received from Atrium or an error occurred in the atrium_query script.' ) return ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir)
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 DiscoveryMain(Framework): logger.info('Start Phase 2 ....Apply Mapping file to ARIS CIs') userExtUcmdbDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + '\\TQLExport\\ARIS\\' inputFilesDirectory = File(userExtUcmdbDir + 'inter\\') inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + 'results\\' directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if (files != None): for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName)-4:].lower() == '.xml' and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn('Intermediate XML not found or invalid. Perhaps no data was received from ARIS or an error occurred in the Pull_from_ARIS script.') return ## Connect to the UCMDB Server, retrieve the results of the TQL ## and generate the output XML files in results directory ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir) logger.info('End Phase 2 ....Apply Mapping file to ARIS CIs')
def DiscoveryMain(Framework): fileSeparator = File.separator # Destination Data userExtUcmdbDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + fileSeparator + 'TQLExport' + fileSeparator + 'hpsim' + fileSeparator inputFilesDirectory = File(userExtUcmdbDir + 'inter' + fileSeparator) inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + 'results' + fileSeparator directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if (files != None): for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName)-4:].lower() == '.xml' and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn('Intermediate XML not found or invalid. Perhaps no data was received from SIM or an error occurred in the SIM_Discovery script.') return ## Connect to the UCMDB Server, retrieve the results of the TQL ## and generate the output XML files in results directory ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir) info('End exportTQL_for_SIM_to_UCMDB.py')
def DiscoveryMain(Framework): logger.info('Start Phase 2 ... Apply Mapping transformation to Atrium CIs') userExtUcmdbDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + '\\TQLExport\\Atrium\\' inputFilesDirectory = File(userExtUcmdbDir + 'inter\\') inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + 'results\\' directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if (files != None): for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName)-4:].lower() == '.xml' and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn('Intermediate XML not found or invalid. Perhaps no data was received from Atrium or an error occurred in the atrium_query script.') return ## Generate the output XML files in results directory ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) integrationAPI = IntegrationAPI(ip, "atrium_map.py") integrationAPI.processDir(userExtUcmdbDir) logger.info('End Phase 2 ... Apply Mapping transformation to Atrium CIs')
def createCMDBConnection(i__LocalShell): logger.info('************* START createCMDBConnection *************') l__HostName = CollectorsParameters.getValue( CollectorsParameters.KEY_SERVER_NAME) l__HTTPPort = int( CollectorsParameters.getValue( CollectorsParameters.KEY_SERVER_PORT_HTTP)) l__HTTPSPort = int( CollectorsParameters.getValue( CollectorsParameters.KEY_SERVER_PORT_HTTPS)) l__ProtocolParameters = ProtocolDictionaryManager.getProtocolParameters( 'genericprotocol', netutils.resolveIP(i__LocalShell, l__HostName)) l__UserName = '' for l__Protocol in l__ProtocolParameters: if l__Protocol.getProtocolAttribute( 'protocol_username') == C__INTEGRATION_USER: l__UserName = l__Protocol.getProtocolAttribute('protocol_username') l__UserPassword = l__Protocol.getProtocolAttribute( 'protocol_password') break if not l__UserName: logger.error('Error Username Protocol not initialized') return None #logger.debug('Accessing uCMDB = ',(l__HostName, l__HTTPPort, l__UserName)) # try http first try: logger.debug('Attempting HTTP connection') l__Provider = UcmdbServiceFactory.getServiceProvider( 'http', l__HostName, l__HTTPPort) except: logger.debug('HTTP connection failed, trying HTTPS') UcmdbServiceFactory.initSSL() l__Provider = UcmdbServiceFactory.getServiceProvider( 'https', l__HostName, l__HTTPSPort) l__Credentials = l__Provider.createCredentials(l__UserName, l__UserPassword) l__ClientContext = l__Provider.createClientContext("UD") o__UcmdbService = l__Provider.connect(l__Credentials, l__ClientContext) logger.info('************* END createCMDBConnection *************') return o__UcmdbService
def DiscoveryMain(Framework): logger.info('Start ', SCRIPT_NAME) logger.info('Start Phase 1 ... Query Remedy Atrium for data') # dryrunMode = Framework.getParameter('DryRunMode') # Get BMC Namespace bmcNamespace = Framework.getParameter('BMC_NameSpace') if bmcNamespace == None or bmcNamespace == "": bmcNamespace = "BMC.CORE" # Get chunk size - size of data in every query to Remedy/Atrium maxPerCall = Framework.getParameter('ChunkSize') if maxPerCall != None and maxPerCall.isnumeric(): maxPerCall = int(maxPerCall) else: maxPerCall = 500 # Get MAX CI size - size of data in every query to Remedy/Atrium maxCIs = Framework.getParameter('MaxCIs') if maxCIs != None and maxCIs.isnumeric(): maxCIs = int(maxCIs) else: maxCIs = 100000 ucmdbServerIp = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) # File and directory names userExtDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + '\\TQLExport\\Atrium\\' intermediatesDir = userExtDir + 'inter\\' mapingFilesListFileName = userExtDir + 'tqls.txt' mappingFileNameList = checkDiscoveryResources(mapingFilesListFileName, userExtDir, Framework, intermediatesDir) if not mappingFileNameList: return None # GET ARS context - login information, etc. that is needed to make ARS connection context = getArsContext(Framework, ucmdbServerIp) if context != None: for mappingFileName in mappingFileNameList: (classList, linkList) = getMapping(userExtDir + 'data\\' + mappingFileName + '.xml', bmcNamespace, ucmdbServerIp) if (dryrunMode != None): dryrunMode = dryrunMode.lower() if dryrunMode == 'true': logger.info('[NOTE] UCMDB Integration is running in DryRun Mode, No query executed against ATRIUM.') debugPrint(4, '[' + SCRIPT_NAME + ':DiscoveryMain] Got classList: <%s>' % classList) debugPrint(4, '[' + SCRIPT_NAME + ':DiscoveryMain] Got linkList: <%s>' % linkList) return pullDataFromAtrium(context, classList, linkList, maxPerCall, maxCIs, intermediatesDir, mappingFileName) else: logger.error("Unable to create Remedy/Atrium login context. Check that username, password, server and port are defined correctly.") return None logger.info('End ', SCRIPT_NAME)
def osh_createIpOsh(iSeriesOsh, defaultIp): _vector = ObjectStateHolderVector() # Create IP OSH ------------------------------------ ipOsh = modeling.createIpOSH(defaultIp) ipOsh.setAttribute('ip_probename', CollectorsParameters.getValue(CollectorsParameters.KEY_COLLECTORS_PROBE_NAME)) _vector.add(ipOsh) _vector.add(iSeriesOsh) linkOsh = modeling.createLinkOSH('containment', iSeriesOsh, ipOsh) _vector.add(linkOsh) return _vector
def checkLock(Framework): probe = CollectorsParameters.getValue(CollectorsParameters.KEY_PROBE_MGR_IP) if (probe is None) or (len(str(probe)) == 0): logger.debug('Probe manager ip is not specified in the DiscoveryProbe.properties file, using probe ID') probe = CollectorsParameters.getValue(CollectorsParameters.KEY_COLLECTORS_PROBE_NAME) jobType = INVENTORY_JOB_TYPE jobId = Framework.getDiscoveryJobId() lockTime = System.currentTimeMillis() lockExpiration = System.currentTimeMillis() + LOCK_AGE_PERIOD_MILLISECONDS lock = Lock(probe, jobType, jobId, lockTime, lockExpiration) logger.debug('Checking remote lock with current lock:', str(lock.getLockInfo())) triggerid = Framework.getTriggerCIData('id') logger.debug('Checking lock for probe ', probe, ' and jobid ', jobId, ' and triggerid ', triggerid) client = Framework.getConnectedClient() options = getClientOptionsMap(client) lockOption = options.get(ScannerNodeLock) if (lockOption is None) or (len(lockOption.strip()) == 0): logger.debug('Lock on scanner node for probe "' + lock.probe + '" and job "' + lock.jobId + '" is not exists') return 0 remoteLock = extractLock(lockOption) logger.debug('Found remote lock:', str(remoteLock.getLockInfo())) if remoteLock.isLockExpired(): logger.debug('Lock on remote node is already expired, renewing lock on the node') options = HashMap() options.put(ScannerNodeLock, lock.getLockInfo()) client.setOptionsMap(options) elif not lock.isSameLock(remoteLock): logger.debug( 'Lock on remote node is owned by another probe/job (' + remoteLock.probe + '/' + remoteLock.jobId + ')') if remoteLock.jobType == CALLHOME_JOB_TYPE: return ScannerNodeLockedByCallHome return 0 return 1
def osh_createIpOsh(iSeriesOsh, defaultIp): _vector = ObjectStateHolderVector() # Create IP OSH ------------------------------------ ipOsh = modeling.createIpOSH(defaultIp) ipOsh.setAttribute( 'ip_probename', CollectorsParameters.getValue( CollectorsParameters.KEY_COLLECTORS_PROBE_NAME)) _vector.add(ipOsh) _vector.add(iSeriesOsh) linkOsh = modeling.createLinkOSH('containment', iSeriesOsh, ipOsh) _vector.add(linkOsh) return _vector
def DiscoveryMain(Framework): logger.info("Start Phase 2 ....Apply Mapping file to ARIS CIs") userExtUcmdbDir = ( CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + "\\TQLExport\\ARIS\\" ) inputFilesDirectory = File(userExtUcmdbDir + "inter\\") inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + "results\\" directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if files != None: for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName) - 4 :].lower() == ".xml" and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn( "Intermediate XML not found or invalid. Perhaps no data was received from ARIS or an error occurred in the Pull_from_ARIS script." ) return ## Connect to the UCMDB Server, retrieve the results of the TQL ## and generate the output XML files in results directory ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir) logger.info("End Phase 2 ....Apply Mapping file to ARIS CIs")
def testScript(): userExtUcmdbDir = 'E:\\data\\Desktop\\Pull_From_Remedy_backup\\' + 'TQLExport\\Atrium\\' inputFilesDirectory = File(userExtUcmdbDir + 'inter\\') inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + 'results\\' directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if (files != None): for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName)-4:].lower() == '.xml' and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn('Intermediate XML not found or invalid. Perhaps no data was received from Atrium or an error occurred in the atrium_query script.') return ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir)
def DiscoveryMain(Framework): logger.info('Start Phase 2 ... Apply Mapping transformation to Atrium CIs') userExtUcmdbDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder( ) + '\\TQLExport\\Atrium\\' inputFilesDirectory = File(userExtUcmdbDir + 'inter\\') inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + 'results\\' directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if (files != None): for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName) - 4:].lower() == '.xml' and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn( 'Intermediate XML not found or invalid. Perhaps no data was received from Atrium or an error occurred in the atrium_query script.' ) return ## Generate the output XML files in results directory ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) integrationAPI = IntegrationAPI(ip, "atrium_map.py") integrationAPI.processDir(userExtUcmdbDir) logger.info('End Phase 2 ... Apply Mapping transformation to Atrium CIs')
def DiscoveryMain(Framework): logger.info('Start Phase 2 ....Apply Mapping file to Troux CIs') # Destination Data userExtUcmdbDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + '\\TQLExport\\Troux\\' outfilePathDir = userExtUcmdbDir + 'results\\' infilePathDir = userExtUcmdbDir + 'inter' directory = File(outfilePathDir) outfiles = directory.listFiles() directory = File(infilePathDir) infiles = directory.listFiles() ## Clean up the output directory before we run if (outfiles != None): for file in outfiles: file.delete() ## We can only process if Phase 1 created a Intermediate file to process ## Connect to the UCMDB Server, retrieve the results of the Mapping File ## and generate the output XML files in results directory try: ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir) except: pass #Framework.reportWarning(msg) #logger.warnException(msg) logger.info('End Phase 2 ....Apply Mapping file to Troux CIs')
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 DiscoveryMain(Framework): fileSeparator = File.separator # Destination Data userExtUcmdbDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder( ) + fileSeparator + 'TQLExport' + fileSeparator + 'hpsim' + fileSeparator inputFilesDirectory = File(userExtUcmdbDir + 'inter' + fileSeparator) inputFiles = inputFilesDirectory.listFiles() filePathDir = userExtUcmdbDir + 'results' + fileSeparator directory = File(filePathDir) files = directory.listFiles() ## Clean up the existing result XML files if (files != None): for file in files: file.delete() ## Make sure we have XML files in the intermediate directory xmlFileInIntermediatesDirectory = 0 for inputFile in inputFiles: inputFileName = inputFile.getName() if inputFileName[len(inputFileName) - 4:].lower() == '.xml' and inputFile.length() > 0: xmlFileInIntermediatesDirectory = 1 if not xmlFileInIntermediatesDirectory: logger.warn( 'Intermediate XML not found or invalid. Perhaps no data was received from SIM or an error occurred in the SIM_Discovery script.' ) return ## Connect to the UCMDB Server, retrieve the results of the TQL ## and generate the output XML files in results directory ip = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir) info('End exportTQL_for_SIM_to_UCMDB.py')
def DiscoveryMain(Framework): try: cmdbServerHost = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) cmdbServerIp = None if netutils.isValidIp(cmdbServerHost): cmdbServerIp = cmdbServerHost else: cmdbServerIp = netutils.getHostAddress(cmdbServerHost, cmdbServerHost) protocol = getNnmProtocol(Framework, cmdbServerIp) cmdbConnection = getCmdbConnectionDetails(Framework, protocol, cmdbServerHost, cmdbServerIp) nnmConnection = getNnmConnectionDetails(Framework, protocol) logger.debug(str(cmdbConnection)) cmdbToNnmIds = getUCMDBIDs(cmdbConnection, nnmConnection.serverIp, Framework) logger.debug(str(nnmConnection)) updateNNM(cmdbToNnmIds, nnmConnection, Framework) except GeneralException, ex: Framework.reportError(str(ex))
def DiscoveryMain(Framework): logger.info('Start Phase 2 ....Apply Mapping file to Troux CIs') # Destination Data userExtUcmdbDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder( ) + '\\TQLExport\\Troux\\' outfilePathDir = userExtUcmdbDir + 'results\\' infilePathDir = userExtUcmdbDir + 'inter' directory = File(outfilePathDir) outfiles = directory.listFiles() directory = File(infilePathDir) infiles = directory.listFiles() ## Clean up the output directory before we run if (outfiles != None): for file in outfiles: file.delete() ## We can only process if Phase 1 created a Intermediate file to process ## Connect to the UCMDB Server, retrieve the results of the Mapping File ## and generate the output XML files in results directory try: ip = CollectorsParameters.getValue( CollectorsParameters.KEY_SERVER_NAME) exportTQL(ip, userExtUcmdbDir) except: pass #Framework.reportWarning(msg) #logger.warnException(msg) logger.info('End Phase 2 ....Apply Mapping file to Troux CIs')
def mainFunction(Framework): logger.info('Starting NNM_Integration_Utils:mainFunction') ## retrieve Framework data maxPerCall = Framework.getParameter('maxPerCall') maxObjects = Framework.getParameter('maxObjects') nonL2Devices = Framework.getParameter('nonL2Devices') completeHosts = Framework.getParameter('completeHosts') ucmdbServerIp = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) if not netutils.isValidIp(ucmdbServerIp): ucmdbServerIp = netutils.getHostAddress(ucmdbServerIp, ucmdbServerIp) server = Framework.getDestinationAttribute('ip_address') credentialIds = Framework.getAvailableProtocols(ucmdbServerIp, NNM_PROTOCOL) if credentialIds.__len__() == 0: logger.error('NNM Protocol is not defined. Exiting discovery') return ObjectStateHolderVector() elif credentialIds.__len__() > 1: logger.warn('More than one NNM Protocols are defined. Only the last one will be used.') for credentialId in credentialIds: #server = Framework.getProtocolProperty(credentialId, 'nnmprotocol_server') # the nnm server's ip is now retrieved from the trigger port = Framework.getProtocolProperty(credentialId, 'nnmprotocol_port') username = Framework.getProtocolProperty(credentialId, 'nnmprotocol_user') try: password = Framework.getProtocolProperty(credentialId, 'nnmprotocol_password') except: password = '' nnmprotocol = Framework.getProtocolProperty(credentialId, 'nnmprotocol_protocol') logger.debug('Server: %s, Port: %s, Protocol: %s, Username: %s, MaxPerCall: %s, MaxObjects: %s' % (server, port, nnmprotocol, username, maxPerCall, maxObjects)) ## determine whether to discover non-Layer2 devices (servers, printers, load balancers, etc) if notNull(nonL2Devices) and nonL2Devices == 'true': discoverNonL2Devices = 1 else: discoverNonL2Devices = 0 ## determine whether to discover the hosts (switches, routers, servers, etc.) as complete hosts. If this is set to false, it is recommended to have the complete hosts initially discovered in the CMDB if notNull(completeHosts) and completeHosts == 'true': completeHosts = 1 else: completeHosts = 0 ## create an instance of the API stub api = NNMiApi(server, port, username, password, maxPerCall, maxObjects, nnmprotocol, Framework) ## get the filters required to retrieve data based on offset and maxObjects constraints. filters = api.getFilters() ## retrieve NNM data into maps ipMap = getIPAddressObjects(api, filters) ## IP Objects ndMap = getNodeObjects(api, filters) ## Host Objects nwMap = getIPSubnetObjects(api, filters) ## Network Objects ifMap = getInterfaceObjects(api, filters) ## Interface Objects l2Map = getL2ConnectionLinks(api, filters) ## Layer2 Connections ptMap = getPortObjects(api, filters) ## Port Objects vlMap = {} cdMap = {} if len(ptMap) > 0: # only get vlans/card if ports are available vlMap = getVLANObjects(api, filters) ## VLAN Objects cdMap = getCardObjects(api, filters) ## Card Objects ## create map of hosts and it's IPs hostIpMap = createHostIpMap(ipMap, ndMap) ## fix - to only send back one IP address per host hostIpMap = createHostSingleIpMap(hostIpMap) ## create map of hosts and it's interfaces and a second map of host_name[interface_name]=interface_id (the key is the way NNM stores layer2 connections e.g. Host1[If1], Host2[If2], Host3[If3] (nodeIfMap, hostIfMap) = createNodeInterfaceMap(ifMap, ndMap) # map to store MAC Addresses and their hostIDs (used to prevent creation of duplicate interfaces on the same host which have the same mac address) macHostMap = {} ## create the OSHs for hosts, their IPs, interfaces and networks vector1 = create_Hosts_Ips_Interfaces(ipMap, ndMap, ifMap, nwMap, ptMap, vlMap, cdMap, hostIpMap, hostIfMap, completeHosts, discoverNonL2Devices, macHostMap) ## send results back as the objects are created... Framework.sendObjects(vector1) vector1 = None ## create layer 2 connections [HOST-->Interface-->(layer2)<--Interface<--Host or HOST-->Interface-->(layer2)<--Interface<--Concentrator objects and relationships] vector2 = createLayer2Links(ipMap, ndMap, ifMap, l2Map, hostIpMap, nodeIfMap, macHostMap) ## create final result vector and add all other data to it resultVector = ObjectStateHolderVector() resultVector.addAll(vector2) return resultVector
def acquireScannerLock(Framework): client = Framework.getConnectedClient() probe = CollectorsParameters.getValue(CollectorsParameters.KEY_PROBE_MGR_IP) if (probe is None) or (len(str(probe)) == 0): logger.debug('Probe manager ip is not specified in the DiscoveryProbe.properties file, using probe ID') probe = CollectorsParameters.getValue(CollectorsParameters.KEY_COLLECTORS_PROBE_NAME) if (probe is None) or (len(str(probe)) == 0): errorMessage = 'Failed to identify probe name. Lock was not set.' logger.debug(errorMessage) Framework.reportError(errorMessage) Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE) return lockTime = System.currentTimeMillis() lockExpiration = System.currentTimeMillis() + LOCK_AGE_PERIOD_MILLISECONDS jobId = Framework.getDiscoveryJobId() jobType = INVENTORY_JOB_TYPE lock = Lock(probe, jobType, jobId, lockTime, lockExpiration) lockValue = lock.getLockInfo() logger.debug('Trying to lock node with value:', lockValue) existingLock = setNewLockIfExistingLockEmpty(client, lockValue) if (existingLock is None) or (len(existingLock) == 0): # lock was acquired return lockValue else: # found existing lock on remote machine remoteLock = extractLock(existingLock) logger.debug('Node was already locked:', remoteLock.printLockInfo()) if not remoteLock.isLockExpired(): # the lock is more or less fresh if lock.isSameLock(remoteLock): # this is our own lock, just renew it logger.debug('Found lock of same probe/job pair, renewing lock on the node') options = HashMap() options.put(ScannerNodeLock, lockValue) client.setOptionsMap(options) return lockValue # check whether we need to forcefully remove lock, happens in call home based inventory discovery forceAcquire = Framework.getParameter("IsForceLockAcquire") if forceAcquire == 'true': options = HashMap() options.put(ScannerNodeLock, lockValue) client.setOptionsMap(options) return lockValue # if the remote lock was owned by a call home inventory job, we should cancel the current job if remoteLock.jobType == CALLHOME_JOB_TYPE: logger.debug('Remote node was locked by call home inventory job, will cancel the current ' + jobId) return ScannerNodeLockedByCallHome logger.debug('Found valid lock is of different job/probe, will try next time') return None logger.debug('The found lock is already aged, to be removed') if not removeLockOption(Framework): return None # as there can be another probe / job trying to connect to this node, after removing existing lock # we don't set our own lock directly (as it can be removed by another probe/job) but go to sleep for some # time r = Random() waitTime = r.nextInt() % 5 + 1 logger.debug('Going to wait for ' + str(waitTime) + ' seconds before retry to lock') event = Event() event.wait(waitTime) existingLock1 = setNewLockIfExistingLockEmpty(client, lockValue) if (existingLock1 is None) or (len(existingLock1) == 0): # lock was acquired at last!!!! return lockValue # there are other lucky guys return None
def DiscoveryMain(Framework): logger.info('Start ', SCRIPT_NAME) logger.info('Start Phase 1 ... Query Remedy Atrium for data') # dryrunMode = Framework.getParameter('DryRunMode') # Get BMC Namespace bmcNamespace = Framework.getParameter('BMC_NameSpace') if bmcNamespace == None or bmcNamespace == "": bmcNamespace = "BMC.CORE" # Get chunk size - size of data in every query to Remedy/Atrium maxPerCall = Framework.getParameter('ChunkSize') if maxPerCall != None and maxPerCall.isnumeric(): maxPerCall = int(maxPerCall) else: maxPerCall = 500 # Get MAX CI size - size of data in every query to Remedy/Atrium maxCIs = Framework.getParameter('MaxCIs') if maxCIs != None and maxCIs.isnumeric(): maxCIs = int(maxCIs) else: maxCIs = 100000 ucmdbServerIp = CollectorsParameters.getValue( CollectorsParameters.KEY_SERVER_NAME) # File and directory names userExtDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder( ) + '\\TQLExport\\Atrium\\' intermediatesDir = userExtDir + 'inter\\' mapingFilesListFileName = userExtDir + 'tqls.txt' mappingFileNameList = checkDiscoveryResources(mapingFilesListFileName, userExtDir, Framework, intermediatesDir) if not mappingFileNameList: return None # GET ARS context - login information, etc. that is needed to make ARS connection context = getArsContext(Framework, ucmdbServerIp) if context != None: for mappingFileName in mappingFileNameList: (classList, linkList) = getMapping( userExtDir + 'data\\' + mappingFileName + '.xml', bmcNamespace, ucmdbServerIp) if (dryrunMode != None): dryrunMode = dryrunMode.lower() if dryrunMode == 'true': logger.info( '[NOTE] UCMDB Integration is running in DryRun Mode, No query executed against ATRIUM.' ) debugPrint( 4, '[' + SCRIPT_NAME + ':DiscoveryMain] Got classList: <%s>' % classList) debugPrint( 4, '[' + SCRIPT_NAME + ':DiscoveryMain] Got linkList: <%s>' % linkList) return pullDataFromAtrium(context, classList, linkList, maxPerCall, maxCIs, intermediatesDir, mappingFileName) else: logger.error( "Unable to create Remedy/Atrium login context. Check that username, password, server and port are defined correctly." ) return None logger.info('End ', SCRIPT_NAME)
def DiscoveryMain(Framework): logger.info("Start Phase 1 ... Pull from Troux") ######################################################## # Set up the Directory that will be used for the intermediate XML output # and the input # Get the input file that we will use from Troux ######################################################## userExtTrouxDir = ( CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + "\\TQLExport\\Troux\\" ) ucmdbServerIp = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) Trouxfile = None f = None Trouxfile = Framework.getParameter("Troux_TUX_file") if Trouxfile == None: logger.info("Troux TUX input file is not specified") ######################################################## # Open the output directory and clean up old files ######################################################## interPathDir = userExtTrouxDir + "inter\\" directory = File(interPathDir) files = directory.listFiles() logger.info(Trouxfile) # Delete the files in the output directory so we have a clean area if files != None: for file in files: file.delete() # Make sure we have a valid input file if os.path.exists(Trouxfile): foundfile = "false" TQLSFile = "%sTQLS.txt" % (userExtTrouxDir) tqlsFile = "%stqls.txt" % (userExtTrouxDir) if os.path.exists(TQLSFile): foundfile = "true" f = open(TQLSFile) logger.info("Reading file ", TQLSFile) elif os.path.exists(tqlsFile): foundfile = "true" f = open(tqlsFile) logger.info("Reading file ", TQLSFile) else: logger.info("Error \\TQLExport\\Troux\\tqls.txt file missing") if foundfile == "true": for nextName in f.readlines(): if notNull(nextName) and nextName[0:1] != "#": Outfile = nextName.strip() processTrouxXML(userExtTrouxDir, interPathDir, Trouxfile, Outfile) f.close() else: msg = "Input TUX File does not Exist" Framework.reportWarning(msg) logger.info("End Phase 1.... Pull from Troux")
def mainFunction(Framework): SCRIPT = "%s.py:" % __name__ logger.info('%s mainFunction' % SCRIPT) ## retrieve Framework data maxPerCall = Framework.getParameter('maxPerCall') maxObjects = Framework.getParameter('maxObjects') nonL2Devices = Framework.getParameter('nonL2Devices') ucmdbServerIp = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) if not netutils.isValidIp(ucmdbServerIp): ucmdbServerIp = netutils.getHostAddress(ucmdbServerIp, ucmdbServerIp) server = Framework.getDestinationAttribute('ip_address') credentialIds = Framework.getAvailableProtocols(ucmdbServerIp, NNM_PROTOCOL) if credentialIds.__len__() == 0: logger.error('NNM Protocol is not defined. Exiting discovery') return ObjectStateHolderVector() elif credentialIds.__len__() > 1: logger.warn('More than one NNM Protocols are defined. Only the last one will be used.') for credentialId in credentialIds: #server = Framework.getProtocolProperty(credentialId, 'nnmprotocol_server') # the nnm server's ip is now retrieved from the trigger port = Framework.getProtocolProperty(credentialId, 'nnmprotocol_port') username = Framework.getProtocolProperty(credentialId, 'nnmprotocol_user') try: password = Framework.getProtocolProperty(credentialId, 'nnmprotocol_password') except: password = '' nnmprotocol = Framework.getProtocolProperty(credentialId, 'nnmprotocol_protocol') logger.debug('Server: %s, Port: %s, Protocol: %s, Username: %s, MaxPerCall: %s, MaxObjects: %s' % (server, port, nnmprotocol, username, maxPerCall, maxObjects)) ## determine whether to discover non-Layer2 devices (servers, printers, load balancers, etc) if notNull(nonL2Devices) and nonL2Devices == 'true': discoverNonL2Devices = 1 else: discoverNonL2Devices = 0 ## create an instance of the API stub api = NNMiApi(server, port, username, password, maxPerCall, maxObjects, nnmprotocol, Framework) ## get the filters required to retrieve data based on offset and maxObjects constraints. filters = api.getFilters() # initialize attributes createVars() ## retrieve NNM data into maps ipMap = getIPAddressObjects(api, filters) ## IP Objects ndMap = getNodeObjects(api, filters) ## Host Objects nwMap = getIPSubnetObjects(api, filters) ## Network Objects ifMap = getInterfaceObjects(api, filters) ## Interface Objects l2Map = getL2ConnectionLinks(api, filters) ## Layer2 Connections ptMap = getPortObjects(api, filters) ## Port Objects vlMap = {} cdMap = {} if len(ptMap) > 0: # only get vlans/card if ports are available vlMap = getVLANObjects(api, filters) ## VLAN Objects cdMap = getCardObjects(api, filters) ## Card Objects ## create map of hosts and its IPs hostIpMap = createHostIpMap(ipMap, ndMap) ## create map of hosts and its interfaces hostIfMap = createHostInterfaceMap(ifMap, ndMap) ## create map of l2connection and its interfaces connectionIfMap = createConnectionInterfaceMap(l2Map, ifMap) ## create the OSHs for hosts, their IPs, interfaces and networks return processData(ipMap, ndMap, ifMap, nwMap, l2Map, vlMap, ptMap, cdMap, hostIpMap, hostIfMap, connectionIfMap, discoverNonL2Devices, Framework)
def DiscoveryMain(Framework): logger.info('Start Phase 1 ... Pull from Troux') ######################################################## # Set up the Directory that will be used for the intermediate XML output # and the input # Get the input file that we will use from Troux ######################################################## userExtTrouxDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + '\\TQLExport\\Troux\\' ucmdbServerIp = CollectorsParameters.getValue(CollectorsParameters.KEY_SERVER_NAME) Trouxfile = None f = None Trouxfile = Framework.getParameter('Troux_TUX_file') if (Trouxfile == None): logger.info('Troux TUX input file is not specified') ######################################################## # Open the output directory and clean up old files ######################################################## interPathDir = userExtTrouxDir + 'inter\\' directory = File(interPathDir) files = directory.listFiles() logger.info (Trouxfile) # Delete the files in the output directory so we have a clean area if (files != None): for file in files: file.delete() # Make sure we have a valid input file if os.path.exists(Trouxfile): foundfile = 'false' TQLSFile = '%sTQLS.txt' % (userExtTrouxDir) tqlsFile = '%stqls.txt' % (userExtTrouxDir) if os.path.exists(TQLSFile): foundfile = 'true' f = open(TQLSFile) logger.info('Reading file ', TQLSFile) elif os.path.exists(tqlsFile): foundfile = 'true' f = open(tqlsFile) logger.info('Reading file ', TQLSFile) else: logger.info ('Error \\TQLExport\\Troux\\tqls.txt file missing') if foundfile =='true': for nextName in f.readlines(): if notNull(nextName) and nextName[0:1] != '#': Outfile = nextName.strip() processTrouxXML ( userExtTrouxDir, interPathDir, Trouxfile, Outfile) f.close() else: msg = "Input TUX File does not Exist" Framework.reportWarning(msg) logger.info('End Phase 1.... Pull from Troux')
def osh_createTcpConnectionsOsh(lparOsh, primaryIP, knownPortsConfigFile, connections): str_containment = 'containment' _vector = ObjectStateHolderVector() ignoreLocalConnections = 0 ## ER: parameterize probeName = CollectorsParameters.getValue( CollectorsParameters.KEY_COLLECTORS_PROBE_NAME) for conn in connections: dstPort = '' dstAddr = '' srcAddr = '' srcPort = '' id = conn[5] #(dstAddr, dstPort) = _getIpPortFromSocket(localSocket, primaryIP) dstAddr = conn[2].strip() if dstAddr == '0.0.0.0' or dstAddr == '127.0.0.1': dstAddr = primaryIP.strip() dstPort = conn[3].strip() state = conn[9].strip() #(srcAddr, srcPort) = _getIpPortFromSocket(foreignSocket, primaryIP) if upper(state) == 'ESTABLISH': srcAddr = conn[0].strip() srcPort = conn[1].strip() if srcAddr == '127.0.0.1': srcAddr = primaryIP.strip() if ignoreLocalConnections and (srcAddr == dstAddr): continue if isNotNull(dstAddr): destination = '%s:%s' % (dstAddr, dstPort) logger.debug('[', state, '] Current connection: ', srcAddr, ' -> ', destination) # create destination (server) IP and Host -------------------------- dstIpOsh = modeling.createIpOSH(dstAddr) if isNotNull(probeName): dstIpOsh.setAttribute('ip_probename', probeName) dstHostOsh = None if isNotNull(lparOsh): dstHostOsh = lparOsh else: dstHostOsh = modeling.createHostOSH(dstAddr) dstContainedLinkOsh = modeling.createLinkOSH( str_containment, dstHostOsh, dstIpOsh) _vector.add(dstIpOsh) _vector.add(dstHostOsh) _vector.add(dstContainedLinkOsh) # create destination service address object ------------------------ portTypeEnum = TCP_PORT_TYPE_ENUM portName = knownPortsConfigFile.getTcpPortName(int(dstPort)) if upper(state) == 'UDP': portTypeEnum = UDP_PORT_TYPE_ENUM portName = knownPortsConfigFile.getUdpPortName(int(dstPort)) if isNull(portName): portName = dstPort serverPortOsh = modeling.createServiceAddressOsh( dstHostOsh, dstAddr, int(dstPort), portTypeEnum, portName) _vector.add(serverPortOsh) if isNotNull(srcAddr): # create source (client) IP and Host --------------------------- srcIpOsh = modeling.createIpOSH(srcAddr) if isNotNull(probeName): srcIpOsh.setAttribute('ip_probename', probeName) srcHostOsh = modeling.createHostOSH(srcAddr) srcContainedLinkOsh = modeling.createLinkOSH( str_containment, srcHostOsh, srcIpOsh) _vector.add(srcIpOsh) _vector.add(srcHostOsh) _vector.add(srcContainedLinkOsh) # create client-server links ----------------------------------- _vector.add( _createClientServerLinkOsh(dstPort, serverPortOsh, portName, lower(state), srcIpOsh)) # create client server dependency links ------------------------ _vector.add( _createClientServerDependencyLinkOsh( dstHostOsh, dstPort, srcHostOsh, portName)) return _vector
def osh_createTcpConnectionsOsh(lparOsh, primaryIP, knownPortsConfigFile, connections): str_containment = 'containment' _vector = ObjectStateHolderVector() ignoreLocalConnections = 0 ## ER: parameterize probeName = CollectorsParameters.getValue(CollectorsParameters.KEY_COLLECTORS_PROBE_NAME) for conn in connections: dstPort = '' dstAddr = '' srcAddr = '' srcPort = '' id = conn[5] #(dstAddr, dstPort) = _getIpPortFromSocket(localSocket, primaryIP) dstAddr = conn[2].strip() if dstAddr == '0.0.0.0' or dstAddr == '127.0.0.1': dstAddr = primaryIP.strip() dstPort = conn[3].strip() state = conn[9].strip() #(srcAddr, srcPort) = _getIpPortFromSocket(foreignSocket, primaryIP) if upper(state) == 'ESTABLISH': srcAddr = conn[0].strip() srcPort = conn[1].strip() if srcAddr == '127.0.0.1': srcAddr = primaryIP.strip() if ignoreLocalConnections and (srcAddr == dstAddr): continue if isNotNull(dstAddr): destination = '%s:%s' % (dstAddr, dstPort) logger.debug('[', state, '] Current connection: ', srcAddr, ' -> ', destination) # create destination (server) IP and Host -------------------------- dstIpOsh = modeling.createIpOSH(dstAddr) if isNotNull(probeName): dstIpOsh.setAttribute('ip_probename', probeName) dstHostOsh = None if isNotNull(lparOsh): dstHostOsh = lparOsh else: dstHostOsh = modeling.createHostOSH(dstAddr) dstContainedLinkOsh = modeling.createLinkOSH(str_containment, dstHostOsh, dstIpOsh) _vector.add(dstIpOsh) _vector.add(dstHostOsh) _vector.add(dstContainedLinkOsh) # create destination service address object ------------------------ portTypeEnum = TCP_PORT_TYPE_ENUM portName = knownPortsConfigFile.getTcpPortName(int(dstPort)) if upper(state) == 'UDP': portTypeEnum = UDP_PORT_TYPE_ENUM portName = knownPortsConfigFile.getUdpPortName(int(dstPort)) if isNull(portName): portName = dstPort serverPortOsh = modeling.createServiceAddressOsh(dstHostOsh, dstAddr, int(dstPort), portTypeEnum, portName) _vector.add(serverPortOsh) if isNotNull(srcAddr): # create source (client) IP and Host --------------------------- srcIpOsh = modeling.createIpOSH(srcAddr) if isNotNull(probeName): srcIpOsh.setAttribute('ip_probename', probeName) srcHostOsh = modeling.createHostOSH(srcAddr) srcContainedLinkOsh = modeling.createLinkOSH(str_containment, srcHostOsh, srcIpOsh) _vector.add(srcIpOsh) _vector.add(srcHostOsh) _vector.add(srcContainedLinkOsh) # create client-server links ----------------------------------- _vector.add(_createClientServerLinkOsh(dstPort, serverPortOsh, portName, lower(state), srcIpOsh)) # create client server dependency links ------------------------ _vector.add(_createClientServerDependencyLinkOsh(dstHostOsh, dstPort, srcHostOsh, portName)) return _vector