次の方法で共有


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

Comments

  • Anonymous
    January 01, 2003
    OK thanks. Also, I was thinking of changing the runbook, so instead of restarting the HealthService, it just e-mails someone. I don't want it to do that via PowerShell though, I would like the PS script to run, then an e-mail would be sent using Orchestrator IF the Workflows are broken. Can you think of a way to do that?

  • Anonymous
    January 01, 2003
    Hi George No, I just downloaded the ZIP file you provided. I even tried editing the MP, and changing the Assembly reference by adding a .DLL on the end (just to  see) and it gave the same error :( I will try that new MP/DLL now and let you know. Thanks

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Hi I have imported the Management Pack, but I am getting an error when the workflow runs: System.IO.FileNotFoundException: Could not load file or assembly 'CheckSCSMWorkflowStatus' or one of it's dependencies. I have copied the DLL file to the SM Server install directory - any ideas? Thanks

  • Anonymous
    January 01, 2003
    Taylor, The way I would do it.. I would leave it as PowerShell for the event check.. and in the script for the event check I would change it to something like below.


if (!$event) { $OPDOutput = 'True' } else { $OPDOutput = 'False' }

Then add the variable OPDOutput as Published Data on the Run .Net Script Then make another activity for sending the email and on the link, do a check for the Variable and whether or not it is true, so only checks where the event are missing are sent to the users.   Does this make sense?

  • Anonymous
    January 01, 2003
    Taylor, Sorry about the issues you are having with this.  Please try this other copy of the MP and DLL at the following URL. http://sdrv.ms/14p7rke Also just for curiosity sake did you try manually creating the MP with the Authoring Console with the instructions above?  I am in the process of re-imaging my lab at the moment, I will get Service Manager up tomorrow and test to confirm the issue you are having.

  • Anonymous
    January 01, 2003
    This is because their is no description for the event or the source we are using since we are just creating it though PowerShell. The important part is it's running and you see the message we put it in the script. I will update the zip file on this blog tomorrow with the updated file. Thanks for catching the issue.

  • Anonymous
    January 01, 2003
    George Thanks, that works great. I don't know why I didn't think of that. Was a bit busy yesterday. Anyway, thanks for all your help.