SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
ORACLE ENTERPRISE MANAGER

WRITE POWERFUL SCRIPTS
WITH EMCLI
Gökhan Atıl
GÖKHAN ATIL
➤ DBA Team Lead with 15+ years of experience
➤ Oracle ACE Director (2016)

ACE (2011)
➤ 10g/11g and R12 OCP
➤ Founding Member and Vice President of TROUG
➤ Blogger (since 2008) gokhanatil.com
➤ Twitter: @gokhanatil
➤ Co-author of “Expert Oracle Enterprise Manager 12c”
AGENDA
➤ Introduction to EMCLI
➤ EMCLI Verbs
➤ How much Python do I need to know? (Python Cheatsheet)
➤ Sample Scripts
➤ Further Reading
EMCLI is an alternative for the web interface. It enables you to access OEM functionality from
a text-based console.
WHAT IS EMCLI?
Repository
EMCLI
Agents
Web Console
Management Server
Connectors
ALREADY INSTALLED
EMCLI is already installed and configured on OMS server:
$OMS_HOME/bin/emcli
INSTALL EMCLI TO YOUR WORKSTATION
➤ Requires Java version 1.7.0_80 or greater
➤ Supported: Windows, Linux, Solaris, HPUX, Tru64, AIX
➤ Setup >> Command Line Interface
To run EMCLI on Java 1.8 or higher, you need apply patch 17555224 to the weblogic server.
EMCLI with Scripting Mode aka ADVANCED KIT
INSTALL AND CONFIGURE
➤ Download the JAR file, set JAVA_HOME and execute the JAR file:
java -jar emcliadvancedkit.jar -install_dir=<home>
➤ Configure EM CLI:
emcli setup -url="https://host:port/em" -username=<emuser> -trustall
WHY ADVANCED KIT?
➤ Standard mode: This mode provides a simple command-line interface to Enterprise
Manager, and supports the execution of one verb at a time from the command line.
emcli get_targets
➤ Interactive mode: This mode enables you to create a single interactive session with
OMS. It is a Jython shell.
emcli
➤ Scripting mode: In Scripting mode, EMCLI runs Jython scripts containing EMCLI
verbs.
emcli @scriptname.py
Jython is an implementation of the Python designed to run on the Java
EMCLI VERBS
and Python
EMCLI VERBS
➤ A verb is a task or action in the form of a user command that exposes Enterprise
Manager functionality.
➤ In Standard mode, EMCLI expect you enter a verb as the first parameter. Verbs may
take zero or more arguments as input:
emcli verb -1st_argument="value" 

[ -2nd_ argument="value" ]

[ -3th_ argument ]
➤ In Scripting mode, EMCLI verbs are defined as Python functions, and arguments
are entered as function parameters:
verb( 1st_argument="value", 2nd_ argument="value")
400+ VERBS IN 75+ CATEGORIES
➤ Add Host Verbs
➤ Agent Administration Verbs
➤ Agent Upgrade Verbs
➤ BI Publisher Reports Verbs
➤ Blackout Verbs
➤ Credential Verbs
➤ Incident Rules Verbs
➤ Job Verbs
➤ Metric Extension Verbs
➤ Monitoring Templates Verbs
➤ Oracle Cloud Verbs
➤ Provisioning Verbs
➤ Self Update Verbs
➤ User Administration Verbs
GET QUICK HELP
You can get the list of available verbs using “help”:
emcli help
emcli help get_targets
➤ EMCLI verbs returns emcli.response.Response object:
result = emcli.response.Response
.error()

.exit_code()

.isJson()

.out()
➤ In scripting mode, default output format type is JSON for the verbs resulting a list of
items. In interactive mode, to change the output format to JSON, you need to run the
following command:
set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')
JSON - DICT
EMCLI RESPONSE OBJECT
error text

error code (0=success)

is JSON? true/false

JSON or text
[“data”] - LIST
DICT
DICT
DICT
result.out():

{ 'data':
[{'Status': 'Up', 'Warning': '2', 'Status ID': '1',
'Target Type': 'oracle_database', 'Critical':
'1', 'Target Name': 'db000002'},
{'Status': 'Up', 'Warning': '2', 'Status ID': '1',
'Target Type': 'oracle_database', 'Critical': '2',
'Target Name': 'db000001'},
{'Status': 'Up', 'Warning': '2', 'Status ID': '1',
'Target Type': 'oracle_database', 'Critical': '0',
'Target Name': 'db000000'}] }
PYTHON DICTIONARY AND LIST OBJECTS, AND EMCLI RESPONSE
List:

L = [1000,1001,1002,1003]
L[0] is 1000
Dictionary:
D = { "keyA": "red", "keyB": "green" }
D["keyA"] is "red"
Dict containing List containing Dict:
R = { "car":
[ { "brand", "BMW" }, { "brand", "Audi" } ] }
R["car"][0]["brand"] is "BMW"
result.out()["data"][0]
HOW MUCH PYTHON DO I NEED TO KNOW?
➤ Variables (Scalar, List, Dictionary)
No = 10
Name = "Gokhan"
➤ Conditionals
if A == 10:
do_something_good
do_another_good_thing
➤ Loops
for A in list:
print A
➤ Various
print "LOWERCASE".lower()
print "uppercase".upper()
print "Henry " + str(5) + "th"
print 10 + int("5")
print "dbname;orcltest".split(";")
exit()
SAMPLE SCRIPTS
LET’S WRITE OUR FIRST EMCLI SCRIPT!
➤ Goal: Clear stateless alerts of all database targets
➤ Login to OMS (The EMCLI client should be logged in to OMS before executing other
EMCLI verbs)
login( username="GOKHAN", password="123456" )
➤ Get list of all database targets
get_targets( target="oracle_database" )
➤ Clear stateless alert of each database target
clear_stateless_alerts( target_name, target_type, older_than )
➤ Logout
logout()
.out()["data"]
loop
CLEAR STATELESS ALERTS
clearalerts.py
if login( username="GOKHAN", password="123456" ).exit_code()==0:
for target in get_targets( targets="oracle_database" ).out()["data"]:
print "Clearing stateless alerts for " + target["Target Name"]
clear_stateless_alerts(target_name= target["Target Name"],
target_type= target["Target Type"], older_than="0" )
logout()
SAMPLE EMCLI SCRIPT #2
➤ Goal: Apply default host template to all host targets
➤ Login to OMS
➤ Get list of all host templates to find the default template
list_templates(target_type="host")
➤ If it's "default" template, assign it to a variable
➤ Get list of all host targets
get_targets(target="hosts" ).out()["data"]
➤ Apply host tempate to all hosts
apply_template( name, targets, replace_metrics)
➤ Logout
loop
loop
APPLY DEFAULT TEMPLATE TO ALL HOSTS
applyhosttemplate.py
if login( username="GOKHAN", password="123456" ).exit_code()==0:
for template in list_templates( target_type="host" ).out()["data"]:
if template["Default Template"] == "yes":
defaulttemplate = template["Template Name"]
for host in get_targets( targets="host").out()["data"]:
apply_template( name=defaulttemplate, replace_metrics="1",
targets=host["Target Name"] + ":host")
logout()
APPLY DEFAULT TEMPLATE TO ALL HOSTS
applyhosttemplate.py
if login( username="GOKHAN", password="123456" ).exit_code()==0:
for template in list_templates( target_type="host" ).out()["data"]:
if template["Default Template"] == "yes":
defaulttemplate = template["Template Name"]
print defaulttemplate + " will be applied to the following hosts:"
for host in get_targets( targets="host").out()["data"]:
apply_template( name=defaulttemplate, replace_metrics="1",
targets=host["Target Name"] + ":host")
print host["Target Name"]
logout()
SAMPLE EMCLI SCRIPT #3
➤ Goal: Promote all discovered (but unmanaged) single database targets
➤ Login to OMS
➤ Get list of all unmanaged targets (with properties)
get_targets("unmanaged","properties",

target="oracle_database" ).out()["data"]
➤ Parse Hostname from host info
host:db01.server.com;timezone_region:Europe/Istanbul
➤ Promote the database target
add_target( name, type, host, properties,

credentials="UserName:dbsnmp;password:xyz;Role:Normal")
➤ Logout
loop
PROMOTE DATABASE TARGETS
promotetargets.py
if login( username="GOKHAN", password="mypassword" ).exit_code()==0:
for target in get_targets("unmanaged","properties",
targets="oracle_database").out()["data"]:
add_target( name=target['Target Name'], type=target['Target Type'],
host=target['Host Info'],
properties=target['Properties'],
credentials="UserName:dbsnmp;password:xyz;Role:Normal")
logout()
PROMOTE DATABASE TARGETS (PARSING HOSTNAME)
PROMOTE DATABASE TARGETS
promotetargets.py
if login( username="GOKHAN", password="mypassword" ).exit_code()==0:
for target in get_targets("unmanaged","properties",
targets="oracle_database").out()["data"]:
print "Promoting " + target['Target Name']
add_target( name=target['Target Name'], type=target['Target Type'],
host=target['Host Info'].split(';')[0].split(':')[1],
properties=target['Properties'],
credentials="UserName:dbsnmp;password:xyz;Role:Normal")
logout()
SAMPLE EMCLI SCRIPT #4
➤ Goal: Change DBSMP (database user) passwords of all database targets
➤ Login to OMS
➤ Get list of all database targets
get_targets( target="oracle_database" ).out()["data"]
➤ Update DBSNMP user password
update_db_password(target_name,target_type, user_name,

change_at_target, old_password, new_password

retype_new_password)
➤ Logout
➤ Optional: Read old and new password from command line
➤ Optional: Catch Exceptions (in case, user entered wrong password)
loop
CHANGE DBSNMP PASSWORDS
changedbsnmp.py
if login( username="GOKHAN", password="123456" ).exit_code()==0:
for db in get_targets( targets="oracle_database").out()["data"]:
update_db_password (target_name= db["Target Name"],
target_type= db["Target Type"],
change_at_target="yes", user_name="dbsnmp",
old_password="oldpassword",
new_password="newpassword", retype_new_password="newpassword")
logout()
secure programming!?
CHANGE DBSNMP PASSWORDS
changedbsnmp.py
if len(sys.argv) <> 2:
print "Usage: emcli @changedbsnmp.py oldpwd newpwd"
exit()
if login( username="GOKHAN", password="123456" ).exit_code()==0:
for db in get_targets( targets="oracle_database").out()["data"]:
print "Updating dbsnmp password on " + db["Target Name"]
update_db_password (target_name=db["Target Name"], target_type=db["Target Type"],
change_at_target="yes", user_name="dbsnmp", old_password=sys.argv[0],
new_password=sys.argv[1], retype_new_password=sys.argv[1])
logout()
CHANGE DBSNMP PASSWORDS
changedbsnmp.py
if len(sys.argv) <> 2:
print "Usage: emcli @changedbsnmp.py oldpwd newpwd"
exit()
if login( username="GOKHAN", password="mypassword" ).exit_code()==0:
for db in get_targets( targets="oracle_database").out()["data"]:
try:
print "Updating dbsnmp password on " + db["Target Name"]
update_db_password (target_name=db["Target Name"],
target_type=db["Target Type"], change_at_target="yes",user_name="dbsnmp",
old_password=sys.argv[0], new_password=sys.argv[1], retype_new_password=sys.argv[1])
except emcli.exception.VerbExecutionError, e:
print e.error()
logout()
exception block
SAMPLE EMCLI SCRIPT #5
➤ Goal: List databases running on a specific Operating System
➤ Read OS name from run parameters
➤ Login to OMS
➤ Get list of all database targets from the Targets resource
list( resource="Targets", search ).out()["data"]
➤ Find the OS information from the Targets resource (will return one row)
list( resource="Targets", search ).out()["data"][0]
➤ Compare OS names and print target info if they match
➤ Logout
loop
LIST
➤ Lists avaliable "resources" (data sources/management views)
emcli list -help or list( "help" )
➤ Lists columns of a resource
emcli list -resource="Targets" -help
or list( "help", resource="Targets" ) or list( resource="Targets", help=True )
➤ Selection and Projection
list( resource="Targets",columns="TARGET_NAME,TARGET_TYPE",

search="TARGET_TYPE='oracle_database'")
➤ Run SQL query
list( "select * from mgmt$target where target_type='oracle_database'" )
LIST DATABASES
listdatabases.py
if (len(sys.argv) <> 1 ):
print "Usage: emcli @list_targets.py OSname"
exit()
if login( username="gokhan", password="123456" ).exit_code()==0:
for db in list( resource="Targets", search="TARGET_TYPE='oracle_database'" ).out()['data']:
OS = list( resource="Targets",
search="TARGET_NAME='" + db['HOST_NAME'] + "'" ).out()['data'][0]['TYPE_QUALIFIER1']
if ( OS.lower() == sys.argv[0].lower() ):
print db['TARGET_NAME'], OS
logout()
FURTHER READING
➤ Oracle Enterprise Manager 12c Command-Line Interface

by Kellyn Pot'vin-Gorman, Seth Miller, Ray Smith
➤ My blog: http://www.gokhanatil.com
➤ Ray Smith https://oramanageability.wordpress.com
➤ Kellyn Pot’Vin-Gorman http://dbakevlar.com
➤ Python For Beginners https://www.python.org/about/gettingstarted/
➤ The Definitive Guide to Jython http://www.jython.org/jythonbook/en/1.0/
THANK YOU FOR ATTENDING!
ANY QUESTIONS?

Más contenido relacionado

La actualidad más candente

Polymorphic Table Functions in 18c
Polymorphic Table Functions in 18cPolymorphic Table Functions in 18c
Polymorphic Table Functions in 18cAndrej Pashchenko
 
11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilarrehaniltifat
 
How to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata EnvironmentsHow to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata EnvironmentsSandesh Rao
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSmohdoracle
 
PostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performancePostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performanceVladimir Sitnikov
 
Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)magupta26
 
Introducao oracle-sqlplsql-vol2-pt
Introducao oracle-sqlplsql-vol2-ptIntroducao oracle-sqlplsql-vol2-pt
Introducao oracle-sqlplsql-vol2-ptValdinho Pereira
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PGPgDay.Seoul
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptionsrehaniltifat
 
Oracle Security Presentation
Oracle Security PresentationOracle Security Presentation
Oracle Security PresentationFrancisco Alvarez
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuningGuy Harrison
 
Blue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQL
Blue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQLBlue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQL
Blue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQLBlue Medora
 
Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseAltinity Ltd
 
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLTop 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLJim Mlodgenski
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cNelson Calero
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Developmentrehaniltifat
 
Got database access? Own the network!
Got database access? Own the network!Got database access? Own the network!
Got database access? Own the network!Bernardo Damele A. G.
 

La actualidad más candente (20)

Polymorphic Table Functions in 18c
Polymorphic Table Functions in 18cPolymorphic Table Functions in 18c
Polymorphic Table Functions in 18c
 
11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar
 
How to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata EnvironmentsHow to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata Environments
 
Skillwise JCL
Skillwise JCLSkillwise JCL
Skillwise JCL
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
 
PostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performancePostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performance
 
Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)Oracle Forms Tutorial (www.aboutoracleapps.com)
Oracle Forms Tutorial (www.aboutoracleapps.com)
 
Introducao oracle-sqlplsql-vol2-pt
Introducao oracle-sqlplsql-vol2-ptIntroducao oracle-sqlplsql-vol2-pt
Introducao oracle-sqlplsql-vol2-pt
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptions
 
Oracle Security Presentation
Oracle Security PresentationOracle Security Presentation
Oracle Security Presentation
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 
Blue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQL
Blue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQLBlue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQL
Blue Medora Oracle Enterprise Manager (EM12c) Plug-in for PostgreSQL
 
Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouse
 
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLTop 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
 
SQL
SQLSQL
SQL
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12c
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Got database access? Own the network!
Got database access? Own the network!Got database access? Own the network!
Got database access? Own the network!
 

Similar a EM13c: Write Powerful Scripts with EMCLI

EMCLI Crash Course - DOAG Germany
EMCLI Crash Course - DOAG GermanyEMCLI Crash Course - DOAG Germany
EMCLI Crash Course - DOAG GermanyGokhan Atil
 
The Enterprise Manager Command Line by Kellyn Pot'Vin
The Enterprise Manager Command Line by Kellyn Pot'VinThe Enterprise Manager Command Line by Kellyn Pot'Vin
The Enterprise Manager Command Line by Kellyn Pot'VinEnkitec
 
The enterprise manager command line interface2
The enterprise manager command line interface2The enterprise manager command line interface2
The enterprise manager command line interface2Kellyn Pot'Vin-Gorman
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellPhan Hien
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009rsnarayanan
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)ÇözümPARK
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Knoldus Inc.
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Neelkanth Sachdeva
 
Cognitive data capture with Elis - Rossum's technical webinar
Cognitive data capture with Elis - Rossum's technical webinarCognitive data capture with Elis - Rossum's technical webinar
Cognitive data capture with Elis - Rossum's technical webinarPetr Baudis
 
Maximize the power of OSGi
Maximize the power of OSGiMaximize the power of OSGi
Maximize the power of OSGiDavid Bosschaert
 
Maximise the Power of OSGi - Carsten Ziegeler & David Bosschaert
Maximise the Power of OSGi - Carsten Ziegeler & David BosschaertMaximise the Power of OSGi - Carsten Ziegeler & David Bosschaert
Maximise the Power of OSGi - Carsten Ziegeler & David Bosschaertmfrancis
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubEssam Salah
 
Power shell training
Power shell trainingPower shell training
Power shell trainingDavid Brabant
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellSalaudeen Rajack
 
Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Eviljaredhaight
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Binh Nguyen
 
The enterprise manager command line interface2
The enterprise manager command line interface2The enterprise manager command line interface2
The enterprise manager command line interface2Kellyn Pot'Vin-Gorman
 

Similar a EM13c: Write Powerful Scripts with EMCLI (20)

Kscope emcli kpotvin
Kscope emcli kpotvinKscope emcli kpotvin
Kscope emcli kpotvin
 
EMCLI Crash Course - DOAG Germany
EMCLI Crash Course - DOAG GermanyEMCLI Crash Course - DOAG Germany
EMCLI Crash Course - DOAG Germany
 
The Enterprise Manager Command Line by Kellyn Pot'Vin
The Enterprise Manager Command Line by Kellyn Pot'VinThe Enterprise Manager Command Line by Kellyn Pot'Vin
The Enterprise Manager Command Line by Kellyn Pot'Vin
 
The enterprise manager command line interface2
The enterprise manager command line interface2The enterprise manager command line interface2
The enterprise manager command line interface2
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShell
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
Sa
SaSa
Sa
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
 
Cognitive data capture with Elis - Rossum's technical webinar
Cognitive data capture with Elis - Rossum's technical webinarCognitive data capture with Elis - Rossum's technical webinar
Cognitive data capture with Elis - Rossum's technical webinar
 
Maximize the power of OSGi
Maximize the power of OSGiMaximize the power of OSGi
Maximize the power of OSGi
 
Maximise the Power of OSGi - Carsten Ziegeler & David Bosschaert
Maximise the Power of OSGi - Carsten Ziegeler & David BosschaertMaximise the Power of OSGi - Carsten Ziegeler & David Bosschaert
Maximise the Power of OSGi - Carsten Ziegeler & David Bosschaert
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Evil
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010
 
The enterprise manager command line interface2
The enterprise manager command line interface2The enterprise manager command line interface2
The enterprise manager command line interface2
 
Clean Code
Clean CodeClean Code
Clean Code
 

Más de Gokhan Atil

Introduction to Spark with Python
Introduction to Spark with PythonIntroduction to Spark with Python
Introduction to Spark with PythonGokhan Atil
 
Introduction to Cassandra
Introduction to CassandraIntroduction to Cassandra
Introduction to CassandraGokhan Atil
 
SQL or noSQL - Oracle Cloud Day Istanbul
SQL or noSQL - Oracle Cloud Day IstanbulSQL or noSQL - Oracle Cloud Day Istanbul
SQL or noSQL - Oracle Cloud Day IstanbulGokhan Atil
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsGokhan Atil
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAsGokhan Atil
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsGokhan Atil
 
TROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yolu
TROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yoluTROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yolu
TROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yoluGokhan Atil
 
Oracle 12c Database In Memory DBA SIG
Oracle 12c Database In Memory DBA SIGOracle 12c Database In Memory DBA SIG
Oracle 12c Database In Memory DBA SIGGokhan Atil
 
Oracle 12c Database In-Memory
Oracle 12c Database In-MemoryOracle 12c Database In-Memory
Oracle 12c Database In-MemoryGokhan Atil
 
Oracle DB Standard Edition: Başka Bir Arzunuz?
Oracle DB Standard Edition: Başka Bir Arzunuz?Oracle DB Standard Edition: Başka Bir Arzunuz?
Oracle DB Standard Edition: Başka Bir Arzunuz?Gokhan Atil
 
Enterprise Manager 12c ASH Analytics
Enterprise Manager 12c ASH AnalyticsEnterprise Manager 12c ASH Analytics
Enterprise Manager 12c ASH AnalyticsGokhan Atil
 
Using APEX to Create a Mobile User Interface for Enterprise Manager 12c
Using APEX to Create a Mobile User Interface for Enterprise Manager 12cUsing APEX to Create a Mobile User Interface for Enterprise Manager 12c
Using APEX to Create a Mobile User Interface for Enterprise Manager 12cGokhan Atil
 

Más de Gokhan Atil (12)

Introduction to Spark with Python
Introduction to Spark with PythonIntroduction to Spark with Python
Introduction to Spark with Python
 
Introduction to Cassandra
Introduction to CassandraIntroduction to Cassandra
Introduction to Cassandra
 
SQL or noSQL - Oracle Cloud Day Istanbul
SQL or noSQL - Oracle Cloud Day IstanbulSQL or noSQL - Oracle Cloud Day Istanbul
SQL or noSQL - Oracle Cloud Day Istanbul
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAs
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAs
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAs
 
TROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yolu
TROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yoluTROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yolu
TROUG & Turkey JUG Semineri: Veriye erişimin en hızlı yolu
 
Oracle 12c Database In Memory DBA SIG
Oracle 12c Database In Memory DBA SIGOracle 12c Database In Memory DBA SIG
Oracle 12c Database In Memory DBA SIG
 
Oracle 12c Database In-Memory
Oracle 12c Database In-MemoryOracle 12c Database In-Memory
Oracle 12c Database In-Memory
 
Oracle DB Standard Edition: Başka Bir Arzunuz?
Oracle DB Standard Edition: Başka Bir Arzunuz?Oracle DB Standard Edition: Başka Bir Arzunuz?
Oracle DB Standard Edition: Başka Bir Arzunuz?
 
Enterprise Manager 12c ASH Analytics
Enterprise Manager 12c ASH AnalyticsEnterprise Manager 12c ASH Analytics
Enterprise Manager 12c ASH Analytics
 
Using APEX to Create a Mobile User Interface for Enterprise Manager 12c
Using APEX to Create a Mobile User Interface for Enterprise Manager 12cUsing APEX to Create a Mobile User Interface for Enterprise Manager 12c
Using APEX to Create a Mobile User Interface for Enterprise Manager 12c
 

Último

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Último (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

EM13c: Write Powerful Scripts with EMCLI

  • 1. ORACLE ENTERPRISE MANAGER
 WRITE POWERFUL SCRIPTS WITH EMCLI Gökhan Atıl
  • 2. GÖKHAN ATIL ➤ DBA Team Lead with 15+ years of experience ➤ Oracle ACE Director (2016)
 ACE (2011) ➤ 10g/11g and R12 OCP ➤ Founding Member and Vice President of TROUG ➤ Blogger (since 2008) gokhanatil.com ➤ Twitter: @gokhanatil ➤ Co-author of “Expert Oracle Enterprise Manager 12c”
  • 3. AGENDA ➤ Introduction to EMCLI ➤ EMCLI Verbs ➤ How much Python do I need to know? (Python Cheatsheet) ➤ Sample Scripts ➤ Further Reading
  • 4. EMCLI is an alternative for the web interface. It enables you to access OEM functionality from a text-based console. WHAT IS EMCLI? Repository EMCLI Agents Web Console Management Server Connectors
  • 5. ALREADY INSTALLED EMCLI is already installed and configured on OMS server: $OMS_HOME/bin/emcli
  • 6. INSTALL EMCLI TO YOUR WORKSTATION ➤ Requires Java version 1.7.0_80 or greater ➤ Supported: Windows, Linux, Solaris, HPUX, Tru64, AIX ➤ Setup >> Command Line Interface To run EMCLI on Java 1.8 or higher, you need apply patch 17555224 to the weblogic server. EMCLI with Scripting Mode aka ADVANCED KIT
  • 7. INSTALL AND CONFIGURE ➤ Download the JAR file, set JAVA_HOME and execute the JAR file: java -jar emcliadvancedkit.jar -install_dir=<home> ➤ Configure EM CLI: emcli setup -url="https://host:port/em" -username=<emuser> -trustall
  • 8. WHY ADVANCED KIT? ➤ Standard mode: This mode provides a simple command-line interface to Enterprise Manager, and supports the execution of one verb at a time from the command line. emcli get_targets ➤ Interactive mode: This mode enables you to create a single interactive session with OMS. It is a Jython shell. emcli ➤ Scripting mode: In Scripting mode, EMCLI runs Jython scripts containing EMCLI verbs. emcli @scriptname.py Jython is an implementation of the Python designed to run on the Java
  • 10. EMCLI VERBS ➤ A verb is a task or action in the form of a user command that exposes Enterprise Manager functionality. ➤ In Standard mode, EMCLI expect you enter a verb as the first parameter. Verbs may take zero or more arguments as input: emcli verb -1st_argument="value" 
 [ -2nd_ argument="value" ]
 [ -3th_ argument ] ➤ In Scripting mode, EMCLI verbs are defined as Python functions, and arguments are entered as function parameters: verb( 1st_argument="value", 2nd_ argument="value")
  • 11. 400+ VERBS IN 75+ CATEGORIES ➤ Add Host Verbs ➤ Agent Administration Verbs ➤ Agent Upgrade Verbs ➤ BI Publisher Reports Verbs ➤ Blackout Verbs ➤ Credential Verbs ➤ Incident Rules Verbs ➤ Job Verbs ➤ Metric Extension Verbs ➤ Monitoring Templates Verbs ➤ Oracle Cloud Verbs ➤ Provisioning Verbs ➤ Self Update Verbs ➤ User Administration Verbs
  • 12. GET QUICK HELP You can get the list of available verbs using “help”: emcli help emcli help get_targets
  • 13. ➤ EMCLI verbs returns emcli.response.Response object: result = emcli.response.Response .error()
 .exit_code()
 .isJson()
 .out() ➤ In scripting mode, default output format type is JSON for the verbs resulting a list of items. In interactive mode, to change the output format to JSON, you need to run the following command: set_client_property('EMCLI_OUTPUT_TYPE', 'JSON') JSON - DICT EMCLI RESPONSE OBJECT error text
 error code (0=success)
 is JSON? true/false
 JSON or text [“data”] - LIST DICT DICT DICT
  • 14. result.out():
 { 'data': [{'Status': 'Up', 'Warning': '2', 'Status ID': '1', 'Target Type': 'oracle_database', 'Critical': '1', 'Target Name': 'db000002'}, {'Status': 'Up', 'Warning': '2', 'Status ID': '1', 'Target Type': 'oracle_database', 'Critical': '2', 'Target Name': 'db000001'}, {'Status': 'Up', 'Warning': '2', 'Status ID': '1', 'Target Type': 'oracle_database', 'Critical': '0', 'Target Name': 'db000000'}] } PYTHON DICTIONARY AND LIST OBJECTS, AND EMCLI RESPONSE List:
 L = [1000,1001,1002,1003] L[0] is 1000 Dictionary: D = { "keyA": "red", "keyB": "green" } D["keyA"] is "red" Dict containing List containing Dict: R = { "car": [ { "brand", "BMW" }, { "brand", "Audi" } ] } R["car"][0]["brand"] is "BMW" result.out()["data"][0]
  • 15. HOW MUCH PYTHON DO I NEED TO KNOW? ➤ Variables (Scalar, List, Dictionary) No = 10 Name = "Gokhan" ➤ Conditionals if A == 10: do_something_good do_another_good_thing ➤ Loops for A in list: print A ➤ Various print "LOWERCASE".lower() print "uppercase".upper() print "Henry " + str(5) + "th" print 10 + int("5") print "dbname;orcltest".split(";") exit()
  • 17. LET’S WRITE OUR FIRST EMCLI SCRIPT! ➤ Goal: Clear stateless alerts of all database targets ➤ Login to OMS (The EMCLI client should be logged in to OMS before executing other EMCLI verbs) login( username="GOKHAN", password="123456" ) ➤ Get list of all database targets get_targets( target="oracle_database" ) ➤ Clear stateless alert of each database target clear_stateless_alerts( target_name, target_type, older_than ) ➤ Logout logout() .out()["data"] loop
  • 18. CLEAR STATELESS ALERTS clearalerts.py if login( username="GOKHAN", password="123456" ).exit_code()==0: for target in get_targets( targets="oracle_database" ).out()["data"]: print "Clearing stateless alerts for " + target["Target Name"] clear_stateless_alerts(target_name= target["Target Name"], target_type= target["Target Type"], older_than="0" ) logout()
  • 19. SAMPLE EMCLI SCRIPT #2 ➤ Goal: Apply default host template to all host targets ➤ Login to OMS ➤ Get list of all host templates to find the default template list_templates(target_type="host") ➤ If it's "default" template, assign it to a variable ➤ Get list of all host targets get_targets(target="hosts" ).out()["data"] ➤ Apply host tempate to all hosts apply_template( name, targets, replace_metrics) ➤ Logout loop loop
  • 20. APPLY DEFAULT TEMPLATE TO ALL HOSTS applyhosttemplate.py if login( username="GOKHAN", password="123456" ).exit_code()==0: for template in list_templates( target_type="host" ).out()["data"]: if template["Default Template"] == "yes": defaulttemplate = template["Template Name"] for host in get_targets( targets="host").out()["data"]: apply_template( name=defaulttemplate, replace_metrics="1", targets=host["Target Name"] + ":host") logout()
  • 21. APPLY DEFAULT TEMPLATE TO ALL HOSTS applyhosttemplate.py if login( username="GOKHAN", password="123456" ).exit_code()==0: for template in list_templates( target_type="host" ).out()["data"]: if template["Default Template"] == "yes": defaulttemplate = template["Template Name"] print defaulttemplate + " will be applied to the following hosts:" for host in get_targets( targets="host").out()["data"]: apply_template( name=defaulttemplate, replace_metrics="1", targets=host["Target Name"] + ":host") print host["Target Name"] logout()
  • 22. SAMPLE EMCLI SCRIPT #3 ➤ Goal: Promote all discovered (but unmanaged) single database targets ➤ Login to OMS ➤ Get list of all unmanaged targets (with properties) get_targets("unmanaged","properties",
 target="oracle_database" ).out()["data"] ➤ Parse Hostname from host info host:db01.server.com;timezone_region:Europe/Istanbul ➤ Promote the database target add_target( name, type, host, properties,
 credentials="UserName:dbsnmp;password:xyz;Role:Normal") ➤ Logout loop
  • 23. PROMOTE DATABASE TARGETS promotetargets.py if login( username="GOKHAN", password="mypassword" ).exit_code()==0: for target in get_targets("unmanaged","properties", targets="oracle_database").out()["data"]: add_target( name=target['Target Name'], type=target['Target Type'], host=target['Host Info'], properties=target['Properties'], credentials="UserName:dbsnmp;password:xyz;Role:Normal") logout()
  • 24. PROMOTE DATABASE TARGETS (PARSING HOSTNAME)
  • 25. PROMOTE DATABASE TARGETS promotetargets.py if login( username="GOKHAN", password="mypassword" ).exit_code()==0: for target in get_targets("unmanaged","properties", targets="oracle_database").out()["data"]: print "Promoting " + target['Target Name'] add_target( name=target['Target Name'], type=target['Target Type'], host=target['Host Info'].split(';')[0].split(':')[1], properties=target['Properties'], credentials="UserName:dbsnmp;password:xyz;Role:Normal") logout()
  • 26. SAMPLE EMCLI SCRIPT #4 ➤ Goal: Change DBSMP (database user) passwords of all database targets ➤ Login to OMS ➤ Get list of all database targets get_targets( target="oracle_database" ).out()["data"] ➤ Update DBSNMP user password update_db_password(target_name,target_type, user_name,
 change_at_target, old_password, new_password
 retype_new_password) ➤ Logout ➤ Optional: Read old and new password from command line ➤ Optional: Catch Exceptions (in case, user entered wrong password) loop
  • 27. CHANGE DBSNMP PASSWORDS changedbsnmp.py if login( username="GOKHAN", password="123456" ).exit_code()==0: for db in get_targets( targets="oracle_database").out()["data"]: update_db_password (target_name= db["Target Name"], target_type= db["Target Type"], change_at_target="yes", user_name="dbsnmp", old_password="oldpassword", new_password="newpassword", retype_new_password="newpassword") logout() secure programming!?
  • 28. CHANGE DBSNMP PASSWORDS changedbsnmp.py if len(sys.argv) <> 2: print "Usage: emcli @changedbsnmp.py oldpwd newpwd" exit() if login( username="GOKHAN", password="123456" ).exit_code()==0: for db in get_targets( targets="oracle_database").out()["data"]: print "Updating dbsnmp password on " + db["Target Name"] update_db_password (target_name=db["Target Name"], target_type=db["Target Type"], change_at_target="yes", user_name="dbsnmp", old_password=sys.argv[0], new_password=sys.argv[1], retype_new_password=sys.argv[1]) logout()
  • 29. CHANGE DBSNMP PASSWORDS changedbsnmp.py if len(sys.argv) <> 2: print "Usage: emcli @changedbsnmp.py oldpwd newpwd" exit() if login( username="GOKHAN", password="mypassword" ).exit_code()==0: for db in get_targets( targets="oracle_database").out()["data"]: try: print "Updating dbsnmp password on " + db["Target Name"] update_db_password (target_name=db["Target Name"], target_type=db["Target Type"], change_at_target="yes",user_name="dbsnmp", old_password=sys.argv[0], new_password=sys.argv[1], retype_new_password=sys.argv[1]) except emcli.exception.VerbExecutionError, e: print e.error() logout() exception block
  • 30. SAMPLE EMCLI SCRIPT #5 ➤ Goal: List databases running on a specific Operating System ➤ Read OS name from run parameters ➤ Login to OMS ➤ Get list of all database targets from the Targets resource list( resource="Targets", search ).out()["data"] ➤ Find the OS information from the Targets resource (will return one row) list( resource="Targets", search ).out()["data"][0] ➤ Compare OS names and print target info if they match ➤ Logout loop
  • 31. LIST ➤ Lists avaliable "resources" (data sources/management views) emcli list -help or list( "help" ) ➤ Lists columns of a resource emcli list -resource="Targets" -help or list( "help", resource="Targets" ) or list( resource="Targets", help=True ) ➤ Selection and Projection list( resource="Targets",columns="TARGET_NAME,TARGET_TYPE",
 search="TARGET_TYPE='oracle_database'") ➤ Run SQL query list( "select * from mgmt$target where target_type='oracle_database'" )
  • 32. LIST DATABASES listdatabases.py if (len(sys.argv) <> 1 ): print "Usage: emcli @list_targets.py OSname" exit() if login( username="gokhan", password="123456" ).exit_code()==0: for db in list( resource="Targets", search="TARGET_TYPE='oracle_database'" ).out()['data']: OS = list( resource="Targets", search="TARGET_NAME='" + db['HOST_NAME'] + "'" ).out()['data'][0]['TYPE_QUALIFIER1'] if ( OS.lower() == sys.argv[0].lower() ): print db['TARGET_NAME'], OS logout()
  • 33. FURTHER READING ➤ Oracle Enterprise Manager 12c Command-Line Interface
 by Kellyn Pot'vin-Gorman, Seth Miller, Ray Smith ➤ My blog: http://www.gokhanatil.com ➤ Ray Smith https://oramanageability.wordpress.com ➤ Kellyn Pot’Vin-Gorman http://dbakevlar.com ➤ Python For Beginners https://www.python.org/about/gettingstarted/ ➤ The Definitive Guide to Jython http://www.jython.org/jythonbook/en/1.0/
  • 34. THANK YOU FOR ATTENDING! ANY QUESTIONS?