Assuming that you’ve read part 1, you know we are now going to look at how to get data out of SCSM and into Slack without having to be proactive about it. Rather than having to reach into SCSM and get the data, we are going to look at how SCSM can alert us in Slack to changes that are occurring from within.
This is actually quite easy, and we will look at more complicated and comprehensive scenarios for this in the future, but I want to touch on something just about anyone with a little PS knowledge could emulate.
With that in mind our example today will use nothing more than powershell and our own little custom module.
I’d love to say that I build all my scripts from scratch and pretend like I’m just pure genius, but unfortunately I’m just like the rest of you and I borrow from all over the place to build what I need. I’ve built a few simple modules myself but for this project I wanted to start with something you all could get your hands on pretty easily and use that. Additionally, this is more generic than what I’ve built in the past so it should be pretty easily re-useable.
He’s built a pretty simple cmdlet and on top of that it supports pipeline and attachments which some of the others I’ve seen did not. We’ll start with this one.
The first thing we need to do from here is grab a Slack token for our team we want to work in, and we can get that here after signing into our account:
Ok, now we are ready to get to some programming. First we want to setup our powershell script to accept a GUID for our work item and import the PSSlack module and the SMLets modules.
I’ve set a GUID here that I know exists as the default just for testing purposes, but when someone is passing in a value it could be null, so we will check for that and then run a simple test here.
Now we will run a quick test and see that we should have the work item title posted in our Slack channel!
That’s really all there is to it! That’s not to say there isn’t MUCH MUCH more we can do with this, but it’s as simple as that for a single work item. We can even spruce it up a bit using message attachments like this:
And then we get this nicely formatted message in slack:
Awesome, right!? Exactly. Now we can throw in a filter for grabbing incidents created in the last 60 seconds only and then run this in a scheduled task on one of our management servers, or as a workflow and we have a Slack Notification Engine for Service Manager.