Service Management Automation: Integrating into the OData web service
Published Feb 15 2019 08:48 PM 522 Views
First published on TECHNET on Dec 11, 2013

SMA has a number of interfaces to enable you to manage the overall system. The main one you probably use on a daily basis is the Windows Azure Pack admin portal as shown below. This allows you to operate SMA from an experience within the browser.

The second way that you might find useful is through the SMA PowerShell module that can be installed through setup. This allows you to manage all aspects of SMA from PowerShell (you can even use SMA to call SMA actions since this module is installed into the system by default) as shown below. You can also use the SMA PowerShell module from the PowerShell ISE if you want to perform actions from there.

We will cover this module in more detail in a later blog.

In this post I’ll go over another way you can interact with SMA -- by using its OData web service.

Scenarios where the SMA OData web service might be useful include those in which you want an external system to call into SMA based on some event. One example of this is extending SharePoint to call SMA when a new request comes in for some infrastructure items that need to be provisioned, updated, or deleted. Another example is where you have another business workflow system that needs some infrastructure asks during its process, and can call out to SMA to make that happen, and then continue with its business process.

There are probably a number of systems that you have in your organization that might be improved through interacting with SMA to complete some process. You can use SMA to query those systems looking for those events, but it is often a better option if the external system can directly interact with SMA to call a runbook and show progress / errors / etc.

So how do you call into this web service API? First off, you can browse through the service by opening a browser and entering https://<YourServerName>:9090/00000000-0000-0000-0000-000000000000/$metadata . You should see XML similar to the below appear.

I have turned off feed reading view in IE in order to get the xml view of the service. You can do this in the options of IE as shown below:

Each resource defined here can also be navigated to in order to find additional resources associated with it. For example, if you enter https://<YourServerName>:9090/00000000-0000-0000-0000-000000000000/Runbooks you will see a list of all of the runbooks in SMA. The web service follows the OData protocol so you can navigate it the way you would for other OData services. You can read more about OData on http://www.odata.org . It is probably a good idea to navigate around the different resources here to get familiar with what they offer.

Once you have an understanding of how things are modeled in SMA you can now start to interact with the service from an external system. I’ll give an example of calling this from a C# console application that will show you how to work with the service, and that you could reuse for whatever system you need to work with.

You can download this sample from the TechNet Script Gallery.

The first thing you will need to do is to create a service reference to the SMA OData web service as shown below. I called this SMAWebService in the sample.

As SMA is an OData web service, Visual Studio can automatically build the client library by inspecting the $metadata file. This will now allow you to browse and interact with the service from the application. You can see the list of resources by double clicking on the service reference.

We will be using the Orchestrator API resource to perform actions against the web service. Hopefully, the sample has most of the remaining information to get you started.

You will need to import the sample runbook “HelloWorld.ps1” into SMA using the portal and publish it. It is available in the download.

If you look at this runbook you will see that it contains three parameters, a string, an int, and an array of strings. It iterates for the number of times you pass in over the array of names and prints these out. It has a sleep in case you want to interact with the job while it is still running. You will be calling this runbook and setting these parameters from the console application.

Once you have this sample runbook imported and published you can use the console application to call it and then see the output from the job. The console application uses windows authentication so you will need to make sure you have access to the web service.

This should give you a starting point on how you can interact with the SMA OData web service from other systems and integrate and automate your datacenter.

Version history
Last update:
‎Mar 11 2019 10:01 AM
Updated by: