cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

Dynamic SWQL filter based on URL link?

Hi,

Is there a way to build a template view with a filter based on a URL variable?

Today we have 70 sites in Europe. I would like to have a view per site. This view should show me the resources

- Global Application by Status

- Global Last XX Events

- Global Node Status by Site

Based on the custom property "City" I use the filter "Node.CustomProperty.City Like 'XXXX%'" to limit the view to the necessary nodes. As result I have to create 70 views now. New site, new view.

I ask me if it will not possible to get a more dynamic filter which receives the filter value from the URL. Than I have only to adjust the link to the view instead of to set the filter to every resource per view.

Something like this:

URL http://solarwindseoc/Default.aspx?viewId=3003&UseCaching=True&FilterVar1=XXXX

Filter: Node.CustomProperty.City Like %FilterVar1% 

 

Or is there any other option already in eoc_custom_filter in place to get a more dynamic view?

BR NetJoerg  

5 Replies
Level 12

Hi

Did you get any further on this one? Have the same issue but with like a few thousand sites....

0 Kudos

You won't get anywhere just by tweaking the url, as the filters are a property of the view object itself not a component of the url.  It is very possible to script up view creation though with the API.  I have a script I use for building app dashboards in regular orion where I build a template view an then clone it as many times as necessary and apply filters to each of those clones.  It's somewhat specific to my use case so I can't post the whole thing here, but have a look at the API documentation here:

GitHub - solarwinds/OrionSDK: SDK for the SolarWinds Orion platform, including tools, documentation,...

and the main verbs you would be interested would be used like so (in powershell)

invoke-swisverb $swis "Orion.Views" "CloneView" @(

           #View to clone

           "$viewtemplateid",

           #name to give

           "Application - $($view.Applications)"

           )

invoke-swisverb $swis "Orion.Views" "CloneViewContents" @(

    #source view

    "$viewtemplateid",

    #destination view

    "$newviewid"  

    )

invoke-swisverb $swis "Orion.Limitations" "CreateLimitation" @( "$limittype",$null,@("$($limit.containerid)"),$null,$null )

Set-SwisObject $swis -Uri "swis://$uriroot/Orion/Orion.Views/ViewID=$($view.viewid)" -Properties @{"limitationid"="$($view.limitationid)"}

- Marc Netterfield, Github
0 Kudos

Hmmm, thanks mesverrum​!!

That might be a possibility. Even though I would rather have one dynamic view instead of thousands of copies I guess this is a possibility.

It's worth trying out anyway.

Guess I would need a custom query with search also to find the right view also.... 🙂

0 Kudos

Yeah, you can use a custom query resource with some swql in it to search out the links to any particular view

- Marc Netterfield, Github
0 Kudos

Finally got time to test this and thought I'd give back by sharing my solution. Thanks mesverrum​ for all input!

So, we wanted to clone a view and create one view with limitation per siteID, where siteid is a custom property where we have enabled limitation on it. (I'm no PS programmer so I hope the code don't look to bad...) The customer has move than 1000 sites...

#region Connect to SWIS 

# Import the SolarWinds PowerShell Module if needed 

# install with "Install-Module -Name SwisPowerShell" 

 

If (!(Get-Module SwisPowerShell)) { 

    Import-Module SwisPowerShell 

 

 

# Connect to SWIS 

 

 

$hostname = "localhost"

$username = 'admin'

$password = '' 

$swis = Connect-Swis -UserName $username -Password $password -Hostname $hostname

 

 

#endregion

#region Variables and Get site to create view for

$siteid="0004"

$ViewName="SiteView - $siteid"

# LimitationTypeID, different for each custom built limitation, look in SELECT * FROM Orion.Limitations

$limittype=57

# ViewID to clone

$viewtemplateid="144"

#endregion

#region Clone View

# Clone View

$newviewid=invoke-swisverb $swis "Orion.Views" "CloneView" @(

    #View to clone

    "$viewtemplateid",

    #name to give

    "$ViewName"

    )

$newviewid2=$newviewid.'#text'

# Clone view content

invoke-swisverb $swis "Orion.Views" "CloneViewContents" @(

    #source view

    "$viewtemplateid",

    #destination view

    "$newviewid2" 

    )

#endregion

#region Create Limitation on view

# Create the limitation

$NewLImitationID=invoke-swisverb $swis "Orion.Limitations" "CreateLimitation" @( '57',$null,@("$($Siteid)"),$null,$null )

$newLimitationID2=$NewLImitationID.'#text'

# Bind the new limitation to the new view

Set-SwisObject $swis -Uri "swis://$hostname/Orion/Orion.Views/ViewID=$newviewid2" -Properties @{"limitationid"="$newLimitationID2"}

#endregion

After that I created one summaryview to list all these subviews, incl a search.

Just a normal "Custom Query" where:

Custom SWQL query=

SELECT

    ViewTitle,

    CONCAT('http://orionserver:8787/Orion/SummaryView.aspx?netobject=&ViewID=', ViewID) as [_LinkFor_ViewTitle]

FROM Orion.Views

WHERE ViewTitle LIKE 'SiteView - %'

and Search SWQL Query=

SELECT

    ViewTitle,

    CONCAT('http://orionserver:8787/Orion/SummaryView.aspx?netobject=&ViewID=', ViewID) as [_LinkFor_ViewTitle]

FROM Orion.Views

WHERE

   ViewTitle LIKE '%${SEARCH_STRING}%'

  AND ViewTitle LIKE 'SiteView%'

Hope it helps and/or inspires someone out there!

0 Kudos