SCOM 2012 – Meets MS Flow and Service Bus or How to Translate Alerts

translate

Everything is going international and everything is interconnected. Microsoft is providing many technologies to build bridges between different technologies and systems. I like the idea to build connectors to have a system A talking to system B within a matter of seconds. Microsoft Flow is such a technology which will interconnect systems with each other. Although the idea behind Microsoft Flow is not new, there are other providers like IFTTT or Zapier which are much longer on the market. The differences lie in connecting to endpoints, transforming data and sending to a target. Depending on your needs you will use one or the other or you might want to interconnect one task automation engine with the other. Lifehacker.com gives a short comparison:

  • IFTTT: IFTTT is super easy to use. As the name suggests, you set up a trigger: that’s the “if.” Then you pick a reaction, that’s the “that.” IFTTT supports 320 popular services, including Dropbox, Drive, WordPress, Twitter, and plenty of others. IFTTT calls these “recipes,” and you can browse recipes made by other people, which makes it easy to come up with ideas for how you can use the service on your own. On top of the web site, IFTTT also has Android and iOS apps so you can take the experience on the go. IFTTT is free. On Android, IFTTT and Tasker work very similarly.
  • Zapier: Zapier works just like IFTTT, but instead of “recipes” the service calls your actions “zaps.” Zapier focuses more on business app integration, so it supports niche corporate apps, like Recurly, HelloSign, and MySQL. Zapier is also more customizable. Where IFTTT limits itself to two steps (this happens, then that happens), Zapier supports multi-step zaps (this happens, then that, that, and that). That said, Zapier doesn’t have mobile apps. It’s also not free. While Zapier has a free plan, it limits you to five zaps at once, locks off access to certain apps, and can only make two-step zaps (just like IFTTT). For $20/month, you unlock Zapier’s real power, including access to all 500+ app integrations and multi-step zaps.
  • Microsoft Flow: Flow is the newest automation tool on the block and it’s the most limited. As you’d expect, Flow’s strength is its integration with Microsoft apps and services. Flow works like IFTTT, with two-step automation recipes called “templates.” Also like IFTTT, you can browse other people’s templates or share your own. Currently, Flow is a “preview” build on the web, which aside from being a bit limited in scope, also limits it to work or school email accounts. Chances are, that doesn’t include you, unless your company is deep in the Microsoft ecosystem or you’re a student. But hey, at least there’s also an iPhone version. For now, Flow is free as long as it’s in preview.

In our example I will use Microsoft Azure Service Bus, PowerShell, Microsoft Flow, Office 365 to help my old friend SCOM to translate alerts in many languages. Sounds cool? Yes it really is!

First we need to setup Microsoft Azure Service Bus Queue. So what is Service Bus (Source)?

Service Bus is a multi-tenant cloud service, which means that the service is shared by multiple users. Each user, such as an application developer, creates a namespace, then defines the communication mechanisms she needs within that namespace. shows how this looks.

image

Within a namespace, you can use one or more instances of four different communication mechanisms, each of which connects applications in a different way. The choices are:

  • Queues, which allow one-directional communication. Each queue acts as an intermediary (sometimes called a broker) that stores sent messages until they are received. Each message is received by a single recipient.
  • Topics, which provide one-directional communication using subscriptions-a single topic can have multiple subscriptions. Like a queue, a topic acts as a broker, but each subscription can optionally use a filter to receive only messages that match specific criteria.
  • Relays, which provide bi-directional communication. Unlike queues and topics, a relay doesn’t store in-flight messages-it’s not a broker. Instead, it just passes them on to the destination application.
  • Event Hubs, which provide event and telemetry ingress to the cloud at massive scale, with low latency and high reliability.

As you can see a queue is the simplest part to use in Service Bus, it reminds me a bit like a printer queue, instead of sending documents, you are able to send messages. Ok so let’s install a queue…

Service Bus Queue

Got to the classic Azure portal http://manage.windowsazure.com and go to Service Bus

clip_image001

…and click Create

clip_image002

Then provide a name for your namespace, in my case I have choosen returnone, configure the type which is Messaging for our Queue and the Messaging Tier I choose Standard. If you want to know the differences go here. And finally choose the region, the closest place to your other resources. In my case West Europe.

Your namespace should be visible…

clip_image004

…select the Queue and create a new Queue

clip_image005

…choose Quick Create

clip_image002

…now your Queue will be visible…

clip_image004[5]

Next click on to the Queue and choose Configure. Provide a policy name like scom and choose the permissions Send and Listen. We use both permissions, because we need this policy to listen and send messages to Service Bus. Hit Save and now you should see an output like this…

clip_image006

…go to the Dashboard and click Connection Information right on the bottom of the console. You will be prompted with a dialog which shows you a connection string, that we will use in the next steps…

clip_image008

That’s it we have configured Service Bus and a Queue. Next we will configure Microsoft Flow.

Microsoft Flow

Go to https://flow.microsoft.com/ and register and login with your account. Microsoft Flow is currently in preview phase and therefore for free. Select My flows and click Create new flow. Choose Service Bus – When a message is received in queue

clip_image002[5]

Next enter a connection name and the connection string…

clip_image004[7]

The connection string you get when you configure the Service Bus it looks like this

Endpoint=sb://returnone.servicebus.windows.net/;
SharedAccessKeyName=[Your AccessKeyName];
SharedAccessKey=blablablbalbababallalbal=

Remove the “EntityPath=blabla” part of the connection string. It is not needed, and the Flow would not work! It throws an error like this…

image

Next add the next activity Translate Text. This will use Microsoft Translator, where you might first want to login and create an account. See https://www.microsoft.com/en-us/translator for more details and sign-up. Create a connection, in my case I already have a connection, it looks a bit different, when you create a new connection…

clip_image005[5]

I tried to create a second, new connection, but for some reason I ran into an error. If you are starting from scratch you should be able to create the connection seamlessly…

clip_image006

If you managed to setup the connection, add in the Text section the Content data from the previous activity and also select a Target language, in my case German….

clip_image007

As final activity we will use Send email. Just add it and configure it, it is pretty self explaining. In the screenshot, we us the To property from the Service Bus message for the recipient of the mail, for this demo the subject is just static and the Body of the will be the translated text…

clip_image008

Next save this flow as DEMO

clip_image010

Your flow is now visible und should look like this…

clip_image012

As a next step we need to create a PowerShell script and configure the Command Notification Channel in SCOM for executing the script and sending the alert data to Service Bus. I will try to explain each part of the script…

PowerShell Script

There are three string parameters, one for the alert name, one for the alert description and one for the mail recipient.

image

Next we import the Service Bus and the OperationsManager module…

image

Because we need to connect to Service Bus, we need the connection string which is stored in a RunAs account in SCOM. See this post about more details…

image

Next, we create just the alert message string and limit the characters to 250 characters length. If you want to have all data sent, just uncomment the line…

image

Here we create a client instance of the for Service Bus and pass the connection string…

image

This is the tricky part. Because Service Bus usually wraps the message content in XML, it won’t be useful for us. We just want to have the plain text, therefore we “cheat” on the Service Bus API and send the message string in UTF8 characters. This will tell the API that we handle the string. Then we create a memory stream object…

image

Next, we create the Service Bus message object, pass the memory stream, assign a GUID to the message id, add the message recipient address and add some properties (just for demo)…

image

Finally we trigger the send method…

image

You can download the script from TechNet Gallery, here. The Service Bus DLL is available here on nuget https://www.nuget.org/packages/WindowsAzure.ServiceBus/ .

Next we will embed the script into the Command Notification Channel in SCOM.

Command Notification Channel

Well I am not going into details how to configure a Command Notification Channel, there are plenty of posts on the internet like this here, that explains very well how to do it.

I saved the script above as Send-SBMessage40.ps1 in C:\Temp on my management server and copied also the Microsoft.ServiceBus.dll into the same directory…

clip_image001[4]

The Command Notification Channel configuration looks like this…

clip_image003

Full path of the command file:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Command line parameters (Note: make sure you change the mail address)

-Command “& ‘”C:\temp\Send-SBMessage40.ps1″‘” ‘$Data[Default=’Not Present’]/Context/DataItem/AlertName$’ ‘$Data[Default=’Not Present’]/Context/DataItem/AlertDescription$’ ‘user@domain.ch’

Startup folder for the command line:

C:\Windows\System32\WindowsPowerShell\v1.0

After configuration you will have the channel available…

clip_image005

Next assign this channel to a Subscription which is also very well explained in this article.

That’s the entire procedure now you just need to trigger an alert :). I configured my subscription to fire on any alert on any status. This means I just can change the status from Closed to New and the channel will fire. So a sample alert…

image

… will end up in German like this…

image

It is kind of fun to see the translation which not always matches the in a perfect sense :D. But you might want to try some foreign languages. Be aware of the fact, that Service Bus and especially Microsoft Translator as some limits. Before you start to use MS Translator you should know that the Free trial is limited to  2’000’000  characters per month somehow I managed to reach this limit…

image

I hope you get this thing going and you have as much fun as I have!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s