Tags

, , , ,

We use OEM to populate other system management systems at our company by providing configuration and metric data of all kinds.  When we get requests that require data that OEM doesn’t collect out of the box, we build metric extensions.

If you’ve worked with 12c metric extensions you know that the agents appear to perform these special metric collections whenever OEM feels like it.  At least that’s the way it seems.

I need to be able to collect these metrics at-will in response to user complaints or requests, so I put together a SQL query that builds the EM CLI commands to force a collection using the collect_metric verb.

In this example I want to collect a metric named ME$DEMO01 from all the members of an OEM group named rays_demo_hosts.

SELECT 'emcli collect_metric -target_type=host -target_name='
                || target_name
                || ' -metric_name="ME\$DEMO01"'
 AS cli_command
 FROM sysman.mgmt$group_members
 WHERE target_type = 'host' AND group_name = 'rays_demo_hosts';

That query results several lines like this:

emcli collect_metric -target_type=host -target_name=hostinmind01.madeup.com -metric_name="ME\$DEMO01"

Deployment Method 1 – Cut and Paste

The simplest means of executing this script is to execute the query in a tool like TOAD (or even at the command line) and copy and paste each line into an emcli session.

Deployment Method 2 – Spool into an argfile

If you decide to spool the results to a file, remove the keyword emcli from the query first and then execute the block using the emcli argfile verb.

SET echo OFF
SET heading OFF feedback OFF

spool /tmp/me_demo.lst
 SELECT 'collect_metric -target_type=host -target_name='
                || target_name
                || ' -metric_name="ME\$DEMO01"'
 AS cli_command
 FROM sysman.mgmt$group_members
 WHERE target_type = 'host' AND group_name = 'rays_demo_hosts';
spool off

Then:

emcli login -username=SYSMAN

emcli sync

emcli argfile /tmp/demo.lst

Deployment Method 3 – OEM Job System

The two steps from Deployment Method 2 can be built into a simple OEM Job to run on any host with SQL+ and EM CLI client installed (like your OEM management server), using this kind of logic:

#!/bin/bash

export ORACLE_HOME=/x/home/oracle/product/em/MW12105/oms
export EMCLI=${ORACLE_HOME}/bin/emcli
SQL_CONNECT=<sysman connect string to OMR>
SYSMAN_PWD=<   >
export SPOOLFILE=/tmp/me_demo.lst

# -------------------------------------------------------------------------

${ORACLE_HOME}/bin/sqlplus -S ${SQL_CONNECT} <<EOF
SET echo OFF
SET pages 999 lines 32767 trimspool ON head OFF feedback OFF
spool ${SPOOLFILE}

SELECT 'collect_metric -target_type=host -target_name='
 || target_name
 || ' -metric_name="ME\$DEMO01"'
 AS cli_command
 FROM sysman.mgmt$group_members
 WHERE target_type = 'host' AND group_name = 'rays_demo_hosts';

spool off
exit
EOF

$EMCLI logout
$EMCLI login -username=SYSMAN -password=${SYSMAN_PWD} -force
$EMCLI sync
$EMCLI argfile ${SPOOLFILE}
$EMCLI logout

export SQL_CONNECT=" "
export SYSMAN_PWD=" "

exit 0

I generally create two versions of the same Job – one with a scheduled recurring time and a second to run immediately, with names like update_me_demo01 and update_me_demo01_immediate, respectively.