Quantcast
Channel: THWACK: Popular Discussions - Orion SDK
Viewing all articles
Browse latest Browse all 3719

How do I use PowerShell To Add Graphs To A View?

$
0
0

I am looking for a way to add resources to a view, via PowerShell.

Currently, using SWQL Studio to invoke "AddResourceToView", I can supply the 3 arguments (viewId, config, & moveColliding), and successfully add a new resource to a view.

I want to put that workflow into a PowerShell script, allowing me to easily change the view and SWQL query results.


This is what I have, so far:

Here is the standard connection part of the script:

# Connections, and stuff

$ErrorActionPreference = 'Stop'

# Set up the hostname, username, and password for the source system
$hostname = "meow";
#$password1 = New-Object System.Security.SecureString  #"" | ConvertTo-SecureString -asPlainText -Force
$username = "arf"
$password = "moo" | ConvertTo-SecureString -asPlainText -Force

# Load the SwisSnapin if not already loaded
if (!(Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {
    Add-PSSnapin "SwisSnapin"
}

# Connect to the source system
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$swis = Connect-Swis -Credential $credential -Hostname $hostname

function IsEmpty($str) {
    $str -eq $null -or $str -eq '' -or $str.GetType() -eq [DBNull]
}

 

 

Here is the part where I set the arguments for the verb jammy-thing:

# Verb argument 1

# The "AddResourceToView" verb requires 3 arguments to successfully add a new resource to a view. (I think it only requires the first 2)
# The "AddResourceToView" verb requires "viewId", "config", & "moveColliding", in this order.
# Verb argument 1
# This is the viewID of the page/view on which to add the new graph(s).
$viewId="211"
#$viewId=[int32]211

 

 

# Verb argument 2 (I am not actually using the "\" character before "<resource...", but this post seems to keep removing the rest of the lines for some reason.

# The "config" argument should be a string containing xml like this:
# https://thwack.solarwinds.com/message/344536#344536
# This is the SWQL query that will return the "config" portion, having filled in the Node/Interface data in the appropriate places.
#$configs= Get-SwisData $swis "SELECT '\<resource name="Custom Object Resource" file="/Orion/NetPerfMon/Resources/Misc/CustomObjectResource.ascx" column="1" position="1" title="" subtitle=""><properties><property name="AutoHide" value="0"/><property name="Calculate95thPercentile" value="0"/><property name="CalculateSum" value="0"/><property name="CalculateTrendLine" value="0"/><property name="ChartDateSpan" value="2"/><property name="ChartInitialZoom" value="24h"/><property name="ChartName" value="AvgBps-Line"/><property name="ChartSubtitle" value="${ZoomRange}"/><property name="ChartTitle" value="${Caption}"/><property name="CustomObjectMode" value="0"/><property name="EmbeddedObjectResource" value="/Orion/Interfaces/Resources/InterfaceCharts/InterfaceChart.ascx;ChartName=AvgBps-Line;ChartInitialZoom=48h;Calculate95thPercentile=0;CalculateSum=0;CalculateTrendLine=0;ChartDateSpan=1;SampleSize=5;ChartTitle=${Caption};ChartSubTitle=${ZoomRange};ShowTitle=1;"/><property name="EntityName" value="Orion.NPM.Interfaces"/><property name="FilterEntities" value="False"/><property name="HideThreshold" value="0"/><property name="Initialized" value="True"/><property name="NetObjectID" value="I:'+TOSTRING(n.Interfaces.InterfaceID)+'"/><property name="NetObjectPrefix" value="I"/><property name="NumberOfSeriesToShow" value="0"/><property name="ObjectUri" value="'+n.Interfaces.Uri+'"/><property name="SampleSize" value="5"/><property name="SelectedEntities" value="'+TOSTRING(n.Interfaces.InterfaceID)+'"/><property name="ShowTitle" value="1"/><property name="SubTitle" value=""/><property name="Title" value=""/></properties></resource>' AS [AvgBps-Line_configCol-1] FROM Orion.Nodes AS n WHERE n.Interfaces.CustomProperties.Comments='InternetUplink'"
$configs= [String[]](Get-SwisData $swis "SELECT '\<resource name=""Custom Object Resource"" file=""/Orion/NetPerfMon/Resources/Misc/CustomObjectResource.ascx"" column=""1"" position=""1"" title="""" subtitle=""""><properties><property name=""AutoHide"" value=""0""/><property name=""Calculate95thPercentile"" value=""0""/><property name=""CalculateSum"" value=""0""/><property name=""CalculateTrendLine"" value=""0""/><property name=""ChartDateSpan"" value=""2""/><property name=""ChartInitialZoom"" value=""24h""/><property name=""ChartName"" value=""AvgBps-Line""/><property name=""ChartSubtitle"" value=""${ZoomRange}""/><property name=""ChartTitle"" value=""${Caption}""/><property name=""CustomObjectMode"" value=""0""/><property name=""EmbeddedObjectResource"" value=""/Orion/Interfaces/Resources/InterfaceCharts/InterfaceChart.ascx;ChartName=AvgBps-Line;ChartInitialZoom=48h;Calculate95thPercentile=0;CalculateSum=0;CalculateTrendLine=0;ChartDateSpan=1;SampleSize=5;ChartTitle=${Caption};ChartSubTitle=${ZoomRange};ShowTitle=1;""/><property name=""EntityName"" value=""Orion.NPM.Interfaces""/><property name=""FilterEntities"" value=""False""/><property name=""HideThreshold"" value=""0""/><property name=""Initialized"" value=""True""/><property name=""NetObjectID"" value=""I:'+TOSTRING(n.Interfaces.InterfaceID)+'""/><property name=""NetObjectPrefix"" value=""I""/><property name=""NumberOfSeriesToShow"" value=""0""/><property name=""ObjectUri"" value=""'+n.Interfaces.Uri+'""/><property name=""SampleSize"" value=""5""/><property name=""SelectedEntities"" value=""'+TOSTRING(n.Interfaces.InterfaceID)+'""/><property name=""ShowTitle"" value=""1""/><property name=""SubTitle"" value=""""/><property name=""Title"" value=""""/></properties></resource>' AS [meow] FROM Orion.Nodes AS n WHERE n.Interfaces.CustomProperties.Comments='InternetUplink'")
#$configs= [String](Get-SwisData $swis "SELECT '\<resource name=""Custom Object Resource"" file=""/Orion/NetPerfMon/Resources/Misc/CustomObjectResource.ascx"" column=""1"" position=""1"" title="""" subtitle=""""><properties><property name=""AutoHide"" value=""0""/><property name=""Calculate95thPercentile"" value=""0""/><property name=""CalculateSum"" value=""0""/><property name=""CalculateTrendLine"" value=""0""/><property name=""ChartDateSpan"" value=""2""/><property name=""ChartInitialZoom"" value=""24h""/><property name=""ChartName"" value=""AvgBps-Line""/><property name=""ChartSubtitle"" value=""${ZoomRange}""/><property name=""ChartTitle"" value=""${Caption}""/><property name=""CustomObjectMode"" value=""0""/><property name=""EmbeddedObjectResource"" value=""/Orion/Interfaces/Resources/InterfaceCharts/InterfaceChart.ascx;ChartName=AvgBps-Line;ChartInitialZoom=48h;Calculate95thPercentile=0;CalculateSum=0;CalculateTrendLine=0;ChartDateSpan=1;SampleSize=5;ChartTitle=${Caption};ChartSubTitle=${ZoomRange};ShowTitle=1;""/><property name=""EntityName"" value=""Orion.NPM.Interfaces""/><property name=""FilterEntities"" value=""False""/><property name=""HideThreshold"" value=""0""/><property name=""Initialized"" value=""True""/><property name=""NetObjectID"" value=""I:'+TOSTRING(n.Interfaces.InterfaceID)+'""/><property name=""NetObjectPrefix"" value=""I""/><property name=""NumberOfSeriesToShow"" value=""0""/><property name=""ObjectUri"" value=""'+n.Interfaces.Uri+'""/><property name=""SampleSize"" value=""5""/><property name=""SelectedEntities"" value=""'+TOSTRING(n.Interfaces.InterfaceID)+'""/><property name=""ShowTitle"" value=""1""/><property name=""SubTitle"" value=""""/><property name=""Title"" value=""""/></properties></resource>' AS [meow] FROM Orion.Nodes AS n WHERE n.Interfaces.CustomProperties.Comments='InternetUplink'")
#$configs= Get-SwisData $swis "SELECT '\<resource name=""Custom Object Resource"" file=""/Orion/NetPerfMon/Resources/Misc/CustomObjectResource.ascx"" column=""1"" position=""1"" title="""" subtitle=""""><properties><property name=""AutoHide"" value=""0""/><property name=""Calculate95thPercentile"" value=""0""/><property name=""CalculateSum"" value=""0""/><property name=""CalculateTrendLine"" value=""0""/><property name=""ChartDateSpan"" value=""2""/><property name=""ChartInitialZoom"" value=""24h""/><property name=""ChartName"" value=""AvgBps-Line""/><property name=""ChartSubtitle"" value=""${ZoomRange}""/><property name=""ChartTitle"" value=""${Caption}""/><property name=""CustomObjectMode"" value=""0""/><property name=""EmbeddedObjectResource"" value=""/Orion/Interfaces/Resources/InterfaceCharts/InterfaceChart.ascx;ChartName=AvgBps-Line;ChartInitialZoom=48h;Calculate95thPercentile=0;CalculateSum=0;CalculateTrendLine=0;ChartDateSpan=1;SampleSize=5;ChartTitle=${Caption};ChartSubTitle=${ZoomRange};ShowTitle=1;""/><property name=""EntityName"" value=""Orion.NPM.Interfaces""/><property name=""FilterEntities"" value=""False""/><property name=""HideThreshold"" value=""0""/><property name=""Initialized"" value=""True""/><property name=""NetObjectID"" value=""I:'+TOSTRING(n.Interfaces.InterfaceID)+'""/><property name=""NetObjectPrefix"" value=""I""/><property name=""NumberOfSeriesToShow"" value=""0""/><property name=""ObjectUri"" value=""'+n.Interfaces.Uri+'""/><property name=""SampleSize"" value=""5""/><property name=""SelectedEntities"" value=""'+TOSTRING(n.Interfaces.InterfaceID)+'""/><property name=""ShowTitle"" value=""1""/><property name=""SubTitle"" value=""""/><property name=""Title"" value=""""/></properties></resource>' AS [meow] FROM Orion.Nodes AS n WHERE n.Interfaces.CustomProperties.Comments='InternetUplink'"

 

 

# Verb argument 3

# This is the 3rd, and final, verb argument required to create the new resource on the page.
# Setting this to "True" will bump down any resource already configured to the same column/row as the resource being added.
#$moveColliding="True"
#$moveColliding=[boolean]"True"

 

# And here is the part where I think it is supposed to loop through each result, from the SWQL query in argument 2, and add a new resource to the view from argument 1

foreach ($config in $configs) {    # config.meow = the data from the SWQL query?
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @("$viewId", @{config=$config.meow})
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @("$viewId", @{config="$config.meow"})    Invoke-SwisVerb $swis Orion.Views AddResourceToView @("$viewId", $config.meow)
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @($viewId, $configs)
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @($viewId, $configs, $moveColliding)
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @{viewId=$viewId, $configs, $moveColliding}
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @(@{viewId=$viewId, $configs, $moveColliding})
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @(@($viewId, $configs, $moveColliding))
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @(@($viewId, $config.meow, $moveColliding))
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @( ,@($viewId, $config.meow, $moveColliding))
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @( ,@($viewId, @{config = $config.meow}, $moveColliding))
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @($viewId, @{config = $config.meow}, $moveColliding)
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @("$viewId", @{config = $config.meow}, "$moveColliding")
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @(@($viewId), @{config = $config.meow}, $moveColliding)
#    Invoke-SwisVerb $swis Orion.Views AddResourceToView @(@(211), @{config = $config.meow}, $moveColliding)
}

 

 

 

As you can see by the commented lines above, I have tried several different ways. I have searched through numerous different Thwack posts, related to SDK, API, PowerShell, Invoke-SwisVerb, etc., and have tried to apply advice from those various posts, with no success.

 

Most of the different ways I have failed ended with actual error messages in PowerShell ISE, as seen below:

Invoke-SwisVerb : Verb Orion.Views.AddResourceToView cannot unpackage parameter 1 of type System.String
Invoke-SwisVerb : Object of type 'System.String[]' cannot be converted to type 'System.String'.
Invoke-SwisVerb : There are multiple root elements. Line 1, position 1544.
Get-SwisData : Cannot bind parameter 'Parameters'. Cannot convert the "SELECT '
Invoke-SwisVerb : Type 'System.Management.Automation.PSObject' with data contract name 'PSObject:http://schemas.datacontract.org/2004/07/System.Management.Automation' is not expected. 
Invoke-SwisVerb : There was an error generating the XML document.

 

 

While I have virtually no idea what I am doing here (that's why they make labs, right?), I was able to get, what I think, is a valid error message, as in the script ran, but each attempt to add the new resource failed. (As opposed to the script itself failing)

PS C:\Users\Administrator> Z:\powershell script examples\DEV_Add_Graph_To_View.ps1


xmlns                                                                          #text
-----                                                                          -----
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract false

 

 

 

 

This is the SWQL query I use to build the config file, which works fine when I copy/paste the results from the SWQL query into the invoke page within SWQL Studio, but not PowerShell.

SELECT
'<resource name="Custom Object Resource" file="/Orion/NetPerfMon/Resources/Misc/CustomObjectResource.ascx" column="1" position="1" title="" subtitle=""><properties><property name="AutoHide" value="0"/><property name="Calculate95thPercentile" value="0"/><property name="CalculateSum" value="0"/><property name="CalculateTrendLine" value="0"/><property name="ChartDateSpan" value="2"/><property name="ChartInitialZoom" value="24h"/><property name="ChartName" value="AvgBps-Line"/><property name="ChartSubtitle" value="${ZoomRange}"/><property name="ChartTitle" value="${Caption}"/><property name="CustomObjectMode" value="0"/><property name="EmbeddedObjectResource" value="/Orion/Interfaces/Resources/InterfaceCharts/InterfaceChart.ascx;ChartName=AvgBps-Line;ChartInitialZoom=48h;Calculate95thPercentile=0;CalculateSum=0;CalculateTrendLine=0;ChartDateSpan=1;SampleSize=5;ChartTitle=${Caption};ChartSubTitle=${ZoomRange};ShowTitle=1;"/><property name="EntityName" value="Orion.NPM.Interfaces"/><property name="FilterEntities" value="False"/><property name="HideThreshold" value="0"/><property name="Initialized" value="True"/><property name="NetObjectID" value="I:'+TOSTRING(n.Interfaces.InterfaceID)+'"/><property name="NetObjectPrefix" value="I"/><property name="NumberOfSeriesToShow" value="0"/><property name="ObjectUri" value="'+n.Interfaces.Uri+'"/><property name="SampleSize" value="5"/><property name="SelectedEntities" value="'+TOSTRING(n.Interfaces.InterfaceID)+'"/><property name="ShowTitle" value="1"/><property name="SubTitle" value=""/><property name="Title" value=""/></properties></resource>' AS [meow]
FROM Orion.Nodes AS n
WHERE n.Interfaces.CustomProperties.Comments='InternetUplink'

 

 

 

I am hoping someone can point me in the direction closest to the answer I seek.

 

 

Thank you,

 

-Will


Viewing all articles
Browse latest Browse all 3719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>