Create Blackout for Multiple Targets on EM13c

    Feb 26, 2017 4:12:27 AM by Gokhan Atil

    The notifications emails of a “planned” downtime is one of the annoying things of monitoring systems. You forget creating blackout and you start a maintenance work, and you get lots of notifications mails. Most of the time, the target which goes down, also affect other targets so it will multiple the number of unwanted notifications mails. Good thing is, it’s very easy to create blackouts on EM13c. We can do it through web console, emctl or emcli tools. A one-liner is enough for it:

    emctl start blackout BlackOutName -nodeLevel

    The above code will create a blackout for the all targets on the server. We can achieve the same thing by EMCLI:

    emcli create_blackout -name="BlackOutName" -reason="you know we need to do it" -add_targets="myserver:host" 
    -propagate_targets -schedule="duration:-1" # indefinite

    If we use emcli, we have more options such as creating repeating blackouts, entering a reason for blackout, enabling blackout for a group of targets (which resides on different hosts).

    What if we need to create blackout for multiple targets. As I mentioned, EMCLI can be used to create blackout for groups. We can create groups on EM13c, and instead of passing names of all targets in a group, we can give the group name:

    #
    # Sample EMCLI Python script file to create blackout for multiple targets
    #
    # check number of arguments

    if len(sys.argv) <> 2:
    print "Usage to start a blackout: emcli @multiblackout.py targets.csv blackout_name"
    print "Usage to stop a blackout: emcli @multiblackout.py stop blackout_name"
    exit()

    blackout_name = sys.argv[1].upper()

    # login to OMS

    login( username="SYSMAN", password="yoursupersecretpassword" )

    if sys.argv[0].lower() == "stop":
    stop_blackout( name= blackout_name )
    # comment below line to keep old blackouts
    delete_blackout( name = blackout_name )
    print "%s blackout stopped and deleted." % blackout_name
    exit()

    # open file for reading

    f = open( sys.argv[0], 'r' )
    # variable to keep all targets
    alltargets = ""

    # loop for each line of the file

    for target in f:
    # build alltargets string
    alltargets += target.replace("n","") + ";"

    create_blackout( name = blackout_name, add_targets=alltargets, reason=blackout_name, schedule="duration:-1" )

    The script accepts two parameters. First parameter is the path of the file containing the targets, the second parameter is the name of the blackout. The targets file should be something like this:

    DBNAME1:oracle_database
    DBNAME2:oracle_database
    MYHOST5:host

    After you create a blackout, you can stop (and delete) the blackout by running it again, but this time you need to enter “stop” as the file name:

    ./emcli @multiblackout.py /home/oracle/mytargets.txt TESTBLACKOUT
    ./emcli @multiblackout.py stop TESTBLACKOUT

    If you have any questions about the script, please do not hesitate to ask. By the way I’m aware that the script has lack of error handling, can be written more efficent but I’m not trying to provide a script library to you

    I’m sharing a simple version so you can write your own (and better) script.

     

    Tags: Oracle

    Gokhan Atil

    Written by Gokhan Atil

    Gokhan Atil has over 15 years of experience in the IT industry and a strong background in database management (Oracle 8i,9i,10g,11g), software development and UNIX systems. He is an Oracle certified professional for EBS R12, Oracle 10g and 11g. Gokhan specializes in high availability solutions, performance tuning and monitoring tools. Gokhan is a founding member and current vice president of Turkish Oracle User Group (TROUG). He’s also a member of Independent Oracle User Group (IOUG). Gokhan presented at various conferences, and he is one of co-authors of “Expert Oracle Enterprise Manager 12c” book.