示例#1
0
def ejecutaOSB(userAdmin, passAdmin, portAdmin, hostnameAdmin, ambiente):
 now = datetime.datetime.now()
 sessionName = "SesionScriptOSB_"+str(now.day)+"_"+str(now.month)+"_"+str(now.year)+"_"+ambiente
 print "t3", hostnameAdmin, portAdmin, "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME
 serviceURL = JMXServiceURL("t3", hostnameAdmin, int(portAdmin), "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME)
 h = Hashtable()
 h.put(Context.SECURITY_PRINCIPAL, userAdmin)
 h.put(Context.SECURITY_CREDENTIALS, passAdmin)
 h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote")
 conn = JMXConnectorFactory.connect(serviceURL, h)

 arregloAllProject = []
 arregloAllProxy = []
 arregloAllBS = []
 arregloAllServicesURI = []
 arregloAllDependentS = []
 
 mbconn = conn.getMBeanServerConnection()
 sm = JMX.newMBeanProxy(mbconn, ObjectName.getInstance(SessionManagementMBean.OBJECT_NAME), SessionManagementMBean)
 sm.createSession(sessionName)
 configMBean = JMX.newMBeanProxy(mbconn, ObjectName.getInstance("com.bea:Name=" + ALSBConfigurationMBean.NAME + "." + sessionName + ",Type=" + ALSBConfigurationMBean.TYPE), ALSBConfigurationMBean)
 print "##############################"
 print "###Se genera conexion a OSB###"
 print "##############################"
 arregloAllProject=displayAllProjectsAndServices(ambiente, configMBean)
 arregloAllProxy=getAllProxyServices(ambiente, configMBean)
 arregloAllBS=getAllBusinessServices(ambiente, configMBean)                               
 arregloAllServicesURI=getAllServiceURIs(ambiente, configMBean)
 arregloAllDependentS=getDependentServices(ambiente, configMBean)
 sm.discardSession(sessionName)
 conn.close()
	
 return arregloAllProject, arregloAllProxy, arregloAllBS, arregloAllServicesURI, arregloAllDependentS
示例#2
0
def connectToJMX(args):
    # Basic JMX connection, always required
    trust_managers = array([TrustAllX509TrustManager()], TrustManager)

    sc = SSLContext.getInstance("SSL")
    sc.init(None, trust_managers, None)
    SSLContext.setDefault(sc)
    jmx_url = JMXServiceURL("service:jmx:rmi:///jndi/rmi://" +
                            args.targetHost + ":" + args.targetPort +
                            "/jmxrmi")

    print "[+] Connecting to: " + str(jmx_url)
    try:
        # for passing credentials for password
        if args.jmxpassword and args.jmxrole:
            print("[+] Using credentials: " + str(args.jmxrole) + " / " +
                  str(args.jmxpassword))
            credentials = array([args.jmxrole, args.jmxpassword], String)
            environment = {JMXConnector.CREDENTIALS: credentials}
            jmx_connector = JMXConnectorFactory.connect(jmx_url, environment)
        else:
            jmx_connector = JMXConnectorFactory.connect(jmx_url)

        print "[+] Connected: " + str(jmx_connector.getConnectionId())
        bean_server = jmx_connector.getMBeanServerConnection()
        return bean_server
    except:
        print "[-] Error: Can't connect to remote service"

        if "Authentication failed! Invalid username or password" in str(
                sys.exc_info()[1]):
            print "[-] Authentication failed! Invalid username or password"

        sys.exit(-1)
    def __createJMXConnection(self):
        "create JMX connection"

        self.__jmxConnection = None
        self.__jmxConnector = None

        try:
            jmxServiceUrl = JMXServiceURL(self.__jmxUrl)
            env = Hashtable()
            cred = array([self.__jmxUser, self.__jmxPassword], String)
            env.put("jmx.remote.credentials", cred)
            logger.info("Connecting to Oracle Coherence MBean Server:" +
                        ` jmxServiceUrl `)
            self.__jmxConnector = JMXConnectorFactory.connect(
                jmxServiceUrl, env)
            self.__jmxConnection = self.__jmxConnector.getMBeanServerConnection(
            )
            logger.info(
                "Successfully connected to Oracle Coherence MBean Server:" +
                ` jmxServiceUrl `)
        except:
            type, value, traceback = sys.exc_info()
            logger.finer("JMX Connection error:" + ` value `)
            self.__jmxConnection = None
            try:
                if self.__jmxConnector:
                    self.__jmxConnector.close()
                    self.__jmxConnector = None
            except:
                type, value, traceback = sys.exc_info()
                logger.finer("JMX Connector close error:" + ` value `)
示例#4
0
def connectToJMX(args):
    # Basic JMX connection, always required
    jmx_url = JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + args.targetHost + ":" + args.targetPort + "/jmxrmi")
    print "[+] Connecting to: " + str(jmx_url)
    jmx_connector = JMXConnectorFactory.connect(jmx_url)
    print "[+] Connected: " + str(jmx_connector.getConnectionId())
    bean_server = jmx_connector.getMBeanServerConnection()
    return bean_server
示例#5
0
文件: mjet.py 项目: w20di/mjet
def jxmrmi_url(args):
    print "[+] Using JMX RMI"

    from javax.management.remote import JMXServiceURL

    jmx_url = JMXServiceURL("service:jmx:rmi:///jndi/rmi://" +
                            args.targetHost + ":" + args.targetPort + "/jmxrmi")
    return jmx_url
示例#6
0
	def connectAdvanced(self,host,port,map):
		print "Connecting to the server..."
		System.setProperty("javax.net.ssl.trustStore", self.trustStore)
		System.setProperty("javax.net.ssl.trustStorePassword", self.trustStorePassword)
		url = JMXServiceURL("REST", host, port, "/IBMJMXConnectorREST")
		self.connector = JMXConnectorFactory.newJMXConnector(url, map)
		self.connector.connect()
		print "Successfully connected to the server " + '"' + host + ':%i"' % port
示例#7
0
def connectToJMX(args):
    # Basic JMX connection, always required
    jmx_url = JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + args.targetHost + ":" + args.targetPort + "/jmxrmi")
    print "[+] Connecting to: " + str(jmx_url)
    try:
        jmx_connector = JMXConnectorFactory.connect(jmx_url)
        print "[+] Connected: " + str(jmx_connector.getConnectionId())
        bean_server = jmx_connector.getMBeanServerConnection()
        return bean_server
    except IOException:
        print "[-] Error: Can't connect to remote service"
        sys.exit(-1)
示例#8
0
def get_mbean_server_connection(hostname, port, username, password):
    if verbose:
        print >> sys.stderr, "Conectandome al servidor de jmx..."
    jmx_service_url = JMXServiceURL(
        "t3", hostname, port,
        "/jndi/%s" % DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME)
    credentials_map = HashMap()
    credentials_map.put(Context.SECURITY_PRINCIPAL, username)
    credentials_map.put(Context.SECURITY_CREDENTIALS, password)
    credentials_map.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
                        "weblogic.management.remote")
    return JMXConnectorFactory.connect(jmx_service_url, credentials_map)
示例#9
0
文件: mjet.py 项目: w20di/mjet
def jmxmp_url(args):
    print "[+] Using JMX Message Protocol"
    if not os.path.isfile("./jars/opendmk_jmxremote_optional_jar-1.0-b01-ea.jar"):
        print "[-] Error: Did not find opendmk_jmxremote_optional_jar-1.0-b01-ea.jar in jars directory. Please download it from https://mvnrepository.com/artifact/org.glassfish.external/opendmk_jmxremote_optional_jar/1.0-b01-ea and move it into the jars directory"
        print "[-] Example: java -cp jython.jar:jars/opendmk_jmxremote_optional_jar-1.0-b01-ea.jar org.python.util.jython mjet.py ..."
        sys.exit(1)

    print "[+] Using opendmk_jmxremote_optional_jar-1.0-b01-ea.jar
        
    from javax.management.remote import JMXServiceURL
    jmx_url = JMXServiceURL("service:jmx:jmxmp://" +
                            args.targetHost + ":" + args.targetPort + "/")
    return jmx_url
示例#10
0
文件: sjet.py 项目: wolfscrew/sjet
def connectToJMX(args):
    # Basic JMX connection, always required
    trust_managers = array([TrustAllX509TrustManager()], TrustManager)

    sc = SSLContext.getInstance("SSL")
    sc.init(None, trust_managers, None)
    SSLContext.setDefault(sc)
    jmx_url = JMXServiceURL("service:jmx:rmi:///jndi/rmi://" +
                            args.targetHost + ":" + args.targetPort +
                            "/jmxrmi")
    print "[+] Connecting to: " + str(jmx_url)
    try:
        jmx_connector = JMXConnectorFactory.connect(jmx_url)
        print "[+] Connected: " + str(jmx_connector.getConnectionId())
        bean_server = jmx_connector.getMBeanServerConnection()
        return bean_server
    except IOException:
        print "[-] Error: Can't connect to remote service"
        sys.exit(-1)
示例#11
0
def open_jmx_connection(url):
    """Connect to JMX instance

    Args:
        url (str): jmx url to connect to

    Returns:
        jmxConnector: jmx server connection
        MBeanServerConnection: bean server connection

    """

    try:
        jmxServiceUrl = JMXServiceURL(url);
        jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl);
        mBeanServerConnection = jmxConnector.getMBeanServerConnection()
    except Exception, e:
        logger.error('Cannot connect to JMX instance. Error: ' + str(e))
        return None, None
示例#12
0
def main():
    parser = argparse.ArgumentParser(
        description="Dump JMX metrics to InfluxDB DML file")
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=0,
                        help='More verbose output, can use several times.')
    parser.add_argument("-s",
                        "--server",
                        default="127.0.0.1",
                        help="Server IP address")
    parser.add_argument("-p",
                        "--port",
                        type=int,
                        default=7199,
                        help="Port number")
    parser.add_argument("-u", "--user", default=None, help="User name")
    parser.add_argument("-P", "--password", default=None, help="Password")
    parser.add_argument("-r",
                        "--period",
                        default=60,
                        type=int,
                        help="Sampling period in seconds.")
    parser.add_argument("-o",
                        "--output",
                        default="cassandra_jmx_mon-{host}-{ts}.dat",
                        help="Password")
    parser.add_argument(
        "-R",
        "--rotate-hours",
        default=None,
        type=int,
        help="Output file rotation period in hours, default is no rotation.")
    parser.add_argument("-C",
                        "--compress",
                        default=False,
                        action="store_true",
                        help="Compress output file.")
    parser.add_argument("-c",
                        "--config",
                        default="cassandra_jmx_mon.yaml",
                        help="YAML configuration file.")
    parser.add_argument("-D",
                        "--database",
                        default="ap_proto",
                        help="Name of the InfluxDB database.")
    parser.add_argument("-H",
                        "--host",
                        default=socket.gethostname(),
                        help="Add host name as a tag.")
    parser.add_argument(
        "-d",
        "--dump",
        default=False,
        action="store_true",
        help="Dump full list of metrics and attributes and exit")

    args = parser.parse_args()

    # configure logging
    _configLogger(args.verbose)

    # Set the signal handler
    signal.signal(signal.SIGINT, intHandler)

    # connect to server
    environment = {}
    if args.user or args.password:
        credentials = array([args.user, args.password], String)
        environment = {JMXConnector.CREDENTIALS: credentials}
    jmxServiceUrl = JMXServiceURL(
        'service:jmx:rmi:///jndi/rmi://{}:{}/jmxrmi'.format(
            args.server, args.port))
    jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl, environment)

    with closing(jmxConnector):
        conn = jmxConnector.getMBeanServerConnection()

        if args.dump:
            _dump(conn)
            return

        config = _read_config(args.config)
        _run(conn, config, args)
providerURL = "t3://" + host + ":" + port + "/soa-infra"
print providerURL

mbeanRuntime = "weblogic.management.mbeanservers.runtime"
jmxProtoProviderPackages = "weblogic.management.remote"
mBeanName = "oracle.soa.config:Application=soa-infra,j2eeType=CompositeLifecycleConfig,name=soa-infra"
jndiProps = Hashtable()
jndiProps.put(Context.PROVIDER_URL, providerURL)
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory")
jndiProps.put(Context.SECURITY_PRINCIPAL, username)
jndiProps.put(Context.SECURITY_CREDENTIALS, password)

myLocator = LocatorFactory.createLocator(jndiProps)
jmxurl = "service:jmx:t3://" + host + ":" + port + "/jndi/" + mbeanRuntime
serviceURL = JMXServiceURL(jmxurl)
ht = Hashtable()
ht.put("java.naming.security.principal", username)
ht.put("java.naming.security.credentials", password)
ht.put("jmx.remote.protocol.provider.pkgs", jmxProtoProviderPackages)
jmxConnector = JMXConnectorFactory.newJMXConnector(serviceURL, ht)
jmxConnector.connect()
mbsc = jmxConnector.getMBeanServerConnection()
mbean = ObjectName(mBeanName)

compositedn = CompositeDN("EAIUCM", "CompositeName", "1.0")
# Change composite and version no.
composite = myLocator.lookupComposite(compositedn)
filter = CompositeInstanceFilter()

format = SimpleDateFormat("yyyy-MM-dd HH:mm")
示例#14
0
if __name__=='__main__':
	signal.signal(signal.SIGINT, sig_handler)
        credentials = array(["",""],String)
        environment = {JMXConnector.CREDENTIALS:credentials}
	if len(sys.argv[1:])==5:
		serverUrl = sys.argv[1]
		outputdir=sys.argv[2]
		cores=sys.argv[3]
		pid=sys.argv[4]
		filename=sys.argv[5]
		opDir=os.path.join(os.path.dirname(__file__),outputdir)
		# if os.path.exists(opDir):
		#	shutil.rmtree(opDir)
		# os.makedirs(opDir)
		jmxServiceUrl = JMXServiceURL('service:jmx:rmi:///jndi/rmi://'+str(serverUrl)+':7199/jmxrmi');
		jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl,environment);
		mBeanServerConnection = jmxConnector.getMBeanServerConnection()
		print('started')
		while True:
			count['count']=count['count']+1
			print(count['count'])
			thread1=AntiEntropyStageActive()
			thread2=CacheCleanupExecutorActive()
			thread3=CompactionExecutorActive()
			thread4=GossipStageActive()
			thread5=HintsDispatcherActive()
			thread6=InternalResponseStageActive()
			thread7=MemtableFlushWriterActive()
			thread8=MemtablePostFlushActive()
			thread9=MemtableReclaimMemoryActive()