4 Advanced EM CLI Script Examples

This chapter provides examples of using EM CLI to write scripts and automate routine tasks. To use these scripts, Oracle recommends that you are experienced with scripting languages and familiar with Jython (Python for the Java platform).

4.1 Changing Lifecycle Status Properties

To assist you in writing scripts, this section analyzes a sample script that changes the lifecycle status properties.

Example 4-1 enables an Enterprise Manager administrator to change the lifecycle status of all the Oracle databases (release 11.2) in their test environment from Test to Production. Without this script, you would have to sign in to the Enterprise Manager Cloud Control console, and identify all the release 11.2 databases, then manually change the property to Production for each database target from the target's home page.

You can reuse this script whenever there is a request to change a set of targets to a different Lifecycle status.

Note:

Line numbers are provided only for explanatory purposes for Table 4-1. For a copy-ready script, see Example A-5 in Sample Scripts.

Example 4-1 LifeCyclePropertyChange.py

#Disclaimer
#EXCEPT WHERE EXPRESSLY PROVIDED OTHERWISE, THE SITE, AND ALL CONTENT PROVIDED ON 
#OR THROUGH THE SITE, ARE PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS. ORACLE  
#EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED,  
#INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
#FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT WITH RESPECT TO THE SITE AND ALL  
#CONTENT PROVIDED ON OR THROUGH THE SITE. ORACLE MAKES NO WARRANTY THAT: (A) THE  
#SITE OR CONTENT WILL MEET YOUR REQUIREMENTS; (B) THE SITE WILL BE AVAILABLE ON AN  
#UNINTERRUPTED, TIMELY, SECURE,OR ERROR-FREE BASIS; (C) THE RESULTS THAT MAY BE 
#OBTAINED FROM THE USE OF THE SITE OR ANY CONTENT PROVIDED ON OR THROUGH THE SITE 
#WILL BE ACCURATE OR RELIABLE; OR (D) THE QUALITY OF ANY CONTENT PURCHASED OR  
#OBTAINED BY YOU ON OR THROUGH THE SITE WILL MEET YOUR EXPECTATIONS.
#ANY CONTENT ACCESSED, DOWNLOADED OR OTHERWISE OBTAINED ON OR THROUGH THE USE OF 
#THE SITE IS USED AT YOUR OWN DISCRETION AND RISK. ORACLE SHALL HAVE NO  
#RESPONSIBILITY FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT 
#RESULTS FROM THE DOWNLOAD OR USE OF CONTENT.
#ORACLE RESERVES THE RIGHT TO MAKE CHANGES OR UPDATES TO, AND MONITOR THE USE OF,  
#THE SITE AND CONTENT PROVIDED ON OR THROUGH THE SITE AT ANY TIME WITHOUT NOTICE.
 1 from emcli import *
 2 
 3 search_list = ['PROPERTY_NAME=\'DBVersion\'','TARGET_TYPE= \'oracle_database\'','PROPERTY_VALUE LIKE \'11.2%\'']
 4 
 5 if len(sys.argv) == 2: 

 6        print login(username=sys.argv[0]) 
 7        l_prop_val_to_set = sys.argv[1] 
 8        l_targets = list(resource="TargetProperties", search=search_list, columns="TARGET_NAME,TARGET_TYPE,PROPERTY_NAME") 
 9        for target in l_targets.out()['data']:
10             t_pn =  'LifeCycle Status' 
11             print "INFO: Setting Property name " + t_pn + " to value " + l_prop_val_to_set
12             print set_target_property_value(property_records=target['TARGET_NAME']+":"+target['TARGET_TYPE']+":"+t_pn+":"+l_prop_val_to_set)
13  else: ]
14        print "\n ERROR: Property value argument is missing" 
15        print "\n INFO: Format to run this file is filename.py <username> <Database Target LifeCycle Status Property Value>"

4.1.1 Script Analysis

Table 4-1 provides an analysis of each line of the code.

Table 4-1 Line-by_Line Script Analysis

Lines Description

1

Jython import construct to import all EM CLI verb functions in the current program.

3

search_list is a variable to pass to the search option in the list verb. This example uses escape characters to represent single quotes. To pass more than one value for the same option in the list verb, define as comma separated values, surrounded by square brackets.

5

Defines an if condition to ensure the user provides two arguments with the script, otherwise the script prints an error message (defined in lines #15, 16)

6

Provides a login to Enterprise Manager. You can remove this if you have set up EM CLI with autologin. For more information about setup and autologin, see Downloading and Deploying the EM CLI Client with the Script Option and the setup and the login verbs.

7

l_prop_val_to_set is a variable. This is the property value to be set. Remember that this script is changing this value from Test to Production. You can change this value to any acceptable Lifecycle property value. For a list of valid values, see the modify_lifecycle_stage_name verb or the Oracle Enterprise Manager Cloud Control Administrator's Guide.

8

Stores the output of the list verb in l_targets. In the list verb, this script passes the resource as TargetProperties, and search as the search_list variable. This script specifies three columns:

  • target_name

  • target_type

  • property_name

9

Defines a for loop. The data in l_targets is available in JSON format. This loop iterates through the information target property information returned from the list verb.

For information about JSON processing, see JSON Processing

10

Sets t_pn to the LifeCycle Status value.

11

Provides a progress message to the user stating that the script is setting the LifeCycle Status to the value passed to the script from the command line.

12

Defines the set_target_property_value verb, which sets the value using the property_records option. When this verb is set for a target pair, it moves to the next one. This example shows three databases, but in reality, use this script for a larger number of databases.

13 -15

Else statement combined with the if condition in line #5. If the arguments specified in line #5 are not provided correctly, then the script displays one of the following error messages:

  • Property value argument is missing

  • Format to run this file is filename.py <username> <Database Target LifeCycle Status Property Value>

4.1.2 Script Output

Running Example 4-1 provides the following output:

Example 4-2 Output from LifeCyclePropertyChange.py

$ emcli @myScript.py user Production

Login successful

INFO: Setting Property name LifeCycle Status to value Production for db1
Properties updated successfully
INFO: Setting Property name LifeCycle Status to value Production for db2
Properties updated successfully
INFO: Setting Property name LifeCycle Status to value Production for db3
Properties updated successfully

Logout successful

4.2 Changing Your Database Password

To assist you in writing scripts, this section analyzes a sample script that changes the password of your database.

Example 4-3 is useful if you want to reset the database password on a regular basis for security compliance. If you change the database password in a target database, then Enterprise Manager monitoring for that target database is unavailable. To ensure consistent monitoring, you would have to sign in to the Enterprise Manager Cloud Control UI, select the required database target and change the password for each and every database, which is very time-consuming.

By using Example 4-3, you can add a number of databases to a group and then change the password for all these databases within the group.

Note:

Line numbers are provided only for explanatory purposes for Table 4-2. For a copy-ready script, see Example A-6 in Sample Scripts.

Example 4-3 dbPasswordChange.py

#Disclaimer
#EXCEPT WHERE EXPRESSLY PROVIDED OTHERWISE, THE SITE, AND ALL CONTENT PROVIDED ON 
#OR THROUGH THE SITE, ARE PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS. ORACLE  
#EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED,  
#INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
#FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT WITH RESPECT TO THE SITE AND ALL  
#CONTENT PROVIDED ON OR THROUGH THE SITE. ORACLE MAKES NO WARRANTY THAT: (A) THE  
#SITE OR CONTENT WILL MEET YOUR REQUIREMENTS; (B) THE SITE WILL BE AVAILABLE ON AN  
#UNINTERRUPTED, TIMELY, SECURE,OR ERROR-FREE BASIS; (C) THE RESULTS THAT MAY BE 
#OBTAINED FROM THE USE OF THE SITE OR ANY CONTENT PROVIDED ON OR THROUGH THE SITE 
#WILL BE ACCURATE OR RELIABLE; OR (D) THE QUALITY OF ANY CONTENT PURCHASED OR  
#OBTAINED BY YOU ON OR THROUGH THE SITE WILL MEET YOUR EXPECTATIONS.
#ANY CONTENT ACCESSED, DOWNLOADED OR OTHERWISE OBTAINED ON OR THROUGH THE USE OF 
#THE SITE IS USED AT YOUR OWN DISCRETION AND RISK. ORACLE SHALL HAVE NO  
#RESPONSIBILITY FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT 
#RESULTS FROM THE DOWNLOAD OR USE OF CONTENT.
#ORACLE RESERVES THE RIGHT TO MAKE CHANGES OR UPDATES TO, AND MONITOR THE USE OF,  
#THE SITE AND CONTENT PROVIDED ON OR THROUGH THE SITE AT ANY TIME WITHOUT NOTICE.

 1 from emcli  import *
 2 from emcli.exception import VerbExecutionError
 3 import sys
 4 import time
 5 
 6 def check_job_status(job):
 7   count=0
 8   while (count < 10):
 9    count = count + 1
10    obj = emcli.get_jobs(job_id=job)
11    #print obj.out()
12    for entry in obj.out()['data']:
13        l_status = entry['Status ID']
14        l_exec_id = entry['Execution ID']
15        #print entry['Status ID']
16        if (l_status == '5'):
17            print "Job completed successfully"
18            count=100
19        elif (l_status == '4'):
20            l_resp = get_job_execution_detail(execution=l_exec_id, showOutput=True, xml=True)
21            print "Job failed, error details "
22            print "Output " + str(l_resp.out())
23            count=100
24        else:
25            time.sleep(2)
26 
27 def update_db_pwd_for_target(p_target_name, p_target_type, p_old_password, p_new_password):
28    l_target_name = p_target_name
29    l_target_type = p_target_type
30    print "Changing the password for member : name = " + l_target_name + " type = " + l_target_type
31    try :
32        l_resp = update_db_password (target_name=l_target_name,
33                                  target_type = l_target_type,
34                                  change_at_target="yes",
35                                  user_name="dbsnmp",
36                                  old_password=p_old_password,
37                                  new_password=p_new_password,
38                                  retype_new_password=p_new_password)
39        l_job_submitted = l_resp.out()['JobId']
40        check_job_status(l_job_submitted)
41    except emcli.exception.VerbExecutionError, e:
42        print "ERROR : Change Password failed for name = " + l_target_name + " type = " + l_target_type
43        print "ERROR : " + e.error()
44 
45 def update_db_pwd_for_group(p_group, p_old_password, p_new_password):
46    print "Changing the password for group - " + p_group + " from " + p_old_password + " to " + p_new_password
47    members = get_group_members(name=p_group).out()['data']
48    for member in members:
49        l_target_name = member['Target Name']
50        l_target_type = member['Target Type']
51        update_db_pwd_for_target(l_target_name, l_target_type, p_old_password, p_new_password)
52 
53 
54 #Set the OMS URL to connect to
56 set_client_property('EMCLI_OMS_URL','https://myoms.com/em')
57 #Accept all the certificates
58 set_client_property('EMCLI_TRUSTALL','true')
59 
60 login(username=sys.argv[0])
61 
62 
63 l_grp_name = 'maurGroup'
64 
65 l_group_members = ['db1:oracle_database','db2:oracle_database','db3:rac_database']
66 
67 
68 
69 res = create_group(name = l_grp_name, add_targets = l_group_members)
70  
71 print "Listing members for group " + l_grp_name
72 
73 for member in get_group_members(name=l_grp_name).out()['data']:
74    print member
75 
76 
77 y_n_input = raw_input('Now lets change the password for all the members in this group(y/n)')
78 if y_n_input != 'y':
79  exit(0)
80 
81 l_tgt_username = "dbsnmp"
82 l_old_password = "secret1"
83 l_new_password = "secret2"
84   
85 update_db_pwd_for_group(l_grp_name, l_old_password, l_new_password)

4.2.1 Script Analysis

Table 4-2 provides an analysis of each line of the code.

Table 4-2 Line-by_Line Script Analysis

Lines Description

1-2

Imports all EM CLI verbs, and imports VerbExecutionError.

3-4

Imports Jython libraries.

6-25

Defines the job where the script updates the database password for each member of the l_grp_name group. After each successful job completion, the script displays a message to the user, and waits 2 seconds before processing the next job, unless there are any errors or all database passwords are updated.

27-43

Defines variables for updating the database password on each target member of the l_grp_name group. While the script successfully updates the database password, it provides the following message to the user before proceeding to update the password of the next database target:

Changing the password for member : name = database_name type = database_type

45-51

Defines a loop to get all members from the l_grp_name group and update the password for each member as defined in line #85. When the script starts processing this loop, it provides this message to the user:

Changing the password for group - l_grp_name from l_old_password to l_new_password

54-58

Necessary connection to OMS to retrieve all targets. Before connecting to the OMS, you must set the OMS connection details using the set_client_property() function. This sets the OMS URL to https://myoms.com/em and enables the client to trust all certificates.

Note that none of these details are stored in disk. These details are stored in memory and only last for a single script execution. For more information on client properties, enter help('client_properties') from the interactive shell.

You can define EMCLI_OMS_URL and EMCLI_TRUSTALL variables as environment variables if you do not want to set these in your script. If you have downloaded certificates somewhere, you can also use the environment variable EMCLI_CERT_LOC to point to the certificate directory. In this case, you do not need EMCLI_TRUSTALL. For more information, see Interactive Mode — Connecting to an Oracle Management Server (OMS).

60

Provides a login to the OMS. You can remove this if you have set up EM CLI with autologin. For more information about setup and autologin, see Downloading and Deploying the EM CLI Client with the Script Option and the setup and the login verbs.

63

l_grp_name is a variable for the group name

65

l_group_members is a variable for the array of the database name and type.

69

Adds members from l_group_members to the l_grp_name group

71-74

Provides a message to users while the script is adding members to the l_grp_name group

77-79

Provides a prompt to users to decide if they want to continue with the script. If the user enters n, then the script exits. If the user enters y, then the script proceeds.

81

l_tgt_username is a variable for the user name of the database owner.

82

l_old_password is a variable for the existing password associated with the database owner.

83

l_new_password is a variable for the new password associated with the database owner.

85

Replaces the existing password with the new password for all members of the l_grp_name group.

4.2.2 Script Output

Running Example 4-3 provides the following output:

Example 4-4 Output From dbPasswordChange.py

$ emcli @myScript.py user 
Enter password : **********

Listing members for group maurGroup
('Target Name': 'aixsdbsi', 'Target Type': 'oracle_database')
('Target Name': 'winsidb1', 'Target Type': 'oracle_database')
('Target Name': 'db10g', 'Target Type': 'rac_database')
('Target Name': 'solcdbone', 'Target Type': 'rac_database')
Now let's change the password for all the members in this group (y/n)y
Changing the password for group - maurGroup from secret1 to secret2
Changing the password for member : name = aixsdbsi type = oracle_database
Job completed successfully
Changing the password for member : name = winsidb1 type = oracle_database
Job completed successfully
Changing the password for member : name = db10g type = rac_database
Job completed successfully
Changing the password for member : name = solcdbone type = rac_database
Job completed successfully

Logout successful

4.3 Promoting Discovered Targets

To assist you in writing scripts, this section analyzes a sample script that promotes discovered Oracle Database targets.

Consider a corporate environment where databases are added for each user requesting an instance using their UI. Most companies automate the entire process from database creation, adding data files, and so on. As part of your automation process, at the end, you can add this script.

Example 4-5 promotes the databases automatically, which are then ready to be monitored by Enterprise Manager. This removes the necessity for you to have to log in to the Enterprise Manager Cloud Control UI and promote the databases manually.

Note:

Line numbers are provided only for explanatory purposes for Table 4-3. For a copy-ready script, see Example A-7 in Sample Scripts.

Example 4-5 promote_discovered_dbs.py

#Disclaimer
#EXCEPT WHERE EXPRESSLY PROVIDED OTHERWISE, THE SITE, AND ALL CONTENT PROVIDED ON 
#OR THROUGH THE SITE, ARE PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS. ORACLE  
#EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED,  
#INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
#FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT WITH RESPECT TO THE SITE AND ALL  
#CONTENT PROVIDED ON OR THROUGH THE SITE. ORACLE MAKES NO WARRANTY THAT: (A) THE  
#SITE OR CONTENT WILL MEET YOUR REQUIREMENTS; (B) THE SITE WILL BE AVAILABLE ON AN  
#UNINTERRUPTED, TIMELY, SECURE,OR ERROR-FREE BASIS; (C) THE RESULTS THAT MAY BE 
#OBTAINED FROM THE USE OF THE SITE OR ANY CONTENT PROVIDED ON OR THROUGH THE SITE 
#WILL BE ACCURATE OR RELIABLE; OR (D) THE QUALITY OF ANY CONTENT PURCHASED OR  
#OBTAINED BY YOU ON OR THROUGH THE SITE WILL MEET YOUR EXPECTATIONS.
#ANY CONTENT ACCESSED, DOWNLOADED OR OTHERWISE OBTAINED ON OR THROUGH THE USE OF 
#THE SITE IS USED AT YOUR OWN DISCRETION AND RISK. ORACLE SHALL HAVE NO  
#RESPONSIBILITY FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT 
#RESULTS FROM THE DOWNLOAD OR USE OF CONTENT.
#ORACLE RESERVES THE RIGHT TO MAKE CHANGES OR UPDATES TO, AND MONITOR THE USE OF,  
#THE SITE AND CONTENT PROVIDED ON OR THROUGH THE SITE AT ANY TIME WITHOUT NOTICE.
 
  1 from emcli.exception import VerbExecutionError
  2 import sys
  3  
  4 alltargets=False
  5 targetparms=0
  6 uname=''
  7 pword=''
  8 url=''
  9 monitor_pw=''
 10 
 11 def helpUsage():
 12    print 'Usage: promote_discovered_dbs.py [-help]'   
 13    print '[-all] Add all discovered Single Instance DBs'   
 14    print '[-targets <target1:target2:...] Add only targets listed'   
 15    sys.exit()
 16    
 17 for i in range(len(sys.argv)):
 18    if sys.argv[i] in ("-help"):
 19            helpUsage()   
 20    elif sys.argv[i] in ("-targets"):
 21            if i+1 < len(sys.argv):
 22                    targetparms = sys.argv[i+1]
 23    else:
 24                    print 'Usage: promote_discovered_dbs.py [-help]'
 25                    print '[-all] Add all discovered Single Instance DBs'
 26                    print '[-targets <target1:target2:...] Add only targets listed'
 27                    sys.exit()
 28     elif sys.argv[i] in ("-url"):
 29            if i+1 < len(sys.argv):
 30                    url = sys.argv[i+1]
 31     elif sys.argv[i] in ("-username"):
 32            if i+1 < len(sys.argv):
 33                    uname = sys.argv[i+1]
 34    elif sys.argv[i] in ("-password"):      
 35            if i+1 < len(sys.argv):         
 36                    pword = sys.argv[i+1]            
 37    elif sys.argv[i] in ("-monitor_pw"):      
 38            if i+1 < len(sys.argv):          
 39                    monitor_pw = sys.argv[i+1]            
 40    elif sys.argv[i] in ("-all"):      
 41                    alltargets = True         
 42            
 43 # Make sure user did not specify target list and all targets.
 44 if alltargets<>0 and targetparms <>0:         
 45             print 'Cannot specify target list and all switch'            
 46    print 'Usage: promote_discovered_dbs.py -url <EM URL> -username <username> -password <password> -monitor_pw <password>'       
 47    print '[-all] Add all discovered SI Databses'
 48    print '[-targets <target1:target2:...] Add only list targets'
 49    print '[-help]'
 50    sys.exit()
 51
 52 if len(uname)==0 or len(pword)==0 or len(url)==0:
 53         print 'Missing required arguments (-url, -username, -password)' 
 54         print 'Usage: promote_discovered_dbs.py -url <EM URL> -username <username> -password <password> -monitor_pw <password>'
 55         print '[-all] Add all discovered SI Databses'
 56         print '[-targets <target1:target2:...] Add only list targets'
 57             print '[-help]'
 58         sys.exit()
 59
 60 # Set Connection properties and logon
 61 set_client_property('EMCLI_OMS_URL',url)
 62 set_client_property('EMCLI_TRUSTALL','true')
 63 login(username=uname,password=pword) 
 64
 65 cred_str = "UserName:dbsnmp;password:" + monitor_pw + ";Role:Normal" 
 66
 67 if targetparms <> 0: 
 68    targetparms = targetparms.replace(":",":oracle_database;")+":oracle_database"
 69    target_array = get_targets(unmanaged=True,properties=True,targets=targetparms).out()['data']
 70 elif alltargets:   
 71    target_array = get_targets(targets="oracle_database",unmanaged=True,properties=True ).out()['data']
 72 else:
 73     print 'Missing required arguments (-targets or -all)'
 74    helpUsage() 
 75   
 76 if len(target_array) > 0:
 77    for target in target_array:
 78                     print 'Adding target ' + target['Target Name'] + '...',
 79
 80            for host in str.split(target['Host Info'],";"):
 81                if host.split(":")[0] == "host":]
 82                    print host.split(":")[1]
 83            try:
 84                res1 = add_target(type='oracle_database',name=target['Target Name'],host=host.split(":")[1], credentials=cred_str,properties=target['Properties'])
 85                print 'Succeeded'
 86                     except VerbExecutionError, e:
 87                print 'Failed'
 88                print e.error()
 89                print 'Exit code:'+str(e.exit_code())
 90 else:
 91    print 'INFO: There are no targets to be promoted. Please verify the targets in Enterprise Manager webpages.'
 92
 

4.3.1 Script Analysis

Table 4-3 provides an analysis of each line of the code.

Table 4-3 Line-by_Line Script Analysis

Lines Description

1

Imports all EM CLI verbs, and imports VerbExecutionError.

2

Imports Jython libraries.

4-9

Sets variables:

  • uname: User name that allows access to Enterprise Manager

  • pword: Password associated with the user name

  • url: Enterprise Manager URL

  • monitor_pw: Password that allows monitoring of targets

10

Defines input arguments.

11-15

Defines the message displayed to the user if they run the script with invalid or missing arguments:

Usage: promote_discovered_dbs.py [-help][-all] Add all discovered Single Instance DBs[-targets <target1:target2:...] Add only targets listed

17-41

Defines a For loop that checks that the input variables (defined in lines 4 to 9) are valid and present, otherwise the script terminates and displays the message defined in lines 11-15.

43-50

Defines an If statement to check that the user doesn't provide the -targets and the -all arguments when running the script. If the user enters both arguments, then the scripts terminates and displays the message defined in lines 11-15.

52-58

Defines an If statement to check that user provides the user name, password, and URL of Enterprise Manager when running the script. If any of these arguments are missing, then the scripts terminates and displays the message defined in lines 11-15.

60-62

Necessary connection to OMS to retrieve all targets. Before connecting to the OMS, you must set the OMS connection details using the set_client_property() function. This sets the OMS URL to https://myoms.com/em and enables the client to trust all certificates.

Note that none of these details are stored in disk. These details are stored in memory and only last for a single script execution. For more information on client properties, enter help('client_properties') from the interactive shell.

You can define EMCLI_OMS_URL and EMCLI_TRUSTALL variables as environment variables if you do not want to set these in your script. If you have downloaded certificates somewhere, you can also use the environment variable EMCLI_CERT_LOC to point to the certificate directory. In this case, you do not need EMCLI_TRUSTALL. For more information, see Interactive Mode — Connecting to an Oracle Management Server (OMS).

63

Provides a login to the OMS. You can remove this if you have set up EM CLI with autologin. For more information about setup and autologin, see Downloading and Deploying the EM CLI Client with the Script Option and the setup and the login verbs.

65

Defines a variable for the credential string required for monitoring targets.

67

Defines an if statement to determine if the -targets argument is provided and if targets exist.

68

Sets the value for target_params

69

Sets the values for target_array, using the targets (where the list of targets is defined by targetparams), unmanaged, and properties parameters of the get_targets verb. When it is set for the first target, the script then moves on to the next target.

70-71

Defines an else if statement to set the values for target_array if the -all option is provided when running the script, using the targets, unmanaged, and properties parameters of the get_targets verb. When it is set for the first target, the script then moves on to the next target.

72-74

Defines an else statement in case the -targets or -all options are not provided when running the script. If this happens, the script terminates and displays the message defined in lines 11-15.

76-78

Determines if there is data in the array, and if there is data, the script displays a message similar to the following:

Adding target abchost.us.example.com... host.us.example.com

80-82

Extracts the host name from the host information

83-88

Adds the targets to the Management Repository using the add_target verb and displays the following message:

Succeeded

If the script fails to add targets to the Management Repository, then it displays the following message:

Failed

90

From line 76, if there are no targets in the array, the script terminates, and displays the following message to the user:

INFO: There are no targets to be promoted. Please verify the targets in Enterprise Manager webpages.Logout successful

4.3.2 Script Output

Running Example 4-5 with various options provides the following outputs:

Example 4-6 Output from promote_discovered_dbs.py with -all option

$ emcli @promote_discovered_dbs.py -url https://host.us.example.com:7799/em -username sysman -password welcome1 -monitor_pw welcome1 -all
Adding target sid7458.us.example.com... host.us.example.com
Succeeded
Logout successful

Example 4-7 Output from promote_discovered_dbs.py with -targets option

$ emcli @promote_discovered_dbs.py -url https://host.us.example.com:7799/em -username sysman -password welcome1 -monitor_pw welcome1 -targets sid7458.us.example.com
Adding target sid7458.us.example.com... host.us.example.com
Succeeded
Adding target db1... host.us.example.com
Succeeded
Adding target db2... host.us.example.com
Succeeded
Adding target db3... host.us.example.com
Succeeded
Logout successful

Example 4-8 Output from promote_discovered_dbs.py with -targets option

$ emcli @promote_discovered_dbs.py -url https://host.us.example.com:7799/em -username sysman -password welcome1 -monitor_pw welcome1 -targets db1:db2:db3
Adding target db1... host.us.example.com
Succeeded
Adding target db2... host.us.example.com
Succeeded
Adding target db3... host.us.example.com
Succeeded
Logout successful

Example 4-9 Output from promote_discovered_dbs.py where the specified targets do not exist

$ emcli @promote_discovered_dbs.py -url https://host.us.example.com:7799/em -username sysman -password welcome1 -monitor_pw welcome1 -targets abc
INFO: There are no targets to be promoted. Please verify the targets in Enterprise Manager webpages.
Logout successful

Example 4-10 Output from promote_discovered_dbs.py where no targets are available for promotion

$ emcli @promote_discovered_dbs.py -url https://host.us.example.com:7799/em -username sysman -password welcome1 -monitor_pw welcome1 -all
INFO: There are no targets to be promoted. Please verify the targets in Enterprise Manager webpages.
Logout successful

Example 4-11 Output from promote_discovered_dbs.py where the -all or -targets option is missing

$ emcli @promote_discovered_dbs.py -url https://host.us.example.com:7799/em -username sysman -password welcome1 -monitor_pw welcome1
Missing required arguments (-targets or -all)
Usage: promote_discovered_dbs.py [-help]
[-all] Add all discovered Single Instance DBs
[-targets <target1:target2:...] Add only targets listed
Logout successful