Feeds:
Posts

Visualizing S3D Data With SCA CmdLets & Graphviz

Visualizing data as a graph is a very effective way to “understand” the data. A graph can be thought of as a node with edges that link to related data. In this blog we’ll look at how to automate graphs for a couple of S3D scenarios:

• Reporting plant versions

This graph relates S3D version with plants that are at the same version.

• Reporting IFC status for plants in a site

This shows IFC status for plants serviced by an IFC Server

A .doc file is provided below with sample PowerShell script. Just download the file, rename to .zip and extract the .ps1 file within.

A Taste of Graphviz

Graphviz is an open source graph visualization tool that help you create such type of graphs using it’s DOT language to layout the structure.

So the above layout can be written in dot language as:

digraph graphname {
rankdir=TB
node [shape=box]
Server [label="Server-01"]
P1 [label="Plant-01"]
P2 [label="Plant-02"]

Server->P1 [label="V11"]
Server->P2 [label="V11 R1"]
}

In this case:

• digraph – Specifies a directional graph (most common)
• rankdir – Specifies the direction of layout: TopBottom or LeftRight (LR)
• label – Specifies the label for each node
• -> – Links a node with it’s related node

Calling Graphviz from PowerShell

For Windows, there’s a zip package that can be downloaded from Graphviz site. We’ll be using the dot.exe from this package to construct graph bitmaps. So go ahead and download the zip and extract the exe to somewhere in your path. In my case, it under the current folder where I’m running the PowerShell ISE.

To run the above command in PowerShell, use this snippet:

@"
digraph graphname {
rankdir=TB;
node [shape=box]
Server [label="Server-01"]
P1 [label="Plant-01"]
P2 [label="Plant-02"]
Server->P1 [label="V11"]
Server->P2 [label="V11 R1"]
}
"@ | .\Graphviz\bin\dot.exe -Tpng -o .\Test.png



Highlight the lines above and right-click to choose the option to “Run Selection”. This will execute the highlighted text and you should see a Test.png in your current folder. The –Tpng –o .\Test.png clause instructs dot.exe to output a “png” file and save it as Test.png.

Using SCA CmdLets with Graphviz

Since SCA comes with a host of CmdLets that allow you to probe Site, Plant and IFC information, let’s see how we can use a couple of these in concert with Graphviz to output something useful for a S3D administrator.

Couple of scenarios one can think of are:

• Outputting list of plants under a site with their versions
• Outputting IFC status for a list of plant

Visualizing S3D Versions:

Let’s look at the 1st one. SCA has a cmdlet, Get-SCAPlantInfo which when invoked as:

Get-SCAPlantInfo <server> -AllPlants

will output a list of all plants on the server. Something like this:

So if we needed to output this information with version as a starting node and plant name as edges, it would look something like this in .dot language:

digraph S {
rankdir=TB;
"09.01.16.00" ->"S3D"
"09.01.16.00"->"S3D_Copy"
}

To automate the creation of this grammar, we can use a PowerShell script that acts as a DSL for the DOT language as detailed in a blog by Doug Finke here (and explained in his book Windows PowerShell for Developers – a great read).

Using the PowerShell script we can wrap the calls to create a new graph and add edges within it:

New-Graph S {
Get-SCAPlantInfo Local_SQL --AllPlants | ForEach {Add-Edge $_.Version$_.Plant}
} | .\Graphviz\bin\dot.exe -Tpng -o .\Plants.png

The resultant Plant.png shows this (below). You can already see the usefulness in visualizing this data :

Visualizing IFC Status

Taking this a step further, Get-SCAPlantInfo has an –OnlyIFCStatus option that lets you output IFC information for a plant. Something like this:

If we want to run it against all the plants in a site and create a data graph, we would need to:

1. Gather all plants on the server using Get-SCAPlantInfo –AllPlants
2. Filter the ones that we’re interested in maybe by site or name
3. Call Get-SCAPlantInfo with the plant and use –OnlyIFCStatus to get ifc data