In this post I will demonstrate an example on how to use the popular team collaboration tool Slack together with Azure Automation to retrieve data from your on-premise SCSM environment. The data in this example are Incidents retrieved via an Azure Powershell runbook. The setup is very simple and does not require any development skills (only a little powershell Smiley). The scope could easily be extended to more useful scenarious such as sending reviewal messages to your managers or perhaps a Change Advisory Board (CAB) to accept or decline Review Activities in their small team meeting room. This is just a proof of concept. If you have the Cireson Portal, check out their post for inspiration on a more advanced setup utilizing their web API.

 

Why Slack ?

Slack  is a Web 2.0 IRC tool that is meant for real-time communication within a team and is used widely today from small friend groups to large company teams working together. What I love about slack is the simplicity of the look and functionality,  but probably the most important part is its huge amount of integration possibilities; both custom integration where you can hook up your own Web API or creating incoming or outgoing webhooks (as this example will use), but you can also add out-of-the-box integrations such as twitter, news feeds, spotify etc. Check out this post from my beaver friend (yes I have a beaver as a friend) on how to get most out of Slack.

 

Solution

The end result of my little proof of concept is this:

1) You log in to the slack team channel you have decided to integrate the SCSM data to.

2) You write a custom specified slashcommand to retrieve Incidents:

slack01

3) An outgoing azure webhook triggers and launches an Azure Automation Runbook. This powershell runbook queries your scsm database (using a hybrid worker) and sends an incoming webhook back to Slack with the output of the scsm data:

slack02

That’s it – now we got data from our on-premise SCSM environment into our little team chat channel.

 

How to steps

1. Prepare Azure Automation:

  • Log on to Azure Portal and setup an Azure Automation account if you don’t have one already.
  • Download and install a Hybrid Worker Agent on a computer on your network that is NOT an SCSM Management Server, but have network access to that machine (SCSM has an outdated Microsoft Monitoring Agent that permits you from installing the newer OMS Agent unfortunately). This requires an OMS subscription (you can quickly setup a free account to get started). Setup instructions here
  • On your Automation page, click All Settings:

image

  • Add a credential asset from the Assets menu and input an account with SCSM Administrator rights (e.g. your Operating Service accunt)

image-> – image->image->image

  • Click Hybrid Worker Group from your Automation main page and attach the newly created Credential as a Run As Credential to your Hybrid Worker:

 image  -> image -> – image –> image

  • Create an empty Powershell Runbook and name it Get-SCSMIncidentsToSlack (or something similar). We will add the code inside later.

image-> image

  • Save and publish the Runbook so we can add a Webhook.
  • Create a Webhook and make it run on your Hybrid Worker:

image-> image -> image -> imageOBS! Copy this URL as it will disapear after you click OK

  • Modify Run Settings and choose your Hybrid Worker:

image

 

 

2. Install SMlets

  • On your non-SCSM machine with the Hybrid Worker Installed: Install SMlets and the SCSM Console to get the assemblies needed for SMlets cmdlets. If you don’t want to install an SCSM Console you can follow this guide here.
  • Test it if it works. Ex. Open Powershell and write:

image

  • OBS! In this setup I have not installed the SM Console, but just the assemblies following the guide above. If you installed the SM Console, you need to add an $SMDefaultComputer =  <SCSMServer> after import-module smlets in your script or just use –Computer <SCSMServer> for each cmdlet.

3. Setup Slack integration

  • Go to your slack team or create a new one at slack.com
  • Click on App and Integration:

image

  • Click Build in the top-right corner –> Build Custom Integration
  • First start by creating an Incoming Webhook
  • Select a channel to post to, e.g. #general
  • Copy and save the Webhook URL (this will be used in our Azure runbook), optional change the name and icon image. Then press Save Settings
  • Now create a Slash Command
  • Choose a name, e.g. getincident (you cannot make capital letters or camel case, only small)
  • Now paste the Azure Webhook URL in at URL( s) . Method should be POST

image

 

  • Optional write some helping text and change the icon. The click Save Integration

3. Edit Azure Powershell Runbook Script

  • Almost there! Now we just need to edit our Runbook:

 

image

$ErrorActionPreference = "stop"; #---------------------------------------------- #Get Incidents from SCSM #---------------------------------------------- write-output "Starting job..." #Ensure Smlets module is loaded write-output "Loading module..." if (!(get-module smlets)){import-module smlets} #Retrieve incidents write-output "Retrieving incidents..." $Incidents = get-scsmobject -class (get-scsmclass system.workitem.incident$) #Format to selected properties on Incident and adjust width: $Output = $Incidents | ft Id, Title -AutoSize | out-string #---------------------------------------------- #Post to Slack #---------------------------------------------- if ($Output) { $uri = "https://hooks.slack.com/services/<YourSlackTokenIds>" $body = @" { "username":"SCSM BOT", "text": "$Output", } "@ Invoke-WebRequest -Uri $uri -Body $body -ContentType "Application/json" -Method Post -UseBasicParsing }

 

In the top I’m simply getting all Incidents from SCSM (feel free to do make a –Filter on specific Incidents)

In the bottom I’m then sending the output of my Incidents to slash using the Slack incoming webhook and an Invoke-WebRequest. Slash has a variety of different JSON formats to construct your message with and make it look cooler with attachments etc. This is a very simple one.

  • That’s it. Save and Publish your Runbook and test it out by writing /getincidents in your channel. It takes a little while for the runbook to queue and run. As shown on the screenshot in the top of the post, the data was retrieved in less than a minute for my setup here.

 

Have fun Smiley