Open for Voting

Add ability to change Node Details Poller from the SDK/Powershell

Whilst I understand I can update the node details poller on the manage pollers page, its limited to manually selecting groups of devices. I'd find it really handy to be able to script this using powershell, e.g. when adding new devices via script. I already set custom properties, other pollers automatically and the node details poller is the only one thats missing.

See below for a pic of the node details poller item that I am referring to.

This has been discussed @ https://thwack.solarwinds.com/product-forums/the-orion-platform/f/orion-sdk/95734/updating-node-details-poller-from-powershell - see here for more info.

Thanks

Richard

Parents
  • ,
    Thanks for putting in this feature request (I'm currently doing via direct edit of the DB). The "Node Details Poller" might be too limiting, would be good to have them implement a more generic "DeviceStudio Poller" assignment/de-assignment option over the API.

  • Martin can I ask if you have any powershell code you can share to update via the DB?

  • Hi ,

    Sure can, sorry for the delay.

    I'm using the PowerShell module 'SqlServer' which is available on the PowerShell Gallery. I have some examples for both PowerShell and Python on my Github repo: https://github.com/martincrothers/code_samples/tree/main/snippets/ms_sql

    Here's an example read query to provide familiarity:

    Import-Module SqlServer
    
    $ServerInstance = "SQLSERVERNAME\INSTANCE"
    $Database = "SolarWindsOrion"
    
    <#	The below string is the SQL query.
    	My databases include the ".[dbo]" between the database name and table, sometimes that's not the case.
    	I chose to insert the database name into the FROM statement via the existing database name variable from above.
    	This is just selecting the top 3 records of nodes, with only the Caption value.
    #>
    $Query = @"
    SELECT TOP 3 Caption
    FROM [{0}].[dbo].[NodesData]
    "@ -f $Database
    
    <#	Here we invoke the SQL Query.
    	This version is using the Active Directory account (I assume Kerberos token) of the user runing the PowerShell instance.
    	If you need to use a SQL account instead, choose the Username + Password or Credential parameters. Unfortunately those
    	parameters cannot be used with Active Directory based accounts due to limitations of the PowerShell module. If you need
    	to run the command with a different Active Directory user you will need to either: execute PowerShell with that account,
    	or if trying to use "Invoke-Command" to execute this step under a different set of credentials you will need to have
    	"CredSSP" enabled on the machine running the script. As I understand it using CredSSP is not recommended for security
    	reasons.
    #>
    Invoke-Sqlcmd -ServerInstance $ServerInstance -Database $Database -Query $Query 

    To actually assign a DeviceStudio type poller to a node, use this query:

    UPDATE [{0}].[dbo].[DeviceStudio_PollerAssignments]
    SET [Enabled] = 1
    WHERE [ID] IN (
      SELECT PA.ID
      FROM [{0}].[dbo].[DeviceStudio_PollerAssignments] PA
      INNER JOIN [{0}].[dbo].[DeviceStudio_Pollers] P
      ON PA.PollerID = P.PollerID
      WHERE P.Name = '{1}' AND PA.NetObjectType = 'N' AND PA.NetObjectID = {2}
    );
    /*
      0 = databse name
      1 = DeviceStudio poller name
      2 = NodeID
    */

    I used the -f string method of inserting those variables into this query in the same manner as the above example.

    Hope this helps! Slight smile

  • This is fantastic, thanks Martin.
    I've integrated it into my script and its working perfectly.

    Keeps me going until the API is updated.

Comment Children
No Data