Recently I was working with Automation team, where the requirement is to discover & promote oracle databases to OEM13c using with silent installation where no -MAN EMDBA needs to add those targets manually in OEM. Initially I thought it could be quite challenging but later on after familiarizing the EM CLI I have created perl script which can discover & promote targets directly into your ADMIN_GROUPS in OEM13c.

  1. Install EM CLI on the Oracle Database server.
  2. Update the below scripts which appropriate the passwords & directory locations.
  3. This script has Error handling codes which Chef/puppet automation tools required.

Set your env to EMCLI and run below script.
For Example we are promoting TEST01 database on dbadeeeds servers to OEM13c into LifeCycle property=Development & Department=Dev_Dal

bin/perl discover_promote.pl dbadeeds.systems.com TEST01 Dev Dev_Dal promote

#!/bin/perl
#
#Title:discover_promote.pl
#Author: Sandeep R Narani
#Date:01/26/2018
## Version N.0 --Updated with new arugments & log function
##### Version N.1 --Updated with Host & ASM set properties files
###################### Usage 'perl discover_promote.pl dbadeeds.systems.com TEST01 Dev Dev_Dal promote' #################
######################/bin/perl discover_promote.pl hostname SID LifeCycle Department  #################
use strict;
use warnings;
use Net::SMTP;
my $host_name = $ARGV[0];
my $sysman_pwd= $ARGV[1];
my $sid = $ARGV[2];
my $lifecycle = $ARGV[3];
my $department = $ARGV[4];
my $check_promote = $ARGV[5];
my $num_args = $#ARGV+1;
my $dbsnmp_pwd = 'dbsnmp_pwd';
my $asm_pwd = 'asm_pwd';
my $time_now = localtime();
#my $sysman_pwd='asm_sysman_pwd';
my $file_name = "/u01/app/oracle/platform/emcli/log/discover_SID_".$sid.".txt";
my $emcli_home_bin="/u01/app/oracle/product/13.2.0.0/emcli";
my $logfile = "/u01/app/oracle/platform/emcli/log/discover_".$sid.".log";
my $Subject="Discovering & promoting the targets to 13EM";
open STDOUT, '>>', "$logfile" or die "Can't redirect STDOUT: $!";
open STDERR, ">&STDOUT"  or die "Can't add to  STDOUT: $!";
if ($num_args != 6) {
    print "\nUsage: perl discover_promote.pl       \n";
    }

    if ($num_args == 6) {
    open(FH, ">".$file_name) or die $!;
    print FH "host_name=".$host_name."\n";
    print FH "db_creds=".$sid.":dbsnmp,".$dbsnmp_pwd.",SYSDBA\n";
    print FH "target_type=oracle_database\n";
    print FH "db_status=up\n";
    print FH "\tasm_creds=asmsnmp,".$asm_pwd.",SYSDBA\n";
    print FH "\tglobal_props=LifeCycle Status:".$lifecycle.",Department:".$department;
    close(FH) or die $!;
    }

if ($num_args == 6){
    print "\nStart Time: ".$time_now."\n";
    emcli_login();

if ($ARGV[5] eq 'check') {
	emcli_check_target();
    }
    
    if ($ARGV[5] eq 'promote'){
	emcli_promote_target();
    }

   if ($ARGV[5] eq 'debug'){
	emcli_debug_target();
    }
set_target_property();
my $end_time = localtime();
    print "\nEnd time: ".$end_time."\n";
    emcli_logout();
}

##################################################Sub Programs##########################################
sub emcli_login{
	print "\n";
	system($emcli_home_bin.'/emcli login -username=sysman -password='.$sysman_pwd);
	system($emcli_home_bin.'/emcli sync');
	print "\n";
}

sub emcli_logout{
	print "\n";
	system($emcli_home_bin.'/emcli logout');
	print "\n";
}

sub emcli_promote_target{
	print "\n";
	system($emcli_home_bin.'/emcli discover_db -input_file=db_discovery_file:"'.$file_name.'" -promote');
	print "\n";
}

sub emcli_check_target{
	print "\n";
	system($emcli_home_bin.'/emcli discover_db -input_file=db_discovery_file:"'.$file_name.'" -check');
	print "\n";
}

sub emcli_debug_target{
	print "\n";
	system($emcli_home_bin.'/emcli discover_db -input_file=db_discovery_file:"'.$file_name.'" -debug');
	print "\n";
}
sub set_target_property {
print "\n";
system($emcli_home_bin.'/emcli set_target_property_value -property_records="'.$host_name.':host:Department:'.$department.'"');
system($emcli_home_bin.'/emcli set_target_property_value -property_records="'.$host_name.':host:"Lifecycle\ Status":'.$lifecycle.'"');
system($emcli_home_bin.'/emcli set_target_property_value -property_records="+ASM_'.$host_name.':osm_instance:Department:'.$department.'"');
system($emcli_home_bin.'/emcli set_target_property_value -property_records="+ASM_'.$host_name.':osm_instance:"Lifecycle\ Status":'.$lifecycle.'"');
print"\n";
	} 

Here is the output location and script name

dbadeeds:/u01/app/oracle/platform/emcli/log>
oracle:LISTENER $ cat discover_TEST01.log
Start Time: Mon Jan 30 22:16:53 2017

Login successful
Synchronized successfully


Please wait while the targets are being discovered and added/promoted...
The following targets have been promoted successfully on dbadeeds.systems.com:
  LISTENER_dbadeeds.systems.com:Listener
  +ASM_dbadeeds.systems.com:Automatic Storage Management
  
The following targets have been promoted successfully on dbadeeds.systems.com:
  TEST01.dbadeeds.systems.com:Database Instance
  TEST01.dbadeeds.systems.com:Database System



Properties updated successfully
Properties updated successfully
Properties updated successfully
Properties updated successfully

End time: Mon Jan 30 22:17:05 2017

Logout successful

 

2 responses to “Discover & Promote Targets to OEM13c from Oracle Database servers using EMCLI”

  1. OEM Agents & EM CLi Silent Installation | DBADEEDS Avatar

    […] ← Previous […]

    Like

  2. Keenan Magpuri Avatar

    I am typically to blogging and i really recognize your content. The article has really peaks my interest. I’m going to bookmark your website and hold checking for brand new information.

    Like

Leave a comment