Querying the status of a discovery task

Problem this snippet solves:

The script you need for this task must:

  1. Identify the Enterprise Manager system on which you want to initiate a query discovery task status process, specifying username and password as needed.
  2. Specify the task ID of the task you are interested in.
  3. Initialize the API.
  4. Run the API.

How to use this snippet:

To query the status of a discovery task:

  1. Create a script similar to the code sample shown below.
  2. From a command prompt, run your script.
  3. When the code finishes running, the query status task(s) are added to the user interface on Enterprise Manager. The tasks you queried are also listed on the command line interface window.

Code :

/**
 * A class for testing the Management::EM::get_task_status iControl interface.
 */

public class ManagementEMGetTaskStatus {
    
    private static int MIN_ARGS = 3;
    private static String USAGE = 
        "ManagementEMGetTaskStatus    " +
        "[] ...";
    private static int EM_PORT = 443;


    /**
     * The main method.
     *
     * @param args command line arguments
     */

    public static void main(String[] args) {

        if (args.length < MIN_ARGS) {
            System.err.println("Usage: " + USAGE);
            System.exit(1);
        }

        String emAddress = args[0];
        String emUsername = args[1];
        String emPassword = args[2];

        String[] taskIds = new String[args.length - MIN_ARGS];

        for (int i = 0; i < taskIds.length; i++) {
            taskIds[i] = args[i + MIN_ARGS];
        }

        iControl.ManagementEMTaskStatus[] statuses = null;

        try {
            iControl.Interfaces ic = new iControl.Interfaces();
            ic.initialize(emAddress, EM_PORT, emUsername, emPassword);

            statuses = ic.getManagementEM().get_task_status(taskIds);

            if (statuses.length != taskIds.length) {
              throw new Exception("wrong number of status values returned");
            }
        }
        catch (Exception e) {
            System.err.println("Failed to get task status: " + e.getMessage());
            System.exit(1);
        }

        for (int i = 0; i < taskIds.length; i++) {
            System.out.print("Task ");
            System.out.print(taskIds[i]);
            System.out.print(": ");
            System.out.println(statuses[i]);
        }

    } // public static void main

} // public class ManagementEMGetTaskStatus
Published Mar 07, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment