This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SDK 101 - walk me through a change/delete please?

So, first up... we have a LAB server so I can destroy it as much as I want... and as we are getting more and more pressured to automate, automate, automate I now need to start looking at how to do things, via a script. Then I can test on the LAB server before deploying for real.

One of our common issues is that we get engineers that just don't pay attention, and when they add new nodes to monitor they include lots of stuff we don't care about. This primarily happens on 3rd party kit where we have an SNMP view - so we don't care about the CPU, RAM, storage locations, etc as one hopes all our 3rd parties have their own monitoring solution which keeps tabs on these.

So a basic clean up script would entail going off and finding all nodes that have the following in them and delete them.

Anybody want to take a stab at helping a n00b in this area?

  • I'm assuming that you've already watched SolarWinds Lab #86 so I'm not going to cover things here that I already covered there.

    What you need to understand for DELETE operations is that the only thing you need is the URI (Uniform Resource Indicator) of the element you want to delete.

    Each individual 'Managed Entity' in an Orion system has a URI.  It's not a default shown element in SWQL Studio, but you can get it by selecting "Generate Select Statement (with Inherited Properties)."

    In your above example, you are showing only volumes, so that's where I'm going with this example.

    Important Note: I don't have any Juniper devices, so my queries will be fake and you'll need to test in your own environment.

    The query that I would use would be something like this:

    -- Human Readable Query for Enumerating Volumes to Delete --
    SELECT [V].Caption
         , [V].Type
         , [V].Node.Vendor
         , [V].Node.Caption AS [NodeName]
         , [V].Uri
    FROM Orion.Volumes AS [V]
    WHERE [V].Type IN ( 'Fixed Disk', 'Virtual Memory', 'RAM' ) --Add other filters here as needed
      AND [V].Node.Vendor = 'Juniper'

    This will get the Volume's Caption, the Volume's Type, the Node Vendor, the Node Caption, and the Volume's URI and filter for only a couple types of volumes and where the vendor of the Node is 'Juniper'.  (I'm bolding the Volume URI here because it's important that you realize that this is the thing we'll be deleting and not the Node's URI, which would delete the entire Node and its children).

    Realistically, we don't need the Caption, Type, or Node Vendor in the returned data set because we only want to operate on the Volume's URI.

    -- Minimal Query for Enumerating Volumes to Delete --
    SELECT [V].Uri
    FROM Orion.Volumes AS [V]
    WHERE [V].Type IN ( 'Fixed Disk', 'Virtual Memory', 'RAM' ) --Add other filters here as needed
      AND [V].Node.Vendor = 'Juniper'

    The above only returns what we need to go forward.  The one before makes the list more 'human' readable.

    Once you are happy with the results of the query, then you can execute the deletion. (I'm using examples from my own environment for the SWQL - change as necessary for your own)

    #region Connect to Orion Server
    # Build the connection to your Orion server
    # There are a few ways to connect to the Orion server:
    # Using 'Orion' Credentials <-- The simplest method
    $SwisConnection = Connect-Swis -Hostname "OrionServer.Domain.Local" -UserName 'myAdminUser' -Password 'myAdminPassword'
    # Using 'Windows Integrated Authentication' with the current logged in user <-- My preferred method when possible
    # $SwisConnection = Connect-Swis -Hostname "OrionServer.Domain.Local" -Trusted
    # Or Running it directly ON the Orion server and using the certificate for validation
    # $SwisConnection = Connect-Swis -Hostname "OrionServer.Domain.Local" -Certificate
    #endregion Connect to Orion Server
    #region Define Query and Get Data
    # This is the SWQL Query we defined
    # I use a here-string (with the '@' symbols) because I think it's easier to read
    $Swql = @"
    SELECT [V].Caption
         , [V].Type
         , [V].Node.Vendor
         , [V].Node.Caption AS [NodeName]
         , [V].Uri
    FROM Orion.Volumes AS [V]
    WHERE [V].Type IN ( 'Fixed Disk', 'Virtual Memory', 'RAM' ) --Add other filters here as needed
      AND [V].Caption LIKE '/dev%'
      AND [V].Node.Vendor = 'Linux'
    # Get the Data from the Query
    $VolumesToDelete = Get-SwisData -SwisConnection $SwisConnection -Query $Swql
    #endregion Define Query and Get Data
    #region Perform the Deletion
    # cycle through each volume
    ForEach ( $Volume in $VolumesToDelete ) {
        # Write something to the screen for this example
        Write-Host "We are deleting $( $Volume.Caption ) from $( $Volume.NodeName ) [URI: $( $Volume.Uri )]" -ForegroundColor Red
        # Do the actual deletion
        Remove-SwisObject -SwisConnection $SwisConnection -Uri $Volume.Uri
    Write-Host "We're all done with the deletion" -ForegroundColor Green
    #endregion Perform the Deletion

    And that's all it takes to delete things from Orion via the API.  It can be extended to ANYTHING with a URI (nearly everything), so you should be careful.  It doesn't have a "are you sure" option.

  • Many thanks I am saving this to One Note for reference and I will work through it step by little step.

    I may (make that almost certainly will) be back with questions but first a refresh on Lab #86 is in order.

Reply Children
No Data