EMCLI Opens Windows for OEM Interaction

Oct 22, 2013 / By Andrey Goryunov

Tags: , , ,

Oracle Enterprise Manager 12c rel.3 not only comes with EMCLI in interactive and scripting mode,
but also opens ways to interact with OEM through building a custom GUI.

Using Jython with Java Swing libraries can bring EMCLI usage to a new level.
Just imagine developing an application that will communicate with the OMS server and respond
to dynamically changing criteria…

To show how Java libraries can be used together with EMCLI verbs, I created
the code which accepts link and a password to connect to OEM and returns the number of oracle_database
targets configured in the enterprise manager.

The code should be executed in interactive mode and to do it you would need to enter
or copy/paste the code below and initialize the class simply by typing Example()

You will get a window where you can put a proper OEM link, type a password, and connect to OEM.

Moreover, EMCLI won’t finish its session if you close the window and you would
be able to start window in the same manner again.

from javax.swing import *
from java.lang import *
from emcli import *
from java.awt import *
class Example:
  def loginOEM(self,event):
    set_client_property('EMCLI_OMS_URL',self.textfield1.text)
    set_client_property('EMCLI_TRUSTALL','true')
    set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')
    l=login(username='sysman', password=self.pwdfield1.text)
    if str(l).find('Login successful') == 0:
      res = get_targets(targets='oracle_database')
      self.label1.setText("Number of targets: " + str(len(res.out()['data'])))
      logout()
    else:
      self.label1.setText(str(l))
  def __init__(self):
    frame = JFrame("OEM interaction")
    frame.setSize(200, 150)
    pnl = JPanel()
    self.textfield1 = JTextField('http://<oms>:7788/em', 15)
    pnl.add(self.textfield1)
    self.pwdfield1 = JPasswordField('',15)
    pnl.add(self.pwdfield1)
    loginButton = JButton('Login',actionPerformed=self.loginOEM)
    pnl.add(loginButton)
    self.label1 = JLabel("Status:")
    frame.add(pnl)
    frame.add(self.label1, BorderLayout.PAGE_END)
    frame.pack()
    frame.setVisible(True)

Happy Jython developing!

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>