Using the Integra CLI

  • Posted on: 6 February 2015
  • By: David La Motta

For the die-hards out there, this post is going to show you how to use the Integra command line interface. Since we know you have been playing with Integra and have been creating and scheduling workflows, running actions and testing things out, we know you may have started accumulating a little bit of debris in the Integra database. As you may have seen in the Integra User Guide, in order to clean providers, actions, workflows and schedules, we need to remove things in the opposite order:  schedules first, then workflows, actions and providers at last.  This post is going to show you how to use the Integra CLI to clean your environment; we're also going to do something fun with Groovy as a bonus exercise at the end of the post.  No skipping ahead!

The Integra installer will leave the CLI configured and ready for you to use.  We'll be working on a Linux shell throughout the remainder of this blog post.  

Time to start typing away.

The Integra CLI command (integra-cli) is a shell script that is doing not much more than executing Java with a .jar file.  You could invoke the CLI like that yourself, but we personally like the convenience of the shell script.  Now that we know the CLI is behaving properly, lets cache our credentials and connection information so we can reduce our typing.  Lets do that, you will thank us later.

As you may imagine, the host, port and protocol are the exact same information you enter in the Settings tab on the vCenter plugin.  Namely, this is information where the Integra Reactor is running.  The default credentials for the Reactor are admin / integra.  Now that we have our credentials saved, lets see what we have in terms of debris.  Well run a series of commands that will show schedules, workflows, actions and providers, so that we can see what we have.  After removing everything we'll run those same commands to verify we have indeed cleaned things up.

As you can see, we don't have any schedules but we do have 1 workflow, 7 actions and 4 providers.  Time to throw them on the chopping block, but before we do lets check something out.  If you don't know the parameters a particular CLI command takes, just type the command and add -help to the parameters.  Like this:

As you see, removing a workflow only requires an ID.  If you recall, we don't need to provide the connection parameters because they are cached in our credentials file.  You are welcome; we thought you would appreciate that!

We know we have 1 workflow, so we'll simply pass in that ID to the CLI.

Workflow gone.  Lets now take care of removing actions.

I am sure you are getting the hang of this.  With our actions gone, lets nuke the providers.

Simple like that.  If we now check out what we have, we'll see empty lists galore.

And that is all there is to it.  Doing things in the CLI can be definitely a quick alternative for doing certain operations.

Bonus: using the Integra APIs to do the clean up

As you may already be imagining, there is one caveat:  what if we have hundreds, even thousands of providers, actions, workflows and schedules?  Doing an Up-Arrow and replacing the ID for the entry you wish to remove becomes non-practical.  Luckily, Integra has a REST API and several SDKs, so you can script a much more powerful solution that cleans Integra in one sweeping motion.  Lets check out how we would do that.

The example is a Groovy script that will remove all the things that we removed with the CLI, but it will also go one level deeper and even remove schedule results.  Groovy runs on the JVM, and as such we can use the Java REST SDK to code our script.

  1. import com.emitrom.integra.core.configuration.Providers
  2. import com.emitrom.integra.core.configuration.Schedules
  3. import com.emitrom.integra.core.configuration.WorkflowActions
  4. import com.emitrom.integra.core.configuration.Workflows
  5. import com.emitrom.integra.core.schedules.ScheduleResults
  7. import
  8. import
  9. import
  11. class IntegraClean {
  12.     public static void main(args) {
  13.         def cli = new CliBuilder(usage: 'IntegraClean [options]')
  14.         cli.u(longOpt: 'url', args: 1, argName: 'restURL''Integra REST URL', required: true)
  15.         def options = cli.parse(args)
  17.         // make sure we got stuff
  18.         assert options
  19.         String baseUrl = options.url
  21.         // tack on a trailing slash if the input doesn't provide one
  22.         if (!baseUrl.endsWith('/')) {
  23.             baseUrl += '/'
  24.         }
  26.         Authenticator myAuth = new Authenticator() {
  27.             protected PasswordAuthentication getPasswordAuthentication() {
  28.                 return new PasswordAuthentication("admin""integra".toCharArray());
  29.             }
  30.         };
  32.         Authenticator.setDefault(myAuth);
  34.         Client client = ClientBuilder.newClient()
  35.         WebTarget target =
  37.         deleteSchedules(target)
  38.         deleteWorkflows(target)
  39.         deleteWorkflowActions(target)
  40.         deleteProviders(target)
  41.         deleteScheduleResults(target)
  42.     }
  44.     private static void deleteSchedules(WebTarget target) {
  45.         println "\nDeleting schedules..."
  46.         def schedulesPath = 'schedules/'
  48.         Schedules schedules = target.path(schedulesPath).request().get(Schedules.class)
  49.         int schedulesDeleted = 0
  51.         schedules?.getSchedule().each() { schedule ->
  52.             target.path(schedulesPath +
  53.             println 'Deleted ' +
  54.             schedulesDeleted++
  55.         }
  57.         println 'Schedules deleted: ' + schedulesDeleted
  58.     }
  60.     private static void deleteWorkflows(WebTarget target) {
  61.         println "\nDeleting workflows..."
  62.         def workflowsPath = 'workflows/'
  64.         Workflows workflows = target.path(workflowsPath).request().get(Workflows.class)
  65.         int workflowsDeleted = 0
  67.         workflows?.getWorkflow().each() { workflow ->
  68.             target.path(workflowsPath +
  69.             println 'Deleted ' +
  70.             workflowsDeleted++
  71.         }
  73.         println 'Workflows deleted: ' + workflowsDeleted
  74.     }
  76.     private static void deleteWorkflowActions(WebTarget target) {
  77.         println "\nDeleting actions..."
  78.         def workflowActionsPath = 'workflow_actions/'
  80.         WorkflowActions workflowActions = target.path(workflowActionsPath).request().get(WorkflowActions.class)
  81.         int actionsDeleted = 0
  83.         workflowActions?.workflowAction?.each() { action ->
  84.             target.path(workflowActionsPath +
  85.             println 'Deleted ' +
  86.             actionsDeleted++
  87.         }
  89.         println 'Actions deleted: ' + actionsDeleted
  90.     }
  92.     private static void deleteProviders(WebTarget target) {
  93.         println "\nDeleting providers..."
  94.         def providersPath = 'providers/'
  96.         Providers providers = target.path(providersPath).request().get(Providers.class)
  97.         int providersDeleted = 0
  99.         providers?.getProvider().each() { provider ->
  100.             target.path(providersPath +
  101.             println 'Deleted ' +
  102.             providersDeleted++
  103.         }
  105.         println 'Providers deleted: ' + providersDeleted
  106.     }
  108.     private static void deleteScheduleResults(WebTarget target) {
  109.         println "\nDeleting schedule results..."
  110.         def scheduleResultsPath = 'schedules_results/'
  112.         ScheduleResults scheduleResults = target.path(scheduleResultsPath).request().get(ScheduleResults.class)
  113.         int schedulesDeleted = 0
  115.         scheduleResults?.getScheduleResults().each() { scheduleResult ->
  116.             target.path(scheduleResultsPath +
  117.             println 'Deleted ' +
  118.             schedulesDeleted++
  119.         }
  121.         println 'Schedule results deleted: ' + schedulesDeleted
  122.     }
  123. }


In this post we showed you a quick glimpse of using the Integra CLI and also one of the flavors of the Integra SDKs.  In particular, we used the CLI and the Java REST SDK to do some cleanup, which involved removing everything that a user can configure in Integra.  We expect our users to leverage the REST API and the SDKs for ease of management.  As always, if you are trying things out and get stuck along the way, reach out in our Google+ community and ask away.

Happy automating!