Blog | Apr 16, 2014

EM CLI-Enterprise Manager functionality through text-based console

EM CLI (Enterprise Manager Command Line Interface)

The first thing we think of when we hear of Oracle Enterprise Manager (OEM) is a web-based graphical interface (GUI), but a GUI is not the only way an OEM can be accessed. It also has a command line interface, which can be used as an alternative to the GUI to perform several tasks. Though not very popular among users, the unpopularity is not due to any drawbacks or limitations, a user just has to remember more commands than with a GUI. However, as OEM has evolved so has EM CLI.
Integration between EM CLI and Enterprise Manager’s security and user administration now allows users to carry out activities with same level of security, restrictions and confidentiality as when using the graphical OEM interface. The output is in the form of text instead of graphics or images.

The following tasks can be accomplished through EM CLI:
• Monitoring and auditing actions performed by users in the graphical interface.
• Create new enterprise manager administrator accounts.
• Adding/deleting targets, submitting/deleting jobs, creating/deleting users.
• Monitoring individual targets, groups, jobs and blackouts.

The above was a brief overview, now let’s focus on few concepts, basic working architecture as well the installation of EM CLI that will help to illustrate EM CLI in a much broader way.

Concepts

• Verbs

Verb is a user command which open ups Enterprise Manager Functionality. We perform actions using verb by passing parameters. Parameters can be mandatory or optional depending upon the task we want to accomplish.
There are 333 EM CLI verbs. Details for each verb can be found in the Oracle Document 17786-02 and also with command line (EMCLI –help).
In the below example, login is a verb.

emcli login  -username=<EM_Console_Username> [-password=<EM_Console_Password>]  [-force]

[ ] indicates that the parameter is optional

• Modes

EM CLI offers users with three different modes.

• Standard command-line mode

This is the basic mode prior to Enterprise Manager Cloud Control version 12.1.0.3. It is the simplest command-line interface to Enterprise Manager, and supports the execution of one verb at a time from the command line.

e.g.
emcli create_group -name=my_group -add_targets="mymachine.myco.com:host"

• Interactive mode

This mode uses Jython shell. Jython is a successor of JPython, an implementation of the Python programming language written in Java. In this mode a single interactive session can be created with the Oracle Management Service (OMS), where you enter commands, view the output and respond to or manipulate the output.

e.g.
emcli> create_group(name='my_group'..)

• Script mode

Script mode is helpful when performing many tasks in a go. This mode can be used when updating database passwords or listing group members. We can also create Jython scripts using this mode, save those scripts as files and then use these files as a parameter to EM CLI

e.g.
emcli @createuser.py

Components

• EM CLI Client

The EM CLI Client needs to be installed on every host from which its usage is required. We can install the client in any directory either on the same machine as the EM CLI Management Services or on any machine available in the network.

• EM CLI OMS

The EM CLI Oracle Management Service (OMS) is installed as part of the OMS and it is the interface between the EM CLI Client and the OMS itself.

Working and Architecture

The EM CLI utility can be invoked by calling its name, just like SQLPLUS, RMAN among others. Unlike SQLPLUS, EM CLI does not require a subshell when used in a shell script. You can call by its name like any other UNIX utility.

When invoked, EM CLI implements client-server architecture, in which EM CLI is the client, and the Oracle Management Services (OMS) is the server. A typical verb may take zero or more arguments as input. The EM CLI client passes the input to the OMS for processing. The EM CLI client connects to the OMS and establishes a user session, which is used across verb executions until a logout is initiated.

In some respects, the EM CLI client functions as a command-line equivalent of an Enterprise Manager Cloud Control console. The EM CLI OMS is automatically installed with the OMS and serves as a communication conduit between the EM CLI client and the OMS.

Installation of EM CLI Client

1) Download the EM CLI Client kit (emclikit.jar).
http(s)://your_oms_home:port/em/console/emcli/download

2) Make sure you have Java JDK 1.4.2 or greater version when using with 10.2.0.4 Grid Control and JDK 1.6.0_24 or higher installed for Enterprise Manager Cloud Control 12c and ensure that your JAVA_HOME and PATH environment variables are properly set to the Java JDK installation.

3) Install the EM CLI Client using the following:
cd <directory where you downloaded emclikit.jar>
java -jar emclikit,jar client -install_dir=<emcli_client_dir>

Once it is installed, you can run the EM CLI from the install directory (or add it to your PATH variable if you prefer). After installation, only these basic commands are initially configured and available for use:
• argfile (to execute commands from a file)
• help
• login/logout
• setup (to configure communication with the OMS)
• status
• sync (to synchronize with the OMS)
• version

Configuring the EM CLI Client

Post installation there are only a limited number of operational verbs, to install the remaining commands for full functionality and to communicate with the OMS, the setup command must be run. The setup command configures the EM CLI Client to interface with the EM CLI OMS extension, which in turn communicates with its OMS.

./emcli setup -url=http://your_oms_home:port/em -username=em_admin_user

After you have successfully installed and configured the EM CLI client you can perform activities similar to the ones that are done using a graphical interface.

To verify the current EM CLI Client setup information
./emcli setup (for basic info)
./emcli status (for more detailed info)

EM CLI Login

Before you execute any command you need to login in to the client unless the auto login option is specified during setup.

EM CLI Client setup is in secure mode by default (-noautologin is the default option for the setup command). This means that each time it is used you will have to issue a login command and specify a username/password combination to be able to run commands to your OMS. The non-secure option for setup is -autologin. This mode will also automatically re-login after a session timeout. Session timeout defaults to 45 minutes. Autologin should only be configured on secured client systems.

$. /emcli login  -username=<EM_Console_Username> [-password=<EM_Console_Password>]  [-force]
-username is the EM user
-password is the password, you will be prompted if you do not specify this as part of the command line which is more secure
-force logs you in even if there was an existing session/connection

For logout

$./emcli logout

EM CLI log files

Log files are generated by EM CLI when we invoke EMCLI. These logs contain informational and error messages and are stored in form of stack traces and can be used for troubleshooting but in routine they are of little use. These logs can be removed anytime and removing them will have no impact on EM CLI operation.

Once a log file grows up to 0.5 MB which is the maximum limit it gets overwritten or switched. The location of these log files is generally specified as configuration directory during setup from the -dir option, but if it is not specified during setup, EM CLI assumes the .emcli configuration directory is located within your local home directory:

CONFIG_DIR/.emcli.log
CONFIG_DIR/.emcli.log.1


or

local.dir/.emcli/.emcli.log
local.dir/.emcli/.emcli.log.1

What’s New in EMCLI

Oracle Enterprise Manager 12c R3 comes with a new EMCLI kit called ‘EMCLI with Scripting Option’. Unlike the classic EMCLI, this new kit provides a Jython-based scripting environment along with the large collection of verbs to use. This scripting environment enables users to use established programming language constructs like loops (for, or while), conditional statements (if-else), etc in both interactive and scripting mode.

Additional features of new EMCLI are:
•  Jython based scripting environment
•  Interactive and scripting mode
•  Standardized output format using JSON
•  Can connect to any EM environment (no need to run EMCLI setup …)
•  Stateless communication with OMS (no user data is stored with the client)
•  Generic list function for EM resources
•  Ability to run user-defined SQL queries to access published repository views


Summary
• EMCLI has most of the capabilities as its graphical-based counterpart but has the added benefit of being much faster and getting automated easily.
• After release 3 of EM12c, EMCLI is now not only interactive; it uses the mature Python language as the interpreter. Specifically, it uses the Java implementation called Jython.

References

http://docs.oracle.com/cd/E24628_01/em.121/e17786/toc.htm
https://blogs.oracle.com/oem/entry/oracle_enterprise_manager_12c_release
http://www.databasejournal.com/article.php/3896401/Karen-Reliford.htm