Integrating Nakivo with Powershell

In this post I’ll show how to implement Nakivo RESTful API under Powershell using the cmdlet Invoke-RestMethod: an elegant and powerful way to call RESTFul API, implementing method GET, POST, PUT,… and handling results in object-oriented way (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-5.1).

Using Nakivo API

Nakivo RESTFul API are accessible by the following endpoint: https://<nakivo_director_ip>:4443/c/router. It’s possible to perform the following actions:

  • Authentication
  • Inventory management
  • Job management
  • Repository management
  • Backup object Management
  • Transporter management

Every call must be a POST request that send a json data composed by:

  • action: a string which contains the action invoked (Authentication, Inventory,…)
  • method: a string which contains the method referred to the action invoked (login, getDiscoveryItem, …)
  • data: array or JSON which contains the parameters for the invoked method
  • tid: an integer which contains the transaction id (it must be increased to handle multiple requests per time)
  • type: a string that must be “rpc” all times (probably referred to another implementation)

The result is a json which contains the operation result and the object data which contains further objects and arrays. Check official documentation here: https://helpcenter.nakivo.com/display/AR/API+Reference+Overview

To interact with the director is important handle the session retrieved after authentication management. If the user used in the authentication process, has the right permission, the next calls are authorized to interact with Nakivo actions and methods. I suggest to create a user for API implementation purpose which have a specific access; it’s not a good practice give administration rights to every application user due security concern.

Every time a new code is implemented is important to set the correct user rights the fits exactly in what the application need to do; but remember that if use active directory user you should not permit the password expiration, otherwise it could affect the application functionality

When you start the interaction with Nakivo API, you should perform a similar flow:

NewImage

Then is possible concatenate further actions/methods or logout to close the session.

Before connect (untrusted ssl certificate issue)

During my test it could happen that due client execution policy, you could get a thrusting error message, that rejects the call due to not verified ssl end-point certificate. To workaround simply copy, paste and execute the following code, before starting using the calls:

Authentication Process

Before starting the call is important declare a new “webrequestsession” object that will filled with the token data when you successful login:

Next it’s necessary compose the json with action AuthenitcationManagement, method login and authentication data:

Finally call the API using Invoke-RestMethod:

Here the results and the content of session variable after a succesful login:

NewImage

NewImage

Display Inventory information

After a successful login, you’re able to start the interaction with the other actions, remembering the inclusion of the $session var valorized during the login process which could be valid only if time doesn’t expire, or if isn’t invoked the logout method.

It’s time to show what Nakivo inventory discovery knows about the virtual infrastructure. Here the example:

And this is my result set in my lab:

NewImage

Showing Job

IMHO the most important part of the interaction, is the job and recovery interactions. This time I’m showing how to display the information about the already configured jobs and how to display a single job. (In my next post I’ll show how to create/modify and launch a job).

The action JubSummaryManagement has a method called getGroupInfo that show the list of the jobs. This is important to get a single job by id and start with the interaction:

Note: to get all jobs the data variable must contain [null]. The list contained in the object $data3 shows a job called “childJobsIds” that has id number 1.

NewImage

Then is possible to show job detail giving this id into data parameter:

This is the result:

NewImage

NewImage

Enjoy!

Disclaimer

This post is sponsored by Nakivo. Thoughts and experiences around Nakivo product come from my own.

Salva

Salva Salva Salva Salva Salva Salva Salva Salva Salva Salva Salva

   Send article as PDF