Dec 6, 2017

Enterprise Manager Command Line Interface - emcli

The Enterprise Manager Command Line Interface (EM CLI) enables users to access Enterprise Manager functionality through a command-line interface or scripts. It is accessible through classic programming language constructs, enabling tasks to be created and run either from the command-line or programatically. EM CLI enables you to access Enterprise Manager Cloud Control functionality from text-based consoles (shells and command-line windows) for a variety of operating systems.

EM CLI is fully integrated with Enterprise Manager's security and user administration functions, enabling you to carry out operations using EM CLI with the same security and confidentiality as the Enterprise Manager Cloud Control console. For example, you can only see and operate on targets for which you are authorized.

Examples of EM CLI tasks you can accomplish are as follows:
  • Create a new Enterprise Manager administrator account.
  • Monitor and manage targets, jobs, groups, and blackouts.
  • Enable batch/complex tasks on multiple Agents or targets.
Integrate Enterprise Manager with third-party or custom software through scripts. Actions that are part of a customer's business model can be performed through scripts.

EM CLI Architecture:

























Here are some some sample commands:

1. Login and logout to/fronm em console window

$./emcli login -username=user_name
$./emcli login -username=SYSMAN
$ ./emcli logout

2. Sync OMS repository:

./emcli login -username=SYSMAN
./emcli sync

3. Check the connection mode, if complete, then offline the EMCLI

bin]$./emcli set_connection_mode -mode=offline

Why offline?
when set offline, then connection not allowed Oracle support.

4. Checking Incidents:

./emcli get_resolution_states

e.g.,
bin]$ ./emcli get_resolution_states
Incident resolution states
        10 - Work in progress
        90 - Resolved
Problem resolution states
        10 - Work in progress
        90 - Resolved
$

5. Redirect output ( similar to Unix)

$./emcli get_procedure_xml -procedure="PROC_GUID" > test_proc.xml

6. List all Targets

$./emcli get_targets

Output: List all added targets

[oracle@labdevbox bin]$ ./emcli get_targets
Status  Status           Target Type           Target Name
 ID
1       Up               cluster               laboradbc1
-9      N/A              group                 ADMexam0
-9      N/A              group                 Prod-exam
-9      N/A              group                 All
-9      N/A              group                 MC-exam
-9      N/A              group                 Test-exam
1       Up               has                   has_laboradbc1a.example.com
.....

7. List all database Targets

./emcli get_targets -targets="oracle_database"

Output : List database targets

bin]$ ./emcli get_targets -targets="oracle_database"
Status  Status           Target Type           Target Name
 ID
1       Up               oracle_database       testbox_testbox4
1       Up               oracle_database       testbox_testbox3
1       Up               oracle_database       sampletestdb.example.com
0       Down             oracle_database       temptstdb
1       Up               oracle_database       emtest
0       Down             oracle_database       devdb_labdevbox
1       Up               oracle_database       testbox_testbox2
1       Up               oracle_database       testbox_testbox1
[oracle@labdevbox bin]$


Note: There are various target type. You just mention like below:
Listener - get_targets(targets='%oracle_listener%')
RAC database - get_targets(targets='%rac_database%')
Stand-alone db - get_targets(targets='%oracle_database%'
Oracle metadata - get_targets(targets='%oracle_emd%')

8. find - What platforms are supported?

emcli get_supported_platforms

e.g.,

 bin]$ ./emcli get_supported_platforms
-----------------------------------------------
Version = 13.2.0.0.0
 Platform = Linux x86-64
-----------------------------------------------
Version = 13.2.0.0.0
 Platform = Microsoft Windows x64 (64-bit)
-----------------------------------------------
Version = 12.1.0.4.0
 Platform = Linux x86-64
-----------------------------------------------
Platforms list displayed successfully.

9. Delete a target from OEM cloud control:

./emcli delete_target -name="temptstdb" -type="oracle_database"

e.g.,
$ ./emcli delete_target -name="temptstdb" -type="oracle_database"

Target "temptstdb:oracle_database" deleted successfully
$

verify now:

$./emcli get_targets -targets="oracle_database"
Status  Status           Target Type           Target Name
 ID
1       Up               oracle_database       testbox_testbox4
1       Up               oracle_database       testbox_testbox3
1       Up               oracle_database       sampletestdb.example.com
1       Up               oracle_database       emtest
0       Down             oracle_database       devdb_labdevbox
1       Up               oracle_database       testbox_testbox2
1       Up               oracle_database       testbox_testbox1
bin]$


10. Add target database to OEM cloud:

Syntax:
$ ./emcli add_target -name=”ORACLE_SID” -type=”oracle_database” -host=”$oemhost” -credentials=”UserName:dbsnmp;password:dbsnmp_password;Role:Normal” -
properties=”SID:ORACLE_SID;Port:1521;OracleHome:;MachineName:\”

11. Mange Black-outs:

a) Create a Black-out:

./emcli create_blackout -name="CPU Patch 12062017" -reason="to be done" -add_targets="emtest:oracle_database" -schedule="duration::10"

$ ./emcli create_blackout -name="CPU Patch 12062017" -reason="to be done" -add_targets="emtest:oracle_database" -schedule="duration::10"
Error: Only Super Administrators are allowed to add a new reason (the get_blackout_reasons command will list the reasons you can use)
bin]$

Fix: Connect to SYSMAN user or user with super admin previllege and then try.

Think: How fast could you blackout entire environment for maintenance window with this scripted.

b) List blackouts:

./emcli get_blackout_targets -name=Blackout_Name
e.g.,

$ ./emcli get_blackout_targets -name="CPU Patch 12062017"
Target Name       Target Type      Status       Status ID
testbox_testbox1  oracle_database  In Blackout  1
bin]$

c) Stop Blackout:

Simply state the name of the blackout and the agent will issue a stop to the OMS

$ ./emcli stop_blackout -name="Linux Patch 12062017"

Think? How quickly could you end a blackout of environment post maintenance?

Note:  Get pre-defined blackout reasons. i.e., What Oracle make default for you.
./emcli get_blackout_reasons

d) Delete a blackout:

Syntax: ./emcli delete_blackout -name="blackout_name"

e.g.,
$./emcli delete_blackout -name="Linux Patch 12062017"

12) Stop and start an agent from OMS server

a) Stop agent:

$ ./emcli stop_agent -agent_name="dbahost-local:3872" -host_username=oracle
Host User password:
The Shut Down operation is in progress for the Agent: dbahost-local:3872
The Agent "dbahost-local:3872" has been stopped successfully.

Output:

Oracle Enterprise Manager Cloud Control 13c Release 2
Copyright (c) 1996, 2016 Oracle Corporation. All rights reserved.Stopping agent ... stopped.

b) Start AGENT:

$./emcli start_agent -agent_name="dbahost-local:3872" -host_username=oracle
Host User password:
The Start Up operation is in progress for the Agent: dbahost-local:3872
The Agent "dbahost-local:3872" has been started successfully.

Output:

Oracle Enterprise Manager Cloud Control 13c Release 2
Copyright (c) 1996, 2016 Oracle Corporation. All rights reserved.Starting agent ..................................... started.

13. Change password for dbsnmp user of target database

This will prompt for old password and new password.

$ ./emcli update_db_password -target_name="example2" -target_type="oracle_database" -user_name="dbsnmp" -change_at_target=yes

Enter value for old_password :
Enter value for new_password :
Enter value for retype_new_password :
Successfully submitted a job to change the password in Enterprise Manager and on the target database: "example2"


2 comments:

Translate >>