Blog Archives

How to package Integration Packs for Microsoft Orchestrator

When you write your own integration packs for Microsoft Orchestrator, it becomes important to understand how you publish them to Orchestrator in order to be used. The process is simple and is described below:

Build your Visual Studio project for creating the integration pack. Once done you should be able to see a .dll file in the debut folder under bin. This is all we need to import the integration pack into the orchestrator.1

Step 1:

Open the Orchestrator Integration Pack Wizard on your Orchestrator Server.

2

Click on next and enter the details as required. Under Resource File, select the path of the .dll file and click on next.

3

Click on Add to add the Activities.

4

Select the Activities one at a time and click on next when finished.

5

6

Click on next once done. Click next on the screen below.

7

Select the target folder where the output file (.oip) would be stored.

8

Finish the Wizard by clicking next on the remaining screens. The oip file should now be available in the location specified above.

Step 2:

Open Deployment Manager and right click on Integration Packs and select “Register IP with Orchestrator Management Server”. IP Registration Wizard will open.

9

Click on next and select the oip file created in step 1.

10

Click on next and proceed to finish the Wizard.

In the Orchestrator Deployment Manager, Right click on the Integration Packs again and click on Deploy IP to Runbook server.

11

Add the Orchestrator Server where you want to push this and click on next.

12

Proceed to finish the Wizard.

Now open your Orchestrator designer on the server above and you should see your IP under the Activities.

Advertisements

Integrate ServiceNow with Microsoft Orchestrator

ServiceNow(SN) can be integrated with Microsoft Orchestrator using out of the box REST Integration Pack however, it is a very complex process when it comes to read and write data from/to SN. Some paid management packs are also available in the market however if you are planning to build your own to save cost or better control, following information can give you a kick start.

There are two components to make this connectivity, first being authentication and then the queries you want to run. But before that there are some prerequisites that you may need to perform before you can successfully connect to SN:

  1. Make sure the URL for your SN instance (better to use demo instances in the beginning) should be accessible without any proxy
  2. You should have valid admin credentials to the instance
  3. The SN should be set to respond to REST queries and if you are using any ID other than the admin, then that ID should be allowed to fetch data via REST
  4. You should have Visual Studio as well as API for SN and REST
  5. You should have the basic understanding on how to package a management pack and publish it to the Orchestrator

Leave your queries in the comments if you need any further information on these prerequisites. The code given below is just to give you an idea to kick start and by no mean is the best way to code.

Connectivity:

In order to connect to SN and authenticate, use the following code. Once you create the MP using the code below, in Orchestrator, you should see a SN connectivity menu. Type the required details and your settings are now saved and ready to be used in the MP.

using System;
using System.Net;
using System.Net.Mail;
using System.Xml;
using System.Xml.XPath;
namespace Microsoft.SystemCenter.Orchestrator.Integration.Examples.ServiceNow
{
 [ActivityData("ServiceNow Configuration")]
 public class ServiceNowSettings
 {
 private String url = string.Empty;
 private String userName = string.Empty;
 private String password = string.Empty;
 //private string[] test = new string[2000];
 [ActivityInput, ActivityOutput]
 public String URL
 {
 get { return url; }
 set { url = value; }
 }
[ActivityInput, ActivityOutput]
 public String UserName
 {
 get { return userName; }
 set { userName = value; }
 }
[ActivityInput(PasswordProtected = true), ActivityOutput]
 public String Password
 {
 get { return password; }
 set { password = value; }
 }
 [ActivityMethod]
 public string[] Main()
 {
 string UrlRequest = URL+"/api/now/table/sys_db_object?sysparm_limit=10000&sysparm_order_direction=name";
HttpWebRequest request = WebRequest.Create(UrlRequest) as HttpWebRequest;
 request.PreAuthenticate = true;
 request.Credentials = new NetworkCredential(UserName, Password);
 request.Method = "GET";
 request.ContentType = "application/xml";
 request.Accept = "application/xml";
 HttpWebResponse response = request.GetResponse() as HttpWebResponse;
XmlDocument xmlDoc = new XmlDocument();
 xmlDoc.Load(response.GetResponseStream());
 XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
 nsmgr.AddNamespace("rest", "http://schemas.microsoft.com/search/local/ws/rest/");
for each location
 XmlNodeList locationElements = xmlDoc.SelectNodes("//result", nsmgr);
int i = 0;
 foreach (XmlNode location in locationElements)
 {
i++;
 }
 string[] arr1 = new string[i];
 int j = 0;
 foreach (XmlNode location in locationElements)
 {
 arr1[j] = location.SelectSingleNode(".//name", nsmgr).InnerText;
 j++;
 }
 Array.Sort(arr1);
 return arr1;} 
 [ActivityOutput]
 public string[] Test
 {
 get { return Main(); }
}}}

Fetching the Data:

For fetching the data, in the same VS project, create another class and use the following code. Once you recreate the MP, you should now see the Fetch Data option under your MP in Orchestrator, drag it to the runbook and use the setting saved, build your query, save the query result to any log file and run the runbook. The results should be visible in the log file.

using System;
using System.Net;
using System.Net.Mail;
using Microsoft.SystemCenter.Orchestrator.Integration;
using System.Xml.XPath;
using System.Xml;
using System.Collections.Generic;
namespace Microsoft.SystemCenter.Orchestrator.Integration.Examples.ServiceNow
{
[Activity("Select Table")]
 public class SelectTable : IActivity
 {
 private ServiceNowSettings settings;
 public string t1;
[ActivityConfiguration]//(Usage = ConfigurationUsage.ExecuteOnly)]
 public ServiceNowSettings Settings
 {
 set { settings = value; }
 get { return settings; }
 }
 public void Design(IActivityDesigner designer)
 {
 designer.AddInput("Select Table").WithListBrowser(settings.Test);
 designer.AddFilter("active");
 designer.AddFilter("assigned_to");
 designer.AddOutput("Selected Table");
}
public void Execute(IActivityRequest request1, IActivityResponse response1)
 {
 string seltable = request1.Inputs["Select Table"].AsString();
 response1.Publish("Selected Table", seltable);
}
}
}

Fetching Incidents:

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(settings.URL + "/incident.do?WSDL");
 webRequest.PreAuthenticate = true;
 webRequest.Credentials = new NetworkCredential(settings.UserName, settings.Password);
 //webRequest.Timeout = // details elided
 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
 XPathDocument xpathDocument = new XPathDocument(webResponse.GetResponseStream());
 XPathNavigator xpathNavigator = xpathDocument.CreateNavigator();
XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
 xmlNamespaceManager.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
 int i = 0;
 //foreach (XPathNavigator node in xpathNavigator.Select("//xsd:element/@getKeys", xmlNamespaceManager))
 foreach (XPathNavigator node in xpathNavigator.Select("//xsd:schema/xsd:element[5]/xsd:complexType/xsd:sequence/xsd:element/@name", xmlNamespaceManager))
 {
 i++;
 }
 //Console.ReadLine();//Console.WriteLine("Show all formatted addresses: Option 1");
string[] arr1 = new string[i];
 int j = 0;
 foreach (XPathNavigator node in xpathNavigator.Select("//xsd:schema/xsd:element[5]/xsd:complexType/xsd:sequence/xsd:element/@name", xmlNamespaceManager))
{
 arr1[j] = node.Value;
 j++;
 }
 //Array.Sort(arr1);
 return arr1;}

You can create multiple options in the MP to read, delete, update data in SN. Use a SQL DB to store and manipulate data before uploading to SN again. Your other applications or automation systems can read from this SQL DB and update it once the tasks are completed and upload the results in SN.