Monitor System Center 2012 – Service Manager workflows with Orchestrator

I have came across multiple times where the Service Manager workflows stop running.  When this happens all ticket activities stop, i,e New tickets won't move to Active, Activities wont move from Pending to In  Progress, etc. At this point you have to stop the HealthService delete out the HealthServiceState folder on the Primary Management server and restart the HealthService, this pulls down on the management packs again and workflows begin running again.

Well this can happen during off hours and can cause a headache if no one notices, Chris Jones and I came up with a simple workflow and runbook to automate this task. This is broken up into 2 sections, the Service Manager section and Orchestrator section.

Below are the manual steps to recreate this. You can also download the Management Pack and Orchestrator Export below. As always test runbooks and Management Packs in a Development Environment first.

Service Manager

  1. Open up the Service Manager Authoring Tool and create a new Management Pack

  2. Right click Workflows and click Create.

  3. Give the workflow a name and click Advanced.

  4. Set the Maxinum time to run the workflow to 1 minute and click OK, then click Next.

  5. Choose Run at a scheduled time or at scheduled intervals, and click Next.

  6. Choose Other interval and enter 5 minutes for the Frequency.

  7. On the Summary screen click Create

  8. Drag the Windows PowerShell Script Activiity to the Designer pane.

  9. In the Details pane, give the workflow a name such as WorkflowStatusChecker

  10. Click on the PowerShell activity in the Designer pane and click the ellipse on Script Body.

  11. Enter the following into the Script Body.

    write-eventlog -computername $MGMTSVR -logname "Operations Manager" -entrytype Information -Source "Service Manager Console" -eventID 5555 -message "Workflows are

    Running"  

  12. Click Script Properties on the left hand side. Enter MGMTSVR in the Name field and then click the ellipse to the right of Value.

  13. Expand your powershell script, expand runTaskActivity1, click SDKServer and click OK.

  14. Click OK

  15. Click Save

  16. Import the Management Pack into Service Manager and copy the workflow (.dll) file to the "Program Files\Microsoft System Center 2012\Service Manager" folder.

Orchestrator

 

  1. Open System Center 2012 Orchestrator Runbook Designer
  2. Create a new runbook
  3. Under Scheduling on the Activities pane drag Monitor Date/Time to the designer.
  4. Rename the Activity.
  5. Double click the Activity and change Interval to Every 10 minutes.  By making the schedule higher we ensure that There wont be a chance for the activity to be missed.
  6. Click OK.
  7. Under System on the Activities pane drag Run .Net Script to the designer.
  8. Rename the Activity.
  9. Double click the activity, change the Language Type to PowerShell.
  10. Paste the script into the window and replace servername with your server, or use a Variable for Server Name.

# Get's today's date and time / reads the OpsMgr log and looks for the workflow event written by SCSM.

# The 'where' filters the info for the event ID 5555 and checks to ensure the time the event was written

# is greater than negative 8 mins from the current date / time.

 

$today = Get-Date

$event = Get-Eventlog -ComputerName servername -log "Operations Manager" -source "Service Manager Console" | where{ $_.eventID -eq 5555 -and $_.TimeWritten -gt $today.AddMinutes(-8) }

 

<# !$event checks if the event exists, if it does not it begins the workflow fix: write event log stating

 the workflows aren't working properly, stops the service, sleeps for 10 seconds (time for the service to stop)

 deletes the HealthService folder, writes an event to the event log stating cleanup is complete.

 if the event exists, it echos "worked".

 #>

 

if (!$event)

{

 write-eventlog -computername servername -logname "Operations Manager" -entrytype Warning -Source "Service Manager Console" -eventID 5557 -message "Workflows are not working, beginning workflow clean up."

Invoke-Command -ComputerName servername {Stop-Service HealthService}

 sleep 20

 Remove-Item '\servername $\Program Files\Microsoft System Center 2012\Service Manager\Health Service State' -recurse -force

 sleep 20

Invoke-Command -ComputerName servername {Start-Service HealthService}

 sleep 20

 write-eventlog -computername servername -logname "Operations Manager" -entrytype Information -Source "Service Manager Console" -eventID 5558 -message "Workflow clean up complete."

}

 

else {write-eventlog -computername servername -logname "Operations Manager" -entrytype Information -Source "Service Manager Console" -eventID 5556 -message "Workflows are working properly. No action required."}

 

Clear-Variable -name event

 

  Save the Runbook and start it. How Orchestrator will monitor the event log of the Service Manager server for the event 5555, if workflows are found running it will log a 5556 event, if they are not working it will log a 5557 correct the issue and create an event 5558. All event numbers can 
 be changed though as long as the workflow for Service Manager is updated as well.
  

 

 

SCSMHealthJobs.zip