Feeds:
Posts
Comments

Archive for the ‘Automation’ Category

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.

image

  • Reporting IFC status for plants in a site

This shows IFC status for plants serviced by an IFC Server

image

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.

image

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

image

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:

image

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 :

SNAGHTML2a9cfb38

 

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:

image

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
  4. Use Add-NewEdge to add the plant with IFC data

image

And we get the resultant graph:

image

 

That should be all. You can take these concepts and use it with other CmdLets like Get-SCADbServerInfo (db & user info), Get-SCAComputerInfo, etc. Hopefully this will encourage you to use Graphviz and SCA CmdLets to easily and efficiently visualize S3D data.

PowerShell Script

Read Full Post »