SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
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?

Weitere ähnliche Inhalte

Was ist angesagt?

Backup & recovery with rman
Backup & recovery with rmanBackup & recovery with rman
Backup & recovery with rmanitsabidhussain
 
Less17 moving data
Less17 moving dataLess17 moving data
Less17 moving dataAmit Bhalla
 
alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)
alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)
alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)Alphorm
 
Weblogic 12c installation (oracle linux)
Weblogic 12c installation (oracle linux)Weblogic 12c installation (oracle linux)
Weblogic 12c installation (oracle linux)Osama Mustafa
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19cMaria Colgan
 
Rman Presentation
Rman PresentationRman Presentation
Rman PresentationRick van Ek
 
Oracle Enterprise Manager 12c - OEM12c Presentation
Oracle Enterprise Manager 12c - OEM12c PresentationOracle Enterprise Manager 12c - OEM12c Presentation
Oracle Enterprise Manager 12c - OEM12c PresentationFrancisco Alvarez
 
base de donnée (Modèle Relationnel)
base de donnée (Modèle Relationnel)base de donnée (Modèle Relationnel)
base de donnée (Modèle Relationnel)n allali
 
Oracle Audit vault
Oracle Audit vaultOracle Audit vault
Oracle Audit vaultuzzal basak
 
Oracle User Management
Oracle User ManagementOracle User Management
Oracle User ManagementArun Sharma
 
Afficher des Données Issues de Plusieurs Tables : SQL Oracle
Afficher des Données Issues de Plusieurs Tables : SQL OracleAfficher des Données Issues de Plusieurs Tables : SQL Oracle
Afficher des Données Issues de Plusieurs Tables : SQL Oraclewebreaker
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - VoldWilliam Lee
 
Oracle data pump
Oracle data pumpOracle data pump
Oracle data pumpmarcxav72
 
WebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionWebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionJames Bayer
 
Less04 database instance
Less04 database instanceLess04 database instance
Less04 database instanceAmit Bhalla
 

Was ist angesagt? (20)

Backup & recovery with rman
Backup & recovery with rmanBackup & recovery with rman
Backup & recovery with rman
 
Less17 moving data
Less17 moving dataLess17 moving data
Less17 moving data
 
alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)
alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)
alphorm.com - Formation Oracle Database 11g DBA 1 (1Z0-052)
 
Weblogic 12c installation (oracle linux)
Weblogic 12c installation (oracle linux)Weblogic 12c installation (oracle linux)
Weblogic 12c installation (oracle linux)
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19c
 
Rman Presentation
Rman PresentationRman Presentation
Rman Presentation
 
Oracle Enterprise Manager 12c - OEM12c Presentation
Oracle Enterprise Manager 12c - OEM12c PresentationOracle Enterprise Manager 12c - OEM12c Presentation
Oracle Enterprise Manager 12c - OEM12c Presentation
 
base de donnée (Modèle Relationnel)
base de donnée (Modèle Relationnel)base de donnée (Modèle Relationnel)
base de donnée (Modèle Relationnel)
 
Oracle Audit vault
Oracle Audit vaultOracle Audit vault
Oracle Audit vault
 
Oracle User Management
Oracle User ManagementOracle User Management
Oracle User Management
 
Introduction à pl/sql
Introduction à pl/sqlIntroduction à pl/sql
Introduction à pl/sql
 
Em13c New Features- Two of Two
Em13c New Features- Two of TwoEm13c New Features- Two of Two
Em13c New Features- Two of Two
 
Security in ORACLE RDBMS
Security in ORACLE RDBMSSecurity in ORACLE RDBMS
Security in ORACLE RDBMS
 
Afficher des Données Issues de Plusieurs Tables : SQL Oracle
Afficher des Données Issues de Plusieurs Tables : SQL OracleAfficher des Données Issues de Plusieurs Tables : SQL Oracle
Afficher des Données Issues de Plusieurs Tables : SQL Oracle
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 
Oracle data pump
Oracle data pumpOracle data pump
Oracle data pump
 
WebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionWebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload Protection
 
Less04 database instance
Less04 database instanceLess04 database instance
Less04 database instance
 
Less03 db dbca
Less03 db dbcaLess03 db dbca
Less03 db dbca
 

Ähnlich wie 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
 
Oracle Enterprise Manager 12c: EMCLI Crash Course
Oracle Enterprise Manager 12c: EMCLI Crash CourseOracle Enterprise Manager 12c: EMCLI Crash Course
Oracle Enterprise Manager 12c: EMCLI Crash CourseGokhan Atil
 
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
 

Ähnlich wie 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
 
Oracle Enterprise Manager 12c: EMCLI Crash Course
Oracle Enterprise Manager 12c: EMCLI Crash CourseOracle Enterprise Manager 12c: EMCLI Crash Course
Oracle Enterprise Manager 12c: EMCLI Crash Course
 
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
 

Mehr von 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
 
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
 

Mehr von Gokhan Atil (11)

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
 
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
 

Kürzlich hochgeladen

WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 

Kürzlich hochgeladen (20)

WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
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...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 

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?