Cloud Management Platform Management Packs vRealize Operations

Blast Off: Advanced Usage of the vRealize Operations REST API

By: Mike Langdon, Blue Medora

In an earlier post I showed you the basics of the vRealize Operations Manager REST API. I called that one Straight-up Flying, but mostly showed you how to walk with the API. With this post, we’ll get a lot closer to airborne by reaching into vRealize to create SQL Server adapter instances, start them collecting and delete them again.

1-sql-heat

Figure 1The Management Pack for Microsoft SQL Server

You might be asking yourself, why would I want to create adapters with the REST API when I can just make them in the regular user interface? Well, what if you have 200+ SQL Server instances and your DevOps has gotten a little too good at rapid builds and teardowns? Being able to automatically create adapters could be pretty handy in that situation.

This example can create an arbitrary number of SQL Server instances and will allow you to start or delete them. Like the earlier post, the complete code is available in a public git repository with permissive licensing.

2-creds

Figure 2Maybe don’t use sa and admin for your credentials.

The first step in using this code is creating vROps credentials for the SQL instances you want to target, as seen in Figure 2. A slightly more ambitious script would also create credentials on the fly, but let’s hope your DBA takes pity on you and gives you the same credential set for every server.

3-help

Figure 3Use the –help, Luke

Second, we’ll collect the SQL Server hostnames, instance names and ports and put them together in a JSON string as shown in the script’s help dialog (Figure 3). You’ll end up with a string that looks something like this:

‘[{“name”:”nod-mssql12-win”, “credential”:”mssql_cred”}, {“name”:”nod-mssql14-h1a”, “credential”:”mssql_cred”, “instance”:”SQLSERVERENT”, “port”:”11433”}]’

Note that “instance” and “port” are optional here and will use the standard defaults if omitted. Check out a JSON validator if you run into any issues here.

4-create

Figure 4Creating a couple of adapter instances

Now we’re ready to use the script. We’ll use the ‘–create’ or ‘-c’ flag as shown in Figure 4. If we follow the execution in the source code, we can see both GET and POST HTTP methods in action. First we GET the credentials we need from the server, then we make a JSON request from the input and POST it to the vROps server to create the new adapters. If we jump back into the vROps GUI, we see immediate results (Figure 5).

5-created

Figure 5 Results!

Looking at Figure 5, you’ll notice that the adapter instances are not started. Conveniently, the output from the ‘–create’ request contains the input for the ‘–start’ command (Figure 6). Digging into the source code again, you’ll see the HTTP PUT method is used to start the adapters.

6-start

Figure 6Start your adapters

Finally, if you made a mistake creating adapters, the output from ‘–create’ can be piped into the delete command as well. This request implements, you guessed it, the HTTP DELETE method.

7-delete

Figure 7Clean up

If you need to create a lot of SQL Server adapter instances in a hurry, this script works now. You could plug it into a vRealize Orchestrator workflow that also creates a database. This code can also be easily reused for other management packs. Moreover, because the HTTP GET, POST, PUT and DELETE methods are all abstractly implemented in the ‘RestvROpsClient’ class, this script is an excellent springboard for calling almost any method in the vRealize Operations REST API. Dig into the code now!