One feature of Oracle Enterprise Manager that is not always utilized is EMCLI, short for Enterprise Manager Command Line Interface. Like WLST it can be used in several modes: standard command-line, Interactive and Script. The script mode is based on Jython. Does it sound familiar? Yes, you will be able to re-use your P(J)ython skills from WLST scripting.
To start you off, you need Java and the EMCLI Client kit. There are two versions of the client. One "light weight" standard without the scripting functionality, and one advanced with all the modes. They are hopefully already available to you from the Enterprise Manager OMS server. Read more about the modes, pre-reqs etc. in the userinterface, or just download the kits directly. Open a browser and use the URL's:
Standard kit: https://<your_em_host:port>/em/public_lib_download/emcli/kit/emclikit.jar
Script kit: https://<your_em_host:port>/em/public_lib_download/emcli/kit/emcliadvancedkit.jar
You probably want to have the advanced kit with scripting functionality.
Once downloaded, you install by:
Java -jar emcliadvancedkit.jar
Next start creating Jython scripts. This is an example you could use as a starting point. It will take username as an input.
from emcli import *
#Set the OMS URL to connect to
set_client_property('EMCLI_OMS_URL','https://<your_em_install>:7801/em')
#Accept all the certificates
set_client_property('EMCLI_TRUSTALL','true')
inp_username=sys.argv[0]
#Login to the OMS
login (username=inp_username)
print version()
targets_array = get_targets(targets='weblogic_domain').out()['data']
for target in targets_array:
Invoke it by running
emcli @print_domains.py sysman
where you may exchange sysman with another user.
The result should be something like:
C:\emcli>emcli @print_domains.py sysman
Enter password ********
Oracle Enterprise Manager 12c EM CLI Version 12.1.0.4.0
/OCS_SOA_soa_domain/soa_domain
/OCS_osb_domain/osb_domain
/WLS_12c_base_domain/base_domain
/EMGC_GCDomain/GCDomain
Logout successful
C:\emcli>
You could also use EMCLI to refresh several domains at the same time. For that you need to create an input file (E=enable, D=disable, R=removes deleted targets):
/OCS_osb_domain/osb_domain,E /OCS_SOA_soa_domain/soa_domain,E /demo_wl_server/wl_server,ESave the file as domain_refresh.csv, and the jython script refresh_domains.py looks like::
from emcli import *
#Set the OMS URL to connect to
set_client_property('EMCLI_OMS_URL','https://<your_em_install>:7801/em')
#Accept all the certificates
set_client_property('EMCLI_TRUSTALL','true')
inp_username=sys.argv[0]
#Login to the OMS
login (username=inp_username)
print version()
refresh_wls(input_file="domain_refresh_file:c:\emcli\domain_refresh.csv")
Invoke it by running
emcli @refresh_domains.py sysman
Adding targets
This just an example of the things you can do with EMCLI. A full list of verbs etc. is located here.

No comments:
Post a Comment