def start(self): "start enabler" logger.info("Enter start") copyContainerEnvironment() self.__initOptions() if self.__composeFile: self.__composeCreate() self.__composeStart() self.__composePs() else: reuseContainer = Boolean.parseBoolean(getVariableValue("REUSE_DOCKER_CONTAINER", "false")) reuseImage = Boolean.parseBoolean(getVariableValue("REUSE_DOCKER_IMAGE", "true")) llen = len(self.__dockerContainerName) for index in range(llen): if reuseContainer and self.__containerExists(index): self.__start(index) elif reuseImage and self.__imageExists(index): self.__run(index) elif listItem(self.__dockerContext, index): self.__build(index) self.__run(index) else: self.__pull(index) self.__run(index) while index < (llen - 1): logger.info("Waiting for container to start:" + listItem(self.__dockerContainerName, index)) time.sleep(float(self.__startInterval)) if self.__isContainerRunning(index): break logger.info("Exit start")
def start(self): "start enabler" logger.info("Enter start") copyContainerEnvironment() self.__initOptions() reuseContainer = Boolean.parseBoolean( getVariableValue("REUSE_DOCKER_CONTAINER", "false")) reuseImage = Boolean.parseBoolean( getVariableValue("REUSE_DOCKER_IMAGE", "true")) llen = len(self.__dockerContainerName) for index in range(llen): if reuseContainer and self.__containerExists(index): self.__start(index) elif reuseImage and self.__imageExists(index): self.__run(index) elif listItem(self.__dockerContext, index): self.__build(index) self.__run(index) else: self.__pull(index) self.__run(index) while index < (llen - 1): logger.info("Waiting for container to start:" + listItem(self.__dockerContainerName, index)) time.sleep(float(self.__startInterval)) if self.__isContainerRunning(index): break logger.info("Exit start")
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() logger.debug('Start nmap_osfingerprint.py') ip = Framework.getDestinationAttribute('ip_address') timeout = Framework.getParameter('nmap_host_timeout') if not str(timeout).isdigit(): msg = "Timeout parameter value must be a digit" logger.debug(msg) errormessages.resolveAndReport(msg, ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME, Framework) return OSHVResult timeout = int(timeout) * 1000 scanKnownPortsOnly = Boolean.parseBoolean( Framework.getParameter('scan_known_ports_only')) portstoscan = Framework.getParameter('scan_these_ports_only') doServiceFingerprints = Boolean.parseBoolean( Framework.getParameter('Perform_Port_Fingerprints')) createApp = Boolean.parseBoolean( Framework.getParameter('Create_Application_CI')) discoverOsName = Boolean.parseBoolean( Framework.getParameter('discover_os_name')) nmapLocation = Framework.getParameter('nmap_location') #discover_UDP_Ports = int(Framework.getParameter('Discover_UDP_Ports')) discoverUdpPorts = 0 agent_root_dir = CollectorsParameters.BASE_PROBE_MGR_DIR agent_ext_dir = agent_root_dir + CollectorsParameters.getDiscoveryResourceFolder( ) + CollectorsParameters.FILE_SEPARATOR tmp_file_name = agent_ext_dir + string.replace( ip, '.', '_') + time.strftime("%H%M%S", time.gmtime( time.time())) + 'nmap.xml' syncNmapPortConfigFile(agent_root_dir) logger.debug('temp file for storing nmap results: ', tmp_file_name) try: client = Framework.createClient( ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) try: performNmapDiscover(client, ip, tmp_file_name, timeout, agent_ext_dir, scanKnownPortsOnly, portstoscan, doServiceFingerprints, discoverUdpPorts, nmapLocation) if os.path.exists(tmp_file_name): logger.debug('start processing the nmap results') processNmapResult(tmp_file_name, OSHVResult, discoverOsName, doServiceFingerprints, createApp, Framework) else: raise ValueError, 'Error nmap result file is missing: %s' % tmp_file_name finally: client.close() File(tmp_file_name).delete() except Exception, e: msg = str(e.getMessage()) logger.debug(msg) errormessages.resolveAndReport(msg, ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME, Framework)
def DiscoveryMain(Framework): shell = None try: try: protocolName = __getProtocolName(Framework) discoverSharePointUrls = Boolean.parseBoolean(Framework.getParameter('discoverSharePointUrls')) reportIntermediateWebService = Framework.getParameter('reportIntermediateWebService') if reportIntermediateWebService: reportIntermediateWebService = Boolean.parseBoolean(reportIntermediateWebService) else: #set default value reportIntermediateWebService = 1 relativeCommandTimeoutMultiplier = Framework.getParameter('relativeCommandTimeoutMultiplier') relativeCommandTimeoutMultiplier = int(relativeCommandTimeoutMultiplier) client = Framework.createClient() shell = ShellFactory().createShell(client) logger.debug('getting SharePoint discoverer for protocol %s' % protocolName) discoverer = sharepoint_win_shell.getDiscoverer(shell, protocolName, relativeCommandTimeoutMultiplier) logger.debug('got discoverer') resources = _discoverSharePoint(discoverer) resources.build() return resources.report(discoverSharePointUrls, reportIntermediateWebService) except SharePointException: logger.reportError() logger.debugException('') except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, protocolName, Framework) except: strException = logger.prepareJythonStackTrace('') errormessages.resolveAndReport(strException, protocolName, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() client = None layer2_connections_cdp = None layer2_connections_lldp = None try: try: client = Framework.createClient() except: errMsg = 'Exception while creating %s client: %s' % ( ClientsConsts.SNMP_PROTOCOL_NAME, sys.exc_info()[1]) errormessages.resolveAndReport(str(sys.exc_info()[1]), ClientsConsts.SNMP_PROTOCOL_NAME, Framework) logger.debugException(errMsg) else: host_id = Framework.getDestinationAttribute('hostId') discover_cdp_mib = Boolean.parseBoolean( Framework.getParameter('discoverCdpMib')) discover_lldp_mib = Boolean.parseBoolean( Framework.getParameter('discoverLldpMib')) local_device_discoverer = LocalDeviceDiscoverer(client, host_id) local_devices = local_device_discoverer.get_local_devices() if not local_devices or len(local_devices) == 0: logger.reportError('Failed to get local device info') if discover_cdp_mib: cdp_discoverer = CdpDiscoverer(client) remote_devices_cdp = cdp_discoverer.get_remote_devices() if remote_devices_cdp: layer2_connections_cdp = get_layer2_connections( local_devices, remote_devices_cdp) for layer2_connection in layer2_connections_cdp: OSHVResult.addAll( build_layer2_connection(layer2_connection)) if discover_lldp_mib: lldp_discoverer = LldpDiscoverer(client) remote_devices_lldp = lldp_discoverer.get_remote_devices() if remote_devices_lldp: layer2_connections_lldp = get_layer2_connections( local_devices, remote_devices_lldp) for layer2_connection in layer2_connections_lldp: OSHVResult.addAll( build_layer2_connection(layer2_connection)) if (not layer2_connections_cdp or len(layer2_connections_cdp) == 0) and (not layer2_connections_lldp or len(layer2_connections_lldp) == 0): logger.reportError('No data collected') finally: if client != None: client.close() return OSHVResult
def initializeServices(self): self.discoverDependLinks = 1 self.shouldCountClients = 0 self.updateUtilizationInfo = Boolean.parseBoolean(self.getParameterValue('updateUtilizationInfo')) self.onlyHostDependLinks = Boolean.parseBoolean(self.getParameterValue('onlyHostDependLinks')) self.ignoreUnackedTcpConn = Boolean.parseBoolean(self.getParameterValue('ignoreUnackedTcpConn')) self.minimalClients = 0 self.minimalOctets = 0 self.minimalPackets = 0
def DiscoveryMain(Framework): properties = Properties() SITE_ID = Framework.getDestinationAttribute('SITE_ID') instance_number = Framework.getDestinationAttribute('instance_number') connection_client = Framework.getDestinationAttribute('connection_client') logger.debug('Connecting to a SAP instance number:', str(instance_number)) properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_SYSNUMBER, instance_number) if (connection_client is not None) and (connection_client != 'NA'): logger.debug('Connecting to a SAP system with client:', str(connection_client)) properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_CLIENT, connection_client) discoverScenarioProcesses = Boolean.parseBoolean(Framework.getParameter('discoverScenarioProcesses')) GET_PROCESS_STEPS = Boolean.parseBoolean(Framework.getParameter('getProcessSteps')) reportCIsInChunks = Boolean.parseBoolean(Framework.getParameter('reportCIsInChunks')) errormsg = '' client = None try: try: client = Framework.createClient(properties) solman = saputils.SapSolman(client) except (NoClassDefFoundError, MissingJarsException, ExceptionInInitializerError): errormsg = 'SAP drivers are missing' logger.debugException(errormsg) except: errormsg = 'Connection failed' logger.debugException(errormsg) else: try: sVector, sysToOshPairs = discoverSystems(solman) Framework.sendObjects(sVector) sVector.clear() sysNames = [system.getName() for system, _ in sysToOshPairs] sys_name_to_system = {} for system, _ in sysToOshPairs: sys_name_to_system[system.getName()] = system component2system = logicalComponents(sysNames, solman) businessProcesses(Framework, solman, component2system, sys_name_to_system, SITE_ID, GET_PROCESS_STEPS, reportCIsInChunks, discoverScenarioProcesses) except: strmsg = str(sys.exc_info()[1]) if (strmsg.upper().find('TABLE_NOT_AVAILABLE') > -1): errmsg = 'No solution manager found' logger.debugException(errmsg) Framework.reportError(errmsg) else: # unknown exception caught raise except JException, ex: ex_info = ex.getMessage() errormessages.resolveAndReport(ex_info, 'SAP JCO', Framework)
def isStampEnabled(Framework, ip): from java.lang import Boolean enableStampingParameter = Framework.getParameter('enableStamping') onlyStampingClientParameter = Framework.getParameter('onlyStampingClient') logger.debug("Parameter for enableStamping:", enableStampingParameter) logger.debug("Parameter for onlyStampingClient:", onlyStampingClientParameter) enableStamping = Boolean.parseBoolean(enableStampingParameter) onlyStampingClient = Boolean.parseBoolean(onlyStampingClientParameter) isClientIP = isClientTypeIP(ip) return enableStamping and (not onlyStampingClient or isClientIP)
def isStampEnabled(Framework, ip): from java.lang import Boolean enableStampingParameter = Framework.getParameter('enableStamping') onlyStampingClientParameter = Framework.getParameter('onlyStampingClient') logger.debug("Parameter for enableStamping:", enableStampingParameter) logger.debug("Parameter for onlyStampingClient:", onlyStampingClientParameter) enableStamping = Boolean.parseBoolean(enableStampingParameter) onlyStampingClient = Boolean.parseBoolean(onlyStampingClientParameter) isClientIP = isClientTypeIP(ip) return enableStamping and (not onlyStampingClient or isClientIP)
def initializeServices(self): self.updateUtilizationInfo = 1 self.discoverDependLinks = Boolean.parseBoolean(self.getParameterValue('discoverDependLinks')) self.onlyHostDependLinks = 0 self.ignoreUnackedTcpConn = 0 self.shouldCountClients = 1 self.discoverIP = self.Framework.getDestinationAttribute('ip_address') self.hostId = self.Framework.getDestinationAttribute('hostId') self.minimalClients = Integer.parseInt(self.Framework.getParameter('minClients')) self.minimalOctets = Integer.parseInt(self.Framework.getParameter('minOctets')) self.minimalPackets = Integer.parseInt(self.Framework.getParameter('minPackets')) self.protocols = self.Framework.getParameter('protocols') self.disregardListenPorts = Boolean.parseBoolean(self.getParameterValue('disregardListenPorts'))
def shouldInstallScanner(scannerPlatformConfig, Framework, shell): shouldInstall = 0 #staring to check scanner version on remote machine isUpgradeAllowed = Boolean.parseBoolean(Framework.getParameter('IsScannerUpgradeAllowed')) logger.debug('Parameter isUpgradeAllowed:', isUpgradeAllowed) IsDowngradeAllowed = Boolean.parseBoolean(Framework.getParameter('IsScannerDowngradeAllowed')) logger.debug('Parameter IsDowngradeAllowed:', IsDowngradeAllowed) if isUpgradeAllowed and IsDowngradeAllowed: logger.debug('Upgrade and Downgrade allowed, installing scanner in any case') shouldInstall = 1 else: remoteScannerVersion = Framework.getDestinationAttribute('scannerVersion') if (remoteScannerVersion is None) or (len(str(remoteScannerVersion)) == 0) or (str(remoteScannerVersion) == 'NA'): logger.debug('Remote scanner version is unavailable, going to execute scanner upgrade') shouldInstall = 1 else: logger.debug('Scanner already found on remote machine') installerFileName = scannerPlatformConfig.getScannerExecutable() installerVersioninstallerXmlFilePath = CollectorsParameters.PROBE_MGR_RESOURCES_DIR + 'ud_scanners' + str(File.separator) + installerFileName + '-version.xml' logger.debug('Checking installer version in file ', installerVersioninstallerXmlFilePath) installerXmlFile = File(installerVersioninstallerXmlFilePath) if installerXmlFile.exists() and installerXmlFile.isFile(): installerVersion = getInstallerVersion(installerXmlFile, Framework) logger.debug('Current scanner version ', installerVersion) m = re.search('([\d\.]+) build ([\d]+)', remoteScannerVersion) if m: remoteScannerVersion = m.group(1)+'.'+m.group(2) logger.debug('Remote scanner version ', remoteScannerVersion) if compareVersions(installerVersion, remoteScannerVersion) > 0: if isUpgradeAllowed: logger.debug('Upgrade should be perfomed') shouldInstall = 1 else: logger.debug('Upgrade is not allowed') elif compareVersions(installerVersion, remoteScannerVersion) < 0: if IsDowngradeAllowed: logger.debug('Downgrade should be perfomed') shouldInstall = 1 else: logger.debug('Downgrade is not allowed') else: logger.debug('Scanner should be installed') shouldInstall = 1 else: if isUpgradeAllowed: logger.debug('Going to upgrade scanner, version file not exists:', installerVersioninstallerXmlFilePath) shouldInstall = 1 return shouldInstall
def __activate__(self, context): self.velocityContext = context self.services = context["Services"] self.request = context["request"] self.response = context["response"] self.contextPath = context["contextPath"] self.formData = context["formData"] self.page = context["page"] self.uaActivated = False useDownload = Boolean.parseBoolean(self.formData.get("download", "true")) self.__isPreview = Boolean.parseBoolean(self.formData.get("preview", "false")) self.__previewPid = None self.__hasPid = False uri = URLDecoder.decode(self.request.getAttribute("RequestURI")) matches = re.match("^(.*?)/(.*?)/(?:(.*?)/)?(.*)$", uri) if matches and matches.group(3): oid = matches.group(3) pid = matches.group(4) self.__metadata = JsonConfigHelper() self.__object = self.__getObject(oid) self.__oid = oid # If we have a PID if pid: self.__hasPid = True if useDownload: # Download the payload to support relative links download = DownloadData() download.__activate__(context) else: # Render the detail screen with the alternative preview self.__readMetadata(oid) self.__previewPid = pid # Otherwise, render the detail screen else: self.__readMetadata(oid) self.__previewPid = self.getPreview() if self.__previewPid: self.__previewPid = URLEncoder.encode(self.__previewPid, "UTF-8") else: # require trailing slash for relative paths q = "" if self.__isPreview: q = "?preview=true" self.response.sendRedirect("%s/%s/%s" % (self.contextPath, uri, q))
def DiscoveryMain(Framework): fileName = Framework.getParameter('file_name').replace( '%PROBE_MGR_RESOURCES_DIR%', CollectorsParameters.PROBE_MGR_RESOURCES_DIR) string_list_delimiter = Framework.getParameter('string_list_delimiter') integer_list_delimiter = Framework.getParameter('integer_list_delimiter') relationship_attr_delimiter = Framework.getParameter( 'relationship_attr_delimiter') set_empty_value_flag = Boolean.parseBoolean( Framework.getParameter('set_empty_value')) if not (fileName and string_list_delimiter and integer_list_delimiter and relationship_attr_delimiter): logger.reportError('Not all job parameters are set.') return try: workbook = xlsutils.openXlFile(fileName) if workbook: classModel = ConfigFilesManagerImpl.getInstance( ).getCmdbClassModel() classModelUtil = xlsutils.ClassModelUtils(classModel, integer_list_delimiter, string_list_delimiter) importer = WorkSheetImporter(workbook, classModelUtil, set_empty_value=set_empty_value_flag) return importer.processWorkbook() except JavaException, ex: logger.reportError(ex.getMessage()) ex.printStackTrace() logger.errorException('')
def __discoverInstalledSoftware(Framework, OSHVResult, client): discoverSoftwareOld = Boolean.parseBoolean( Framework.getParameter('discoverInstalledSoftwareByOldMechanism')) softNameToInstSoftOSH = {} try: if discoverSoftwareOld: #we close client here since in the software discovery we had to open another client #since we changing namespace and reference registry instead of wmi logger.debug( 'The software is discovered using old mechanism. This mechanism is very non-efficient and thus discovery might take time.' ) client.close() client = None wmi_dis_software_lib.mainFunction(Framework, OSHVResult, softNameToInstSoftOSH) #reopen general WMI client since it will be used in Plug-ins logger.debug("Reopening WMI client") client = createWmiClient(Framework) else: wmi_dis_software_lib.mainFunctionWithWbem(Framework, client, OSHVResult, softNameToInstSoftOSH) except: errobj = errorobject.createError( errorcodes.FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['software', 'wmi'], 'Failed to discover software by wmi') logger.reportErrorObject(errobj) logger.errorException('Failed to discover software by wmi') return (softNameToInstSoftOSH, client)
def __init__(self, Framework): Netlinks_Service.NetlinksService.__init__(self, Framework) shouldIgnoreLocal = self.getParameterValue('ignoreLocalConnections') if shouldIgnoreLocal == None: shouldIgnoreLocal = 'false' self.ignoreLocalConnections = Boolean.parseBoolean(shouldIgnoreLocal) self.dependencyNameIsKey = modeling.checkIsKeyAttribute( 'dependency', 'dependency_name') self.dependencySourceIsKey = modeling.checkIsKeyAttribute( 'dependency', 'dependency_source') ignoredIpsList = self.getParameterValue('ignoredIps') self.ignoredIps = None if ignoredIpsList != None: ipPatterns = ignoredIpsList.split(',') if (len(ipPatterns) > 0) and (ipPatterns[0] != ''): for ipPattern in ipPatterns: pattern = String(ipPattern) pattern = String(pattern.replaceAll("\.", "\\\.")) pattern = String(pattern.replaceAll("\*", "\\\d+")) try: m = Pattern.compile(pattern) if self.ignoredIps == None: self.ignoredIps = ArrayList() self.ignoredIps.add(m) except: logger.debug('Failed to compile ip pattern:', ipPattern) self.initializeServices()
def DiscoveryMain(Framework): protocolName = "NTCMD" OSHVResult = ObjectStateHolderVector() param = Framework.getParameter('discoverSoftware') if (param != None) and not Boolean.parseBoolean(param): logger.debug( 'No discovery for software by NTCMD, parameter discoverSoftware is false' ) return OSHVResult hostID = Framework.getDestinationAttribute('hostId') hostOSH = modeling.createOshByCmdbIdString('host', hostID) clientShUtils = None try: props = Properties() props.setProperty(AgentConstants.PROP_NTCMD_AGENT_COMMAND_TIMEOUT, '100000') client = Framework.createClient(props) if client is None: raise Exception, 'Failed to create NTCMD client' except Exception, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, protocolName, Framework)
def __composeDown(self): logger.info("Enter docker compose down") try: project = getVariableValue("DOCKER_COMPOSE_PROJECT", self.__compName) cmdlist=[self.__dockerCompose, "--file", self.__composeFile, "--project-name", project, "down"] removeImage = Boolean.parseBoolean(getVariableValue("REMOVE_DOCKER_IMAGE", "false")) if removeImage: cmdlist.extend(["--rmi", "all"]) removeOptions = getVariableValue("DOCKER_REMOVE_OPTIONS") if removeOptions and removeOptions.find("--volumes=true") >= 0: cmdlist.append("--volumes") logger.info("Executing:"+ list2str(cmdlist)) os.environ["DOCKER_HOST"] = "tcp://" + self.__dockerAddr os.environ["COMPOSE_HTTP_TIMEOUT"] = "300" self.__lock() retcode = call(cmdlist) logger.info("Return code:" + str(retcode)) except: type, value, traceback = sys.exc_info() logger.severe("composeDown error:" + `value`) raise finally: self.__unlock() logger.info("Exit docker compose down")
def disHPUX(host_obj, client, Framework = None, langBund = None, pid2Process = None): hostId = Framework.getDestinationAttribute('hostId') discoverProcesses = Boolean.parseBoolean(Framework.getParameter('discoverProcesses')) myVec = ObjectStateHolderVector() # Better format, but not supported on all HPUX systems #r = client.executeCmd('ps -e -o pid,time,sz,comm,args') r = client.execCmd('ps -ef')#V@@CMD_PERMISION tty protocol execution if r == None: return myVec lines = '' if(re.search('\r\n',r)): lines = r.split('\r\n') elif (re.search('\n',r)): lines = r.split('\n') else: return myVec processList = [] pdu = None try: pdu = processdbutils.ProcessDbUtils(Framework) hostOSH = None for line in lines: ## Reg for processes with args res = re.search('(\w+)\s+(\d+).*\s\d+\:\d\d\s([0-9a-zA-Z_.\[\]\-+:/]+)\s(.*)',line) if(res): cleanArgs = res.group(4) else: ## Reg for processes with no args res = re.search('(\w+)\s+(\d+).*\s\d+\:\d\d\s([0-9a-zA-Z_.\-+:/]+)',line) if(res): cleanArgs = '' if(res): owner = res.group(1) commAndPath = res.group(3) pid = res.group(2) cleanCommand = '' if commAndPath.find('/') == -1: cleanCommand = commAndPath else: res2 = re.search('(.*/)([^/]+)',commAndPath) if (res2): cleanCommand = res2.group(2) else: continue if hostOSH == None: hostOSH = modeling.createOshByCmdbIdString('host', hostId) commandLine = cleanCommand + ' ' + cleanArgs addProcess(pdu, hostId, cleanCommand, pid, commandLine, commAndPath, cleanArgs, processList, discoverProcesses, myVec, hostOSH, None, owner) pdu.flushHostProcesses(hostId) if pid2Process is not None: pid2Process.putAll(pdu.getProcessCmdMap()) finally: if pdu != None: pdu.close() return myVec
def __init__(self, Framework): Netlinks_Service.NetlinksService.__init__(self, Framework) shouldIgnoreLocal = self.getParameterValue('ignoreLocalConnections') if shouldIgnoreLocal == None: shouldIgnoreLocal = 'false' self.ignoreLocalConnections = Boolean.parseBoolean(shouldIgnoreLocal) self.dependencyNameIsKey = modeling.checkIsKeyAttribute('dependency', 'dependency_name') self.dependencySourceIsKey = modeling.checkIsKeyAttribute('dependency', 'dependency_source') ignoredIpsList = self.getParameterValue('ignoredIps') self.ignoredIps = None if ignoredIpsList != None: ipPatterns = ignoredIpsList.split(',') if (len(ipPatterns) > 0) and (ipPatterns[0] != ''): for ipPattern in ipPatterns: pattern = String(ipPattern) pattern = String(pattern.replaceAll("\.", "\\\.")) pattern = String(pattern.replaceAll("\*", "\\\d+")) try: m = Pattern.compile(pattern) if self.ignoredIps == None: self.ignoredIps = ArrayList() self.ignoredIps.add(m) except: logger.debug('Failed to compile ip pattern:', ipPattern) self.initializeServices()
def __activate__(self, context): self.services = context["Services"] self.page = context["page"] self.formData = context["formData"] self.sessionState = context["sessionState"] self.request = context["request"] self.pageName = context["pageName"] self.__portal = context["page"].getPortal() sessionNav = self.__portal.get("portal/use-session-navigation", "true") self.__useSessionNavigation = Boolean.parseBoolean(sessionNav) self.__result = JsonConfigHelper() if self.__useSessionNavigation: self.__pageNum = self.sessionState.get("pageNum", 1) else: self.__pageNum = 1 self.__selected = ArrayList() self.__fqParts = [] self.__searchField = self.formData.get("searchField", "full_text") if self.__portal.getName() != self.lastPortalId: self.sessionState.remove("fq") self.sessionState.remove("pageNum") self.__pageNum = 1 self.lastPortalId = self.__portal.getName() self.__search()
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() logger.info ("Starting IMS Discovery") DiscoverIMSDB = Boolean.parseBoolean(Framework.getParameter('DiscoverIMSDB')) # create LPAR node from the ID passed in hostId = Framework.getDestinationAttribute(PARAM_HOST_ID) lparOsh = None if eview_lib.isNotNull(hostId): lparOsh = modeling.createOshByCmdbIdString('host_node', hostId) ls = eview_lib.EvShell(Framework) IMSSubSysDict = getIMSSubSys(ls, lparOsh) OSHVResult.addAll(getIMSActRegions(ls,lparOsh, IMSSubSysDict )) if DiscoverIMSDB and len(IMSSubSysDict) > 0: databaseAreaDictionary = {} databaseDictionary = {} OSHVResult.addAll(getIMSDB(ls, IMSSubSysDict, databaseAreaDictionary , databaseDictionary)) OSHVResult.addAll(getAREAs(ls, IMSSubSysDict, databaseAreaDictionary , databaseDictionary)) OSHVResult.addAll(processPrograms(ls,IMSSubSysDict, Framework)) ls.closeClient() logger.info ("Finished IMS Discovery") return OSHVResult
def __composeDown(self): logger.info("Enter docker compose down") try: project = getVariableValue("DOCKER_COMPOSE_PROJECT", self.__compName) cmdlist = [ self.__dockerCompose, "--file", self.__composeFile, "--project-name", project, "down" ] removeImage = Boolean.parseBoolean( getVariableValue("REMOVE_DOCKER_IMAGE", "false")) if removeImage: cmdlist.extend(["--rmi", "all"]) removeOptions = getVariableValue("DOCKER_REMOVE_OPTIONS") if removeOptions and removeOptions.find("--volumes=true") >= 0: cmdlist.append("--volumes") logger.info("Executing:" + list2str(cmdlist)) os.environ["DOCKER_HOST"] = "tcp://" + self.__dockerAddr os.environ["COMPOSE_HTTP_TIMEOUT"] = "300" self.__lock() retcode = call(cmdlist) logger.info("Return code:" + str(retcode)) except: type, value, traceback = sys.exc_info() logger.severe("composeDown error:" + ` value `) raise finally: self.__unlock() logger.info("Exit docker compose down")
def getPayloadContent(self): mimeType = self.__mimeType print " * single.py: payload content mimeType=%s" % mimeType contentStr = "" if mimeType.startswith("text/"): if mimeType == "text/html": contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s"></iframe>' % ( contextPath, portalId, self.__oid, ) else: pid = self.__oid[self.__oid.rfind("/") + 1 :] payload = self.__storage.getPayload(self.__oid, pid) print " * single.py: pid=%s payload=%s" % (pid, payload) if payload is not None: sw = StringWriter() sw.write("<pre>") IOUtils.copy(payload.getInputStream(), sw) sw.write("</pre>") sw.flush() contentStr = sw.toString() elif ( mimeType == "application/pdf" or mimeType.find("vnd.ms") > -1 or mimeType.find("vnd.oasis.opendocument.") > -1 ): # get the html version if exist... pid = os.path.splitext(self.__pid)[0] + ".htm" print " * single.py: pid=%s" % pid # contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s/%s"></iframe>' % \ # (contextPath, portalId, self.__oid, pid) payload = self.__storage.getPayload(self.__oid, pid) saxReader = SAXReader(Boolean.parseBoolean("false")) try: document = saxReader.read(payload.getInputStream()) slideNode = document.selectSingleNode("//*[local-name()='body']") # linkNodes = slideNode.selectNodes("//img") # contentStr = slideNode.asXML(); # encode character entities correctly slideNode.setName("div") out = ByteArrayOutputStream() format = OutputFormat.createPrettyPrint() format.setSuppressDeclaration(True) format.setExpandEmptyElements(True) writer = XMLWriter(out, format) writer.write(slideNode) writer.close() contentStr = out.toString("UTF-8") except: traceback.print_exc() contentStr = '<p class="error">No preview available</p>' elif mimeType.startswith("image/"): src = "%s/%s" % (self.__oid, self.__pid) contentStr = ( '<a class="image" href="%(src)s" style="max-width:98%%">' '<img src="%(src)s" style="max-width:100%%" /></a>' % {"src": self.__pid} ) return contentStr
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() snmpMethod = getFrameworkParameter(Framework, 'snmpMethod', SnmpQueries.defaultSnmpMethod) backupSnmpMethod = getFrameworkParameter(Framework, 'backupSnmpMethod', SnmpQueries.defaultBackupSnmpMethod) moonWalkBulkSize = int(getFrameworkParameter(Framework, 'moonWalkBulkSize', SnmpQueries.defaultMoonWalkBulkSize)) moonWalkSleep = long(getFrameworkParameter(Framework, 'moonWalkSleep', SnmpQueries.defaultMoonWalkSleep)) snmpBulkSize = int(getFrameworkParameter(Framework, 'snmpBulkSize', SnmpQueries.defaultSnmpBulkSize)) discoverUnknownIPs = Boolean.parseBoolean(Framework.getParameter('discoverUnknownIPs')) #getting DestinationData from Framework; the method is protected. destination = Framework.getCurrentDestination() discoveredHostIpList = SnmpQueries.getSnmpIpDataOneDestination(snmpMethod, snmpBulkSize, moonWalkBulkSize, moonWalkSleep, Boolean.FALSE, destination) logger.debug('Discover ARP by %s returned %s objects' % (snmpMethod, str(discoveredHostIpList.size()))) if (discoveredHostIpList.size() == 0) and (snmpMethod != backupSnmpMethod): discoveredHostIpList = SnmpQueries.getSnmpIpDataOneDestination(backupSnmpMethod, snmpBulkSize, moonWalkBulkSize, moonWalkSleep, Boolean.FALSE, destination) logger.debug('Discover ARP by %s returned %s objects' % (backupSnmpMethod, str(discoveredHostIpList.size()))) if (discoveredHostIpList.size()==0): Framework.reportWarning('Failed to discover SNMP IP data') return OSHVResult discoveredHostArpList = SnmpQueries.getSnmpArpDataOneDestination(snmpMethod, snmpBulkSize, moonWalkBulkSize, moonWalkSleep, Boolean.FALSE, destination) discoveredHostArpList.addAll(SnmpQueries.getSnmpArpDataOneDestination(snmpMethod, snmpBulkSize, moonWalkBulkSize, moonWalkSleep, Boolean.FALSE, Boolean.TRUE, destination)) if (discoveredHostArpList.size()==0) and (snmpMethod != backupSnmpMethod): discoveredHostArpList = SnmpQueries.getSnmpArpDataOneDestination(backupSnmpMethod, snmpBulkSize, moonWalkBulkSize, moonWalkSleep, Boolean.FALSE, destination) discoveredHostArpList.addAll(SnmpQueries.getSnmpArpDataOneDestination(backupSnmpMethod, snmpBulkSize, moonWalkBulkSize, moonWalkSleep, Boolean.FALSE, Boolean.TRUE, destination)) if (discoveredHostArpList.size()==0): Framework.reportWarning('Failed to discover SNMP ARP data') return OSHVResult networkOSH = None for i in range(discoveredHostArpList.size()): currArp = discoveredHostArpList.get(i) for currIp in discoveredHostIpList: if networkOSH is None: networkOSH = modeling.createNetworkOSH(currIp.netaddr, currIp.netmask) OSHVResult.add(networkOSH) if (currIp.domain == 'unknown') and not discoverUnknownIPs: continue if not netutils.isValidMac(currArp.designatedMacAddress): continue #report start designatedIpNetAddress = IPv4(currArp.designatedIpAddress, currIp.netmask).getFirstIp().toString(); if designatedIpNetAddress == currIp.netaddr: hostOSH = modeling.createHostOSH(currArp.designatedIpAddress) OSHVResult.add(hostOSH) OSHVResult.add(modeling.createLinkOSH('member', networkOSH, hostOSH)) ipOsh = modeling.createIpOSH(currArp.designatedIpAddress, currIp.netmask) OSHVResult.add(ipOsh) OSHVResult.add(modeling.createLinkOSH('member', networkOSH, ipOsh)) ifOsh = modeling.createInterfaceOSH(netutils.parseMac(currArp.designatedMacAddress), hostOSH) OSHVResult.add(ifOsh) OSHVResult.add(modeling.createLinkOSH('containment', ifOsh, ipOsh)) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() client = None layer2_connections_cdp = None layer2_connections_lldp = None try: try: client = Framework.createClient() except: errMsg ='Exception while creating %s client: %s' % (ClientsConsts.SNMP_PROTOCOL_NAME, sys.exc_info()[1]) errormessages.resolveAndReport(str(sys.exc_info()[1]), ClientsConsts.SNMP_PROTOCOL_NAME, Framework) logger.debugException(errMsg) else: host_id = Framework.getDestinationAttribute('hostId') discover_cdp_mib = Boolean.parseBoolean(Framework.getParameter('discoverCdpMib')) discover_lldp_mib = Boolean.parseBoolean(Framework.getParameter('discoverLldpMib')) local_device_discoverer = LocalDeviceDiscoverer(client, host_id) local_devices = local_device_discoverer.get_local_devices() if not local_devices or len(local_devices) == 0: logger.reportError('Failed to get local device info') if discover_cdp_mib: cdp_discoverer = CdpDiscoverer(client) remote_devices_cdp = cdp_discoverer.get_remote_devices() if remote_devices_cdp: layer2_connections_cdp = get_layer2_connections(local_devices, remote_devices_cdp) for layer2_connection in layer2_connections_cdp: OSHVResult.addAll(build_layer2_connection(layer2_connection)) if discover_lldp_mib: lldp_discoverer = LldpDiscoverer(client) remote_devices_lldp = lldp_discoverer.get_remote_devices() if remote_devices_lldp: layer2_connections_lldp = get_layer2_connections(local_devices, remote_devices_lldp) for layer2_connection in layer2_connections_lldp: OSHVResult.addAll(build_layer2_connection(layer2_connection)) if (not layer2_connections_cdp or len(layer2_connections_cdp) == 0) and (not layer2_connections_lldp or len(layer2_connections_lldp) == 0): logger.reportError('No data collected') finally: if client != None: client.close() return OSHVResult
def bool_params(self, **kwargs): for name, default_value in kwargs.iteritems(): value = self.__framework.getParameter(name) if value is not None: value = Boolean.parseBoolean(value) else: value = default_value self.__obj[name] = value return self
def disWinOS(host_obj, shell, Framework, langBund = None, pid2Process = None): discoverProcesses = Boolean.parseBoolean(Framework.getParameter('discoverProcesses')) OSHVResult = None if discoverProcesses: OSHVResult = ObjectStateHolderVector() if not NTCMD_HR_Dis_Process_Lib.discoverProcessesByWmic(shell, OSHVResult, host_obj, Framework, pid2Process): NTCMD_HR_Dis_Process_Lib.discoverProcesses(shell, OSHVResult, host_obj, Framework, pid2Process) return OSHVResult
def bool_params(self, **kwargs): for name, default_value in kwargs.iteritems(): value = self.__framework.getParameter(name) if value is not None: value = Boolean.parseBoolean(value) else: value = default_value self.__obj[name] = value return self
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() logger.debug('Start nmap_osfingerprint.py') ip = Framework.getDestinationAttribute('ip_address') timeout = Framework.getParameter('nmap_host_timeout') if not str(timeout).isdigit(): msg = "Timeout parameter value must be a digit" logger.debug(msg) errormessages.resolveAndReport(msg, ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME, Framework) return OSHVResult timeout = int(timeout) * 1000 scanKnownPortsOnly = Boolean.parseBoolean(Framework.getParameter('scan_known_ports_only')) portstoscan = Framework.getParameter('scan_these_ports_only') doServiceFingerprints =Boolean.parseBoolean(Framework.getParameter('Perform_Port_Fingerprints')) createApp = Boolean.parseBoolean(Framework.getParameter('Create_Application_CI')) discoverOsName =Boolean.parseBoolean(Framework.getParameter('discover_os_name')) nmapLocation = Framework.getParameter('nmap_location') #discover_UDP_Ports = int(Framework.getParameter('Discover_UDP_Ports')) discoverUdpPorts = 0 agent_root_dir=CollectorsParameters.BASE_PROBE_MGR_DIR agent_ext_dir = agent_root_dir + CollectorsParameters.getDiscoveryResourceFolder() + CollectorsParameters.FILE_SEPARATOR tmp_file_name = agent_ext_dir + string.replace(ip,'.','_') + time.strftime("%H%M%S",time.gmtime(time.time())) + 'nmap.xml' syncNmapPortConfigFile(agent_root_dir) logger.debug('temp file for storing nmap results: ', tmp_file_name) try: client = Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) try: performNmapDiscover(client, ip, tmp_file_name,timeout,agent_ext_dir,scanKnownPortsOnly,portstoscan,doServiceFingerprints, discoverUdpPorts, nmapLocation) if os.path.exists(tmp_file_name): logger.debug('start processing the nmap results') processNmapResult(tmp_file_name, OSHVResult, discoverOsName, doServiceFingerprints, createApp, Framework) else: raise ValueError, 'Error nmap result file is missing: %s' % tmp_file_name finally: client.close() File(tmp_file_name).delete() except Exception, e: msg = str(e.getMessage()) logger.debug(msg) errormessages.resolveAndReport(msg, ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME, Framework)
def initializeServices(self): self.updateUtilizationInfo = 1 self.discoverDependLinks = Boolean.parseBoolean( self.getParameterValue('discoverDependLinks')) self.onlyHostDependLinks = 0 self.ignoreUnackedTcpConn = 0 self.shouldCountClients = 1 self.discoverIP = self.Framework.getDestinationAttribute('ip_address') self.hostId = self.Framework.getDestinationAttribute('hostId') self.minimalClients = Integer.parseInt( self.Framework.getParameter('minClients')) self.minimalOctets = Integer.parseInt( self.Framework.getParameter('minOctets')) self.minimalPackets = Integer.parseInt( self.Framework.getParameter('minPackets')) self.protocols = self.Framework.getParameter('protocols') self.disregardListenPorts = Boolean.parseBoolean( self.getParameterValue('disregardListenPorts'))
def getPayloadContent(self): mimeType = self.__mimeType print " * detail.py: payload content mimeType=%s" % mimeType contentStr = "" if mimeType == "application/octet-stream": dcFormat = self.__json.get("response/docs/dc_format") if dcFormat is not None: dcFormat = dcFormat[1:-1] print dcFormat, mimeType if dcFormat != mimeType: return "<div><em>(File not found)</em></div>" else: return "<div><em>(Binary file)</em></div>" elif mimeType.startswith("text/"): if mimeType == "text/html": contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s"></iframe>' % \ (contextPath, portalId, self.__oid) else: pid = self.__oid[self.__oid.rfind("/")+1:] payload = self.__storage.getPayload(self.__oid, pid) #print " * detail.py: pid=%s payload=%s" % (pid, payload) if payload is not None: sw = StringWriter() sw.write("<pre>") IOUtils.copy(payload.getInputStream(), sw) sw.write("</pre>") sw.flush() contentStr = sw.toString() elif mimeType == "application/pdf" or mimeType.find("vnd.ms")>-1 or mimeType.find("vnd.oasis.opendocument.")>-1: # get the html version if exist... pid = os.path.splitext(self.__pid)[0] + ".htm" print " * detail.py: pid=%s" % pid #contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s/%s"></iframe>' % \ # (contextPath, portalId, self.__oid, pid) payload = self.__storage.getPayload(self.__oid, pid) saxReader = SAXReader(Boolean.parseBoolean("false")) try: document = saxReader.read(payload.getInputStream()) slideNode = document.selectSingleNode("//*[local-name()='body']") #linkNodes = slideNode.selectNodes("//img") #contentStr = slideNode.asXML(); # encode character entities correctly slideNode.setName("div") out = ByteArrayOutputStream() format = OutputFormat.createPrettyPrint() format.setSuppressDeclaration(True) format.setExpandEmptyElements(True) writer = XMLWriter(out, format) writer.write(slideNode) writer.close() contentStr = out.toString("UTF-8") except: traceback.print_exc() contentStr = "<p class=\"error\">No preview available</p>" return contentStr
def clickSaveBtn(event): global table global frame global heading rowCount = table.getRowCount() i = 0 if (heading.getText() == "Attendence"): while (i < rowCount): teacherId = table.getValueAt(i, 0) teacherName = table.getValueAt(i, 1) date = table.getValueAt(i, 2) if (Boolean.parseBoolean(str(table.getValueAt(i, 3)))): present = 'P' else: present = 'A' ta = domain.TeacherAttendence() setattr(ta, 'teacherId', teacherId) setattr(ta, 'teacherName', teacherName) setattr(ta, 'date', date) setattr(ta, 'present', present) i = i + 1 srv.saveTeacherAttendence(ta) JOptionPane.showMessageDialog(None, "Attendence for today has been saved") elif (heading.getText() == "Update Attendence"): while (i < rowCount): teacherId = table.getValueAt(i, 0) date = table.getValueAt(i, 2) if (Boolean.parseBoolean(str(table.getValueAt(i, 3)))): present = 'P' else: present = 'A' i = i + 1 srv.updateTeacherAttendence(teacherId, date, present) JOptionPane.showMessageDialog(None, "Attendence for today has been updated") frame.dispose()
def cleanup(self): "cleanup" logger.info("Enter cleanup") try: copyContainerEnvironment() removeContainer = Boolean.parseBoolean(getVariableValue("REMOVE_DOCKER_CONTAINER", "true")) removeImage = Boolean.parseBoolean(getVariableValue("REMOVE_DOCKER_IMAGE", "false")) for index in range(len(self.__dockerContainerName) - 1, -1, -1): if removeContainer: self.__rm(index) if removeImage: self.__rmi(index) except: type, value, traceback = sys.exc_info() logger.warning("cleanup error:" + `value`) logger.info("Exit cleanup")
def __init__(self, Framework): self.Framework = Framework self.conn = self.Framework.getProbeDatabaseConnection(ProcessToProcess.CONTEXT) self.knownPortsConfigFile = self.Framework.getConfigFile(CollectorsParameters.KEY_COLLECTORS_SERVERDATA_PORTNUMBERTOPORTNAME) self.shouldIgnoreLocal = Boolean.parseBoolean(self.Framework.getParameter('ignoreP2PLocalConnections')) self.knownListeningPorts = self.getKnownListeningPortsSet() self.requestedServices = self.getRequestedPortsSet() self.hostID = Framework.getDestinationAttribute('hostId') self.ignoredProcesses = HashSet() self.processMap = {} self.getProcessesToFilter()
def removeScanData(Framework): RemoveScanData = Boolean.parseBoolean( Framework.getParameter('RemoveScanData')) remoteScanFileLocation = Framework.getProperty( InventoryUtils.STATE_PROPERTY_REMOTE_SCAN_FILE_LOCATION) remoteScanFileLogLocation = os.path.splitext( remoteScanFileLocation)[0] + '.log' scannerExecutableRemotePath = Framework.getProperty( InventoryUtils.SCANNER_EXECUTABLE_REMOTE_PATH) scannerConfigRemotePath = Framework.getProperty( InventoryUtils.SCANNER_CONFIG_REMOTE_PATH) protocolName = Framework.getProperty( InventoryUtils.STATE_PROPERTY_CONNECTED_SHELL_PROTOCOL_NAME) isUDA = protocolName == ClientsConsts.DDM_AGENT_PROTOCOL_NAME if RemoveScanData and not isUDA and (remoteScanFileLocation is not None): if not InventoryUtils.deleteFile(Framework, remoteScanFileLocation): errorMessage = 'Failed to delete scan file ' + remoteScanFileLocation logger.debug(errorMessage) Framework.reportError(errorMessage) Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) return if RemoveScanData and not isUDA and (remoteScanFileLogLocation is not None): if not InventoryUtils.deleteFile(Framework, remoteScanFileLogLocation): errorMessage = 'Failed to delete scan log ' + remoteScanFileLogLocation logger.debug(errorMessage) Framework.reportError(errorMessage) Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) return if RemoveScanData and not isUDA and (scannerExecutableRemotePath is not None): logger.debug("Remove scan executable file:", scannerExecutableRemotePath) if not InventoryUtils.deleteFile(Framework, scannerExecutableRemotePath): errorMessage = 'Failed to delete scan executable file ' + scannerExecutableRemotePath logger.debug(errorMessage) Framework.reportError(errorMessage) Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) return if RemoveScanData and not isUDA and (scannerConfigRemotePath is not None): logger.debug("Remove scan config file:", scannerConfigRemotePath) if not InventoryUtils.deleteFile(Framework, scannerConfigRemotePath): errorMessage = 'Failed to delete scan config file ' + scannerConfigRemotePath logger.debug(errorMessage) Framework.reportError(errorMessage) Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) return Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def DiscoveryMain(Framework): shell = None try: try: protocolName = __getProtocolName(Framework) discoverSharePointUrls = Boolean.parseBoolean( Framework.getParameter('discoverSharePointUrls')) reportIntermediateWebService = Framework.getParameter( 'reportIntermediateWebService') if reportIntermediateWebService: reportIntermediateWebService = Boolean.parseBoolean( reportIntermediateWebService) else: #set default value reportIntermediateWebService = 1 relativeCommandTimeoutMultiplier = Framework.getParameter( 'relativeCommandTimeoutMultiplier') relativeCommandTimeoutMultiplier = int( relativeCommandTimeoutMultiplier) client = Framework.createClient() shell = ShellFactory().createShell(client) logger.debug('getting SharePoint discoverer for protocol %s' % protocolName) discoverer = sharepoint_win_shell.getDiscoverer( shell, protocolName, relativeCommandTimeoutMultiplier) logger.debug('got discoverer') resources = _discoverSharePoint(discoverer) resources.build() return resources.report(discoverSharePointUrls, reportIntermediateWebService) except SharePointException: logger.reportError() logger.debugException('') except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, protocolName, Framework) except: strException = logger.prepareJythonStackTrace('') errormessages.resolveAndReport(strException, protocolName, Framework)
def getArchiveDeployProperty(name, properties, default, parse=False): value = default try: if properties: value = properties.getProperty(name) if value and parse: value = Boolean.parseBoolean(value) except: pass return value
def getArchiveDeployProperty(name, properties, default, parse=False): value = default try: if properties: value = properties.getProperty(name) if value and parse: value = Boolean.parseBoolean(value) except: pass return value
def getPayloadContent(self): mimeType = self.__mimeType print " * single.py: payload content mimeType=%s" % mimeType contentStr = "" if mimeType.startswith("text/"): if mimeType == "text/html": contentStr = '<iframe class="iframe-preview" src="%s/download/%s"></iframe>' % \ (portalPath, self.__oid) else: pid = self.__oid[self.__oid.rfind("/") + 1:] payload = self.__storage.getPayload(self.__oid, pid) print " * single.py: pid=%s payload=%s" % (pid, payload) if payload is not None: sw = StringWriter() sw.write("<pre>") IOUtils.copy(payload.getInputStream(), sw) sw.write("</pre>") sw.flush() contentStr = sw.toString() elif mimeType == "application/pdf" or mimeType.find( "vnd.ms") > -1 or mimeType.find( "vnd.oasis.opendocument.") > -1: # get the html version if exist... pid = os.path.splitext(self.__pid)[0] + ".htm" print " * single.py: pid=%s" % pid #contentStr = '<iframe class="iframe-preview" src="%s/download/%s/%s"></iframe>' % \ # (portalPath, self.__oid, pid) payload = self.__storage.getPayload(self.__oid, pid) saxReader = SAXReader(Boolean.parseBoolean("false")) try: document = saxReader.read(payload.getInputStream()) slideNode = document.selectSingleNode( "//*[local-name()='body']") #linkNodes = slideNode.selectNodes("//img") #contentStr = slideNode.asXML(); # encode character entities correctly slideNode.setName("div") out = ByteArrayOutputStream() format = OutputFormat.createPrettyPrint() format.setSuppressDeclaration(True) format.setExpandEmptyElements(True) writer = XMLWriter(out, format) writer.write(slideNode) writer.close() contentStr = out.toString("UTF-8") except: traceback.print_exc() contentStr = "<p class=\"error\">No preview available</p>" elif mimeType.startswith("image/"): src = "%s/%s" % (self.__oid, self.__pid) contentStr = '<a class="image" href="%(src)s" style="max-width:98%%">' \ '<img src="%(src)s" style="max-width:100%%" /></a>' % { "src": self.__pid } return contentStr
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() CmdbOIDFactory = CmdbObjectID.Factory hostId = CmdbOIDFactory.restoreObjectID(Framework.getDestinationAttribute('hostId')) sqlServerId = CmdbOIDFactory.restoreObjectID(Framework.getDestinationAttribute('id')) try: props = Properties() instance_name = Framework.getDestinationAttribute('instanceName') if instance_name and instance_name != 'NA' and instance_name.find('\\') != -1: props.setProperty('sqlprotocol_dbsid', instance_name[instance_name.find('\\')+1:]) mssqlClient = Framework.createClient(props) connection = SqlServerConnection.ClientSqlServerConnection(mssqlClient) logger.debug("got connection") discoveryOptions = SqlServerDiscoveryOptions() discoveryOptions.discoverConfigs = Boolean.parseBoolean(Framework.getParameter('discoverConfigs')) discoveryOptions.discoverDbUser = Boolean.parseBoolean(Framework.getParameter('discoverDbUser')) discoveryOptions.discoverSqlFile = Boolean.parseBoolean(Framework.getParameter('discoverSqlFile')) discoveryOptions.discoverSqlJob = Boolean.parseBoolean(Framework.getParameter('discoverSqlJob')) discoveryOptions.discoverProcedures = Boolean.parseBoolean(Framework.getParameter('discoverStoredProcedures')) discoveryOptions.discoverInternalProcedures = Boolean.parseBoolean(Framework.getParameter('discoverInternalProcedures')) sqlServer = SqlServer.SqlServer(connection, discoveryOptions) OSHVResult.addAll(sqlServer.collectData(hostId, sqlServerId, discoveryOptions.discoverConfigs)) mssqlClient.close() except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, ClientsConsts.SQL_PROTOCOL_NAME, Framework)
def DiscoveryMain(Framework): ''' Discovery process consists of two steps: 1. Connect domain controller and get whole topology 2. Strive to connect to the same controller with the same credentials but in role of global catalog. 2.1 GC indexes more hierarchical data but less object specific data, so not all data will be rediscovered. ''' vector = ObjectStateHolderVector() ## Destination Attribute Section hostId = Framework.getDestinationAttribute('hostId') credentialsId = Framework.getDestinationAttribute('credentials_id') applicationPort = Framework.getDestinationAttribute("application_port") serviceAddressPort = Framework.getDestinationAttribute('port') OU_REPORTING_PARAM = 'reportOUAsConfigurationDocument' isOuUnitsTreeReportedAsConfig = Framework.getParameter(OU_REPORTING_PARAM) isOuUnitsTreeReportedAsConfig = parseBoolean(isOuUnitsTreeReportedAsConfig) tryToDiscoverGlobalCatalogFlag = Boolean.parseBoolean( Framework.getParameter('tryToDiscoverGlobalCatalog')) globalCatalogPort = Framework.getParameter('globalCatalogPort') if not applicationPort or applicationPort == 'NA': applicationPort = serviceAddressPort try: result = DiscoveryResult() vector.addAll( _discoverTopology(Framework, credentialsId, hostId, applicationPort, None, isOuUnitsTreeReportedAsConfig, result)) #no reason to connect to the GC if port is specified in credentials if (tryToDiscoverGlobalCatalogFlag and str(globalCatalogPort).isdigit() and globalCatalogPort != applicationPort): vector.addAll( _discoverTopology(Framework, credentialsId, hostId, globalCatalogPort, tryToDiscoverGlobalCatalogFlag, isOuUnitsTreeReportedAsConfig, result)) dtoToOsh = result.getMap(DOMAINT_DTO_TO_CONFIG_OSH_TYPE) fptools.each(vector.add, dtoToOsh.values()) except Exception, e: msg = 'Failure in discovering Active Directory Topology. %s' % e Framework.reportError(msg) logger.debug(logger.prepareFullStackTrace(msg)) logger.errorException(msg)
def cleanup(self): "cleanup" logger.info("Enter cleanup") try: copyContainerEnvironment() removeContainer = Boolean.parseBoolean( getVariableValue("REMOVE_DOCKER_CONTAINER", "true")) removeImage = Boolean.parseBoolean( getVariableValue("REMOVE_DOCKER_IMAGE", "false")) for index in range(len(self.__dockerContainerName) - 1, -1, -1): if removeContainer: self.__rm(index) if removeImage: self.__rmi(index) except: type, value, traceback = sys.exc_info() logger.warning("cleanup error:" + ` value `) logger.info("Exit cleanup")
def __init__(self): self.__portal = Services.portalManager.get(portalId) sessionNav = self.__portal.get("portal/use-session-navigation", "true") self.__useSessionNavigation = Boolean.parseBoolean(sessionNav) self.__result = JsonConfigHelper() if self.__useSessionNavigation: self.__pageNum = sessionState.get("pageNum", 1) else: self.__pageNum = 1 self.__selected = ArrayList() self.__fqParts = [] self.__searchField = formData.get("searchField", "full_text") self.__search()
def updateWithPrePostScriptCmd(Framework, commandLine): isPrePostScriptAllowed = Boolean.parseBoolean(Framework.getParameter('IsPrePostScriptAllowed')) prePostScriptExecTimeout = Integer.parseInt(Framework.getParameter('PrePostScriptExecTimeout')) logger.debug("isPrePostScriptAllowed:", isPrePostScriptAllowed) if isPrePostScriptAllowed: deltaParams = ' -scripts:. ' scriptTimeoutParam = '' if prePostScriptExecTimeout > 0: scriptTimeoutParam = ' -scriptstimeout:' + str(prePostScriptExecTimeout) + ' ' index = String(commandLine).indexOf(ENTERPRISE_MODE) + String(ENTERPRISE_MODE).length() commandLine = commandLine[0:index] + deltaParams + scriptTimeoutParam + commandLine[index + 1:] logger.debug('After apply pre/post scripts, scanner execution command updated to ', commandLine) return commandLine
def discover_fc_hbas(framework, host_osh, protocol, vector): discoverFcHBAs = Boolean.parseBoolean(framework.getParameter('discoverFcHBAs')) if discoverFcHBAs: import wmi from fc_hba_discoverer import discover_fc_hba_oshs_by_shell client = None try: client = wmi.ClientWrapper(partial(__create_client_fn, framework)) shell = wmi.ShellWrapper(client) oshs = discover_fc_hba_oshs_by_shell(shell, host_osh, protocol) vector.addAll(oshs) finally: client and Sfn(client.close)()
def disLinux(host_obj, client, Framework = None, langBund = None, packageToCmdLine = None, pid2Process = None): hostId = Framework.getDestinationAttribute('hostId') protocol = Framework.getDestinationAttribute('Protocol') discoverProcesses = Boolean.parseBoolean(Framework.getParameter('discoverProcesses')) myVec = ObjectStateHolderVector() timezone = None try: timezone = getTimezone(client) except ValueError, ex: msg = str(ex) errobj = errormessages.resolveError(msg, 'shell') logger.reportWarningObject(errobj)
def __activate__(self, context): self.velocityContext = context self.services = context["Services"] self.log = context["log"] self.sessionState = context["sessionState"] self.portalDir = context["portalDir"] self.__result = None self.__token = None self.__portalName = context["page"].getPortal().getName() self.__authors = [] self.__relatedResources = [] self.__enabledInAllViews = False self.__enabledInViews = [] self.__metadataPrefix = "" self.__sessionExpiry = Long.parseLong(JsonConfig().get("portal/oai-pmh/sessionExpiry")) self.__resumptionTokenList = self.sessionState.get("resumptionTokenList") if self.__resumptionTokenList == None: self.__resumptionTokenList = {} #Check if there's resumption token exist in the formData self.__currentToken = None resumptionToken = self.vc("formData").get("resumptionToken") if resumptionToken: if self.__resumptionTokenList.has_key(resumptionToken): self.__currentToken = self.__resumptionTokenList[resumptionToken] print " * oai.py: formData=%s" % self.vc("formData") self.vc("request").setAttribute("Content-Type", "text/xml") self.__request = OaiPmhVerb(self.vc("formData"), self.__currentToken, self.sessionState) if self.getError() is None and \ self.getVerb() in ["GetRecord", "ListIdentifiers", "ListRecords"]: ## Only list those data if the metadata format is enabled self.__metadataPrefix = self.vc("formData").get("metadataPrefix") if self.__metadataPrefix is None: self.__metadataPrefix = self.__currentToken.getMetadataPrefix() self.__enabledInAllViews = Boolean.parseBoolean(JsonConfig().get("portal/oai-pmh/metadataFormats/%s/enabledInAllViews" % self.__metadataPrefix, "false")) if self.__enabledInAllViews: self.__search() else: self.__enabledInViews = JsonConfig().getList("portal/oai-pmh/metadataFormats/%s/enabledViews" % self.__metadataPrefix) if self.__portalName in self.__enabledInViews: self.__search()
def checkScanFileExistance(Framework): # this step is always finished with success since we DON'T require scan file from previous execution, just nice to have Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS) DownloadScanFileBeforeExecution = Boolean.parseBoolean(Framework.getParameter('DownloadScanFileBeforeExecution')) if DownloadScanFileBeforeExecution: try: client = Framework.getConnectedClient() options = LockUtils.getClientOptionsMap(client) previousExecutionStarted = options.get(InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED) if (previousExecutionStarted is None) or (len(previousExecutionStarted.strip()) == 0): logger.debug('Previous execution timestamp no found, continuing with workflow') return remoteScanFileLocation = options.get(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME) if not InventoryUtils.isPathValid(remoteScanFileLocation): logger.debug('No scan file path found on remote machine, continuing with workflow') return lastSuccessExecuton = Framework.getState().getJobLastSuccessfulRun() logger.debug('Last success execution ' + str(lastSuccessExecuton)) logger.debug('Remote scan file execution ' + str(previousExecutionStarted)) if long(lastSuccessExecuton) > long(previousExecutionStarted): logger.debug('Scan file on probe side is newer than on remote machine, skipping downloading') return logger.debug('Last success execution ' + str(lastSuccessExecuton) + ' older than scan file on remote machine ' + str(remoteScanFileLocation) + '. Going to download scan file:' + str(remoteScanFileLocation)) tempScanFileFolder = CollectorsParameters.PROBE_MGR_TEMPDOWNLOAD + Framework.getDiscoveryJobId() + CollectorsParameters.FILE_SEPARATOR File(tempScanFileFolder).mkdirs() extension = InventoryUtils.getFileExtension(remoteScanFileLocation) tempScanFileName = InventoryUtils.generateScanFileName(Framework, extension) tempScanFile = File(tempScanFileFolder, tempScanFileName) tempScanFilePath = tempScanFile.getCanonicalPath() logger.debug('Try to download scan file to the:', tempScanFilePath) if not InventoryUtils.copyRemoteFileToLocal(Framework, remoteScanFileLocation, tempScanFilePath, 0): logger.debug('Failed to download scan file before current execution') Framework.setProperty(InventoryUtils.STATE_PROPERTY_TEMP_SCAN_FILE, tempScanFilePath) except: reason = str(sys.exc_info()[1]) logger.debug('Failed to check/download scan file from previous execution. Reason:', reason) else: logger.debug('Even not checking whether scan file exists on remote machine or not.')
def DiscoveryMain(Framework): ''' Discovery process consists of two steps: 1. Connect domain controller and get whole topology 2. Strive to connect to the same controller with the same credentials but in role of global catalog. 2.1 GC indexes more hierarchical data but less object specific data, so not all data will be rediscovered. ''' vector = ObjectStateHolderVector() ## Destination Attribute Section hostId = Framework.getDestinationAttribute('hostId') credentialsId = Framework.getDestinationAttribute('credentials_id') applicationPort = Framework.getDestinationAttribute("application_port") serviceAddressPort = Framework.getDestinationAttribute('port') OU_REPORTING_PARAM = 'reportOUAsConfigurationDocument' isOuUnitsTreeReportedAsConfig = Framework.getParameter(OU_REPORTING_PARAM) isOuUnitsTreeReportedAsConfig = parseBoolean(isOuUnitsTreeReportedAsConfig) tryToDiscoverGlobalCatalogFlag = Boolean.parseBoolean( Framework.getParameter('tryToDiscoverGlobalCatalog')) globalCatalogPort = Framework.getParameter('globalCatalogPort') if not applicationPort or applicationPort == 'NA': applicationPort = serviceAddressPort try: result = DiscoveryResult() vector.addAll(_discoverTopology(Framework, credentialsId, hostId, applicationPort, None, isOuUnitsTreeReportedAsConfig, result)) #no reason to connect to the GC if port is specified in credentials if (tryToDiscoverGlobalCatalogFlag and str(globalCatalogPort).isdigit() and globalCatalogPort != applicationPort): vector.addAll(_discoverTopology(Framework, credentialsId, hostId, globalCatalogPort, tryToDiscoverGlobalCatalogFlag, isOuUnitsTreeReportedAsConfig, result)) dtoToOsh = result.getMap(DOMAINT_DTO_TO_CONFIG_OSH_TYPE) fptools.each(vector.add, dtoToOsh.values()) except Exception, e: msg = 'Failure in discovering Active Directory Topology. %s' % e Framework.reportError(msg) logger.debug(logger.prepareFullStackTrace(msg)) logger.errorException(msg)
def discover_fc_hbas(framework, host_osh, protocol, vector): discoverFcHBAs = Boolean.parseBoolean( framework.getParameter('discoverFcHBAs')) if discoverFcHBAs: import wmi from fc_hba_discoverer import discover_fc_hba_oshs_by_shell client = None try: client = wmi.ClientWrapper(partial(__create_client_fn, framework)) shell = wmi.ShellWrapper(client) oshs = discover_fc_hba_oshs_by_shell(shell, host_osh, protocol) vector.addAll(oshs) finally: client and Sfn(client.close)()
def createIpsNetworksOSHV(ipList, sysTable, hostId, hostIsComplete): ipsAndNetworksOSHV = ObjectStateHolderVector() isRoute = checkIsRoute(ipList) hostOSH = modeling.createOshByCmdbId(sysTable.sysClass, hostId) builder = HostBuilder(hostOSH) builder.setAsRouter(isRoute, __NOT_SET_ROLE) if str(sysTable.sysModel).lower() != 'unknown': builder.setStringAttribute("host_model", sysTable.sysModel) if str(sysTable.sysOs).lower() != 'unknown': builder.setOsName(sysTable.sysOs) if str(sysTable.sysVendor).lower() != 'unknown': builder.setStringAttribute("host_vendor", sysTable.sysVendor) if sysTable.sysName != None and str(sysTable.sysName).lower() != 'unknown': builder.setStringAttribute("host_snmpsysname", sysTable.sysName) if sysTable.sysNodeName is not None: builder.setStringAttribute("host_hostname", sysTable.sysNodeName) hostOSH = builder.build() ipsAndNetworksOSHV.add(hostOSH) for ip in ipList: if not isValidIP(ip): continue #create ip object ipOSH = modeling.createIpOSH(ip.ipAddr, ip.ipNetMask) #create network object networkOSH = modeling.createNetworkOSH(ip.ipAddr, ip.ipNetMask) if ip.nettype != None and int(ip.nettype) > 0: networkOSH.setEnumAttribute("network_nettype", int(ip.nettype)) #create member link object ( end1(network) and end2(ip) ) memberLinkOSHIpNetwork = modeling.createLinkOSH("member", networkOSH, ipOSH) #create member link object ( end1(network) and end2(host) ) memberLinkOSHHostNetwork = modeling.createLinkOSH("member", networkOSH, hostOSH) #create contained link object ( end1(host) and end2(ip) ) if Boolean.parseBoolean(hostIsComplete): containedLinkOSHIpHost = modeling.createLinkOSH("contained", hostOSH, ipOSH) ipsAndNetworksOSHV.add(containedLinkOSHIpHost) ipsAndNetworksOSHV.add(ipOSH) ipsAndNetworksOSHV.add(networkOSH) ipsAndNetworksOSHV.add(memberLinkOSHIpNetwork) ipsAndNetworksOSHV.add(memberLinkOSHHostNetwork) return ipsAndNetworksOSHV
def upgradePrePostScript(scannersConfigFile, scannerPlatformConfig, Framework): logger.debug('Installing pre/post script') BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) unixConfig = scannersConfigFile.getPlatformConfiguration('unix', "") #whether run or not pre-scan and post-scan scripts isPrePostScriptAllowed = Boolean.parseBoolean(Framework.getParameter('IsPrePostScriptAllowed')) logger.debug("isPrePostScriptAllowed:", isPrePostScriptAllowed) if not isPrePostScriptAllowed: return isAllUnix = False preScanScriptLocalPath = getPrePostScriptLocalPath(scannerPlatformConfig.getScannerPreScanScriptLocalFile()) logger.debug('preScanScriptLocalPath:', preScanScriptLocalPath) if InventoryUtils.isUnix(platform) and not os.path.exists(preScanScriptLocalPath): logger.debug("No specific platform for the device, use all-unix.") isAllUnix = True preScanScriptLocalPath = getPrePostScriptLocalPath(unixConfig.getScannerPreScanScriptLocalFile()) logger.debug("preScanScriptLocalPath:", preScanScriptLocalPath) postScanScriptLocalPath = getPrePostScriptLocalPath(scannerPlatformConfig.getScannerPostScanScriptLocalFile()) logger.debug('postScanScriptLocalPath:', postScanScriptLocalPath) if InventoryUtils.isUnix(platform) and not os.path.exists(postScanScriptLocalPath): logger.debug("No specific platform for the device, use all-unix.") isAllUnix = True postScanScriptLocalPath = getPrePostScriptLocalPath(unixConfig.getScannerPostScanScriptLocalFile()) logger.debug('postScanScriptLocalPath:', postScanScriptLocalPath) preScanScriptRemotePath = BASEDIR + scannerPlatformConfig.getScannerPreScanScriptRemoteFile() logger.debug('preScanScriptRemotePath:', preScanScriptRemotePath) postScanScriptRemotePath = BASEDIR + scannerPlatformConfig.getScannerPostScanScriptRemoteFile() logger.debug('postScanScriptRemotePath:', postScanScriptRemotePath) if os.path.exists(preScanScriptLocalPath): InventoryUtils.copyLocalFileToRemote(Framework, preScanScriptLocalPath, preScanScriptRemotePath) if os.path.exists(postScanScriptLocalPath): InventoryUtils.copyLocalFileToRemote(Framework, postScanScriptLocalPath, postScanScriptRemotePath) # upgrade resource files for PrePostScript upgradePrePostScriptResource(isAllUnix, Framework) Framework.setProperty(InventoryUtils.SCANNER_PRE_SCAN_SCRIPT_REMOTE_PATH, preScanScriptRemotePath) Framework.setProperty(InventoryUtils.SCANNER_POST_SCAN_SCRIPT_REMOTE_PATH, postScanScriptRemotePath)
def isMsSqlConnectionPortValid(Framework, client): (_, db_type) = dbMetaParams[client.getProtocolDbType().lower()] if db_type == 'sqlserver': try: filterForwardedPorts = Boolean.parseBoolean( Framework.getParameter('handleSQLBrowserMappings')) except: logger.debugException('') filterForwardedPorts = False if filterForwardedPorts: listening_ports = getMsSqlServerSidePort(client) if listening_ports and not (str(client.getPort()) in listening_ports): logger.warn( 'Encountered a situation when connection port is not among listening ports of database. Skipping.' ) return False return True
def updateWithPrePostScriptCmd(Framework, commandLine): isPrePostScriptAllowed = Boolean.parseBoolean( Framework.getParameter('IsPrePostScriptAllowed')) prePostScriptExecTimeout = Integer.parseInt( Framework.getParameter('PrePostScriptExecTimeout')) logger.debug("isPrePostScriptAllowed:", isPrePostScriptAllowed) if isPrePostScriptAllowed: deltaParams = ' -scripts:. ' scriptTimeoutParam = '' if prePostScriptExecTimeout > 0: scriptTimeoutParam = ' -scriptstimeout:' + str( prePostScriptExecTimeout) + ' ' index = String(commandLine).indexOf(ENTERPRISE_MODE) + String( ENTERPRISE_MODE).length() commandLine = commandLine[ 0:index] + deltaParams + scriptTimeoutParam + commandLine[index + 1:] logger.debug( 'After apply pre/post scripts, scanner execution command updated to ', commandLine) return commandLine
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() CmdbOIDFactory = CmdbObjectID.Factory hostId = CmdbOIDFactory.restoreObjectID( Framework.getDestinationAttribute('hostId')) sqlServerId = CmdbOIDFactory.restoreObjectID( Framework.getDestinationAttribute('id')) try: props = Properties() instance_name = Framework.getDestinationAttribute('instanceName') if instance_name and instance_name != 'NA' and instance_name.find( '\\') != -1: props.setProperty('sqlprotocol_dbsid', instance_name[instance_name.find('\\') + 1:]) mssqlClient = Framework.createClient(props) connection = SqlServerConnection.ClientSqlServerConnection(mssqlClient) logger.debug("got connection") discoveryOptions = SqlServerDiscoveryOptions() discoveryOptions.discoverConfigs = Boolean.parseBoolean( Framework.getParameter('discoverConfigs')) discoveryOptions.discoverDbUser = Boolean.parseBoolean( Framework.getParameter('discoverDbUser')) discoveryOptions.discoverSqlFile = Boolean.parseBoolean( Framework.getParameter('discoverSqlFile')) discoveryOptions.discoverSqlJob = Boolean.parseBoolean( Framework.getParameter('discoverSqlJob')) discoveryOptions.discoverProcedures = Boolean.parseBoolean( Framework.getParameter('discoverStoredProcedures')) discoveryOptions.discoverInternalProcedures = Boolean.parseBoolean( Framework.getParameter('discoverInternalProcedures')) sqlServer = SqlServer.SqlServer(connection, discoveryOptions) OSHVResult.addAll( sqlServer.collectData(hostId, sqlServerId, discoveryOptions.discoverConfigs)) mssqlClient.close() except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, ClientsConsts.SQL_PROTOCOL_NAME, Framework)
def isEnabledDiscovery(discovery, framework=framework): if discovery.jobParameter in ('ec2DiscoveryEnabled', 'rdsDiscoveryEnabled'): return 1 jobParameter = framework.getParameter(discovery.jobParameter) return Boolean.parseBoolean(jobParameter)
def __init__(self, additionalVariables): " initialize Docker Swarm" self.__swarmid = getVariableValue("DOCKER_SWARM_UUID") if not self.__swarmid: raise Exception("DOCKER_SWARM_UUID is required and must be a UUID") elif not isUUID(self.__swarmid): raise Exception("DOCKER_SWARM_ID provided is not a valid UUID") self.__bootDockerSock = getVariableValue("DOCKER_BOOTSTRAP_SOCK") if not self.__bootDockerSock: raise Exception("DOCKER_BOOTSTRAP_SOCK is required") discoveryKeyStore = getVariableValue("DISCOVERY_KEY_STORE") if not discoveryKeyStore: raise Exception("DISCOVERY_KEY_STORE is required") self.__discoveryService = getVariableValue("DISCOVERY_SERVICE") if not self.__discoveryService: raise Exception("DISCOVERY_SERVICE is required") if str(discoveryKeyStore).endswith("/"): discoveryKeyStore = discoveryKeyStore[:-1] self.__discoveryKeyStore = discoveryKeyStore + "/" + self.__swarmid listenAddress = getVariableValue("LISTEN_ADDRESS") self.__mountVolumes = ['', ''] self.__dockerContainerName = [ "swarm_join", "swarm_manage", "swarm_registrator" ] self.__dockerImage = ["swarm"] self.__command = ["join"] dockerPort = ":" + getVariableValue("DOCKER_PORT", "2375") self.__dockerAddr = listenAddress + dockerPort args = ["--advertise", self.__dockerAddr, self.__discoveryKeyStore] self.__commandArgs = [list2str(args)] self.__networkMode = ['--net=host'] self.__dockerImage.append("swarm") self.__command.append("manage") managePort = getVariableValue("MANAGE_PORT", "4000") self.__manageAddr = listenAddress + ":" + managePort strategy = getVariableValue("DOCKER_SWARM_STRATEGY", "spread") if strategy not in ["spread", "binpack", "random"]: strategy = "spread" args = [ "-H", ":" + managePort, "--strategy", strategy, " --replication", "--advertise", self.__manageAddr, self.__discoveryKeyStore ] self.__commandArgs.append(list2str(args)) self.__networkMode.append('--net=host') registrator = getVariableValue("DOCKER_IMAGE_REGISTRATOR") if registrator: self.__dockerImage.append(registrator) self.__networkMode.append('--net=host') self.__mountVolumes.append( '--volume=/var/run/docker.sock:/tmp/docker.sock') self.__command.append(self.__discoveryService) self.__commandArgs.append('') self.__basedir = getVariableValue("CONTAINER_WORK_DIR") self.__running = [False, False, False] self.__stats = [] self.__dockerStats = {} self.__runningContainers = [] self.__dockerLog = getVariableValue("DOCKER_CONTAINER_LOGS") if not self.__dockerLog: self.__dockerLog = os.path.join(self.__basedir, "docker.log") self.__sudo = Boolean.parseBoolean( getVariableValue("USE_SUDO", "false")) self.__compName = proxy.container.currentDomain.name self.__compName = re.sub("[\s]+", "", self.__compName) self.__dockerCompose = getVariableValue("DOCKER_COMPOSE_PATH") self.__detachSwarm = Boolean.parseBoolean( getVariableValue("DETACH_SWARM_ON_SHUTDOWN", "false")) self.__forceReconfig = Boolean.parseBoolean( getVariableValue("FORCE_RECONFIG", "true")) self.__deploydir = os.path.join( getVariableValue("COMPOSE_DEPLOY_DIRECTORY", self.__basedir), self.__swarmid) self.__swarmNetwork = getVariableValue("DOCKER_SWARM_NETWORK") self.__lockExpire = int(getVariableValue("LOCK_EXPIRE", "300000")) self.__lockWait = int(getVariableValue("LOCK_WAIT", "30000")) self.__role = "replica" self.__lockExpire = int(getVariableValue("LOCK_EXPIRE", "300000")) self.__lockWait = int(getVariableValue("LOCK_WAIT", "30000"))