02 Apr 2014

Visualize Runbook Nesting in Service Management Automation

Currently I’m working alot on SMA (Service Management Automation) and the transitions from SC Orchestrator. One big advantage SC Orchestrator still has, is the visualization, especially when following the best practice. Runbooks should not contain too many activities and should be generalized wherever possible. This keeps the Runbooks clean and reusable. So how can you nest Runbooks in SMA?
Generally this is explained in my SMA Whitepaper on the TechNet Gallery.

But what if you want to get a quick overview of your current nestings in SMA, where Runbook1 calls Runbook2 and Runbook2 calls Runbook3 and 4?

I created a small Powershell Workflow, which can also be used as a SMA Runbook to display current Runbook nestings.

Workflow Get-SMARunbookNesting
{
    param(
    [Parameter(Mandatory=$true)]
    [STRING]$WebServiceEndpoint,
    [Parameter(Mandatory=$true)]
    [ValidateSet("Published","Draft")] 
    [STRING]$RunbookType="Published"
    )

    $Runbooks = Get-SmaRunbook -WebServiceEndpoint $WebServiceEndpoint | Sort-Object RunbookName
    $RBTypeString = $RunbookType + "RunbookVersionID"
    $RunbookNames = ($Runbooks | Select RunbookName).RunbookName | Sort-Object

    Write-Output ""
    Write-OutPut "---------"
    Write-Output "Nestings:"
    Write-OutPut "---------"
    Write-Output ""
    Foreach ($rb in $Runbooks)
    {
        If ($rb.$RBTypeString)
        {
            $rbcode = (Get-SmaRunbookDefinition -Id $rb.RunbookID -Type $RunbookType -WebServiceEndpoint $WebServiceEndpoint).Content
            Foreach ($rbname in $RunbookNames)
            {
                If (($rbcode -cmatch "\b$rbname\b") -and ($($rb.RunbookName) -ne $rbname))
                {
                    Write-OutPut "$($rb.RunbookName) ==> $rbname"
                }
            }
        }
    }
}

The workflow requests two parameters, the SMA Web Service Endpoint and the type of Runbooks to query for nestings, either “Draft” or “Published” is accepted here.

Here’s what you neet to kick of this workflow:

  • SMA Powershell Module installed on the machine, the WF gets executed. If launched as an SMA Runbook, The SMA Powershell Module must be deployed on each Runbook Worker
  • Runbook or WF executed with SMA Admin Credentials

The result then looks like this:

Known Limitations:

The workflow gathers all Runbook names and recursively searches in each runbook for explicit calls to other Runbooks using a regular expression. Therefore, if you add Child Runbooks names for other purposes than explicitely calling them (e.g. in comments), the results might not be apropriate.